Merge
authorlana
Thu, 19 May 2016 19:46:39 +0000
changeset 38490 8b30c52dc414
parent 38482 0cc343dc14db (current diff)
parent 38489 87283d65c557 (diff)
child 38491 777ad2adf246
Merge
--- a/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java	Thu May 19 19:46:39 2016 +0000
@@ -280,6 +280,7 @@
         addField(cv, name, OBJECT_DESC);
     }
 
+    @SuppressWarnings("deprecation")
     static void newFunction(final MethodGenerator mi, final String objName, final String className, final MemberInfo memInfo, final List<MemberInfo> specs) {
         final boolean arityFound = (memInfo.getArity() != MemberInfo.DEFAULT_ARITY);
 
@@ -305,6 +306,7 @@
         mi.invokeVirtual(SCRIPTFUNCTION_TYPE, SCRIPTFUNCTION_SETDOCUMENTATIONKEY, SCRIPTFUNCTION_SETDOCUMENTATIONKEY_DESC);
     }
 
+    @SuppressWarnings("deprecation")
     static void linkerAddGetterSetter(final MethodGenerator mi, final String className, final MemberInfo memInfo) {
         final String propertyName = memInfo.getName();
         // stack: Collection
@@ -334,6 +336,7 @@
         // stack: Collection
     }
 
+    @SuppressWarnings("deprecation")
     static void linkerAddGetterSetter(final MethodGenerator mi, final String className, final MemberInfo getter, final MemberInfo setter) {
         final String propertyName = getter.getName();
         // stack: Collection
--- a/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java	Thu May 19 19:46:39 2016 +0000
@@ -178,6 +178,7 @@
         }
     }
 
+    @SuppressWarnings("deprecation")
     private void callSuper(final MethodGenerator mi) {
         String superClass, superDesc;
         mi.loadThis();
--- a/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MethodGenerator.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MethodGenerator.java	Thu May 19 19:46:39 2016 +0000
@@ -390,6 +390,7 @@
         return EMPTY_LINK_LOGIC_TYPE.equals(type);
     }
 
+    @SuppressWarnings("deprecation")
     void memberInfoArray(final String className, final List<MemberInfo> mis) {
         if (mis.isEmpty()) {
             pushNull();
--- a/nashorn/make/build.xml	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/make/build.xml	Thu May 19 19:46:39 2016 +0000
@@ -775,20 +775,16 @@
   <!-- octane benchmark -->
   <target name="get-octane" depends="init" unless="${test-sys-prop.external.octane}">
     <!-- checkout octane benchmarks -->
-    <exec executable="${svn.executable}">
-       <arg value="--non-interactive"/>
-       <arg value="--trust-server-cert"/>
-       <arg value="checkout"/>
-       <arg value="http://octane-benchmark.googlecode.com/svn/trunk/"/>
+    <exec executable="${git.executable}">
+       <arg value="clone"/>
+       <arg value="https://github.com/chromium/octane"/>
        <arg value="${test.external.dir}/octane"/>
     </exec>
   </target>
   <target name="update-octane" depends="init" if="${test-sys-prop.external.octane}">
     <!-- update octane benchmarks -->
-    <exec executable="${svn.executable}" dir="${test.external.dir}/octane">
-       <arg value="--non-interactive"/>
-       <arg value="--trust-server-cert"/>
-       <arg value="update"/>
+    <exec executable="${git.executable}" dir="${test.external.dir}/octane">
+       <arg value="pull"/>
     </exec>
   </target>
 
--- a/nashorn/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeanLinker.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeanLinker.java	Thu May 19 19:46:39 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -113,7 +113,7 @@
             // Some languages won't have a notion of manipulating collections. Exposing "length" on arrays as an
             // explicit property is beneficial for them.
             // REVISIT: is it maybe a code smell that StandardOperation.GET_LENGTH is not needed?
-            setPropertyGetter("length", GET_ARRAY_LENGTH, ValidationType.IS_ARRAY);
+            setPropertyGetter("length", MethodHandles.arrayLength(clazz), ValidationType.EXACT_CLASS);
         } else if(List.class.isAssignableFrom(clazz)) {
             setPropertyGetter("length", GET_COLLECTION_LENGTH, ValidationType.INSTANCE_OF);
         }
@@ -518,9 +518,6 @@
                 gic.getValidatorClass(), gic.getValidationType());
     }
 
-    private static final MethodHandle GET_ARRAY_LENGTH = Lookup.PUBLIC.findStatic(Array.class, "getLength",
-            MethodType.methodType(int.class, Object.class));
-
     private static final MethodHandle GET_COLLECTION_LENGTH = Lookup.PUBLIC.findVirtual(Collection.class, "size",
             MethodType.methodType(int.class));
 
@@ -537,7 +534,7 @@
         // Thing is, it'd be quite stupid of a call site creator to go though invokedynamic when it knows in advance
         // they're dealing with an array, collection, or map, but hey...
         if(declaredType.isArray()) {
-            return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType));
+            return new GuardedInvocationComponent(MethodHandles.arrayLength(declaredType).asType(callSiteType));
         } else if(Collection.class.isAssignableFrom(declaredType)) {
             return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType));
         } else if(Map.class.isAssignableFrom(declaredType)) {
@@ -546,8 +543,8 @@
 
         // Otherwise, create a binding based on the actual type of the argument with an appropriate guard.
         if(clazz.isArray()) {
-            return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0,
-                    callSiteType), ValidationType.IS_ARRAY);
+            return new GuardedInvocationComponent(MethodHandles.arrayLength(clazz).asType(callSiteType),
+                    Guards.isArray(0, callSiteType), ValidationType.EXACT_CLASS);
         } if(Collection.class.isAssignableFrom(clazz)) {
             return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType(
                     COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF);
--- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Console.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Console.java	Thu May 19 19:46:39 2016 +0000
@@ -30,12 +30,10 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
+import java.io.Writer;
+import java.nio.file.Files;
 import java.util.function.Function;
+import java.util.stream.Collectors;
 import jdk.internal.jline.NoInterruptUnixTerminal;
 import jdk.internal.jline.Terminal;
 import jdk.internal.jline.TerminalFactory;
@@ -43,23 +41,28 @@
 import jdk.internal.jline.WindowsTerminal;
 import jdk.internal.jline.console.ConsoleReader;
 import jdk.internal.jline.console.KeyMap;
-import jdk.internal.jline.console.completer.Completer;
-import jdk.internal.jline.console.history.FileHistory;
+import jdk.internal.jline.extra.EditingHistory;
 
 class Console implements AutoCloseable {
     private static final String DOCUMENTATION_SHORTCUT = "\033\133\132"; //Shift-TAB
     private final ConsoleReader in;
-    private final FileHistory history;
+    private final File historyFile;
 
     Console(final InputStream cmdin, final PrintStream cmdout, final File historyFile,
-            final Completer completer, final Function<String, String> docHelper) throws IOException {
+            final NashornCompleter completer, final Function<String, String> docHelper) throws IOException {
+        this.historyFile = historyFile;
+
         TerminalFactory.registerFlavor(Flavor.WINDOWS, isCygwin()? JJSUnixTerminal::new : JJSWindowsTerminal::new);
         TerminalFactory.registerFlavor(Flavor.UNIX, JJSUnixTerminal::new);
         in = new ConsoleReader(cmdin, cmdout);
         in.setExpandEvents(false);
         in.setHandleUserInterrupt(true);
         in.setBellEnabled(true);
-        in.setHistory(history = new FileHistory(historyFile));
+        in.setHistory(new EditingHistory(in, Files.readAllLines(historyFile.toPath())) {
+            @Override protected boolean isComplete(CharSequence input) {
+                return completer.isComplete(input.toString());
+            }
+        });
         in.addCompleter(completer);
         Runtime.getRuntime().addShutdownHook(new Thread((Runnable)this::saveHistory));
         bind(DOCUMENTATION_SHORTCUT, (ActionListener)evt -> showDocumentation(docHelper));
@@ -75,13 +78,17 @@
     }
 
     private void saveHistory() {
-        try {
-            getHistory().flush();
+        try (Writer out = Files.newBufferedWriter(historyFile.toPath())) {
+            String lineSeparator = System.getProperty("line.separator");
+
+            out.write(getHistory().save()
+                                  .stream()
+                                  .collect(Collectors.joining(lineSeparator)));
         } catch (final IOException exp) {}
     }
 
-    FileHistory getHistory() {
-        return (FileHistory) in.getHistory();
+    EditingHistory getHistory() {
+        return (EditingHistory) in.getHistory();
     }
 
     boolean terminalEditorRunning() {
--- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/HistoryObject.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/HistoryObject.java	Thu May 19 19:46:39 2016 +0000
@@ -36,7 +36,6 @@
 import java.util.function.Consumer;
 import java.util.function.Function;
 import java.util.function.Supplier;
-import jdk.internal.jline.console.history.FileHistory;
 import jdk.internal.jline.console.history.History;
 import jdk.nashorn.api.scripting.AbstractJSObject;
 import jdk.nashorn.api.scripting.JSObject;
@@ -61,11 +60,11 @@
         props = Collections.unmodifiableSet(s);
     }
 
-    private final FileHistory hist;
+    private final History hist;
     private final PrintWriter err;
     private final Consumer<String> evaluator;
 
-    HistoryObject(final FileHistory hist, final PrintWriter err,
+    HistoryObject(final History hist, final PrintWriter err,
             final Consumer<String> evaluator) {
         this.hist = hist;
         this.err = err;
--- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/NashornCompleter.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/NashornCompleter.java	Thu May 19 19:46:39 2016 +0000
@@ -185,6 +185,22 @@
         }
     }
 
+    public boolean isComplete(String input) {
+        try {
+            parser.parse("<shell>", input, null);
+        } catch (final Exception pexp) {
+            // Do we have a parse error at the end of current line?
+            // If so, read more lines from the console.
+            int line = input.split("\n").length;
+            int lastLineLen = input.length() - (input.lastIndexOf("\n") + 1);
+
+            if (isParseErrorAt(pexp, line, lastLineLen)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     // Pattern to match a unfinished member selection expression. object part and "."
     // but property name missing pattern.
     private static final Pattern SELECT_PROP_MISSING = Pattern.compile(".*\\.\\s*");
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MethodEmitter.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MethodEmitter.java	Thu May 19 19:46:39 2016 +0000
@@ -170,9 +170,11 @@
     }
 
     /** Bootstrap for normal indy:s */
+    @SuppressWarnings("deprecation")
     private static final Handle LINKERBOOTSTRAP  = new Handle(H_INVOKESTATIC, Bootstrap.BOOTSTRAP.className(), Bootstrap.BOOTSTRAP.name(), Bootstrap.BOOTSTRAP.descriptor());
 
     /** Bootstrap for array populators */
+    @SuppressWarnings("deprecation")
     private static final Handle POPULATE_ARRAY_BOOTSTRAP = new Handle(H_INVOKESTATIC, RewriteException.BOOTSTRAP.className(), RewriteException.BOOTSTRAP.name(), RewriteException.BOOTSTRAP.descriptor());
 
     /**
@@ -1005,6 +1007,7 @@
      *
      * @return the method emitter
      */
+    @SuppressWarnings("deprecation")
     MethodEmitter loadHandle(final String className, final String methodName, final String descName, final EnumSet<Flag> flags) {
         debug("load handle ");
         pushType(Type.OBJECT.ldc(method, new Handle(Flag.getValue(flags), className, methodName, descName)));
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java	Thu May 19 19:46:39 2016 +0000
@@ -2839,6 +2839,7 @@
             sb.append("$Constructor");
 
             final Class<?> funcClass = Class.forName(sb.toString());
+            @SuppressWarnings("deprecation")
             final T res = clazz.cast(funcClass.newInstance());
 
             if (res instanceof ScriptFunction) {
@@ -2866,6 +2867,7 @@
             final String className = PACKAGE_PREFIX + name + "$Prototype";
 
             final Class<?> funcClass = Class.forName(className);
+            @SuppressWarnings("deprecation")
             final ScriptObject res = (ScriptObject) funcClass.newInstance();
 
             res.setIsBuiltin();
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Thu May 19 19:46:39 2016 +0000
@@ -232,10 +232,10 @@
     }
 
     ByteBuffer getBuffer(final int offset) {
-        return (ByteBuffer)nb.duplicate().position(offset);
+        return nb.duplicate().position(offset);
     }
 
     ByteBuffer getBuffer(final int offset, final int length) {
-        return (ByteBuffer)getBuffer(offset).limit(length);
+        return getBuffer(offset).limit(length);
     }
 }
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFloat32Array.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFloat32Array.java	Thu May 19 19:46:39 2016 +0000
@@ -81,7 +81,7 @@
         private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Float32ArrayData.class, "setElem", void.class, int.class, double.class).methodHandle();
 
         private Float32ArrayData(final FloatBuffer nb, final int start, final int end) {
-            super(((FloatBuffer)nb.position(start).limit(end)).slice(), end - start);
+            super((nb.position(start).limit(end)).slice(), end - start);
         }
 
         @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFloat64Array.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFloat64Array.java	Thu May 19 19:46:39 2016 +0000
@@ -81,7 +81,7 @@
         private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Float64ArrayData.class, "setElem", void.class, int.class, double.class).methodHandle();
 
         private Float64ArrayData(final DoubleBuffer nb, final int start, final int end) {
-            super(((DoubleBuffer)nb.position(start).limit(end)).slice(), end - start);
+            super((nb.position(start).limit(end)).slice(), end - start);
         }
 
         @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt16Array.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt16Array.java	Thu May 19 19:46:39 2016 +0000
@@ -82,7 +82,7 @@
         private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Int16ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
 
         private Int16ArrayData(final ShortBuffer nb, final int start, final int end) {
-            super(((ShortBuffer)nb.position(start).limit(end)).slice(), end - start);
+            super((nb.position(start).limit(end)).slice(), end - start);
         }
 
         @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt32Array.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt32Array.java	Thu May 19 19:46:39 2016 +0000
@@ -81,7 +81,7 @@
         private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Int32ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
 
         private Int32ArrayData(final IntBuffer nb, final int start, final int end) {
-            super(((IntBuffer)nb.position(start).limit(end)).slice(), end - start);
+            super((nb.position(start).limit(end)).slice(), end - start);
         }
 
         @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt8Array.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeInt8Array.java	Thu May 19 19:46:39 2016 +0000
@@ -80,7 +80,7 @@
         private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Int8ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
 
         private Int8ArrayData(final ByteBuffer nb, final int start, final int end) {
-            super(((ByteBuffer)nb.position(start).limit(end)).slice(), end - start);
+            super((nb.position(start).limit(end)).slice(), end - start);
         }
 
         @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJSON.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJSON.java	Thu May 19 19:46:39 2016 +0000
@@ -35,7 +35,10 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.Callable;
+import jdk.nashorn.api.scripting.JSObject;
+import jdk.nashorn.api.scripting.ScriptObjectMirror;
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Function;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
@@ -68,6 +71,17 @@
                 });
     }
 
+    private static final Object JSOBJECT_INVOKER = new Object();
+
+    private static MethodHandle getJSOBJECT_INVOKER() {
+        return Global.instance().getDynamicInvoker(JSOBJECT_INVOKER,
+                new Callable<MethodHandle>() {
+                    @Override
+                    public MethodHandle call() {
+                        return Bootstrap.createDynamicCallInvoker(Object.class, Object.class, Object.class);
+                    }
+                });
+    }
 
     private static final Object REPLACER_INVOKER = new Object();
 
@@ -77,7 +91,7 @@
                     @Override
                     public MethodHandle call() {
                         return Bootstrap.createDynamicCallInvoker(Object.class,
-                            ScriptFunction.class, ScriptObject.class, Object.class, Object.class);
+                            Object.class, Object.class, Object.class, Object.class);
                     }
                 });
     }
@@ -127,9 +141,10 @@
         final StringifyState state = new StringifyState();
 
         // If there is a replacer, it must be a function or an array.
-        if (replacer instanceof ScriptFunction) {
-            state.replacerFunction = (ScriptFunction) replacer;
+        if (Bootstrap.isCallable(replacer)) {
+            state.replacerFunction = replacer;
         } else if (isArray(replacer) ||
+                isJSObjectArray(replacer) ||
                 replacer instanceof Iterable ||
                 (replacer != null && replacer.getClass().isArray())) {
 
@@ -201,18 +216,19 @@
     // stringify helpers.
 
     private static class StringifyState {
-        final Map<ScriptObject, ScriptObject> stack = new IdentityHashMap<>();
+        final Map<Object, Object> stack = new IdentityHashMap<>();
 
         StringBuilder  indent = new StringBuilder();
         String         gap = "";
         List<String>   propertyList = null;
-        ScriptFunction replacerFunction = null;
+        Object         replacerFunction = null;
     }
 
     // Spec: The abstract operation Str(key, holder).
-    private static Object str(final Object key, final ScriptObject holder, final StringifyState state) {
-        Object value = holder.get(key);
+    private static Object str(final Object key, final Object holder, final StringifyState state) {
+        assert holder instanceof ScriptObject || holder instanceof JSObject;
 
+        Object value = getProperty(holder, key);
         try {
             if (value instanceof ScriptObject) {
                 final InvokeByName toJSONInvoker = getTO_JSON();
@@ -221,6 +237,12 @@
                 if (Bootstrap.isCallable(toJSON)) {
                     value = toJSONInvoker.getInvoker().invokeExact(toJSON, svalue, key);
                 }
+            } else if (value instanceof JSObject) {
+                final JSObject jsObj = (JSObject)value;
+                final Object toJSON = jsObj.getMember("toJSON");
+                if (Bootstrap.isCallable(toJSON)) {
+                    value = getJSOBJECT_INVOKER().invokeExact(toJSON, value);
+                }
             }
 
             if (state.replacerFunction != null) {
@@ -262,10 +284,10 @@
 
         final JSType type = JSType.of(value);
         if (type == JSType.OBJECT) {
-            if (isArray(value)) {
-                return JA((ScriptObject)value, state);
-            } else if (value instanceof ScriptObject) {
-                return JO((ScriptObject)value, state);
+            if (isArray(value) || isJSObjectArray(value)) {
+                return JA(value, state);
+            } else if (value instanceof ScriptObject || value instanceof JSObject) {
+                return JO(value, state);
             }
         }
 
@@ -273,7 +295,9 @@
     }
 
     // Spec: The abstract operation JO(value) serializes an object.
-    private static String JO(final ScriptObject value, final StringifyState state) {
+    private static String JO(final Object value, final StringifyState state) {
+        assert value instanceof ScriptObject || value instanceof JSObject;
+
         if (state.stack.containsKey(value)) {
             throw typeError("JSON.stringify.cyclic");
         }
@@ -284,7 +308,8 @@
 
         final StringBuilder finalStr = new StringBuilder();
         final List<Object>  partial  = new ArrayList<>();
-        final List<String>  k        = state.propertyList == null ? Arrays.asList(value.getOwnKeys(false)) : state.propertyList;
+        final List<String>  k        = state.propertyList == null ?
+                Arrays.asList(getOwnKeys(value)) : state.propertyList;
 
         for (final Object p : k) {
             final Object strP = str(p, value, state);
@@ -349,7 +374,9 @@
     }
 
     // Spec: The abstract operation JA(value) serializes an array.
-    private static Object JA(final ScriptObject value, final StringifyState state) {
+    private static Object JA(final Object value, final StringifyState state) {
+        assert value instanceof ScriptObject || value instanceof JSObject;
+
         if (state.stack.containsKey(value)) {
             throw typeError("JSON.stringify.cyclic");
         }
@@ -359,7 +386,7 @@
         state.indent.append(state.gap);
         final List<Object> partial = new ArrayList<>();
 
-        final int length = JSType.toInteger(value.getLength());
+        final int length = JSType.toInteger(getLength(value));
         int index = 0;
 
         while (index < length) {
@@ -413,4 +440,48 @@
 
         return finalStr.toString();
     }
+
+    private static String[] getOwnKeys(final Object obj) {
+        if (obj instanceof ScriptObject) {
+            return ((ScriptObject)obj).getOwnKeys(false);
+        } else if (obj instanceof ScriptObjectMirror) {
+            return ((ScriptObjectMirror)obj).getOwnKeys(false);
+        } else if (obj instanceof JSObject) {
+            // No notion of "own keys" or "proto" for general JSObject! We just
+            // return all keys of the object. This will be useful for POJOs
+            // implementing JSObject interface.
+            return ((JSObject)obj).keySet().toArray(new String[0]);
+        } else {
+            throw new AssertionError("should not reach here");
+        }
+    }
+
+    private static Object getLength(final Object obj) {
+        if (obj instanceof ScriptObject) {
+            return ((ScriptObject)obj).getLength();
+        } else if (obj instanceof JSObject) {
+            return ((JSObject)obj).getMember("length");
+        } else {
+            throw new AssertionError("should not reach here");
+        }
+    }
+
+    private static boolean isJSObjectArray(final Object obj) {
+        return (obj instanceof JSObject) && ((JSObject)obj).isArray();
+    }
+
+    private static Object getProperty(final Object holder, final Object key) {
+        if (holder instanceof ScriptObject) {
+            return ((ScriptObject)holder).get(key);
+        } else if (holder instanceof JSObject) {
+            JSObject jsObj = (JSObject)holder;
+            if (key instanceof Integer) {
+                return jsObj.getSlot((Integer)key);
+            } else {
+                return jsObj.getMember(Objects.toString(key));
+            }
+        } else {
+            return new AssertionError("should not reach here");
+        }
+    }
 }
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint16Array.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint16Array.java	Thu May 19 19:46:39 2016 +0000
@@ -81,7 +81,7 @@
         private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Uint16ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
 
         private Uint16ArrayData(final CharBuffer nb, final int start, final int end) {
-            super(((CharBuffer)nb.position(start).limit(end)).slice(), end - start);
+            super((nb.position(start).limit(end)).slice(), end - start);
         }
 
         @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint32Array.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint32Array.java	Thu May 19 19:46:39 2016 +0000
@@ -84,7 +84,7 @@
         private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Uint32ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
 
         private Uint32ArrayData(final IntBuffer nb, final int start, final int end) {
-            super(((IntBuffer)nb.position(start).limit(end)).slice(), end - start);
+            super((nb.position(start).limit(end)).slice(), end - start);
         }
 
         @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8Array.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8Array.java	Thu May 19 19:46:39 2016 +0000
@@ -81,7 +81,7 @@
         private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Uint8ArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
 
         private Uint8ArrayData(final ByteBuffer nb, final int start, final int end) {
-            super(((ByteBuffer)nb.position(start).limit(end)).slice(), end - start);
+            super((nb.position(start).limit(end)).slice(), end - start);
         }
 
         @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Thu May 19 19:46:39 2016 +0000
@@ -85,7 +85,7 @@
         private static final MethodHandle CLAMP_LONG = staticCall(MethodHandles.lookup(), Uint8ClampedArrayData.class, "clampLong", long.class, long.class).methodHandle();
 
         private Uint8ClampedArrayData(final ByteBuffer nb, final int start, final int end) {
-            super(((ByteBuffer)nb.position(start).limit(end)).slice(), end - start);
+            super((nb.position(start).limit(end)).slice(), end - start);
         }
 
         @Override
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java	Thu May 19 19:46:39 2016 +0000
@@ -2070,6 +2070,7 @@
         }
     }
 
+    @SuppressWarnings("fallthrough")
     private boolean lookaheadIsLetDeclaration(final boolean ofContextualKeyword) {
         assert type == LET;
         for (int i = 1;; i++) {
@@ -2323,6 +2324,7 @@
      *   yield [no LineTerminator here] AssignmentExpression[?In, Yield]
      *   yield [no LineTerminator here] * AssignmentExpression[?In, Yield]
      */
+    @SuppressWarnings("fallthrough")
     private Expression yieldExpression(final boolean noIn) {
         assert inGeneratorFunction();
         // Capture YIELD token.
@@ -2838,6 +2840,7 @@
      * Parse array literal.
      * @return Expression node.
      */
+    @SuppressWarnings("fallthrough")
     private LiteralNode<Expression[]> arrayLiteral() {
         // Capture LBRACKET token.
         final long arrayToken = token;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Thu May 19 19:46:39 2016 +0000
@@ -173,12 +173,14 @@
     private static final Call RUN = interfaceCallNoLookup(Runnable.class, "run", void.class);
 
     // ASM handle to the bootstrap method
+    @SuppressWarnings("deprecation")
     private static final Handle BOOTSTRAP_HANDLE = new Handle(H_INVOKESTATIC,
             Type.getInternalName(JavaAdapterServices.class), "bootstrap",
             MethodType.methodType(CallSite.class, Lookup.class, String.class,
                     MethodType.class, int.class).toMethodDescriptorString());
 
     // ASM handle to the bootstrap method for array populator
+    @SuppressWarnings("deprecation")
     private static final Handle CREATE_ARRAY_BOOTSTRAP_HANDLE = new Handle(H_INVOKESTATIC,
             Type.getInternalName(JavaAdapterServices.class), "createArrayBootstrap",
             MethodType.methodType(CallSite.class, Lookup.class, String.class,
@@ -1048,6 +1050,7 @@
         endMethod(mv);
     }
 
+    @SuppressWarnings("deprecation")
     private void generateFinalizerOverride() {
         final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, "finalize",
                 VOID_METHOD_DESCRIPTOR, null, null));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8066229.js	Thu May 19 19:46:39 2016 +0000
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8066229: Fuzzing bug: Can't find scope depth
+ *
+ * @test
+ * @run
+ */
+
+function f() { x; throw null; (function (){ var x; }); }
+
+try {
+    f();
+    throw new Error("Expected error");
+} catch (e) {
+    if (!(e instanceof ReferenceError)) {
+        throw new Error("Unexpected error: " + e);
+    }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8157160.js	Thu May 19 19:46:39 2016 +0000
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8157160: JSON.stringify does not work on ScriptObjectMirror objects
+ *
+ * @test
+ * @option -scripting
+ * @run
+ */
+
+var SM = Java.type("javax.script.ScriptEngineManager");
+var AJSO = Java.type("jdk.nashorn.api.scripting.AbstractJSObject");
+var Supplier = Java.type("java.util.function.Supplier");
+
+var engine = new SM().getEngineByName("nashorn");
+
+// JSON stringify ScriptObjectMirror instances
+print(JSON.stringify(engine.eval("({ foo : 42 })")));
+print(JSON.stringify(engine.eval("([5, 6, 76, 7])")));
+print(JSON.stringify(engine.eval(<<EOF
+ ({
+     toJSON: function() "hello"
+ })
+EOF
+)));
+
+print(JSON.stringify(engine.eval(<<EOF
+obj = {
+    name: 'nashorn',
+    versions: [ 'es5.1', 'es6' ]
+}
+EOF
+)));
+
+var dm = engine.eval("new Date()");
+print('"' + dm.toJSON() + '"' == JSON.stringify(dm));
+
+// JSON stringifying an arbitrary JSObject impl.
+var jsObj = new AJSO() {
+    keySet: function() {
+        var keys = new java.util.HashSet();
+        keys.add("x");
+        keys.add("y");
+        return keys;
+    },
+
+    getMember: function(name) {
+        if (name == "x") {
+            return 42;
+        } else if (name == "y") {
+            return "hello";
+        }
+    }
+};
+print(JSON.stringify(jsObj));
+
+// try toJSON implementation on JSObject
+var jsObj2 = new AJSO() {
+    getMember: function(name) {
+        if (name == 'toJSON') {
+            return function() {
+                return "my json representation";
+            }
+        }
+    }
+};
+print(JSON.stringify(jsObj2));
+
+var jsObj3 = new AJSO() {
+    getMember: function(name) {
+        if (name == 'toJSON') {
+            return new Supplier() {
+                "get": function() {
+                    return "value from toJSON function";
+                }
+            };
+        }
+    }
+};
+print(JSON.stringify(jsObj3));
+
+// replacer function from another script world
+print(JSON.stringify({
+   foo: "hello"
+}, engine.eval(<<EOF
+    function (key, value) {
+       if (key == "foo") {
+           return value.toUpperCase()
+       }
+       return value;
+    }
+EOF)));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8157160.js.EXPECTED	Thu May 19 19:46:39 2016 +0000
@@ -0,0 +1,9 @@
+{"foo":42}
+[5,6,76,7]
+"hello"
+{"name":"nashorn","versions":["es5.1","es6"]}
+true
+{"x":42,"y":"hello"}
+"my json representation"
+"value from toJSON function"
+{"foo":"HELLO"}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8157250.js	Thu May 19 19:46:39 2016 +0000
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8157250: BeanLinker assumes fixed array type linkage
+ *
+ * @test
+ * @run
+ */
+
+var intArray = Java.type("int[]")
+var doubleArray = Java.type("double[]")
+var arrs = [new intArray(0), new doubleArray(0)]
+for (var i in arrs) arrs[i].length
--- a/nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptEngineSecurityTest.java	Thu May 19 17:48:04 2016 +0000
+++ b/nashorn/test/src/jdk/nashorn/api/scripting/test/ScriptEngineSecurityTest.java	Thu May 19 19:46:39 2016 +0000
@@ -172,7 +172,7 @@
     }
 
     // @bug 8032948: Nashorn linkages awry
-    @SuppressWarnings("serial")
+    @SuppressWarnings({ "serial", "deprecation" })
     public static class FakeProxy extends Proxy {
         public FakeProxy(final InvocationHandler ih) {
             super(ih);