changeset 1624:64abe93e4f2b

Merge.
author Doug Simon <doug.simon@oracle.com>
date Thu, 04 Feb 2016 09:20:31 +0100
parents 3a489ad6eb5e a618d3e89fde
children 4a3246509ad0
files
diffstat 118 files changed, 1972 insertions(+), 741 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Mon Jan 18 23:08:40 2016 -0800
+++ b/.hgtags	Thu Feb 04 09:20:31 2016 +0100
@@ -335,3 +335,5 @@
 74ddd1339c57cf2c2a13e34e1760006c2e54d1fc jdk-9+99
 da397aea8adad7e6f743b60bfe0c415fc8508df5 jdk-9+100
 1916a2c680d8c33b59943dbb6dc2dd2000ec821a jdk-9+101
+e5620875888583d35e9492b62fe27e054df26049 jdk-9+102
+c9406f325a23e9093fa667ad3c594e2efe078f47 jdk-9+103
--- a/make/project.properties	Mon Jan 18 23:08:40 2016 -0800
+++ b/make/project.properties	Thu Feb 04 09:20:31 2016 +0100
@@ -311,7 +311,7 @@
   -XX:+HeapDumpOnOutOfMemoryError
 
 # turn on assertions for tests
-run.test.jvmargs.main=${run.test.jvmargs.common} -esa -ea -da:java.lang.invoke.LambdaFormEditor
+run.test.jvmargs.main=${run.test.jvmargs.common} -esa -ea
 
 # Extra jvmargs that might be useful for debugging
 # and performance improvements/monitoring
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/TypeConverterFactory.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/TypeConverterFactory.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -209,8 +209,8 @@
                 c.add((ConversionComparator)factory);
             }
         }
-        this.factories = l.toArray(new GuardingTypeConverterFactory[l.size()]);
-        this.comparators = c.toArray(new ConversionComparator[c.size()]);
+        this.factories = l.toArray(new GuardingTypeConverterFactory[0]);
+        this.comparators = c.toArray(new ConversionComparator[0]);
         this.autoConversionStrategy = autoConversionStrategy;
     }
 
@@ -285,7 +285,7 @@
             return handle;
         }
         final MethodHandle newHandle =
-                MethodHandles.filterArguments(handle, pos, converters.toArray(new MethodHandle[converters.size()]));
+                MethodHandles.filterArguments(handle, pos, converters.toArray(new MethodHandle[0]));
         converters.clear();
         return newHandle;
     }
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/beans/AccessibleMembersLookup.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/beans/AccessibleMembersLookup.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -133,7 +133,7 @@
     }
 
     Class<?>[] getInnerClasses() {
-        return innerClasses.toArray(new Class<?>[innerClasses.size()]);
+        return innerClasses.toArray(new Class<?>[0]);
     }
 
     /**
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/beans/package-info.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/beans/package-info.java	Thu Feb 04 09:20:31 2016 +0100
@@ -83,6 +83,6 @@
 
 /**
  * Contains the linker for ordinary Java objects.
- * @since 1.9
+ * @since 9
  */
 package jdk.dynalink.beans;
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/linker/package-info.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/linker/package-info.java	Thu Feb 04 09:20:31 2016 +0100
@@ -111,6 +111,6 @@
  * implement the {@link jdk.dynalink.linker.GuardingTypeConverterFactory}
  * interface to provide the logic for these conversions.
  * </p>
- * @since 1.9
+ * @since 9
  */
 package jdk.dynalink.linker;
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/linker/support/CompositeGuardingDynamicLinker.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/linker/support/CompositeGuardingDynamicLinker.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -112,7 +112,7 @@
         for(final GuardingDynamicLinker linker: linkers) {
             l.add(Objects.requireNonNull(linker));
         }
-        this.linkers = l.toArray(new GuardingDynamicLinker[l.size()]);
+        this.linkers = l.toArray(new GuardingDynamicLinker[0]);
     }
 
     /**
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/linker/support/CompositeTypeBasedGuardingDynamicLinker.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/linker/support/CompositeTypeBasedGuardingDynamicLinker.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -157,7 +157,7 @@
         for(final TypeBasedGuardingDynamicLinker linker: linkers) {
             l.add(Objects.requireNonNull(linker));
         }
-        this.classToLinker = new ClassToLinker(l.toArray(new TypeBasedGuardingDynamicLinker[l.size()]));
+        this.classToLinker = new ClassToLinker(l.toArray(new TypeBasedGuardingDynamicLinker[0]));
     }
 
     /**
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/linker/support/package-info.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/linker/support/package-info.java	Thu Feb 04 09:20:31 2016 +0100
@@ -87,6 +87,6 @@
  * by providing basic implementations of some classes as well as various
  * utilities.
  * </p>
- * @since 1.9
+ * @since 9
  */
 package jdk.dynalink.linker.support;
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/support/ChainedCallSite.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/support/ChainedCallSite.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -209,7 +209,7 @@
                 invocations = newInvocations.getFirst();
                 break;
             default:
-                invocations = newInvocations.toArray(new GuardedInvocation[newInvocations.size()]);
+                invocations = newInvocations.toArray(new GuardedInvocation[0]);
         }
         setTarget(target);
         return target;
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/support/package-info.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/support/package-info.java	Thu Feb 04 09:20:31 2016 +0100
@@ -85,6 +85,6 @@
  * <p>Contains classes that make using Dynalink more convenient by providing
  * basic implementations of some classes as well as various utilities.
  * </p>
- * @since 1.9
+ * @since 9
  */
 package jdk.dynalink.support;
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornException.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornException.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -182,7 +182,7 @@
                         st.getFileName(), st.getLineNumber()));
             }
         }
-        return filtered.toArray(new StackTraceElement[filtered.size()]);
+        return filtered.toArray(new StackTraceElement[0]);
     }
 
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ArrayAccessTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ArrayAccessTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   <em>expression</em> [ <em>index</em> ]
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface ArrayAccessTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ArrayLiteralTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ArrayLiteralTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -30,7 +30,7 @@
 /**
  * Represents ECMAScript array literal expression.
  *
- * @since 1.9
+ * @since 9
  */
 public interface ArrayLiteralTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/AssignmentTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/AssignmentTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   <em>variable</em> = <em>expression</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface AssignmentTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BinaryTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BinaryTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *   <em>leftOperand</em> <em>operator</em> <em>rightOperand</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface BinaryTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BlockTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BlockTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -37,7 +37,7 @@
  *   { <em>statements</em> }
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface BlockTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BreakTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BreakTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -35,7 +35,7 @@
  *   break <em>label</em> ;
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface BreakTree extends GotoTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CaseTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CaseTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -39,7 +39,7 @@
  *       <em>statements</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface CaseTree extends Tree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CatchTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CatchTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *       <em>block</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface CatchTree extends Tree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CompilationUnitTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CompilationUnitTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -31,7 +31,7 @@
  * Represents the abstract syntax tree for compilation units (source
  * files)
  *
- * @since 1.9
+ * @since 9
  */
 public interface CompilationUnitTree extends Tree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CompoundAssignmentTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CompoundAssignmentTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *   <em>variable</em> <em>operator</em> <em>expression</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface CompoundAssignmentTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ConditionalExpressionTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ConditionalExpressionTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   <em>condition</em> ? <em>trueExpression</em> : <em>falseExpression</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface ConditionalExpressionTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ConditionalLoopTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ConditionalLoopTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -28,7 +28,7 @@
 /**
  * A mixin for conditional "loop" statements.
  *
- * @since 1.9
+ * @since 9
  */
 public interface ConditionalLoopTree extends LoopTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ContinueTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ContinueTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *   continue <em>label</em> ;
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface ContinueTree extends GotoTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DebuggerTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DebuggerTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *     <em>debugger;</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface DebuggerTree extends StatementTree {
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Diagnostic.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Diagnostic.java	Thu Feb 04 09:20:31 2016 +0100
@@ -40,7 +40,7 @@
  * <p>Line terminator is as defined in ECMAScript specification which is one
  * of { &#92;u000A, &#92;u000B, &#92;u2028, &#92;u2029 }.
  *
- * @since 1.9
+ * @since 9
  */
 public interface Diagnostic {
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DiagnosticListener.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DiagnosticListener.java	Thu Feb 04 09:20:31 2016 +0100
@@ -28,7 +28,7 @@
 /**
  * Interface for receiving diagnostics from Nashorn parser.
  *
- * @since 1.9
+ * @since 9
  */
 @FunctionalInterface
 public interface DiagnosticListener {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DoWhileLoopTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DoWhileLoopTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -35,7 +35,7 @@
  *   while ( <em>expression</em> );
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface DoWhileLoopTree extends ConditionalLoopTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/EmptyStatementTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/EmptyStatementTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,6 +33,6 @@
  *    ;
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface EmptyStatementTree extends StatementTree {}
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ErroneousTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ErroneousTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -28,7 +28,7 @@
 /**
  * A tree node to stand in for a malformed expression.
  *
- * @since 1.9
+ * @since 9
  */
 public interface ErroneousTree extends ExpressionTree {
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ExpressionStatementTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ExpressionStatementTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   <em>expression</em> ;
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface ExpressionStatementTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ExpressionTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ExpressionTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -29,6 +29,6 @@
  * A tree node used as the base class for the different types of
  * expressions.
  *
- * @since 1.9
+ * @since 9
  */
 public interface ExpressionTree extends Tree {}
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ForInLoopTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ForInLoopTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *       <em>statement</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface ForInLoopTree extends LoopTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ForLoopTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ForLoopTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *       <em>statement</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface ForLoopTree extends ConditionalLoopTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionCallTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionCallTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -37,7 +37,7 @@
  *   this . <em>identifier</em> ( <em>arguments</em> )
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface FunctionCallTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionDeclarationTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionDeclarationTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -37,7 +37,7 @@
  *      <em>body</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface FunctionDeclarationTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionExpressionTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionExpressionTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -37,7 +37,7 @@
  *      <em>body</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface FunctionExpressionTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/GotoTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/GotoTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -31,7 +31,7 @@
  * type serves as a super interface for {@link BreakTree} and
  * {@link ContinueTree}.
  *
- * @since 1.9
+ * @since 9
  */
 public interface GotoTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IdentifierTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IdentifierTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   <em>name</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface IdentifierTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IfTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IfTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -39,7 +39,7 @@
  *       <em>elseStatement</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface IfTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/InstanceOfTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/InstanceOfTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   <em>expression</em> instanceof <em>type</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface InstanceOfTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LabeledStatementTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LabeledStatementTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   <em>label</em> : <em>statement</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface LabeledStatementTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LineMap.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LineMap.java	Thu Feb 04 09:20:31 2016 +0100
@@ -29,7 +29,7 @@
  * Provides methods to convert between character positions and line numbers
  * for a compilation unit.
  *
- * @since 1.9
+ * @since 9
  */
 public interface LineMap {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LiteralTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LiteralTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *   <em>value</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface LiteralTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LoopTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LoopTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -28,7 +28,7 @@
 /**
  * A mixin for "loop" statements.
  *
- * @since 1.9
+ * @since 9
  */
 public interface LoopTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/MemberSelectTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/MemberSelectTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   <em>expression</em> . <em>identifier</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface MemberSelectTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/NewTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/NewTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -35,7 +35,7 @@
  *   new <em>identifier</em> ( <em>arguments</em> )
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface NewTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ObjectLiteralTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ObjectLiteralTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -30,7 +30,7 @@
 /**
  * Represents ECMAScript object literal expression.
  *
- * @since 1.9
+ * @since 9
  */
 public interface ObjectLiteralTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ParenthesizedTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ParenthesizedTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *   ( <em>expression</em> )
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface ParenthesizedTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Parser.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Parser.java	Thu Feb 04 09:20:31 2016 +0100
@@ -36,7 +36,7 @@
 /**
  * Represents nashorn ECMAScript parser instance.
  *
- * @since 1.9
+ * @since 9
  */
 public interface Parser {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/PropertyTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/PropertyTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -28,7 +28,7 @@
 /**
  * To represent property setting in an object literal tree.
  *
- * @since 1.9
+ * @since 9
  */
 public interface PropertyTree extends Tree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/RegExpLiteralTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/RegExpLiteralTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -28,7 +28,7 @@
 /**
  * Represents regular expression literal in the source code.
  *
- * @since 1.9
+ * @since 9
  */
 public interface RegExpLiteralTree extends Tree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ReturnTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ReturnTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *   return <em>expression</em>;
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface ReturnTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/StatementTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/StatementTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -29,7 +29,7 @@
  * A tree node used as the base class for the different kinds of
  * statements.
  *
- * @since 1.9
+ * @since 9
  */
 public interface StatementTree extends Tree {
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/SwitchTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/SwitchTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -37,7 +37,7 @@
  *   }
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface SwitchTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ThrowTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ThrowTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   throw <em>expression</em>;
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface ThrowTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Tree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Tree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -31,7 +31,7 @@
  * <p><b>WARNING:</b> This interface and its sub-interfaces are
  * subject to change as the ECMAScript  programming language evolves.
  *
- * @since 1.9
+ * @since 9
  */
 public interface Tree {
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/TreeVisitor.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/TreeVisitor.java	Thu Feb 04 09:20:31 2016 +0100
@@ -51,7 +51,7 @@
  *            methods.  Use {@code Void} for visitors that do not need an
  *            additional parameter.
  *
- * @since 1.9
+ * @since 9
  */
 public interface TreeVisitor<R,P> {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/TryTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/TryTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -39,7 +39,7 @@
  *       <em>finallyBlock</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface TryTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/UnaryTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/UnaryTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -36,7 +36,7 @@
  *   <em>expression</em> <em>operator</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface UnaryTree extends ExpressionTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/UnknownTreeException.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/UnknownTreeException.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  * {@linkplain TreeVisitor tree visitor} to indicate that the
  * visitor was created for a prior version of the language.
  *
- * @since 1.9
+ * @since 9
  */
 public class UnknownTreeException extends RuntimeException {
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/VariableTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/VariableTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,7 +33,7 @@
  *   <em>var</em> <em>name</em> <em>initializer</em> ;
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface VariableTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/WhileLoopTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/WhileLoopTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *     <em>statement</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface WhileLoopTree extends ConditionalLoopTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/WithTree.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/WithTree.java	Thu Feb 04 09:20:31 2016 +0100
@@ -34,7 +34,7 @@
  *     <em>statement</em>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 public interface WithTree extends StatementTree {
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/package-info.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/package-info.java	Thu Feb 04 09:20:31 2016 +0100
@@ -68,7 +68,7 @@
  * </code>
  * </pre>
  *
- * @since 1.9
+ * @since 9
  */
 package jdk.nashorn.api.tree;
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -2996,8 +2996,8 @@
 
             // Copy values and labels to arrays.
             final int       size   = tree.size();
-            final Integer[] values = tree.keySet().toArray(new Integer[size]);
-            final Label[]   labels = tree.values().toArray(new Label[size]);
+            final Integer[] values = tree.keySet().toArray(new Integer[0]);
+            final Label[]   labels = tree.values().toArray(new Label[0]);
 
             // Discern low, high and range.
             final int lo    = values[0];
@@ -5203,7 +5203,7 @@
                 }
             }
         }
-        return names.toArray(new String[names.size()]);
+        return names.toArray(new String[0]);
     }
 
     private static String commonPrefix(final String s1, final String s2) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java	Thu Feb 04 09:20:31 2016 +0100
@@ -335,7 +335,7 @@
                 break;
             case SHR:
                 final long result = JSType.toUint32(lhs.getInt32() >>> rhs.getInt32());
-                return LiteralNode.newInstance(token, finish, JSType.isRepresentableAsInt(result) ? (int) result : (double) result);
+                return LiteralNode.newInstance(token, finish, JSType.toNarrowestNumber(result));
             case SAR:
                 return LiteralNode.newInstance(token, finish, lhs.getInt32() >> rhs.getInt32());
             case SHL:
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FunctionSignature.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FunctionSignature.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -141,7 +141,7 @@
             paramTypeList.add(paramType.getTypeClass());
         }
 
-        this.methodType = MH.type(returnType.getTypeClass(), paramTypeList.toArray(new Class<?>[paramTypes.length]));
+        this.methodType = MH.type(returnType.getTypeClass(), paramTypeList.toArray(new Class<?>[0]));
     }
 
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/Block.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/Block.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -136,7 +136,7 @@
      * @param statements All statements in the block
      */
     public Block(final long token, final int finish, final int flags, final List<Statement> statements) {
-        this(token, finish, flags, statements.toArray(new Statement[statements.size()]));
+        this(token, finish, flags, statements.toArray(new Statement[0]));
     }
 
     private Block(final Block block, final int finish, final List<Statement> statements, final int flags, final Map<String, Symbol> symbols, final LocalVariableConversion conversion) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/LiteralNode.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/LiteralNode.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -250,7 +250,7 @@
     }
 
     private static Expression[] valueToArray(final List<Expression> value) {
-        return value.toArray(new Expression[value.size()]);
+        return value.toArray(new Expression[0]);
     }
 
     /**
@@ -941,7 +941,7 @@
         }
 
         private ArrayLiteralNode setValue(final LexicalContext lc, final List<Expression> value) {
-            return setValue(lc, value.toArray(new Expression[value.size()]));
+            return setValue(lc, value.toArray(new Expression[0]));
         }
 
         @Override
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ASTWriter.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ASTWriter.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -98,7 +98,7 @@
     public Node[] toArray() {
         final List<Node> preorder = new ArrayList<>();
         printAST(new StringBuilder(), preorder, null, "root", root, 0);
-        return preorder.toArray(new Node[preorder.size()]);
+        return preorder.toArray(new Node[0]);
     }
 
     @SuppressWarnings("unchecked")
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ObjectSizeCalculator.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ObjectSizeCalculator.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -328,7 +328,7 @@
             this.fieldsSize = newFieldsSize;
             this.objectSize = roundTo(objectHeaderSize + newFieldsSize, objectPadding);
             this.referenceFields = newReferenceFields.toArray(
-                    new Field[newReferenceFields.size()]);
+                    new Field[0]);
         }
 
         void visit(final Object obj, final ObjectSizeCalculator calc) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArray.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArray.java	Thu Feb 04 09:20:31 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2014, 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
@@ -70,7 +70,6 @@
 import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator;
 import jdk.nashorn.internal.runtime.arrays.ContinuousArrayData;
 import jdk.nashorn.internal.runtime.arrays.IntElements;
-import jdk.nashorn.internal.runtime.arrays.IntOrLongElements;
 import jdk.nashorn.internal.runtime.arrays.IteratorAction;
 import jdk.nashorn.internal.runtime.arrays.NumericElements;
 import jdk.nashorn.internal.runtime.linker.Bootstrap;
@@ -285,7 +284,7 @@
         final long newLen = NativeArray.validLength(newLenDesc.getValue());
 
         // Step 3e - note that we need to convert to int or double as long is not considered a JS number type anymore
-        newLenDesc.setValue(JSType.isRepresentableAsInt(newLen) ? Integer.valueOf((int) newLen) : Double.valueOf((double) newLen));
+        newLenDesc.setValue(JSType.toNarrowestNumber(newLen));
 
         // Step 3f
         // increasing array length - just need to set new length value (and attributes if any) and return
@@ -1043,7 +1042,7 @@
             if (bulkable(sobj) && sobj.getArray().length() + args.length <= JSType.MAX_UINT) {
                 final ArrayData newData = sobj.getArray().push(true, args);
                 sobj.setArray(newData);
-                return newData.length();
+                return JSType.toNarrowestNumber(newData.length());
             }
 
             long len = JSType.toUint32(sobj.getLength());
@@ -1052,7 +1051,7 @@
             }
             sobj.set("length", len, CALLSITE_STRICT);
 
-            return len;
+            return JSType.toNarrowestNumber(len);
         } catch (final ClassCastException | NullPointerException e) {
             throw typeError(Context.getGlobal(), e, "not.an.object", ScriptRuntime.safeToString(self));
         }
@@ -1265,7 +1264,7 @@
             // behaviour of sort is implementation-defined.
         }
 
-        return list.toArray(new Object[array.length]);
+        return list.toArray(new Object[0]);
     }
 
     /**
@@ -1471,7 +1470,7 @@
         final long newLength = len + items.length;
         sobj.set("length", newLength, CALLSITE_STRICT);
 
-        return newLength;
+        return JSType.toNarrowestNumber(newLength);
     }
 
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDebug.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDebug.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -379,7 +379,7 @@
     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
     public static Object getRuntimeEvents(final Object self) {
         final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
-        return q.toArray(new RuntimeEvent<?>[q.size()]);
+        return q.toArray(new RuntimeEvent<?>[0]);
     }
 
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFunction.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFunction.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -130,7 +130,7 @@
             return (Object[])array;
         } else if (array instanceof List) {
             final List<?> list = (List<?>)array;
-            return list.toArray(new Object[list.size()]);
+            return list.toArray(new Object[0]);
         } else if (array == null || array == UNDEFINED) {
             return ScriptRuntime.EMPTY_ARRAY;
         } else if (array instanceof JSObject) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeObject.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeObject.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -702,7 +702,7 @@
             }
 
             if (!propList.isEmpty()) {
-                targetObj.addBoundProperties(sourceObj, propList.toArray(new Property[propList.size()]));
+                targetObj.addBoundProperties(sourceObj, propList.toArray(new Property[0]));
             }
         } else if (source instanceof ScriptObjectMirror) {
             // get enumerable, immediate properties of mirror
@@ -819,7 +819,7 @@
             }
         }
 
-        targetObj.addBoundProperties(source, properties.toArray(new AccessorProperty[properties.size()]));
+        targetObj.addBoundProperties(source, properties.toArray(new AccessorProperty[0]));
     }
 
     private static MethodHandle getBoundBeanMethodGetter(final Object source, final MethodHandle methodGetter) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java	Thu Feb 04 09:20:31 2016 +0100
@@ -791,6 +791,15 @@
         return Double.NaN;
     }
 
+    /**
+     * Convert a long to the narrowest JavaScript Number type. This returns either a
+     * {@link Integer} or {@link Double} depending on the magnitude of {@code l}.
+     * @param l a long value
+     * @return the value converted to Integer or Double
+     */
+    public static Number toNarrowestNumber(final long l) {
+        return isRepresentableAsInt(l) ? Integer.valueOf((int) l) : Double.valueOf((double) l);
+    }
 
     /**
      * JavaScript compliant conversion of Boolean to number
@@ -1727,21 +1736,6 @@
     }
 
     /**
-     * Returns the boxed version of a primitive class
-     * @param clazz the class
-     * @return the boxed type of clazz, or unchanged if not primitive
-     */
-    public static Class<?> getBoxedClass(final Class<?> clazz) {
-        if (clazz == int.class) {
-            return Integer.class;
-        } else if (clazz == double.class) {
-            return Double.class;
-        }
-        assert !clazz.isPrimitive();
-        return clazz;
-    }
-
-    /**
      * Create a method handle constant of the correct primitive type
      * for a constant object
      * @param o object
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyListeners.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyListeners.java	Thu Feb 04 09:20:31 2016 +0100
@@ -54,7 +54,13 @@
      */
     PropertyListeners(final PropertyListeners listener) {
         if (listener != null && listener.listeners != null) {
-            this.listeners = new WeakHashMap<>(listener.listeners);
+            this.listeners = new WeakHashMap<>();
+            // We need to copy the nested weak sets in order to avoid concurrent modification issues, see JDK-8146274
+            synchronized (listener) {
+                for (final Map.Entry<Object, WeakPropertyMapSet> entry : listener.listeners.entrySet()) {
+                    this.listeners.put(entry.getKey(), new WeakPropertyMapSet(entry.getValue()));
+                }
+            }
         }
     }
 
@@ -228,7 +234,15 @@
 
     private static class WeakPropertyMapSet {
 
-        private final WeakHashMap<PropertyMap, Boolean> map = new WeakHashMap<>();
+        private final WeakHashMap<PropertyMap, Boolean> map;
+
+        WeakPropertyMapSet() {
+            this.map = new WeakHashMap<>();
+        }
+
+        WeakPropertyMapSet(final WeakPropertyMapSet set) {
+            this.map = new WeakHashMap<>(set.map);
+        }
 
         void add(final PropertyMap propertyMap) {
             map.put(propertyMap, Boolean.TRUE);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -377,7 +377,7 @@
                 if (Context.DEBUG) {
                     protoInvalidations.add(size);
                 }
-                SwitchPoint.invalidateAll(protoSwitches.values().toArray(new SwitchPoint[size]));
+                SwitchPoint.invalidateAll(protoSwitches.values().toArray(new SwitchPoint[0]));
                 protoSwitches.clear();
             }
         }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -553,7 +553,7 @@
      * @param prototype actual prototype object
      * @return property map
      */
-    private synchronized PropertyMap getAllocatorMap(final ScriptObject prototype) {
+    private PropertyMap getAllocatorMap(final ScriptObject prototype) {
         if (allocatorMap == null || allocatorMap.isInvalidSharedMapFor(prototype)) {
             // The prototype map has changed since this function was last used as constructor.
             // Get a new allocator map.
@@ -993,7 +993,7 @@
         if (bestInvoker.getSwitchPoints() != null) {
             sps.addAll(Arrays.asList(bestInvoker.getSwitchPoints()));
         }
-        final SwitchPoint[] spsArray = sps.isEmpty() ? null : sps.toArray(new SwitchPoint[sps.size()]);
+        final SwitchPoint[] spsArray = sps.isEmpty() ? null : sps.toArray(new SwitchPoint[0]);
 
         return new GuardedInvocation(
                 boundHandle,
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -1334,7 +1334,7 @@
         for (ScriptObject self = this; self != null; self = self.getProto()) {
             keys.addAll(Arrays.asList(self.getOwnKeys(String.class, true, nonEnumerable)));
         }
-        return keys.toArray(new String[keys.size()]);
+        return keys.toArray(new String[0]);
     }
 
     /**
@@ -2146,7 +2146,7 @@
         }
 
         switchPoints.add(getMap().getSwitchPoint(name));
-        return switchPoints.toArray(new SwitchPoint[switchPoints.size()]);
+        return switchPoints.toArray(new SwitchPoint[0]);
     }
 
     private void checkSharedProtoMap() {
@@ -2505,7 +2505,7 @@
             for (ScriptObject self = object; self != null; self = self.getProto()) {
                 keys.addAll(Arrays.asList(self.getOwnKeys(String.class, false, nonEnumerable)));
             }
-            this.values = keys.toArray(new String[keys.size()]);
+            this.values = keys.toArray(new String[0]);
         }
     }
 
@@ -2523,7 +2523,7 @@
                     valueList.add(self.get(key));
                 }
             }
-            this.values = valueList.toArray(new Object[valueList.size()]);
+            this.values = valueList.toArray(new Object[0]);
         }
     }
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Timing.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Timing.java	Thu Feb 04 09:20:31 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2014, 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
@@ -176,7 +176,7 @@
             } catch (final IOException e) {
                 throw new RuntimeException(e);
             }
-            return strs.toArray(new String[strs.size()]);
+            return strs.toArray(new String[0]);
         }
 
         @Override
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/AdaptationResult.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/AdaptationResult.java	Thu Feb 04 09:20:31 2016 +0100
@@ -55,11 +55,17 @@
     static final AdaptationResult SUCCESSFUL_RESULT = new AdaptationResult(Outcome.SUCCESS, "");
 
     private final Outcome outcome;
+    private final RuntimeException cause;
     private final String[] messageArgs;
 
+    AdaptationResult(final Outcome outcome, final RuntimeException cause, final String... messageArgs) {
+        this.outcome = outcome;
+        this.cause = cause;
+        this.messageArgs = messageArgs;
+    }
+
     AdaptationResult(final Outcome outcome, final String... messageArgs) {
-        this.outcome = outcome;
-        this.messageArgs = messageArgs;
+        this(outcome, null, messageArgs);
     }
 
     Outcome getOutcome() {
@@ -67,6 +73,6 @@
     }
 
     ECMAException typeError() {
-        return ECMAErrors.typeError("extend." + outcome, messageArgs);
+        return ECMAErrors.typeError(cause, "extend." + outcome, messageArgs);
     }
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java	Thu Feb 04 09:20:31 2016 +0100
@@ -193,7 +193,7 @@
      * Create a call site and link it for Nashorn. This version of the method conforms to the invokedynamic bootstrap
      * method expected signature and is referenced from Nashorn generated bytecode as the bootstrap method for all
      * invokedynamic instructions.
-     * @param lookup MethodHandle lookup. Ignored as Nashorn only uses public lookup.
+     * @param lookup MethodHandle lookup.
      * @param opDesc Dynalink dynamic operation descriptor.
      * @param type   Method type.
      * @param flags  flags for call type, trace/profile etc.
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Thu Feb 04 09:20:31 2016 +0100
@@ -31,19 +31,21 @@
 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_STATIC;
 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;
 import static jdk.internal.org.objectweb.asm.Opcodes.ACC_VARARGS;
-import static jdk.internal.org.objectweb.asm.Opcodes.ACONST_NULL;
 import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD;
 import static jdk.internal.org.objectweb.asm.Opcodes.ASTORE;
-import static jdk.internal.org.objectweb.asm.Opcodes.DUP;
-import static jdk.internal.org.objectweb.asm.Opcodes.IFNONNULL;
-import static jdk.internal.org.objectweb.asm.Opcodes.ILOAD;
-import static jdk.internal.org.objectweb.asm.Opcodes.ISTORE;
-import static jdk.internal.org.objectweb.asm.Opcodes.POP;
+import static jdk.internal.org.objectweb.asm.Opcodes.D2F;
+import static jdk.internal.org.objectweb.asm.Opcodes.H_INVOKESTATIC;
+import static jdk.internal.org.objectweb.asm.Opcodes.I2B;
+import static jdk.internal.org.objectweb.asm.Opcodes.I2S;
 import static jdk.internal.org.objectweb.asm.Opcodes.RETURN;
+import static jdk.nashorn.internal.codegen.CompilerConstants.interfaceCallNoLookup;
+import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
 import static jdk.nashorn.internal.lookup.Lookup.MH;
 import static jdk.nashorn.internal.runtime.linker.AdaptationResult.Outcome.ERROR_NO_ACCESSIBLE_CONSTRUCTOR;
 
+import java.lang.invoke.CallSite;
 import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles.Lookup;
 import java.lang.invoke.MethodType;
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Constructor;
@@ -56,9 +58,7 @@
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import jdk.internal.org.objectweb.asm.ClassWriter;
 import jdk.internal.org.objectweb.asm.Handle;
@@ -67,8 +67,7 @@
 import jdk.internal.org.objectweb.asm.Type;
 import jdk.internal.org.objectweb.asm.commons.InstructionAdapter;
 import jdk.nashorn.api.scripting.ScriptUtils;
-import jdk.nashorn.internal.runtime.Context;
-import jdk.nashorn.internal.runtime.JSType;
+import jdk.nashorn.internal.codegen.CompilerConstants.Call;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.linker.AdaptationResult.Outcome;
@@ -86,8 +85,7 @@
  * dispatched by name. A single JavaScript function will act as the implementation for all overloaded methods of the
  * same name. When methods on an adapter instance are invoked, the functions are invoked having the ScriptObject passed
  * in the instance constructor as their "this". Subsequent changes to the ScriptObject (reassignment or removal of its
- * functions) are not reflected in the adapter instance; the method implementations are bound to functions at
- * constructor invocation time.
+ * functions) will be reflected in the adapter instance as it is live dispatching to its members on every method invocation.
  * {@code java.lang.Object} methods {@code equals}, {@code hashCode}, and {@code toString} can also be overridden. The
  * only restriction is that since every JavaScript object already has a {@code toString} function through the
  * {@code Object.prototype}, the {@code toString} in the adapter is only overridden if the passed ScriptObject has a
@@ -104,7 +102,7 @@
  * strict or not.
  * </li>
  * <li>
- * If the adapter being generated can have class-level overrides, constructors taking same arguments as the superclass
+ * If the adapter being generated has class-level overrides, constructors taking same arguments as the superclass
  * constructors are created. These constructors simply delegate to the superclass constructor. They are simply used to
  * create instances of the adapter class, with no instance-level overrides, as they don't have them. If the original
  * class' constructor was variable arity, the adapter constructor will also be variable arity. Protected constructors
@@ -115,7 +113,7 @@
  * For adapter methods that return values, all the JavaScript-to-Java conversions supported by Nashorn will be in effect
  * to coerce the JavaScript function return value to the expected Java return type.
  * </p><p>
- * Since we are adding a trailing argument to the generated constructors in the adapter class, they will never be
+ * Since we are adding a trailing argument to the generated constructors in the adapter class with instance-level overrides, they will never be
  * declared as variable arity, even if the original constructor in the superclass was declared as variable arity. The
  * reason we are passing the additional argument at the end of the argument list instead at the front is that the
  * source-level script expression <code>new X(a, b) { ... }</code> (which is a proprietary syntax extension Nashorn uses
@@ -137,51 +135,67 @@
  * implemented securely.
  */
 final class JavaAdapterBytecodeGenerator {
-    private static final Type SCRIPTUTILS_TYPE = Type.getType(ScriptUtils.class);
+    // Field names in adapters
+    private static final String GLOBAL_FIELD_NAME = "global";
+    private static final String DELEGATE_FIELD_NAME = "delegate";
+    private static final String IS_FUNCTION_FIELD_NAME = "isFunction";
+    private static final String CALL_THIS_FIELD_NAME = "callThis";
+
+    // Initializer names
+    private static final String INIT = "<init>";
+    private static final String CLASS_INIT = "<clinit>";
+
+    // Types often used in generated bytecode
     private static final Type OBJECT_TYPE = Type.getType(Object.class);
-    private static final Type CLASS_TYPE  = Type.getType(Class.class);
-
-    static final String OBJECT_TYPE_NAME  = OBJECT_TYPE.getInternalName();
-    static final String SCRIPTUTILS_TYPE_NAME  = SCRIPTUTILS_TYPE.getInternalName();
-
-    static final String INIT = "<init>";
-
-    static final String GLOBAL_FIELD_NAME = "global";
-
-    // "global" is declared as Object instead of Global - avoid static references to internal Nashorn classes when possible.
-    static final String GLOBAL_TYPE_DESCRIPTOR = OBJECT_TYPE.getDescriptor();
-
-    static final String SET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE);
-    static final String VOID_NOARG_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE);
-
     private static final Type SCRIPT_OBJECT_TYPE = Type.getType(ScriptObject.class);
     private static final Type SCRIPT_FUNCTION_TYPE = Type.getType(ScriptFunction.class);
-    private static final Type STRING_TYPE = Type.getType(String.class);
-    private static final Type METHOD_TYPE_TYPE = Type.getType(MethodType.class);
-    private static final Type METHOD_HANDLE_TYPE = Type.getType(MethodHandle.class);
-    private static final String GET_HANDLE_OBJECT_DESCRIPTOR = Type.getMethodDescriptor(METHOD_HANDLE_TYPE,
-            OBJECT_TYPE, STRING_TYPE, METHOD_TYPE_TYPE);
-    private static final String GET_HANDLE_FUNCTION_DESCRIPTOR = Type.getMethodDescriptor(METHOD_HANDLE_TYPE,
-            SCRIPT_FUNCTION_TYPE, METHOD_TYPE_TYPE);
-    private static final String GET_CLASS_INITIALIZER_DESCRIPTOR = Type.getMethodDescriptor(OBJECT_TYPE);
-    private static final Type RUNTIME_EXCEPTION_TYPE = Type.getType(RuntimeException.class);
-    private static final Type THROWABLE_TYPE = Type.getType(Throwable.class);
-    private static final Type UNSUPPORTED_OPERATION_TYPE = Type.getType(UnsupportedOperationException.class);
 
-    private static final String SERVICES_CLASS_TYPE_NAME = Type.getInternalName(JavaAdapterServices.class);
-    private static final String RUNTIME_EXCEPTION_TYPE_NAME = RUNTIME_EXCEPTION_TYPE.getInternalName();
+    // JavaAdapterServices methods used in generated bytecode
+    private static final Call CHECK_FUNCTION = lookupServiceMethod("checkFunction", ScriptFunction.class, Object.class, String.class);
+    private static final Call EXPORT_RETURN_VALUE = lookupServiceMethod("exportReturnValue", Object.class, Object.class);
+    private static final Call GET_CALL_THIS = lookupServiceMethod("getCallThis", Object.class, ScriptFunction.class, Object.class);
+    private static final Call GET_CLASS_OVERRIDES = lookupServiceMethod("getClassOverrides", ScriptObject.class);
+    private static final Call GET_NON_NULL_GLOBAL = lookupServiceMethod("getNonNullGlobal", ScriptObject.class);
+    private static final Call HAS_OWN_TO_STRING = lookupServiceMethod("hasOwnToString", boolean.class, ScriptObject.class);
+    private static final Call INVOKE_NO_PERMISSIONS = lookupServiceMethod("invokeNoPermissions", void.class, MethodHandle.class, Object.class);
+    private static final Call NOT_AN_OBJECT = lookupServiceMethod("notAnObject", void.class, Object.class);
+    private static final Call SET_GLOBAL = lookupServiceMethod("setGlobal", Runnable.class, ScriptObject.class);
+    private static final Call TO_CHAR_PRIMITIVE = lookupServiceMethod("toCharPrimitive", char.class, Object.class);
+    private static final Call UNSUPPORTED = lookupServiceMethod("unsupported", UnsupportedOperationException.class);
+    private static final Call WRAP_THROWABLE = lookupServiceMethod("wrapThrowable", RuntimeException.class, Throwable.class);
+
+    // Other methods invoked by the generated bytecode
+    private static final Call UNWRAP = staticCallNoLookup(ScriptUtils.class, "unwrap", Object.class, Object.class);
+    private static final Call CHAR_VALUE_OF = staticCallNoLookup(Character.class, "valueOf", Character.class, char.class);
+    private static final Call DOUBLE_VALUE_OF = staticCallNoLookup(Double.class, "valueOf", Double.class, double.class);
+    private static final Call LONG_VALUE_OF = staticCallNoLookup(Long.class, "valueOf", Long.class, long.class);
+    private static final Call RUN = interfaceCallNoLookup(Runnable.class, "run", void.class);
+
+    // ASM handle to the bootstrap method
+    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
+    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,
+                    MethodType.class).toMethodDescriptorString());
+
+    // Field type names used in the generated bytecode
+    private static final String SCRIPT_OBJECT_TYPE_DESCRIPTOR = SCRIPT_OBJECT_TYPE.getDescriptor();
+    private static final String OBJECT_TYPE_DESCRIPTOR = OBJECT_TYPE.getDescriptor();
+    private static final String BOOLEAN_TYPE_DESCRIPTOR = Type.BOOLEAN_TYPE.getDescriptor();
+
+    // Throwable names used in the generated bytecode
+    private static final String RUNTIME_EXCEPTION_TYPE_NAME = Type.getInternalName(RuntimeException.class);
     private static final String ERROR_TYPE_NAME = Type.getInternalName(Error.class);
-    private static final String THROWABLE_TYPE_NAME = THROWABLE_TYPE.getInternalName();
-    private static final String UNSUPPORTED_OPERATION_TYPE_NAME = UNSUPPORTED_OPERATION_TYPE.getInternalName();
+    private static final String THROWABLE_TYPE_NAME = Type.getInternalName(Throwable.class);
 
-    private static final String METHOD_HANDLE_TYPE_DESCRIPTOR = METHOD_HANDLE_TYPE.getDescriptor();
-    private static final String GET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(OBJECT_TYPE);
-    private static final String GET_CLASS_METHOD_DESCRIPTOR = Type.getMethodDescriptor(CLASS_TYPE);
-    private static final String EXPORT_RETURN_VALUE_METHOD_DESCRIPTOR = Type.getMethodDescriptor(OBJECT_TYPE, OBJECT_TYPE);
-    private static final String UNWRAP_METHOD_DESCRIPTOR = Type.getMethodDescriptor(OBJECT_TYPE, OBJECT_TYPE);
-    private static final String GET_CONVERTER_METHOD_DESCRIPTOR = Type.getMethodDescriptor(METHOD_HANDLE_TYPE, CLASS_TYPE);
-    private static final String TO_CHAR_PRIMITIVE_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.CHAR_TYPE, OBJECT_TYPE);
-    private static final String TO_STRING_METHOD_DESCRIPTOR = Type.getMethodDescriptor(STRING_TYPE, OBJECT_TYPE);
+    // Some more frequently used method descriptors
+    private static final String GET_METHOD_PROPERTY_METHOD_DESCRIPTOR = Type.getMethodDescriptor(OBJECT_TYPE, SCRIPT_OBJECT_TYPE);
+    private static final String VOID_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE);
 
     // Package used when the adapter can't be defined in the adaptee's package (either because it's sealed, or because
     // it's a java.* package.
@@ -191,11 +205,13 @@
     private static final String JAVA_PACKAGE_PREFIX = "java/";
     private static final int MAX_GENERATED_TYPE_NAME_LENGTH = 255;
 
-    private static final String CLASS_INIT = "<clinit>";
-
     // Method name prefix for invoking super-methods
     static final String SUPER_PREFIX = "super$";
 
+    // Method name and type for the no-privilege finalizer delegate
+    private static final String FINALIZER_DELEGATE_NAME = "$$nashornFinalizerDelegate";
+    private static final String FINALIZER_DELEGATE_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE);
+
     /**
      * Collection of methods we never override: Object.clone(), Object.finalize().
      */
@@ -215,30 +231,13 @@
     private final String superClassName;
     // Binary name of the generated class.
     private final String generatedClassName;
-    private final Set<String> usedFieldNames = new HashSet<>();
     private final Set<String> abstractMethodNames = new HashSet<>();
     private final String samName;
     private final Set<MethodInfo> finalMethods = new HashSet<>(EXCLUDED);
     private final Set<MethodInfo> methodInfos = new HashSet<>();
-    private boolean autoConvertibleFromFunction = false;
+    private final boolean autoConvertibleFromFunction;
     private boolean hasExplicitFinalizer = false;
 
-    /**
-     * Names of static fields holding type converter method handles for return value conversion. We are emitting code
-     * for invoking these explicitly after the delegate handle is invoked, instead of doing an asType or
-     * filterReturnValue on the delegate handle, as that would create a new converter handle wrapping the function's
-     * handle for every instance of the adapter, causing the handle.invokeExact() call sites to become megamorphic.
-     */
-    private final Map<Class<?>, String> converterFields = new LinkedHashMap<>();
-
-    /**
-     * Subset of possible return types for all methods; namely, all possible return types of the SAM methods (we
-     * identify SAM types by having all of their abstract methods share a single name, so there can be multiple
-     * overloads with multiple return types. We use this set when emitting the constructor taking a ScriptFunction (the
-     * SAM initializer) to avoid populating converter fields that will never be used by SAM methods.
-     */
-    private final Set<Class<?>> samReturnTypes = new HashSet<>();
-
     private final ClassWriter cw;
 
     /**
@@ -271,17 +270,22 @@
         generatedClassName = getGeneratedClassName(superClass, interfaces);
 
         cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER, generatedClassName, null, superClassName, getInternalTypeNames(interfaces));
-        generateGlobalFields();
+        generateField(GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+        generateField(DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
 
         gatherMethods(superClass);
         gatherMethods(interfaces);
-        samName = abstractMethodNames.size() == 1 ? abstractMethodNames.iterator().next() : null;
-        generateHandleFields();
-        generateConverterFields();
+        if (abstractMethodNames.size() == 1) {
+            samName = abstractMethodNames.iterator().next();
+            generateField(CALL_THIS_FIELD_NAME, OBJECT_TYPE_DESCRIPTOR);
+            generateField(IS_FUNCTION_FIELD_NAME, BOOLEAN_TYPE_DESCRIPTOR);
+        } else {
+            samName = null;
+        }
         if(classOverride) {
             generateClassInit();
         }
-        generateConstructors();
+        autoConvertibleFromFunction = generateConstructors();
         generateMethods();
         generateSuperMethods();
         if (hasExplicitFinalizer) {
@@ -291,9 +295,8 @@
         cw.visitEnd();
     }
 
-    private void generateGlobalFields() {
-        cw.visitField(ACC_PRIVATE | ACC_FINAL | (classOverride ? ACC_STATIC : 0), GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR, null, null).visitEnd();
-        usedFieldNames.add(GLOBAL_FIELD_NAME);
+    private void generateField(final String name, final String fieldDesc) {
+        cw.visitField(ACC_PRIVATE | ACC_FINAL | (classOverride ? ACC_STATIC : 0), name, fieldDesc, null, null).visitEnd();
     }
 
     JavaAdapterClassLoader createAdapterClassLoader() {
@@ -343,154 +346,84 @@
         return interfaceNames;
     }
 
-    private void generateHandleFields() {
-        final int flags = ACC_PRIVATE | ACC_FINAL | (classOverride ? ACC_STATIC : 0);
-        for (final MethodInfo mi: methodInfos) {
-            cw.visitField(flags, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR, null, null).visitEnd();
+    private void generateClassInit() {
+        final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_STATIC, CLASS_INIT,
+                VOID_METHOD_DESCRIPTOR, null, null));
+
+        // Assign "global = Context.getGlobal()"
+        GET_NON_NULL_GLOBAL.invoke(mv);
+        mv.putstatic(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+
+        GET_CLASS_OVERRIDES.invoke(mv);
+        if(samName != null) {
+            // If the class is a SAM, allow having ScriptFunction passed as class overrides
+            mv.dup();
+            mv.instanceOf(SCRIPT_FUNCTION_TYPE);
+            mv.dup();
+            mv.putstatic(generatedClassName, IS_FUNCTION_FIELD_NAME, BOOLEAN_TYPE_DESCRIPTOR);
+            final Label notFunction = new Label();
+            mv.ifeq(notFunction);
+            mv.dup();
+            mv.checkcast(SCRIPT_FUNCTION_TYPE);
+            emitInitCallThis(mv);
+            mv.visitLabel(notFunction);
+        }
+        mv.putstatic(generatedClassName, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+
+        endInitMethod(mv);
+    }
+
+    /**
+     * Emit bytecode for initializing the "callThis" field.
+     */
+    private void emitInitCallThis(final InstructionAdapter mv) {
+        loadField(mv, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+        GET_CALL_THIS.invoke(mv);
+        if(classOverride) {
+            mv.putstatic(generatedClassName, CALL_THIS_FIELD_NAME, OBJECT_TYPE_DESCRIPTOR);
+        } else {
+            // It is presumed ALOAD 0 was already executed
+            mv.putfield(generatedClassName, CALL_THIS_FIELD_NAME, OBJECT_TYPE_DESCRIPTOR);
         }
     }
 
-    private void generateConverterFields() {
-        final int flags = ACC_PRIVATE | ACC_FINAL | (classOverride ? ACC_STATIC : 0);
-        for (final MethodInfo mi: methodInfos) {
-            final Class<?> returnType = mi.type.returnType();
-            // Handle primitive types, Object, and String specially
-            if(!returnType.isPrimitive() && returnType != Object.class && returnType != String.class) {
-                if(!converterFields.containsKey(returnType)) {
-                    final String name = nextName("convert");
-                    converterFields.put(returnType, name);
-                    if(mi.getName().equals(samName)) {
-                        samReturnTypes.add(returnType);
-                    }
-                    cw.visitField(flags, name, METHOD_HANDLE_TYPE_DESCRIPTOR, null, null).visitEnd();
-                }
-            }
-        }
-    }
-
-    private void generateClassInit() {
-        final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_STATIC, CLASS_INIT,
-                Type.getMethodDescriptor(Type.VOID_TYPE), null, null));
-
-        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getClassOverrides", GET_CLASS_INITIALIZER_DESCRIPTOR, false);
-        final Label initGlobal;
-        if(samName != null) {
-            // If the class is a SAM, allow having a ScriptFunction passed as class overrides
-            final Label notAFunction = new Label();
-            mv.dup();
-            mv.instanceOf(SCRIPT_FUNCTION_TYPE);
-            mv.ifeq(notAFunction);
-            mv.checkcast(SCRIPT_FUNCTION_TYPE);
-
-            // Assign MethodHandle fields through invoking getHandle() for a ScriptFunction, only assigning the SAM
-            // method(s).
-            for (final MethodInfo mi : methodInfos) {
-                if(mi.getName().equals(samName)) {
-                    mv.dup();
-                    loadMethodTypeAndGetHandle(mv, mi, GET_HANDLE_FUNCTION_DESCRIPTOR);
-                } else {
-                    mv.visitInsn(ACONST_NULL);
-                }
-                mv.putstatic(generatedClassName, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR);
-            }
-            initGlobal = new Label();
-            mv.goTo(initGlobal);
-            mv.visitLabel(notAFunction);
-        } else {
-            initGlobal = null;
-        }
-        // Assign MethodHandle fields through invoking getHandle() for a ScriptObject
-        for (final MethodInfo mi : methodInfos) {
-            mv.dup();
-            mv.aconst(mi.getName());
-            loadMethodTypeAndGetHandle(mv, mi, GET_HANDLE_OBJECT_DESCRIPTOR);
-            mv.putstatic(generatedClassName, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR);
-        }
-
-        if(initGlobal != null) {
-            mv.visitLabel(initGlobal);
-        }
-        // Assign "global = Context.getGlobal()"
-        invokeGetGlobalWithNullCheck(mv);
-        mv.putstatic(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
-
-        generateConverterInit(mv, false);
-        endInitMethod(mv);
-    }
-
-    private void generateConverterInit(final InstructionAdapter mv, final boolean samOnly) {
-        assert !samOnly || !classOverride;
-        for(final Map.Entry<Class<?>, String> converterField: converterFields.entrySet()) {
-            final Class<?> returnType = converterField.getKey();
-            if(!classOverride) {
-                mv.visitVarInsn(ALOAD, 0);
-            }
-
-            if(samOnly && !samReturnTypes.contains(returnType)) {
-                mv.visitInsn(ACONST_NULL);
-            } else {
-                mv.aconst(Type.getType(converterField.getKey()));
-                mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getObjectConverter", GET_CONVERTER_METHOD_DESCRIPTOR, false);
-            }
-
-            if(classOverride) {
-                mv.putstatic(generatedClassName, converterField.getValue(), METHOD_HANDLE_TYPE_DESCRIPTOR);
-            } else {
-                mv.putfield(generatedClassName, converterField.getValue(), METHOD_HANDLE_TYPE_DESCRIPTOR);
-            }
-        }
-    }
-
-    private static void loadMethodTypeAndGetHandle(final InstructionAdapter mv, final MethodInfo mi, final String getHandleDescriptor) {
-        // NOTE: we're using generic() here because we'll be linking to the "generic" invoker version of
-        // the functions anyway, so we cut down on megamorphism in the invokeExact() calls in adapter
-        // bodies. Once we start linking to type-specializing invokers, this should be changed.
-        mv.aconst(Type.getMethodType(mi.type.generic().toMethodDescriptorString()));
-        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", getHandleDescriptor, false);
-    }
-
-    private static void invokeGetGlobalWithNullCheck(final InstructionAdapter mv) {
-        invokeGetGlobal(mv);
-        mv.dup();
-        mv.invokevirtual(OBJECT_TYPE_NAME, "getClass", GET_CLASS_METHOD_DESCRIPTOR, false); // check against null Context
-        mv.pop();
-    }
-
-    private void generateConstructors() throws AdaptationException {
+    private boolean generateConstructors() throws AdaptationException {
         boolean gotCtor = false;
+        boolean canBeAutoConverted = false;
         for (final Constructor<?> ctor: superClass.getDeclaredConstructors()) {
             final int modifier = ctor.getModifiers();
             if((modifier & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0 && !isCallerSensitive(ctor)) {
-                generateConstructors(ctor);
+                canBeAutoConverted = generateConstructors(ctor) | canBeAutoConverted;
                 gotCtor = true;
             }
         }
         if(!gotCtor) {
             throw new AdaptationException(ERROR_NO_ACCESSIBLE_CONSTRUCTOR, superClass.getCanonicalName());
         }
+        return canBeAutoConverted;
     }
 
-    private void generateConstructors(final Constructor<?> ctor) {
+    private boolean generateConstructors(final Constructor<?> ctor) {
         if(classOverride) {
             // Generate a constructor that just delegates to ctor. This is used with class-level overrides, when we want
             // to create instances without further per-instance overrides.
             generateDelegatingConstructor(ctor);
-        } else {
-            // Generate a constructor that delegates to ctor, but takes an additional ScriptObject parameter at the
-            // beginning of its parameter list.
-            generateOverridingConstructor(ctor, false);
+            return false;
+        }
 
-            if (samName != null) {
-                if (!autoConvertibleFromFunction && ctor.getParameterTypes().length == 0) {
-                    // If the original type only has a single abstract method name, as well as a default ctor, then it can
-                    // be automatically converted from JS function.
-                    autoConvertibleFromFunction = true;
-                }
-                // If all our abstract methods have a single name, generate an additional constructor, one that takes a
-                // ScriptFunction as its first parameter and assigns it as the implementation for all abstract methods.
-                generateOverridingConstructor(ctor, true);
-            }
+        // Generate a constructor that delegates to ctor, but takes an additional ScriptObject parameter at the
+        // beginning of its parameter list.
+        generateOverridingConstructor(ctor, false);
+
+        if (samName == null) {
+            return false;
         }
+        // If all our abstract methods have a single name, generate an additional constructor, one that takes a
+        // ScriptFunction as its first parameter and assigns it as the implementation for all abstract methods.
+        generateOverridingConstructor(ctor, true);
+        // If the original type only has a single abstract method name, as well as a default ctor, then it can
+        // be automatically converted from JS function.
+        return ctor.getParameterTypes().length == 0;
     }
 
     private void generateDelegatingConstructor(final Constructor<?> ctor) {
@@ -503,14 +436,7 @@
                 Type.getMethodDescriptor(originalCtorType.getReturnType(), argTypes), null, null));
 
         mv.visitCode();
-        // Invoke super constructor with the same arguments.
-        mv.visitVarInsn(ALOAD, 0);
-        int offset = 1; // First arg is at position 1, after this.
-        for (final Type argType: argTypes) {
-            mv.load(offset, argType);
-            offset += argType.getSize();
-        }
-        mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor(), false);
+        emitSuperConstructorCall(mv, originalCtorType.getDescriptor());
 
         endInitMethod(mv);
     }
@@ -548,80 +474,54 @@
         System.arraycopy(originalArgTypes, 0, newArgTypes, 0, argLen);
 
         // All constructors must be public, even if in the superclass they were protected.
-        // Existing super constructor <init>(this, args...) triggers generating <init>(this, args..., scriptObj).
+        // Existing super constructor <init>(this, args...) triggers generating <init>(this, args..., delegate).
         // Any variable arity constructors become fixed-arity with explicit array arguments.
         final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
                 Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
 
         mv.visitCode();
-        // First, invoke super constructor with original arguments. If the form of the constructor we're generating is
-        // <init>(this, args..., scriptFn), then we're invoking super.<init>(this, args...).
-        mv.visitVarInsn(ALOAD, 0);
-        final Class<?>[] argTypes = ctor.getParameterTypes();
-        int offset = 1; // First arg is at position 1, after this.
-        for (int i = 0; i < argLen; ++i) {
-            final Type argType = Type.getType(argTypes[i]);
-            mv.load(offset, argType);
-            offset += argType.getSize();
-        }
-        mv.invokespecial(superClassName, INIT, originalCtorType.getDescriptor(), false);
-
-        // Get a descriptor to the appropriate "JavaAdapterFactory.getHandle" method.
-        final String getHandleDescriptor = fromFunction ? GET_HANDLE_FUNCTION_DESCRIPTOR : GET_HANDLE_OBJECT_DESCRIPTOR;
-
-        // Assign MethodHandle fields through invoking getHandle()
-        for (final MethodInfo mi : methodInfos) {
-            mv.visitVarInsn(ALOAD, 0);
-            if (fromFunction && !mi.getName().equals(samName)) {
-                // Constructors initializing from a ScriptFunction only initialize methods with the SAM name.
-                // NOTE: if there's a concrete overloaded method sharing the SAM name, it'll be overridden too. This
-                // is a deliberate design choice. All other method handles are initialized to null.
-                mv.visitInsn(ACONST_NULL);
-            } else {
-                mv.visitVarInsn(ALOAD, offset);
-                if(!fromFunction) {
-                    mv.aconst(mi.getName());
-                }
-                loadMethodTypeAndGetHandle(mv, mi, getHandleDescriptor);
-            }
-            mv.putfield(generatedClassName, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR);
-        }
+        // First, invoke super constructor with original arguments.
+        final int extraArgOffset = emitSuperConstructorCall(mv, originalCtorType.getDescriptor());
 
         // Assign "this.global = Context.getGlobal()"
         mv.visitVarInsn(ALOAD, 0);
-        invokeGetGlobalWithNullCheck(mv);
-        mv.putfield(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
+        GET_NON_NULL_GLOBAL.invoke(mv);
+        mv.putfield(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
 
-        // Initialize converters
-        generateConverterInit(mv, fromFunction);
+        // Assign "this.delegate = delegate"
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitVarInsn(ALOAD, extraArgOffset);
+        mv.putfield(generatedClassName, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+
+        if (fromFunction) {
+            // Assign "isFunction = true"
+            mv.visitVarInsn(ALOAD, 0);
+            mv.iconst(1);
+            mv.putfield(generatedClassName, IS_FUNCTION_FIELD_NAME, BOOLEAN_TYPE_DESCRIPTOR);
+
+            mv.visitVarInsn(ALOAD, 0);
+            mv.visitVarInsn(ALOAD, extraArgOffset);
+            emitInitCallThis(mv);
+        }
+
         endInitMethod(mv);
 
         if (! fromFunction) {
             newArgTypes[argLen] = OBJECT_TYPE;
             final InstructionAdapter mv2 = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
                     Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
-            generateOverridingConstructorWithObjectParam(mv2, ctor, originalCtorType.getDescriptor());
+            generateOverridingConstructorWithObjectParam(mv2, originalCtorType.getDescriptor());
         }
     }
 
     // Object additional param accepting constructor - generated to handle null and undefined value
     // for script adapters. This is effectively to throw TypeError on such script adapters. See
     // JavaAdapterServices.getHandle as well.
-    private void generateOverridingConstructorWithObjectParam(final InstructionAdapter mv, final Constructor<?> ctor, final String ctorDescriptor) {
+    private void generateOverridingConstructorWithObjectParam(final InstructionAdapter mv, final String ctorDescriptor) {
         mv.visitCode();
-        mv.visitVarInsn(ALOAD, 0);
-        final Class<?>[] argTypes = ctor.getParameterTypes();
-        int offset = 1; // First arg is at position 1, after this.
-        for (int i = 0; i < argTypes.length; ++i) {
-            final Type argType = Type.getType(argTypes[i]);
-            mv.load(offset, argType);
-            offset += argType.getSize();
-        }
-        mv.invokespecial(superClassName, INIT, ctorDescriptor, false);
-        mv.visitVarInsn(ALOAD, offset);
-        mv.visitInsn(ACONST_NULL);
-        mv.visitInsn(ACONST_NULL);
-        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getHandle", GET_HANDLE_OBJECT_DESCRIPTOR, false);
+        final int extraArgOffset = emitSuperConstructorCall(mv, ctorDescriptor);
+        mv.visitVarInsn(ALOAD, extraArgOffset);
+        NOT_AN_OBJECT.invoke(mv);
         endInitMethod(mv);
     }
 
@@ -635,14 +535,6 @@
         mv.visitEnd();
     }
 
-    private static void invokeGetGlobal(final InstructionAdapter mv) {
-        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getGlobal", GET_GLOBAL_METHOD_DESCRIPTOR, false);
-    }
-
-    private static void invokeSetGlobal(final InstructionAdapter mv) {
-        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR, false);
-    }
-
     /**
      * Encapsulation of the information used to generate methods in the adapter classes. Basically, a wrapper around the
      * reflective Method object, a cached MethodType, and the name of the field in the adapter class that will hold the
@@ -652,7 +544,6 @@
     private static class MethodInfo {
         private final Method method;
         private final MethodType type;
-        private String methodHandleFieldName;
 
         private MethodInfo(final Class<?> clazz, final String name, final Class<?>... argTypes) throws NoSuchMethodException {
             this(clazz.getDeclaredMethod(name, argTypes));
@@ -681,21 +572,6 @@
         public int hashCode() {
             return getName().hashCode() ^ type.hashCode();
         }
-
-        void setIsCanonical(final JavaAdapterBytecodeGenerator self) {
-            methodHandleFieldName = self.nextName(getName());
-        }
-    }
-
-    private String nextName(final String name) {
-        int i = 0;
-        String nextName = name;
-        while (!usedFieldNames.add(nextName)) {
-            final String ordinal = String.valueOf(i++);
-            final int maxNameLen = 255 - ordinal.length();
-            nextName = (name.length() <= maxNameLen ? name : name.substring(0, maxNameLen)).concat(ordinal);
-        }
-        return nextName;
     }
 
     private void generateMethods() {
@@ -705,18 +581,25 @@
     }
 
     /**
-     * Generates a method in the adapter class that adapts a method from the original class. The generated methods will
-     * inspect the method handle field assigned to them. If it is null (the JS object doesn't provide an implementation
-     * for the method) then it will either invoke its version in the supertype, or if it is abstract, throw an
-     * {@link UnsupportedOperationException}. Otherwise, if the method handle field's value is not null, the handle is
-     * invoked using invokeExact (signature polymorphic invocation as per JLS 15.12.3). Before the invocation, the
-     * current Nashorn {@link Context} is checked, and if it is different than the global used to create the adapter
-     * instance, the creating global is set to be the current global. In this case, the previously current global is
-     * restored after the invocation. If invokeExact results in a Throwable that is not one of the method's declared
-     * exceptions, and is not an unchecked throwable, then it is wrapped into a {@link RuntimeException} and the runtime
-     * exception is thrown. The method handle retrieved from the field is guaranteed to exactly match the signature of
-     * the method; this is guaranteed by the way constructors of the adapter class obtain them using
-     * {@link #getHandle(Object, String, MethodType, boolean)}.
+     * Generates a method in the adapter class that adapts a method from the
+     * original class. The generated method will either invoke the delegate
+     * using a CALL dynamic operation call site (if it is a SAM method and the
+     * delegate is a ScriptFunction), or invoke GET_METHOD_PROPERTY dynamic
+     * operation with the method name as the argument and then invoke the
+     * returned ScriptFunction using the CALL dynamic operation. If
+     * GET_METHOD_PROPERTY returns null or undefined (that is, the JS object
+     * doesn't provide an implementation for the method) then the method will
+     * either do a super invocation to base class, or if the method is abstract,
+     * throw an {@link UnsupportedOperationException}. Finally, if
+     * GET_METHOD_PROPERTY returns something other than a ScriptFunction, null,
+     * or undefined, a TypeError is thrown. The current Global is checked before
+     * the dynamic operations, and if it is different  than the Global used to
+     * create the adapter, the creating Global is set to be the current Global.
+     * In this case, the previously current Global is restored after the
+     * invocation. If CALL results in a Throwable that is not one of the
+     * method's declared exceptions, and is not an unchecked throwable, then it
+     * is wrapped into a {@link RuntimeException} and the runtime exception is
+     * thrown.
      * @param mi the method info describing the method to be generated.
      */
     private void generateMethod(final MethodInfo mi) {
@@ -734,109 +617,158 @@
                 methodDesc, null, exceptionNames));
         mv.visitCode();
 
-        final Label handleDefined = new Label();
-
         final Class<?> returnType = type.returnType();
         final Type asmReturnType = Type.getType(returnType);
 
-        // See if we have overriding method handle defined
-        if(classOverride) {
-            mv.getstatic(generatedClassName, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR);
-        } else {
-            mv.visitVarInsn(ALOAD, 0);
-            mv.getfield(generatedClassName, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR);
-        }
-        // stack: [handle]
-        mv.visitInsn(DUP);
-        mv.visitJumpInsn(IFNONNULL, handleDefined);
-
-        // No handle is available, fall back to default behavior
-        if(Modifier.isAbstract(method.getModifiers())) {
-            // If the super method is abstract, throw an exception
-            mv.anew(UNSUPPORTED_OPERATION_TYPE);
-            mv.dup();
-            mv.invokespecial(UNSUPPORTED_OPERATION_TYPE_NAME, INIT, VOID_NOARG_METHOD_DESCRIPTOR, false);
-            mv.athrow();
-        } else {
-            mv.visitInsn(POP);
-            // If the super method is not abstract, delegate to it.
-            emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);
-        }
-
-        mv.visitLabel(handleDefined);
-        // Load the creatingGlobal object
-        if(classOverride) {
-            // If class handle is defined, load the static defining global
-            mv.getstatic(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
-        } else {
-            mv.visitVarInsn(ALOAD, 0);
-            mv.getfield(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
-        }
-        // stack: [creatingGlobal, handle]
-        final Label setupGlobal = new Label();
-        mv.visitLabel(setupGlobal);
-
         // Determine the first index for a local variable
         int nextLocalVar = 1; // "this" is at 0
         for(final Type t: asmArgTypes) {
             nextLocalVar += t.getSize();
         }
-        // Set our local variable indices
-        final int currentGlobalVar  = nextLocalVar++;
-        final int globalsDifferVar  = nextLocalVar++;
+        // Set our local variable index
+        final int globalRestoringRunnableVar = nextLocalVar++;
 
+        // Load the creatingGlobal object
+        loadField(mv, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+
+        // stack: [creatingGlobal]
+        SET_GLOBAL.invoke(mv);
+        // stack: [runnable]
+        mv.visitVarInsn(ASTORE, globalRestoringRunnableVar);
+        // stack: []
+
+        final Label tryBlockStart = new Label();
+        mv.visitLabel(tryBlockStart);
+
+        final Label callCallee = new Label();
+        final Label defaultBehavior = new Label();
+        // If this is a SAM type...
+        if (samName != null) {
+            // ...every method will be checking whether we're initialized with a
+            // function.
+            loadField(mv, IS_FUNCTION_FIELD_NAME, BOOLEAN_TYPE_DESCRIPTOR);
+            // stack: [isFunction]
+            if (name.equals(samName)) {
+                final Label notFunction = new Label();
+                mv.ifeq(notFunction);
+                // stack: []
+                // If it's a SAM method, it'll load delegate as the "callee" and
+                // "callThis" as "this" for the call if delegate is a function.
+                loadField(mv, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+                // NOTE: if we added "mv.checkcast(SCRIPT_FUNCTION_TYPE);" here
+                // we could emit the invokedynamic CALL instruction with signature
+                // (ScriptFunction, Object, ...) instead of (Object, Object, ...).
+                // We could combine this with an optimization in
+                // ScriptFunction.findCallMethod where it could link a call with a
+                // thinner guard when the call site statically guarantees that the
+                // callee argument is a ScriptFunction. Additionally, we could use
+                // a "ScriptFunction function" field in generated classes instead
+                // of a "boolean isFunction" field to avoid the checkcast.
+                loadField(mv, CALL_THIS_FIELD_NAME, OBJECT_TYPE_DESCRIPTOR);
+                // stack: [callThis, delegate]
+                mv.goTo(callCallee);
+                mv.visitLabel(notFunction);
+            } else {
+                // If it's not a SAM method, and the delegate is a function,
+                // it'll fall back to default behavior
+                mv.ifne(defaultBehavior);
+                // stack: []
+            }
+        }
+
+        // At this point, this is either not a SAM method or the delegate is
+        // not a ScriptFunction. We need to emit a GET_METHOD_PROPERTY Nashorn
+        // invokedynamic.
+
+        if(name.equals("toString")) {
+            // Since every JS Object has a toString, we only override
+            // "String toString()" it if it's explicitly specified on the object.
+            loadField(mv, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
+            // stack: [delegate]
+            HAS_OWN_TO_STRING.invoke(mv);
+            // stack: [hasOwnToString]
+            mv.ifeq(defaultBehavior);
+        }
+
+        loadField(mv, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
         mv.dup();
-        // stack: [creatingGlobal, creatingGlobal, handle]
+        // stack: [delegate, delegate]
+        final String encodedName = NameCodec.encode(name);
+        mv.visitInvokeDynamicInsn(encodedName,
+                GET_METHOD_PROPERTY_METHOD_DESCRIPTOR, BOOTSTRAP_HANDLE,
+                NashornCallSiteDescriptor.GET_METHOD_PROPERTY);
+        // stack: [callee, delegate]
+        mv.visitLdcInsn(name);
+        // stack: [name, callee, delegate]
+        CHECK_FUNCTION.invoke(mv);
+        // stack: [fnCalleeOrNull, delegate]
+        final Label hasFunction = new Label();
+        mv.dup();
+        // stack: [fnCalleeOrNull, fnCalleeOrNull, delegate]
+        mv.ifnonnull(hasFunction);
+        // stack: [null, delegate]
+        // If it's null or undefined, clear stack and fall back to default
+        // behavior.
+        mv.pop2();
+        // stack: []
 
-        // Emit code for switching to the creating global
-        // Global currentGlobal = Context.getGlobal();
-        invokeGetGlobal(mv);
-        mv.dup();
+        // We can also arrive here from check for "delegate instanceof ScriptFunction"
+        // in a non-SAM method as well as from a check for "hasOwnToString(delegate)"
+        // for a toString delegate.
+        mv.visitLabel(defaultBehavior);
+        final Runnable emitFinally = ()->emitFinally(mv, globalRestoringRunnableVar);
+        final Label normalFinally = new Label();
+        if(Modifier.isAbstract(method.getModifiers())) {
+            // If the super method is abstract, throw UnsupportedOperationException
+            UNSUPPORTED.invoke(mv);
+            // NOTE: no need to invoke emitFinally.run() as we're inside the
+            // tryBlockStart/tryBlockEnd range, so throwing this exception will
+            // transfer control to the rethrow handler and the finally block in it
+            // will execute.
+            mv.athrow();
+        } else {
+            // If the super method is not abstract, delegate to it.
+            emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);
+            mv.goTo(normalFinally);
+        }
 
-        mv.visitVarInsn(ASTORE, currentGlobalVar);
-        // stack: [currentGlobal, creatingGlobal, creatingGlobal, handle]
-        // if(definingGlobal == currentGlobal) {
-        final Label globalsDiffer = new Label();
-        mv.ifacmpne(globalsDiffer);
-        // stack: [creatingGlobal, handle]
-        //     globalsDiffer = false
-        mv.pop();
-        // stack: [handle]
-        mv.iconst(0); // false
-        // stack: [false, handle]
-        final Label invokeHandle = new Label();
-        mv.goTo(invokeHandle);
-        mv.visitLabel(globalsDiffer);
-        // } else {
-        //     Context.setGlobal(definingGlobal);
-        // stack: [creatingGlobal, handle]
-        invokeSetGlobal(mv);
-        // stack: [handle]
-        //     globalsDiffer = true
-        mv.iconst(1);
-        // stack: [true, handle]
+        mv.visitLabel(hasFunction);
+        // stack: [callee, delegate]
+        mv.swap();
+        // stack [delegate, callee]
+        mv.visitLabel(callCallee);
 
-        mv.visitLabel(invokeHandle);
-        mv.visitVarInsn(ISTORE, globalsDifferVar);
-        // stack: [handle]
 
-        // Load all parameters back on stack for dynamic invocation. NOTE: since we're using a generic
-        // Object(Object, Object, ...) type signature for the method, we must box all arguments here.
+        // Load all parameters back on stack for dynamic invocation.
+
         int varOffset = 1;
+        // If the param list length is more than 253 slots, we can't invoke it
+        // directly as with (callee, this) it'll exceed 255.
+        final boolean isVarArgCall = getParamListLengthInSlots(asmArgTypes) > 253;
         for (final Type t : asmArgTypes) {
             mv.load(varOffset, t);
-            boxStackTop(mv, t);
+            convertParam(mv, t, isVarArgCall);
             varOffset += t.getSize();
         }
+        // stack: [args..., callee, delegate]
+
+        // If the resulting parameter list length is too long...
+        if (isVarArgCall) {
+            // ... we pack the parameters (except callee and this) into an array
+            // and use Nashorn vararg invocation.
+            mv.visitInvokeDynamicInsn(NameCodec.EMPTY_NAME,
+                    getArrayCreatorMethodType(type).toMethodDescriptorString(),
+                    CREATE_ARRAY_BOOTSTRAP_HANDLE);
+        }
 
         // Invoke the target method handle
-        final Label tryBlockStart = new Label();
-        mv.visitLabel(tryBlockStart);
-        emitInvokeExact(mv, type.generic());
-        convertReturnValue(mv, returnType, asmReturnType);
-        final Label tryBlockEnd = new Label();
-        mv.visitLabel(tryBlockEnd);
-        emitFinally(mv, currentGlobalVar, globalsDifferVar);
+        mv.visitInvokeDynamicInsn(encodedName,
+                getCallMethodType(isVarArgCall, type).toMethodDescriptorString(),
+                BOOTSTRAP_HANDLE, NashornCallSiteDescriptor.CALL);
+        // stack: [returnValue]
+        convertReturnValue(mv, returnType);
+        mv.visitLabel(normalFinally);
+        emitFinally.run();
         mv.areturn(asmReturnType);
 
         // If Throwable is not declared, we need an adapter from Throwable to RuntimeException
@@ -846,10 +778,7 @@
             // Add "throw new RuntimeException(Throwable)" handler for Throwable
             throwableHandler = new Label();
             mv.visitLabel(throwableHandler);
-            mv.anew(RUNTIME_EXCEPTION_TYPE);
-            mv.dupX1();
-            mv.swap();
-            mv.invokespecial(RUNTIME_EXCEPTION_TYPE_NAME, INIT, Type.getMethodDescriptor(Type.VOID_TYPE, THROWABLE_TYPE), false);
+            WRAP_THROWABLE.invoke(mv);
             // Fall through to rethrow handler
         } else {
             throwableHandler = null;
@@ -857,149 +786,166 @@
         final Label rethrowHandler = new Label();
         mv.visitLabel(rethrowHandler);
         // Rethrow handler for RuntimeException, Error, and all declared exception types
-        emitFinally(mv, currentGlobalVar, globalsDifferVar);
+        emitFinally.run();
         mv.athrow();
-        final Label methodEnd = new Label();
-        mv.visitLabel(methodEnd);
-
-        mv.visitLocalVariable("currentGlobal", GLOBAL_TYPE_DESCRIPTOR, null, setupGlobal, methodEnd, currentGlobalVar);
-        mv.visitLocalVariable("globalsDiffer", Type.BOOLEAN_TYPE.getDescriptor(), null, setupGlobal, methodEnd, globalsDifferVar);
 
         if(throwableDeclared) {
-            mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrowHandler, THROWABLE_TYPE_NAME);
+            mv.visitTryCatchBlock(tryBlockStart, normalFinally, rethrowHandler, THROWABLE_TYPE_NAME);
             assert throwableHandler == null;
         } else {
-            mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrowHandler, RUNTIME_EXCEPTION_TYPE_NAME);
-            mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrowHandler, ERROR_TYPE_NAME);
+            mv.visitTryCatchBlock(tryBlockStart, normalFinally, rethrowHandler, RUNTIME_EXCEPTION_TYPE_NAME);
+            mv.visitTryCatchBlock(tryBlockStart, normalFinally, rethrowHandler, ERROR_TYPE_NAME);
             for(final String excName: exceptionNames) {
-                mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrowHandler, excName);
+                mv.visitTryCatchBlock(tryBlockStart, normalFinally, rethrowHandler, excName);
             }
-            mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, throwableHandler, THROWABLE_TYPE_NAME);
+            mv.visitTryCatchBlock(tryBlockStart, normalFinally, throwableHandler, THROWABLE_TYPE_NAME);
         }
         endMethod(mv);
     }
 
-    private void convertReturnValue(final InstructionAdapter mv, final Class<?> returnType, final Type asmReturnType) {
-        switch(asmReturnType.getSort()) {
-        case Type.VOID:
-            mv.pop();
-            break;
-        case Type.BOOLEAN:
-            JSType.TO_BOOLEAN.invoke(mv);
-            break;
-        case Type.BYTE:
-            JSType.TO_INT32.invoke(mv);
-            mv.visitInsn(Opcodes.I2B);
-            break;
-        case Type.SHORT:
-            JSType.TO_INT32.invoke(mv);
-            mv.visitInsn(Opcodes.I2S);
-            break;
-        case Type.CHAR:
-            // JSType doesn't have a TO_CHAR, so we have services supply us one.
-            mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toCharPrimitive", TO_CHAR_PRIMITIVE_METHOD_DESCRIPTOR, false);
-            break;
-        case Type.INT:
-            JSType.TO_INT32.invoke(mv);
-            break;
-        case Type.LONG:
-            JSType.TO_LONG.invoke(mv);
-            break;
-        case Type.FLOAT:
-            JSType.TO_NUMBER.invoke(mv);
-            mv.visitInsn(Opcodes.D2F);
-            break;
-        case Type.DOUBLE:
-            JSType.TO_NUMBER.invoke(mv);
-            break;
-        default:
-            if(asmReturnType.equals(OBJECT_TYPE)) {
-                // Must hide ConsString (and potentially other internal Nashorn types) from callers
-                mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "exportReturnValue", EXPORT_RETURN_VALUE_METHOD_DESCRIPTOR, false);
-            } else if(asmReturnType.equals(STRING_TYPE)){
-                // Well-known conversion to String. Not using the JSType one as we want to preserve null as null instead
-                // of the string "n,u,l,l".
-                mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "toString", TO_STRING_METHOD_DESCRIPTOR, false);
-            } else {
-                // Invoke converter method handle for everything else. Note that we could have just added an asType or
-                // filterReturnValue to the invoked handle instead, but then every instance would have the function
-                // method handle wrapped in a separate converter method handle, making handle.invokeExact() megamorphic.
-                if(classOverride) {
-                    mv.getstatic(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
-                } else {
-                    mv.visitVarInsn(ALOAD, 0);
-                    mv.getfield(generatedClassName, converterFields.get(returnType), METHOD_HANDLE_TYPE_DESCRIPTOR);
-                }
-                mv.swap();
-                emitInvokeExact(mv, MethodType.methodType(returnType, Object.class));
+    private static MethodType getCallMethodType(final boolean isVarArgCall, final MethodType type) {
+        final Class<?>[] callParamTypes;
+        if (isVarArgCall) {
+            // Variable arity calls are always (Object callee, Object this, Object[] params)
+            callParamTypes = new Class<?>[] { Object.class, Object.class, Object[].class };
+        } else {
+            // Adjust invocation type signature for conversions we instituted in
+            // convertParam; also, byte and short get passed as ints.
+            final Class<?>[] origParamTypes = type.parameterArray();
+            callParamTypes = new Class<?>[origParamTypes.length + 2];
+            callParamTypes[0] = Object.class; // callee; could be ScriptFunction.class ostensibly
+            callParamTypes[1] = Object.class; // this
+            for(int i = 0; i < origParamTypes.length; ++i) {
+                callParamTypes[i + 2] = getNashornParamType(origParamTypes[i], false);
             }
         }
+        return MethodType.methodType(getNashornReturnType(type.returnType()), callParamTypes);
+    }
+
+    private static MethodType getArrayCreatorMethodType(final MethodType type) {
+        final Class<?>[] callParamTypes = type.parameterArray();
+        for(int i = 0; i < callParamTypes.length; ++i) {
+            callParamTypes[i] = getNashornParamType(callParamTypes[i], true);
+        }
+        return MethodType.methodType(Object[].class, callParamTypes);
+    }
+
+    private static Class<?> getNashornParamType(final Class<?> clazz, final boolean varArg) {
+        if (clazz == byte.class || clazz == short.class) {
+            return int.class;
+        } else if (clazz == float.class) {
+            // If using variable arity, we'll pass a Double instead of double
+            // so that floats don't extend the length of the parameter list.
+            // We return Object.class instead of Double.class though as the
+            // array collector will anyway operate on Object.
+            return varArg ? Object.class : double.class;
+        } else if (!clazz.isPrimitive() || clazz == long.class || clazz == char.class) {
+            return Object.class;
+        }
+        return clazz;
+    }
+
+    private static Class<?> getNashornReturnType(final Class<?> clazz) {
+        if (clazz == byte.class || clazz == short.class) {
+            return int.class;
+        } else if (clazz == float.class) {
+            return double.class;
+        } else if (clazz == void.class || clazz == char.class) {
+            return Object.class;
+        }
+        return clazz;
+    }
+
+
+    private void loadField(final InstructionAdapter mv, final String name, final String desc) {
+        if(classOverride) {
+            mv.getstatic(generatedClassName, name, desc);
+        } else {
+            mv.visitVarInsn(ALOAD, 0);
+            mv.getfield(generatedClassName, name, desc);
+        }
     }
 
-    private static void emitInvokeExact(final InstructionAdapter mv, final MethodType type) {
-        mv.invokevirtual(METHOD_HANDLE_TYPE.getInternalName(), "invokeExact", type.toMethodDescriptorString(), false);
+    private static void convertReturnValue(final InstructionAdapter mv, final Class<?> origReturnType) {
+        if (origReturnType == void.class) {
+            mv.pop();
+        } else if (origReturnType == Object.class) {
+            // Must hide ConsString (and potentially other internal Nashorn types) from callers
+            EXPORT_RETURN_VALUE.invoke(mv);
+        } else if (origReturnType == byte.class) {
+            mv.visitInsn(I2B);
+        } else if (origReturnType == short.class) {
+            mv.visitInsn(I2S);
+        } else if (origReturnType == float.class) {
+            mv.visitInsn(D2F);
+        } else if (origReturnType == char.class) {
+            TO_CHAR_PRIMITIVE.invoke(mv);
+        }
     }
 
-    private static void boxStackTop(final InstructionAdapter mv, final Type t) {
+    /**
+     * Emits instruction for converting a parameter on the top of the stack to
+     * a type that is understood by Nashorn.
+     * @param mv the current method visitor
+     * @param t the type on the top of the stack
+     * @param varArg if the invocation will be variable arity
+     */
+    private static void convertParam(final InstructionAdapter mv, final Type t, final boolean varArg) {
+        // We perform conversions of some primitives to accommodate types that
+        // Nashorn can handle.
         switch(t.getSort()) {
-        case Type.BOOLEAN:
-            invokeValueOf(mv, "Boolean", 'Z');
-            break;
-        case Type.BYTE:
-        case Type.SHORT:
-        case Type.INT:
-            // bytes and shorts get boxed as integers
-            invokeValueOf(mv, "Integer", 'I');
-            break;
         case Type.CHAR:
-            invokeValueOf(mv, "Character", 'C');
+            // Chars are boxed, as we don't know if the JS code wants to treat
+            // them as an effective "unsigned short" or as a single-char string.
+            CHAR_VALUE_OF.invoke(mv);
             break;
         case Type.FLOAT:
-            // floats get boxed as doubles
+            // Floats are widened to double.
             mv.visitInsn(Opcodes.F2D);
-            invokeValueOf(mv, "Double", 'D');
+            if (varArg) {
+                // We'll be boxing everything anyway for the vararg invocation,
+                // so we might as well do it proactively here and thus not cause
+                // a widening in the number of slots, as that could even make
+                // the array creation invocation go over 255 param slots.
+                DOUBLE_VALUE_OF.invoke(mv);
+            }
             break;
         case Type.LONG:
-            invokeValueOf(mv, "Long", 'J');
-            break;
-        case Type.DOUBLE:
-            invokeValueOf(mv, "Double", 'D');
-            break;
-        case Type.ARRAY:
-        case Type.METHOD:
-            // Already boxed
+            // Longs are boxed as Nashorn can't represent them precisely as a
+            // primitive number.
+            LONG_VALUE_OF.invoke(mv);
             break;
         case Type.OBJECT:
             if(t.equals(OBJECT_TYPE)) {
-                mv.invokestatic(SCRIPTUTILS_TYPE_NAME, "unwrap", UNWRAP_METHOD_DESCRIPTOR, false);
+                // Object can carry a ScriptObjectMirror and needs to be unwrapped
+                // before passing into a Nashorn function.
+                UNWRAP.invoke(mv);
             }
             break;
-        default:
-            // Not expecting anything else (e.g. VOID)
-            assert false;
-            break;
         }
     }
 
-    private static void invokeValueOf(final InstructionAdapter mv, final String boxedType, final char unboxedType) {
-        mv.invokestatic("java/lang/" + boxedType, "valueOf", "(" + unboxedType + ")Ljava/lang/" + boxedType + ";", false);
+    private static int getParamListLengthInSlots(final Type[] paramTypes) {
+        int len = paramTypes.length;
+        for(final Type t: paramTypes) {
+            final int sort = t.getSort();
+            if (sort == Type.FLOAT || sort == Type.DOUBLE) {
+                // Floats are widened to double, so they'll take up two slots.
+                // Longs on the other hand are always boxed, so their width
+                // becomes 1 and thus they don't contribute an extra slot here.
+                ++len;
+            }
+        }
+        return len;
     }
-
     /**
      * Emit code to restore the previous Nashorn Context when needed.
      * @param mv the instruction adapter
-     * @param currentGlobalVar index of the local variable holding the reference to the current global at method
-     * entry.
-     * @param globalsDifferVar index of the boolean local variable that is true if the global needs to be restored.
+     * @param globalRestoringRunnableVar index of the local variable holding the reference to the global restoring Runnable
      */
-    private static void emitFinally(final InstructionAdapter mv, final int currentGlobalVar, final int globalsDifferVar) {
-        // Emit code to restore the previous Nashorn global if needed
-        mv.visitVarInsn(ILOAD, globalsDifferVar);
-        final Label skip = new Label();
-        mv.ifeq(skip);
-        mv.visitVarInsn(ALOAD, currentGlobalVar);
-        invokeSetGlobal(mv);
-        mv.visitLabel(skip);
+    private static void emitFinally(final InstructionAdapter mv, final int globalRestoringRunnableVar) {
+        mv.visitVarInsn(ALOAD, globalRestoringRunnableVar);
+        RUN.invoke(mv);
     }
 
     private static boolean isThrowableDeclared(final Class<?>[] exceptions) {
@@ -1030,7 +976,7 @@
         mv.visitCode();
 
         emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);
-
+        mv.areturn(Type.getType(mi.type.returnType()));
         endMethod(mv);
     }
 
@@ -1052,7 +998,15 @@
         throw new AssertionError("can't find the class/interface that extends " + cl);
     }
 
-    private void emitSuperCall(final InstructionAdapter mv, final Class<?> owner, final String name, final String methodDesc) {
+    private int emitSuperConstructorCall(final InstructionAdapter mv, final String methodDesc) {
+        return emitSuperCall(mv, null, INIT, methodDesc, true);
+    }
+
+    private int emitSuperCall(final InstructionAdapter mv, final Class<?> owner, final String name, final String methodDesc) {
+        return emitSuperCall(mv, owner, name, methodDesc, false);
+    }
+
+    private int emitSuperCall(final InstructionAdapter mv, final Class<?> owner, final String name, final String methodDesc, final boolean constructor) {
         mv.visitVarInsn(ALOAD, 0);
         int nextParam = 1;
         final Type methodType = Type.getMethodType(methodDesc);
@@ -1062,48 +1016,46 @@
         }
 
         // default method - non-abstract, interface method
-        if (Modifier.isInterface(owner.getModifiers())) {
+        if (!constructor && Modifier.isInterface(owner.getModifiers())) {
             // we should call default method on the immediate "super" type - not on (possibly)
             // the indirectly inherited interface class!
             mv.invokespecial(Type.getInternalName(findInvokespecialOwnerFor(owner)), name, methodDesc, false);
         } else {
             mv.invokespecial(superClassName, name, methodDesc, false);
         }
-        mv.areturn(methodType.getReturnType());
+        return nextParam;
     }
 
     private void generateFinalizerMethods() {
-        final String finalizerDelegateName = nextName("access$");
-        generateFinalizerDelegate(finalizerDelegateName);
-        generateFinalizerOverride(finalizerDelegateName);
+        generateFinalizerDelegate();
+        generateFinalizerOverride();
     }
 
-    private void generateFinalizerDelegate(final String finalizerDelegateName) {
+    private void generateFinalizerDelegate() {
         // Generate a delegate that will be invoked from the no-permission trampoline. Note it can be private, as we'll
         // refer to it with a MethodHandle constant pool entry in the overridden finalize() method (see
         // generateFinalizerOverride()).
         final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PRIVATE | ACC_STATIC,
-                finalizerDelegateName, Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE), null, null));
+                FINALIZER_DELEGATE_NAME, FINALIZER_DELEGATE_METHOD_DESCRIPTOR, null, null));
 
         // Simply invoke super.finalize()
         mv.visitVarInsn(ALOAD, 0);
         mv.checkcast(Type.getType(generatedClassName));
-        mv.invokespecial(superClassName, "finalize", Type.getMethodDescriptor(Type.VOID_TYPE), false);
+        mv.invokespecial(superClassName, "finalize", VOID_METHOD_DESCRIPTOR, false);
 
         mv.visitInsn(RETURN);
         endMethod(mv);
     }
 
-    private void generateFinalizerOverride(final String finalizerDelegateName) {
+    private void generateFinalizerOverride() {
         final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, "finalize",
-                VOID_NOARG_METHOD_DESCRIPTOR, null, null));
+                VOID_METHOD_DESCRIPTOR, null, null));
         // Overridden finalizer will take a MethodHandle to the finalizer delegating method, ...
-        mv.aconst(new Handle(Opcodes.H_INVOKESTATIC, generatedClassName, finalizerDelegateName,
-                Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE)));
+        mv.aconst(new Handle(Opcodes.H_INVOKESTATIC, generatedClassName, FINALIZER_DELEGATE_NAME,
+                FINALIZER_DELEGATE_METHOD_DESCRIPTOR));
         mv.visitVarInsn(ALOAD, 0);
         // ...and invoke it through JavaAdapterServices.invokeNoPermissions
-        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "invokeNoPermissions",
-                Type.getMethodDescriptor(METHOD_HANDLE_TYPE, OBJECT_TYPE), false);
+        INVOKE_NO_PERMISSIONS.invoke(mv);
         mv.visitInsn(RETURN);
         endMethod(mv);
     }
@@ -1157,11 +1109,8 @@
                     final MethodInfo mi = new MethodInfo(typeMethod);
                     if (Modifier.isFinal(m) || isCallerSensitive(typeMethod)) {
                         finalMethods.add(mi);
-                    } else if (!finalMethods.contains(mi) && methodInfos.add(mi)) {
-                        if (Modifier.isAbstract(m)) {
-                            abstractMethodNames.add(mi.getName());
-                        }
-                        mi.setIsCanonical(this);
+                    } else if (!finalMethods.contains(mi) && methodInfos.add(mi) && Modifier.isAbstract(m)) {
+                        abstractMethodNames.add(mi.getName());
                     }
                 }
             }
@@ -1222,7 +1171,7 @@
                 return type2;
             }
             if (c1.isInterface() || c2.isInterface()) {
-                return OBJECT_TYPE_NAME;
+                return OBJECT_TYPE.getInternalName();
             }
             return assignableSuperClass(c1, c2).getName().replace('.', '/');
         } catch(final ClassNotFoundException e) {
@@ -1238,4 +1187,8 @@
     private static boolean isCallerSensitive(final AccessibleObject e) {
         return e.isAnnotationPresent(CallerSensitive.class);
     }
+
+    private static final Call lookupServiceMethod(final String name, final Class<?> rtype, final Class<?>... ptypes) {
+        return staticCallNoLookup(JavaAdapterServices.class, name, rtype, ptypes);
+    }
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Thu Feb 04 09:20:31 2016 +0100
@@ -54,6 +54,7 @@
 import jdk.nashorn.internal.runtime.ECMAException;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
+import jdk.nashorn.internal.runtime.linker.AdaptationResult.Outcome;
 
 /**
  * A factory class that generates adapter classes. Adapter classes allow
@@ -211,7 +212,7 @@
      *         be generated from a ScriptFunction.
      */
     static boolean isAutoConvertibleFromFunction(final Class<?> clazz) {
-        return getAdapterInfo(new Class<?>[] { clazz }).autoConvertibleFromFunction;
+        return getAdapterInfo(new Class<?>[] { clazz }).isAutoConvertibleFromFunction();
     }
 
     private static AdapterInfo getAdapterInfo(final Class<?>[] types) {
@@ -273,7 +274,7 @@
                 } catch (final AdaptationException e) {
                     return new AdapterInfo(e.getAdaptationResult());
                 } catch (final RuntimeException e) {
-                    return new AdapterInfo(new AdaptationResult(AdaptationResult.Outcome.ERROR_OTHER, Arrays.toString(types), e.toString()));
+                    return new AdapterInfo(new AdaptationResult(Outcome.ERROR_OTHER, e, Arrays.toString(types), e.toString()));
                 }
             }
         }, CREATE_ADAPTER_INFO_ACC_CTXT);
@@ -319,6 +320,13 @@
                 getClassAdapterClass(classOverrides, protectionDomain);
         }
 
+        boolean isAutoConvertibleFromFunction() {
+            if(adaptationResult.getOutcome() == AdaptationResult.Outcome.ERROR_OTHER) {
+                throw adaptationResult.typeError();
+            }
+            return autoConvertibleFromFunction;
+        }
+
         private StaticClass getInstanceAdapterClass(final ProtectionDomain protectionDomain) {
             CodeSource codeSource = protectionDomain.getCodeSource();
             if(codeSource == null) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterServices.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterServices.java	Thu Feb 04 09:20:31 2016 +0100
@@ -33,8 +33,11 @@
 import static jdk.internal.org.objectweb.asm.Opcodes.RETURN;
 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
 
+import java.lang.invoke.CallSite;
+import java.lang.invoke.ConstantCallSite;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodHandles.Lookup;
 import java.lang.invoke.MethodType;
 import java.security.AccessController;
 import java.security.CodeSigner;
@@ -43,15 +46,18 @@
 import java.security.PrivilegedAction;
 import java.security.ProtectionDomain;
 import java.security.SecureClassLoader;
+import java.util.Objects;
 import jdk.internal.org.objectweb.asm.ClassWriter;
 import jdk.internal.org.objectweb.asm.Opcodes;
 import jdk.internal.org.objectweb.asm.Type;
 import jdk.internal.org.objectweb.asm.commons.InstructionAdapter;
+import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.Context;
+import jdk.nashorn.internal.runtime.ECMAException;
+import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
 import jdk.nashorn.internal.runtime.ScriptRuntime;
-import jdk.nashorn.internal.runtime.Undefined;
 
 /**
  * Provides static utility services to generated Java adapter classes.
@@ -64,50 +70,47 @@
     }
 
     /**
-     * Given a JS script function, binds it to null JS "this", and adapts its parameter types, return types, and arity
-     * to the specified type and arity. This method is public mainly for implementation reasons, so the adapter classes
-     * can invoke it from their constructors that take a ScriptFunction in its first argument to obtain the method
-     * handles for their abstract method implementations.
-     * @param fn the script function
-     * @param type the method type it has to conform to
-     * @return the appropriately adapted method handle for invoking the script function.
+     * Given a script function used as a delegate for a SAM adapter, figure out
+     * the right object to use as its "this" when called.
+     * @param delegate the delegate function
+     * @param global the current global of the adapter
+     * @return either the passed global, or UNDEFINED if the function is strict.
      */
-    public static MethodHandle getHandle(final ScriptFunction fn, final MethodType type) {
-        // JS "this" will be global object or undefined depending on if 'fn' is strict or not
-        return bindAndAdaptHandle(fn, fn.isStrict()? ScriptRuntime.UNDEFINED : Context.getGlobal(), type);
+    public static Object getCallThis(final ScriptFunction delegate, final Object global) {
+        return delegate.isStrict() ? ScriptRuntime.UNDEFINED : global;
     }
 
     /**
-     * Given a JS script object, retrieves a function from it by name, binds it to the script object as its "this", and
-     * adapts its parameter types, return types, and arity to the specified type and arity. This method is public mainly
-     * for implementation reasons, so the adapter classes can invoke it from their constructors that take a Object
-     * in its first argument to obtain the method handles for their method implementations.
-     * @param obj the script obj
-     * @param name the name of the property that contains the function
-     * @param type the method type it has to conform to
-     * @return the appropriately adapted method handle for invoking the script function, or null if the value of the
-     * property is either null or undefined, or "toString" was requested as the name, but the object doesn't directly
-     * define it but just inherits it through prototype.
+     * Throws a "not.an.object" type error. Used when the delegate passed to the
+     * adapter constructor is not a script object.
+     * @param obj the object that is not a script object.
      */
-    public static MethodHandle getHandle(final Object obj, final String name, final MethodType type) {
-        if (! (obj instanceof ScriptObject)) {
-            throw typeError("not.an.object", ScriptRuntime.safeToString(obj));
-        }
+    public static void notAnObject(final Object obj) {
+        throw typeError("not.an.object", ScriptRuntime.safeToString(obj));
+    }
 
-        final ScriptObject sobj = (ScriptObject)obj;
-        // Since every JS Object has a toString, we only override "String toString()" it if it's explicitly specified
-        if ("toString".equals(name) && !sobj.hasOwnProperty("toString")) {
+    /**
+     * Checks if the passed object, which is supposed to be a callee retrieved
+     * through applying the GET_METHOD_PROPERTY operation on the delegate, is
+     * a ScriptFunction, or null or undefined. These are the only allowed values
+     * for adapter method implementations, so in case it is neither, it throws
+     * a type error. Note that this restriction is somewhat artificial; as the
+     * CALL dynamic operation could invoke any Nashorn callable. We are
+     * restricting adapters to actual ScriptFunction objects for now though.
+     * @param callee the callee to check
+     * @param name the name of the function
+     * @return the callee cast to a ScriptFunction, or null if it was null or undefined.
+     * @throws ECMAException representing a JS TypeError with "not.a.function"
+     * message if the passed callee is neither a script function, nor null, nor
+     * undefined.
+     */
+    public static ScriptFunction checkFunction(final Object callee, final String name) {
+        if (callee instanceof ScriptFunction) {
+            return (ScriptFunction)callee;
+        } else if (JSType.nullOrUndefined(callee)) {
             return null;
         }
-
-        final Object fnObj = sobj.get(name);
-        if (fnObj instanceof ScriptFunction) {
-            return bindAndAdaptHandle((ScriptFunction)fnObj, sobj, type);
-        } else if(fnObj == null || fnObj instanceof Undefined) {
-            return null;
-        } else {
-            throw typeError("not.a.function", name);
-        }
+        throw typeError("not.a.function.value", name, ScriptRuntime.safeToString(callee));
     }
 
     /**
@@ -116,8 +119,8 @@
      * static initializers.
      * @return the thread-local JS object used to define methods for the class being initialized.
      */
-    public static Object getClassOverrides() {
-        final Object overrides = classOverrides.get();
+    public static ScriptObject getClassOverrides() {
+        final ScriptObject overrides = classOverrides.get();
         assert overrides != null;
         return overrides;
     }
@@ -135,29 +138,59 @@
     }
 
     /**
-     * Set the current global scope
-     * @param global the global scope
+     * Set the current global scope to that of the adapter global
+     * @param adapterGlobal the adapter's global scope
+     * @return a Runnable that when invoked restores the previous global
      */
-    public static void setGlobal(final Object global) {
-        Context.setGlobal((ScriptObject)global);
+    public static Runnable setGlobal(final ScriptObject adapterGlobal) {
+        final Global currentGlobal = Context.getGlobal();
+        if (adapterGlobal != currentGlobal) {
+            Context.setGlobal(adapterGlobal);
+            return ()->Context.setGlobal(currentGlobal);
+        }
+        return ()->{};
     }
 
     /**
-     * Get the current global scope
+     * Get the current non-null global scope
      * @return the current global scope
+     * @throws NullPointerException if the current global scope is null.
      */
-    public static Object getGlobal() {
-        return Context.getGlobal();
+    public static ScriptObject getNonNullGlobal() {
+        return Objects.requireNonNull(Context.getGlobal(), "Current global is null");
+    }
+
+    /**
+     * Returns true if the object has its own toString function. Used
+     * when implementing toString for adapters. Since every JS Object has a
+     * toString function, we only override "String toString()" in adapters if
+     * it is explicitly specified and not inherited from a prototype.
+     * @param sobj the object
+     * @return true if the object has its own toString function.
+     */
+    public static boolean hasOwnToString(final ScriptObject sobj) {
+        // NOTE: we could just use ScriptObject.hasOwnProperty("toString"), but
+        // its logic is more complex and this is what it boils down to with a
+        // fixed "toString" argument.
+        return sobj.getMap().findProperty("toString") != null;
+    }
+
+    /**
+     * Delegate to {@link Bootstrap#bootstrap(Lookup, String, MethodType, int)}.
+     * @param lookup MethodHandle lookup.
+     * @param opDesc Dynalink dynamic operation descriptor.
+     * @param type   Method type.
+     * @param flags  flags for call type, trace/profile etc.
+     * @return CallSite with MethodHandle to appropriate method or null if not found.
+     */
+    public static CallSite bootstrap(final Lookup lookup, final String opDesc, final MethodType type, final int flags) {
+        return Bootstrap.bootstrap(lookup, opDesc, type, flags);
     }
 
     static void setClassOverrides(final ScriptObject overrides) {
         classOverrides.set(overrides);
     }
 
-    private static MethodHandle bindAndAdaptHandle(final ScriptFunction fn, final Object self, final MethodType type) {
-        return Bootstrap.getLinkerServices().asType(ScriptObject.pairArguments(fn.getBoundInvokeHandle(self), type, false), type);
-    }
-
     private static MethodHandle createNoPermissionsInvoker() {
         final String className = "NoPermissionsInvoker";
 
@@ -203,16 +236,6 @@
     }
 
     /**
-     * Returns a method handle used to convert a return value from a delegate method (always Object) to the expected
-     * Java return type.
-     * @param returnType the return type
-     * @return the converter for the expected return type
-     */
-    public static MethodHandle getObjectConverter(final Class<?> returnType) {
-        return Bootstrap.getLinkerServices().getTypeConverter(Object.class, returnType);
-    }
-
-    /**
      * Invoked when returning Object from an adapted method to filter out internal Nashorn objects that must not be seen
      * by the callers. Currently only transforms {@code ConsString} into {@code String} and transforms {@code ScriptObject} into {@code ScriptObjectMirror}.
      * @param obj the return value
@@ -233,13 +256,39 @@
     }
 
     /**
-     * Invoked to convert a return value of a delegate function to String. It is similar to
-     * {@code JSType.toString(Object)}, except it doesn't handle StaticClass specially, and it returns null for null
-     * input instead of the string "null".
-     * @param obj the return value.
-     * @return the String value of the return value
+     * Returns a new {@link RuntimeException} wrapping the passed throwable.
+     * Makes generated bytecode smaller by doing an INVOKESTATIC to this method
+     * rather than the NEW/DUP_X1/SWAP/INVOKESPECIAL &lt;init&gt; sequence.
+     * @param t the original throwable to wrap
+     * @return a newly created runtime exception wrapping the passed throwable.
      */
-    public static String toString(final Object obj) {
-        return JavaArgumentConverters.toString(obj);
+    public static RuntimeException wrapThrowable(final Throwable t) {
+        return new RuntimeException(t);
+    }
+
+    /**
+     * Creates and returns a new {@link UnsupportedOperationException}. Makes
+     * generated bytecode smaller by doing INVOKESTATIC to this method rather
+     * than the NEW/DUP/INVOKESPECIAL &lt;init&gt; sequence.
+     * @return a newly created {@link UnsupportedOperationException}.
+     */
+    public static UnsupportedOperationException unsupported() {
+        return new UnsupportedOperationException();
+    }
+
+    /**
+     * A bootstrap method used to collect invocation arguments into an Object array.
+     * for variable arity invocation.
+     * @param lookup the adapter's lookup (not used).
+     * @param name the call site name (not used).
+     * @param type the method type
+     * @return a method that takes the input parameters and packs them into a
+     * newly allocated Object array.
+     */
+    public static CallSite createArrayBootstrap(final MethodHandles.Lookup lookup, final String name, final MethodType type) {
+        return new ConstantCallSite(
+                MethodHandles.identity(Object[].class)
+                .asCollector(Object[].class, type.parameterCount())
+                .asType(type));
     }
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties	Mon Jan 18 23:08:40 2016 -0800
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Functions.properties	Thu Feb 04 09:20:31 2016 +0100
@@ -24,7 +24,7 @@
 
 Object.isSealed=tells if an object is sealed or not
 
-Object.isFrozen=tells if an object is fronzen or not
+Object.isFrozen=tells if an object is frozen or not
 
 Object.isExtensible=tells if an object is extensible or not
 
@@ -32,7 +32,7 @@
 
 Object=creates a new script object or converts given value as a script object
 
-Object.prototype.toString=returns a string representing of this object
+Object.prototype.toString=returns a string representation of this object
 
 Object.prototype.hasOwnProperty=tells whether this object has the specified property or not
 
@@ -42,3 +42,60 @@
 
 Object.bindProperties=binds the source object's properties to the target object (nashorn extension)
 
+Array.isArray=tells whether the argument is an array
+
+Array.prototype.toString=returns a string representation of this array
+
+Array.prototype.assertNumeric=asserts that the array is numeric, throws a type error if this is not the case
+
+Array.prototype.toLocaleString=returns a locale-specific string representation of this array
+
+Array=creates a new array
+
+Array.prototype.concat=concatenates arrays
+
+Array.prototype.join=returns a string representation of the array, with a separator placed between elements
+
+Array.prototype.pop=returns the element from the end of the array, or undefined
+
+Array.prototype.push=appends an element to the end of the array
+
+Array.prototype.reverse=reverses the array
+
+Array.prototype.shift=removes the first element from the array and returns that element
+
+Array.prototype.slice=returns a shallow copy of a slice of the array
+
+Array.prototype.sort=sorts the array
+
+Array.prototype.splice=changes the content of the array by removing and/or adding elements
+
+Array.prototype.unshift=adds one or more elements to the beginning of the array
+
+Array.prototype.indexOf=retrieves the first index of an element in the array, or -1 if the element is not found
+
+Array.prototype.lastIndexOf=retrieves the last index of an element in the array, or -1 if the element is not found
+
+Array.prototype.every=applies a predicate to all elements of the array, returns true if the predicate evaluates to true for all
+
+Array.prototype.some=tests whether a predicate evaluates to true for some element in the array
+
+Array.prototype.forEach=applies a function to all elements in the array
+
+Array.prototype.map=applies a function to all elements in the array, returns the array of results
+
+Array.prototype.filter=returns an array with those elements from this array that match a filter function
+
+Array.prototype.reduce=applies a left-fold to the array and returns the result
+
+Array.prototype.reduceRight=applies a right-fold to the array and returns the result
+
+Function=creates a new function with the given parameters and function body
+
+Function.prototype.toString=returns a string representation of this function
+
+Function.prototype.apply=invokes the function with the given this-reference and arguments array
+
+Function.prototype.call=invokes the function with the given this-reference and arguments
+
+Function.prototype.bind=returns a new function with bound this-reference and arguments
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8147845.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,44 @@
+/*
+ * 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-8147845: Varargs Array functions still leaking longs
+ *
+ * @test
+ * @run
+ */
+
+Assert.assertTrue([].push() === 0);
+Assert.assertTrue([].unshift() === 0);
+Assert.assertTrue(typeof [].push() === 'number');
+Assert.assertTrue(typeof [].unshift() === 'number');
+
+Assert.assertTrue([].push(1, 2, 3) === 3);
+Assert.assertTrue([].unshift(1, 2, 3) === 3);
+Assert.assertTrue(typeof [].push(1, 2, 3) === 'number');
+Assert.assertTrue(typeof [].unshift(1, 2, 3) === 'number');
+
+Assert.assertTrue([].push(1) === 1);
+Assert.assertTrue([].unshift(1) === 1);
+Assert.assertTrue(typeof [].push(1) === 'number');
+Assert.assertTrue(typeof [].unshift(1) === 'number');
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/Hello.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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.
+ */
+
+/**
+ * This is a test program used in the test jjs-option-cp.js
+ */
+public class Hello {
+    public Hello() {
+    }
+
+    public String getString() {
+        return "hello";
+    }
+}
--- a/test/script/nosecurity/JDK-8144221.js	Mon Jan 18 23:08:40 2016 -0800
+++ b/test/script/nosecurity/JDK-8144221.js	Thu Feb 04 09:20:31 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -25,7 +25,6 @@
  * Test that shebang handling works properly.
  *
  * @test
- * @runif os.not.windows
  * @option -scripting
  * @run
  */
@@ -126,8 +125,9 @@
 }
 
 function run(viajjs, name, arg1, arg2) {
-    var prefix = viajjs ? "${jjs} -scripting " : ''
-    $EXEC("${prefix}./shebang.js ${arg1} ${arg2}")
+    var prefix = viajjs ? "${jjs} -scripting " : win ? 'sh -c "' : '',
+        suffix = viajjs ? '' : win ? '"' : ''
+    $EXEC("${prefix}./shebang.js ${arg1} ${arg2}${suffix}")
     print("* ${name} via ${viajjs ? 'jjs' : 'shebang'}")
     print($OUT.trim())
     print($ERR.trim())
@@ -143,8 +143,8 @@
     $EXEC('chmod +x shebang.js')
     run(false, 'noargs', '', '')
     run(true, 'noargs', '', '')
-    run(false, 'withargs', 'a.js', '"hello world"')
-    run(true, 'withargs', 'a.js', '"hello world"')
+    run(false, 'withargs', 'a.js', "'hello world'")
+    run(true, 'withargs', 'a.js', "'hello world'")
     $EXEC('rm shebang.js')
 })
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-common.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,190 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing.
+ * @subtest
+ * @summary test used by all other jjs-option* test cases
+ */
+var javaHome = $ENV.JAVA_HOME,
+    homeJjs = "${javaHome}/bin/jjs",
+    altJjs = $EXEC('which jjs').trim(),
+    homejavac = "${javaHome}/bin/javac",
+    altjavac = $EXEC('which javac').trim()
+
+var Files = Java.type('java.nio.file.Files'),
+    Paths = Java.type('java.nio.file.Paths'),
+    System = Java.type('java.lang.System')
+
+// Initialize default values for variables used in different functions
+var func_cond_p = <<EOD
+$EXIT == 0
+EOD
+
+var func_cond_n = <<EOD
+$EXIT != 0
+EOD
+
+var flag_cond_p = <<EOD
+out == e_outp
+EOD
+
+var flag_cond_n = <<EOD
+out == e_outn
+EOD
+
+var e_outp = "true"
+var e_outn = "false"
+
+// special cases in which arguments used for negative testing also
+var args_p = "-scripting"
+var args_n = "-scripting"
+
+// create file to check -flag passing
+var path_f = Paths.get("temp-flag.js")
+var testflag_file = path_f.toAbsolutePath()
+
+// create file to check -flag functionality
+var path_func = Paths.get("temp-func.js")
+var testfunc_file = path_func.toAbsolutePath()
+
+
+function exists(f) {
+    return Files.exists(Paths.get(f))
+}
+
+var jjs = exists(homeJjs) ? homeJjs : altJjs
+var javac = exists(homejavac) ? homejavac : altjavac
+
+if (!exists(jjs)) {
+    throw "no jjs executable found; tried ${homeJjs} and ${altJjs}"
+}
+
+// write code to testflag_file
+function write_testflag_file() {
+    Files.write(testflag_file, msg_flag.getBytes())
+}
+
+// write code to testfunc_file
+function write_testfunc_file() {
+    Files.write(testfunc_file, msg_func.getBytes())
+}
+
+function flag_test_pass() {
+    print("flag test PASSED")
+}
+
+function flag_test_fail(e_out, out) {
+    print("flag test FAILED expected out:${e_out} found:${out}")
+}
+
+// check functionality of flag,cover both positive and negative cases
+function testjjs_opt_func(args, positive) {
+    $EXEC("${jjs} ${args}")
+    var out = $OUT.trim(),
+        err = $ERR.trim()
+    if (positive) {
+        if (eval(func_cond_p))
+            print("functionality test PASSED")
+        else
+            print("functionality test FAILED. stdout: ${out} -- stderr: ${err}")
+    }
+    else {
+        if (eval(func_cond_n))
+            print("functionality test PASSED")
+        else
+            print("functionality test FAILED. stdout: ${out} -- stderr: ${err}")
+    }
+
+}
+
+// check if corresponding $OPTIONS._XXX is set for given flag
+function testjjs_opt(args, type, func) {
+    $EXEC("${jjs} ${args}")
+    var out = $OUT.trim(),
+        err = $ERR.trim()
+    if (type) {
+        if (eval(flag_cond_p)) {
+            flag_test_pass()
+            if (func)
+                testjjs_opt_func(arg_p, type)
+        }
+        else {
+            flag_test_fail(e_outp, out)
+        }
+    }
+    else {
+        if (eval(flag_cond_n)) {
+            flag_test_pass()
+            if (func)
+                testjjs_opt_func(arg_n, type)
+        }
+        else {
+            flag_test_fail(e_outn, out)
+        }
+    }
+}
+
+// Main entry point to test both flag and its functionality
+function testjjs_flag_and_func(flag, param) {
+    try {
+        var args = "${flag}" + "${param}"
+        write_testflag_file()
+        write_testfunc_file()
+        print("${flag} flag positive test:")
+        testjjs_opt("${args_p} ${args} ${testflag_file}", true, true) // positive test
+        print("${flag} flag negative test:")
+        testjjs_opt("${args_n} ${testflag_file}", false, true)        // negative test
+    } finally {
+        $EXEC("rm ${testflag_file}")
+        $EXEC("rm ${testfunc_file}")
+    }
+}
+
+// Main entry point to check only functionality of given -flag
+function testjjs_functionality(flag, param) {
+    try {
+        var args = "${flag}" + "${param}"
+        write_testfunc_file()
+        print("${flag} flag positive test:")
+        testjjs_opt_func("${args_p} ${args} ${testfunc_file}", true) // positive test
+        print("${flag} flag negative test:")
+        testjjs_opt_func("${args_n} ${testfunc_file}", false)        // negative test
+    } finally {
+        $EXEC("rm ${testfunc_file}")
+    }
+}
+
+// Main entry point to check only -flag settings for given flag
+function testjjs_flag(flag, param) {
+    try {
+        var args = "${flag}" + "${param}"
+        write_testflag_file()
+        print("${flag} flag positive test:")
+        testjjs_opt("${args_p} ${args} ${testflag_file}", true, false) // positive test
+        print("${flag} flag negative test:")
+        testjjs_opt("${args_n} ${testflag_file}", false, false)        // negative test
+    } finally {
+        $EXEC("rm ${testflag_file}")
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-cp.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,61 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test to check if -cp flag and its basic functionality
+ */
+
+load(__DIR__ + "jjs-common.js")
+
+var hello = __DIR__ + "Hello.class";
+var helloj = __DIR__ + "Hello.java";
+
+// code to check -flag
+var msg_flag = "print($OPTIONS._classpath)"
+
+// code to check basic functionality
+var msg_func = <<EOD
+$EXEC("rm -f ${hello}")
+$EXEC("${javac} ${helloj}")
+var v = new Packages.Hello();
+if (v.string != 'hello') {
+    throw new Error("Unexpected property value");
+}
+EOD
+
+// flag test expected output variables
+var e_outp = "__DIR__"
+var e_outn = "null"
+
+// functionality test arguments
+var arg_p = "-scripting -cp ${__DIR__}  ${testfunc_file}"
+var arg_n = "-scripting ${testfunc_file}"
+
+// Testing starts here
+testjjs_flag_and_func("-cp", " __DIR__")
+$EXEC("rm -f ${hello}")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-cp.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,6 @@
+-cp flag positive test:
+flag test PASSED
+functionality test PASSED
+-cp flag negative test:
+flag test PASSED
+functionality test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-define.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,50 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test to check -D flag basic functionality
+ */
+
+load(__DIR__ + "jjs-common.js")
+
+var path_func = Paths.get("temp-property-func.js")
+var testfunc_file = path_func.toAbsolutePath()
+
+// code to check basic functionality
+var msg_func = <<EOD
+try {
+    var System = Java.type('java.lang.System');
+    print(System.getProperty('user.name'))
+    if (System.getProperty('user.name') != "nashorn9")
+        throw new Error("un expected system property user.name value")
+} finally {
+}
+EOD
+
+// Testing starts here
+testjjs_functionality("-D", "user.name=nashorn9")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-define.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,4 @@
+-D flag positive test:
+functionality test PASSED
+-D flag negative test:
+functionality test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-doe.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,61 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test -doe flag and its basic functionality
+ */
+
+load(__DIR__ + "jjs-common.js")
+
+// code to check -flag
+var msg_flag = "print($OPTIONS._dump_on_error)"
+
+// code to check basic functionality
+var msg_func = <<EOD
+print("Hello Nashorn)
+EOD
+
+// flag test expected output variables
+var e_outp = "true"
+var e_outn = "false"
+
+// functionality test arguments
+var arg_p = "-scripting -doe ${testfunc_file}"
+var arg_n = "-scripting ${testfunc_file}"
+
+// functionality condition checks used.
+var func_cond_p = <<'EOD'
+err.indexOf("internal") > -1
+EOD
+
+var func_cond_n = <<'EOD'
+err.indexOf("internal") <= -1
+EOD
+
+// one particular test starts here
+testjjs_flag_and_func("-doe", "")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-doe.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,6 @@
+-doe flag positive test:
+flag test PASSED
+functionality test PASSED
+-doe flag negative test:
+flag test PASSED
+functionality test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-fv.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,60 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test if -fv flag its basic funnctionality
+ */
+
+load(__DIR__ + "jjs-common.js")
+
+// code to check -flag
+var msg_flag = "print($OPTIONS._fullversion)"
+
+// code to check basic functionality
+var msg_func = <<EOD
+var x = "Hello Nashorn"
+EOD
+
+// flag test expected output variables
+var e_outp = "true"
+var e_outn = "false"
+
+// functionality test arguments
+var arg_p = "-scripting -fv ${testfunc_file}"
+var arg_n = "-scripting ${testfunc_file}"
+
+var func_cond_p = <<'EOD'
+err.indexOf("full") > -1
+EOD
+
+var func_cond_n = <<'EOD'
+err.indexOf("full") <= -1
+EOD
+
+// one particular test starts here
+testjjs_flag_and_func("-fv", "")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-fv.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,6 @@
+-fv flag positive test:
+flag test PASSED
+functionality test PASSED
+-fv flag negative test:
+flag test PASSED
+functionality test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-fx.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,49 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * check -fx option.
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test -fx flag and its basic functionality
+ * the JavaFX primary stage is available to Nashorn as a global property $STAGE with -fx
+ * used this to check with and without -fx 
+ */
+
+load(__DIR__ + "jjs-common.js")
+
+var msg_flag = "print(typeof($STAGE)); exit();";
+
+// flag test expected output variables
+var e_outn = "undefined"
+
+// positive flag test condition expression string other than the default
+var flag_cond_p = <<'EOD'
+out != "undefined"
+EOD
+
+// Testing starts here
+testjjs_flag("-fx","")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-fx.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,4 @@
+-fx flag positive test:
+flag test PASSED
+-fx flag negative test:
+flag test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-lang.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,60 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test -lang flag and its basic functionality
+ */
+
+load(__DIR__ + "jjs-common.js")
+
+// code to check -flag
+var msg_flag = "print($OPTIONS._es6)"
+
+// code to check basic functionality
+var msg_func = <<EOD
+const X = 4
+try {
+    X = 55
+    throw new Error("should have thrown TypeError")
+} catch (e) {
+    if (!(e instanceof TypeError)) {
+        throw new Error("TypeError expected, got " + e)
+    }
+}
+EOD
+
+// flag test expected output variables
+var e_outp = "true"
+var e_outn = "false"
+
+// functionality test arguments
+var arg_p = "-scripting --language=es6 ${testfunc_file}"
+var arg_n = "-scripting ${testfunc_file}"
+
+// Testing starts here
+testjjs_flag_and_func("--language", "=es6")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-lang.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,6 @@
+--language flag positive test:
+flag test PASSED
+functionality test PASSED
+--language flag negative test:
+flag test PASSED
+functionality test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-ot.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,43 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test -ot flag
+ */
+
+load(__DIR__ + "jjs-common.js")
+
+var args_n = "-scripting -ot=false"
+var msg_flag = "print($OPTIONS._optimistic_types);";
+
+// flag test expected output variables
+var e_outp = "true"
+var e_outn = "false"
+
+// Testing starts here
+testjjs_flag("-ot","")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-ot.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,4 @@
+-ot flag positive test:
+flag test PASSED
+-ot flag negative test:
+flag test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-scripting.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,60 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test -scripting flag and its basic functionality
+ */
+
+load(__DIR__ + "jjs-common.js")
+
+// code to check -flag
+var msg_flag = "print($OPTIONS._scripting)"
+
+// code to check basic functionality
+var msg_func = <<'EOD'
+var x = "Nashorn"
+var hello = "Hello ${x}"
+if (hello != "Hello Nashorn") {
+    throw new Error("string interploation not working");
+}
+EOD
+
+// flag test expected output variables
+var e_outn = 'ReferenceErrorr: "$OPTIONS" is not defined'
+// negative flag test condition
+var flag_cond_n = 'err.indexOf("$OPTIONS") > -1'
+
+// functionality test arguments
+var arg_p = "-scripting ${testfunc_file}"
+var arg_n = "${testfunc_file}"
+
+var args_p = "",
+    args_n = ""
+
+// Testing starts here
+testjjs_flag_and_func("-scripting", "")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-scripting.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,6 @@
+-scripting flag positive test:
+flag test PASSED
+functionality test PASSED
+-scripting flag negative test:
+flag test PASSED
+functionality test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-strict.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,55 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test  -strict flag and its basic functionality
+ */
+
+load(__DIR__ + "jjs-common.js")
+
+// code to check -flag
+var msg_flag = "print($OPTIONS._strict)"
+
+// code to check basic functionality
+var msg_func = <<EOD
+try {
+    v = "nashorn"
+    throw new Error("should have thrown reference error")
+} catch (e) {
+    if (!(e instanceof ReferenceError)) {
+        throw new Error("ReferenceError expected, got " + e)
+    }
+}
+EOD
+
+// functionality test arguments
+var arg_p = "-scripting -strict ${testfunc_file}"
+var arg_n = "-scripting ${testfunc_file}"
+
+// Testing starts here
+testjjs_flag_and_func("-strict","")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-strict.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,6 @@
+-strict flag positive test:
+flag test PASSED
+functionality test PASSED
+-strict flag negative test:
+flag test PASSED
+functionality test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-version.js	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,50 @@
+/*
+ * 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-8144113: Nashorn: enable jjs testing. 
+ * check if jjs version is same as of java.
+ * @test
+ * @option -scripting
+ * @runif os.not.windows
+ * @run
+ * @summary Test -version flag and its functionality 
+ */
+
+
+load(__DIR__ + "jjs-common.js")
+
+var javaVersion = System.getProperty('java.version')
+
+// code to check -flag
+var msg_flag = 'var x = "Hello Nashorn"'
+
+// flag test expected output variables
+var e_outp = "nashorn ${javaVersion}"
+var e_outn = "Hello Nashorn"
+
+// not sure why version info is found in error stream not in out stream.??
+flag_cond_p = "err.indexOf(e_outp)> -1"
+flag_cond_n = "err.indexOf(e_outp)<= -1"
+
+testjjs_flag("-version","")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/nosecurity/jjs-option-version.js.EXPECTED	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,4 @@
+-version flag positive test:
+flag test PASSED
+-version flag negative test:
+flag test PASSED
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/src/jdk/nashorn/internal/runtime/linker/test/JavaAdapterTest.java	Thu Feb 04 09:20:31 2016 +0100
@@ -0,0 +1,280 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+package jdk.nashorn.internal.runtime.linker.test;
+
+import java.util.Collection;
+import java.util.Deque;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.function.Supplier;
+import javax.script.Bindings;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+import jdk.nashorn.api.scripting.JSObject;
+import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
+import jdk.nashorn.api.scripting.ScriptObjectMirror;
+import jdk.nashorn.internal.runtime.Context;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class JavaAdapterTest {
+    public interface TestConversions {
+        public byte getByte(byte b);
+        public short getShort(short b);
+        public char getChar(char c);
+        public int getInt(int i);
+        public float getFloat(float f);
+        public long getLong(long l);
+        public double getDouble(double d);
+    }
+
+    @Test
+    public static void testBlah() throws ScriptException {
+        final ScriptEngine e = createEngine();
+        e.eval("new java.util.Comparator({})");
+    }
+
+    @Test
+    public static void testConversions() throws ScriptException {
+        final ScriptEngine e = createEngine();
+        e.put("TestConversionsClass", TestConversions.class);
+        final TestConversions tc = (TestConversions)e.eval(
+                "function id(x) { return x };" +
+                "new TestConversionsClass.static({" +
+                "  getByte: id, getShort: id, getChar: id, getInt: id," +
+                "  getFloat: id, getLong: id, getDouble: id });");
+
+        Assert.assertEquals(Byte.MIN_VALUE, tc.getByte(Byte.MIN_VALUE));
+        Assert.assertEquals(Byte.MAX_VALUE, tc.getByte(Byte.MAX_VALUE));
+
+        Assert.assertEquals(Short.MIN_VALUE, tc.getShort(Short.MIN_VALUE));
+        Assert.assertEquals(Short.MAX_VALUE, tc.getShort(Short.MAX_VALUE));
+
+        Assert.assertEquals(Character.MIN_VALUE, tc.getChar(Character.MIN_VALUE));
+        Assert.assertEquals(Character.MAX_VALUE, tc.getChar(Character.MAX_VALUE));
+
+        Assert.assertEquals(Integer.MIN_VALUE, tc.getInt(Integer.MIN_VALUE));
+        Assert.assertEquals(Integer.MAX_VALUE, tc.getInt(Integer.MAX_VALUE));
+
+        Assert.assertEquals(Long.MIN_VALUE, tc.getLong(Long.MIN_VALUE));
+        Assert.assertEquals(Long.MAX_VALUE, tc.getLong(Long.MAX_VALUE));
+
+        Assert.assertEquals(Float.MIN_VALUE, tc.getFloat(Float.MIN_VALUE));
+        Assert.assertEquals(Float.MAX_VALUE, tc.getFloat(Float.MAX_VALUE));
+        Assert.assertEquals(Float.MIN_NORMAL, tc.getFloat(Float.MIN_NORMAL));
+        Assert.assertEquals(Float.POSITIVE_INFINITY, tc.getFloat(Float.POSITIVE_INFINITY));
+        Assert.assertEquals(Float.NEGATIVE_INFINITY, tc.getFloat(Float.NEGATIVE_INFINITY));
+        Assert.assertTrue(Float.isNaN(tc.getFloat(Float.NaN)));
+
+        Assert.assertEquals(Double.MIN_VALUE, tc.getDouble(Double.MIN_VALUE));
+        Assert.assertEquals(Double.MAX_VALUE, tc.getDouble(Double.MAX_VALUE));
+        Assert.assertEquals(Double.MIN_NORMAL, tc.getDouble(Double.MIN_NORMAL));
+        Assert.assertEquals(Double.POSITIVE_INFINITY, tc.getDouble(Double.POSITIVE_INFINITY));
+        Assert.assertEquals(Double.NEGATIVE_INFINITY, tc.getDouble(Double.NEGATIVE_INFINITY));
+        Assert.assertTrue(Double.isNaN(tc.getDouble(Double.NaN)));
+    }
+
+    private static ScriptEngine createEngine() {
+        // Use no optimistic typing so we run faster; short-running tests.
+        return new NashornScriptEngineFactory().getScriptEngine("-ot=false");
+    }
+
+    @Test
+    public static void testUnimplemented() throws ScriptException {
+        final ScriptEngine e = createEngine();
+        final Runnable r = (Runnable) e.eval("new java.lang.Runnable({})");
+        Assert.assertNull(Context.getGlobal());
+        try {
+            r.run();
+            Assert.fail();
+        } catch(final UnsupportedOperationException x) {
+            // This is expected
+        }
+        // Check global has been restored
+        Assert.assertNull(Context.getGlobal());
+    }
+
+    public interface ThrowingRunnable {
+        public void run() throws Throwable;
+    }
+
+    @Test
+    public static void testUnimplementedWithThrowable() throws Throwable {
+        final ScriptEngine e = createEngine();
+        e.put("ThrowingRunnableClass", ThrowingRunnable.class);
+        final ThrowingRunnable r = (ThrowingRunnable) e.eval("new ThrowingRunnableClass.static({})");
+        Assert.assertNull(Context.getGlobal());
+        try {
+            r.run();
+            Assert.fail();
+        } catch(final UnsupportedOperationException x) {
+            // This is expected
+        }
+        // Check global has been restored
+        Assert.assertNull(Context.getGlobal());
+    }
+
+    public interface IntSupplierWithDefault {
+        public default int get() { return 42; }
+    }
+
+    @Test
+    public static void testUnimplementedWithDefault() throws ScriptException {
+        final ScriptEngine e = createEngine();
+        e.put("IntSupplierWithDefault", IntSupplierWithDefault.class);
+        final IntSupplierWithDefault s1 = (IntSupplierWithDefault) e.eval("new IntSupplierWithDefault.static({})");
+        Assert.assertEquals(42, s1.get());
+        final IntSupplierWithDefault s2 = (IntSupplierWithDefault) e.eval("new IntSupplierWithDefault.static({ get: function() { return 43 }})");
+        Assert.assertEquals(43, s2.get());
+    }
+
+    public interface SupplierSupplier {
+        public Supplier<Object> getSupplier();
+    }
+
+    @Test
+    public static void testReturnAdapter() throws ScriptException {
+        final ScriptEngine e = createEngine();
+        e.put("SupplierSupplier", SupplierSupplier.class);
+        final SupplierSupplier s = (SupplierSupplier) e.eval("new SupplierSupplier.static(function(){ return function() { return 'foo' } })");
+        Assert.assertEquals("foo", s.getSupplier().get());
+    }
+
+    public interface MaxParams {
+        public Object method(boolean p1, byte p2, short p3, char p4, int p5, float p6, long p7, double p8,
+                Object p9, Object p10, Object p11, Object p12, Object p13, Object p14, Object p15, Object p16,
+                Object p17, Object p18, Object p19, Object p20, Object p21, Object p22, Object p23, Object p24,
+                Object p25, Object p26, Object p27, Object p28, Object p29, Object p30, Object p31, Object p32,
+                Object p33, Object p34, Object p35, Object p36, Object p37, Object p38, Object p39, Object p40,
+                Object p41, Object p42, Object p43, Object p44, Object p45, Object p46, Object p47, Object p48,
+                Object p49, Object p50, Object p51, Object p52, Object p53, Object p54, Object p55, Object p56,
+                Object p57, Object p58, Object p59, Object p60, Object p61, Object p62, Object p63, Object p64,
+                Object p65, Object p66, Object p67, Object p68, Object p69, Object p70, Object p71, Object p72,
+                Object p73, Object p74, Object p75, Object p76, Object p77, Object p78, Object p79, Object p80,
+                Object p81, Object p82, Object p83, Object p84, Object p85, Object p86, Object p87, Object p88,
+                Object p89, Object p90, Object p91, Object p92, Object p93, Object p94, Object p95, Object p96,
+                Object p97, Object p98, Object p99, Object p100, Object p101, Object p102, Object p103, Object p104,
+                Object p105, Object p106, Object p107, Object p108, Object p109, Object p110, Object p111, Object p112,
+                Object p113, Object p114, Object p115, Object p116, Object p117, Object p118, Object p119, Object p120,
+                Object p121, Object p122, Object p123, Object p124, Object p125, Object p126, Object p127, Object p128,
+                Object p129, Object p130, Object p131, Object p132, Object p133, Object p134, Object p135, Object p136,
+                Object p137, Object p138, Object p139, Object p140, Object p141, Object p142, Object p143, Object p144,
+                Object p145, Object p146, Object p147, Object p148, Object p149, Object p150, Object p151, Object p152,
+                Object p153, Object p154, Object p155, Object p156, Object p157, Object p158, Object p159, Object p160,
+                Object p161, Object p162, Object p163, Object p164, Object p165, Object p166, Object p167, Object p168,
+                Object p169, Object p170, Object p171, Object p172, Object p173, Object p174, Object p175, Object p176,
+                Object p177, Object p178, Object p179, Object p180, Object p181, Object p182, Object p183, Object p184,
+                Object p185, Object p186, Object p187, Object p188, Object p189, Object p190, Object p191, Object p192,
+                Object p193, Object p194, Object p195, Object p196, Object p197, Object p198, Object p199, Object p200,
+                Object p201, Object p202, Object p203, Object p204, Object p205, Object p206, Object p207, Object p208,
+                Object p209, Object p210, Object p211, Object p212, Object p213, Object p214, Object p215, Object p216,
+                Object p217, Object p218, Object p219, Object p220, Object p221, Object p222, Object p223, Object p224,
+                Object p225, Object p226, Object p227, Object p228, Object p229, Object p230, Object p231, Object p232,
+                Object p233, Object p234, Object p235, Object p236, Object p237, Object p238, Object p239, Object p240,
+                Object p241, Object p242, Object p243, Object p244, Object p245, Object p246, Object p247, Object p248,
+                Object p249, Object p250, Object p251, Object p252);
+    }
+
+    @Test
+    public static void testMaxLengthAdapter() throws ScriptException {
+        final ScriptEngine e = createEngine();
+        e.put("MaxParams", MaxParams.class);
+        final MaxParams s = (MaxParams) e.eval("new MaxParams.static(function(){ return arguments })");
+        final ScriptObjectMirror m = (ScriptObjectMirror)s.method(true, Byte.MIN_VALUE, Short.MIN_VALUE, 'a', Integer.MAX_VALUE, Float.MAX_VALUE, Long.MAX_VALUE, Double.MAX_VALUE,
+                "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
+                "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44",
+                "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62",
+                "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
+                "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98",
+                "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114",
+                "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130",
+                "131", "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142", "143", "144", "145", "146",
+                "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", "161", "162",
+                "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178",
+                "179", "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", "191", "192", "193", "194",
+                "195", "196", "197", "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", "210",
+                "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", "221", "222", "223", "224", "225", "226",
+                "227", "228", "229", "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241", "242",
+                "243", "244", "245", "246", "247", "248", "249", "250", "251");
+        Assert.assertEquals(true, m.getSlot(0));
+        Assert.assertEquals(Integer.valueOf(Byte.MIN_VALUE), m.getSlot(1)); // Byte becomes Integer
+        Assert.assertEquals(Integer.valueOf(Short.MIN_VALUE), m.getSlot(2)); // Short becomes Integer
+        Assert.assertEquals(Character.valueOf('a'), m.getSlot(3));
+        Assert.assertEquals(Integer.valueOf(Integer.MAX_VALUE), m.getSlot(4));
+        Assert.assertEquals(Double.valueOf(Float.MAX_VALUE), m.getSlot(5)); // Float becomes Double
+        Assert.assertEquals(Long.valueOf(Long.MAX_VALUE), m.getSlot(6)); // Long was untouched
+        Assert.assertEquals(Double.valueOf(Double.MAX_VALUE), m.getSlot(7));
+        for (int i = 8; i < 252; ++i) {
+            Assert.assertEquals(String.valueOf(i), m.getSlot(i));
+        }
+    }
+
+    public interface TestScriptObjectMirror {
+        public JSObject getJSObject();
+        public ScriptObjectMirror getScriptObjectMirror();
+        public Map<Object, Object> getMap();
+        public Bindings getBindings();
+    }
+
+    @Test
+    public static void testReturnsScriptObjectMirror() throws ScriptException {
+        final ScriptEngine e = createEngine();
+        e.put("TestScriptObjectMirrorClass", TestScriptObjectMirror.class);
+        final TestScriptObjectMirror tsom = (TestScriptObjectMirror)e.eval(
+                "new TestScriptObjectMirrorClass.static({\n" +
+                "  getJSObject: function() { return { 'kind': 'JSObject' } },\n" +
+                "  getScriptObjectMirror: function() { return { 'kind': 'ScriptObjectMirror' } },\n" +
+                "  getMap: function() { return { 'kind': 'Map' } },\n" +
+                "  getBindings: function() { return { 'kind': 'Bindings' } } })\n");
+        Assert.assertEquals(tsom.getJSObject().getMember("kind"), "JSObject");
+        Assert.assertEquals(tsom.getScriptObjectMirror().getMember("kind"), "ScriptObjectMirror");
+        Assert.assertEquals(tsom.getMap().get("kind"), "Map");
+        Assert.assertEquals(tsom.getBindings().get("kind"), "Bindings");
+    }
+
+    public interface TestListAdapter {
+        public List<Object> getList();
+        public Collection<Object> getCollection();
+        public Queue<Object> getQueue();
+        public Deque<Object> getDequeue();
+    }
+
+    @Test
+    public static void testReturnsListAdapter() throws ScriptException {
+        final ScriptEngine e = createEngine();
+        e.put("TestListAdapterClass", TestListAdapter.class);
+        final TestListAdapter tla = (TestListAdapter)e.eval(
+                "new TestListAdapterClass.static({\n" +
+                "  getList: function() { return [ 'List' ] },\n" +
+                "  getCollection: function() { return [ 'Collection' ] },\n" +
+                "  getQueue: function() { return [ 'Queue' ] },\n" +
+                "  getDequeue: function() { return [ 'Dequeue' ] } })\n");
+        Assert.assertEquals(tla.getList().get(0), "List");
+        Assert.assertEquals(tla.getCollection().iterator().next(), "Collection");
+        Assert.assertEquals(tla.getQueue().peek(), "Queue");
+        Assert.assertEquals(tla.getDequeue().peek(), "Dequeue");
+    }
+}
--- a/test/src/jdk/nashorn/internal/test/framework/ParallelTestRunner.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/test/src/jdk/nashorn/internal/test/framework/ParallelTestRunner.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -166,7 +166,7 @@
             final List<String> args = getCompilerArgs();
             int errors;
             try {
-                errors = evaluateScript(out, err, args.toArray(new String[args.size()]));
+                errors = evaluateScript(out, err, args.toArray(new String[0]));
             } catch (final AssertionError e) {
                 final PrintWriter writer = new PrintWriter(err);
                 e.printStackTrace(writer);
@@ -199,7 +199,7 @@
             final ByteArrayOutputStream err = new ByteArrayOutputStream();
 
             try {
-                final int errors = evaluateScript(out, err, args.toArray(new String[args.size()]));
+                final int errors = evaluateScript(out, err, args.toArray(new String[0]));
 
                 if (errors != 0 || err.size() > 0) {
                     if (expectRunFailure) {
--- a/test/src/jdk/nashorn/internal/test/framework/ScriptRunnable.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/test/src/jdk/nashorn/internal/test/framework/ScriptRunnable.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -108,7 +108,7 @@
         int errors;
 
         try {
-            errors = evaluateScript(out, err, args.toArray(new String[args.size()]));
+            errors = evaluateScript(out, err, args.toArray(new String[0]));
         } catch (final AssertionError e) {
             final PrintWriter writer = new PrintWriter(err);
             e.printStackTrace(writer);
@@ -144,7 +144,7 @@
         final File errorFileHandle  = new File(errorFileName);
 
         try (OutputStream outputFile = new FileOutputStream(outputFileName); OutputStream errorFile = new FileOutputStream(errorFileName)) {
-            final int errors = evaluateScript(outputFile, errorFile, args.toArray(new String[args.size()]));
+            final int errors = evaluateScript(outputFile, errorFile, args.toArray(new String[0]));
 
             if (errors != 0 || errorFileHandle.length() > 0) {
                 if (expectRunFailure) {
--- a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -392,7 +392,7 @@
         if (hasOptimisticOverride()) {
             final List<String> newList = new ArrayList<>(Arrays.asList(args));
             newList.add("--optimistic-types=" + OPTIMISTIC_OVERRIDE);
-            return newList.toArray(new String[newList.size()]);
+            return newList.toArray(new String[0]);
         }
         return args;
     }
--- a/tools/fxshell/jdk/nashorn/tools/FXShell.java	Mon Jan 18 23:08:40 2016 -0800
+++ b/tools/fxshell/jdk/nashorn/tools/FXShell.java	Thu Feb 04 09:20:31 2016 +0100
@@ -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
@@ -134,7 +134,7 @@
         }
 
         // Create a Nashorn script engine with specified arguments.
-        engine = factory.getScriptEngine(args.toArray(new String[args.size()]));
+        engine = factory.getScriptEngine(args.toArray(new String[0]));
 
         // Load initial scripts.
         for (String path : paths) {