OpenJDK / jigsaw / jake / nashorn
changeset 1585:dd1ef00eb2b0
Merge
author | chegar |
---|---|
date | Fri, 16 Oct 2015 13:41:24 +0100 |
parents | 63fa31d631f5 0bf2fe0c7b32 |
children | 7aed4ca0e885 |
files | .hgtags make/build.xml src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java test/script/nosecurity/JDK-8044798.js |
diffstat | 52 files changed, 732 insertions(+), 451 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Thu Oct 08 15:02:57 2015 +0200 +++ b/.hgtags Fri Oct 16 13:41:24 2015 +0100 @@ -318,3 +318,5 @@ 8bab0a9d8a638affdd680c5ec783373f71c19267 jdk9-b82 21b86b980a5f0d27f1f758a3e4818d3331387172 jdk9-b83 214b97ba911f4d768c0214098739e32ab54c8503 jdk9-b84 +285628dac94332d95979de365630c93ab8fa9962 jdk9-b85 +e4283eeb182cbdf5004740728a404aac6afa1104 jdk9-b86
--- a/make/build.xml Thu Oct 08 15:02:57 2015 +0200 +++ b/make/build.xml Fri Oct 16 13:41:24 2015 +0100 @@ -216,13 +216,14 @@ <!-- generate javadoc for all Nashorn and ASM classes --> <target name="javadoc" depends="jar"> - <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${src.dir}/overview.html" + <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${nashorn.module.src.dir}/overview.html" extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}" additionalparam="-quiet" failonerror="true" useexternalfile="true"> <classpath> <pathelement location="${build.classes.dir}"/> </classpath> - <fileset dir="${src.dir}" includes="**/*.java"/> + <fileset dir="${nashorn.module.src.dir}" includes="**/*.java"/> + <fileset dir="${nashorn.shell.module.src.dir}" includes="**/*.java"/> <fileset dir="${jdk.asm.src.dir}" includes="**/*.java"/> <link href="http://docs.oracle.com/javase/8/docs/api/"/> <!-- The following tags are used only in ASM sources - just ignore these --> @@ -248,13 +249,13 @@ <!-- generate javadoc only for nashorn extension api classes --> <target name="javadocapi" depends="jar"> - <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${src.dir}/overview.html" + <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="${nashorn.module.src.dir}/overview.html" extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}" additionalparam="-quiet" failonerror="true" useexternalfile="true"> <classpath> <pathelement location="${build.classes.dir}"/> </classpath> - <fileset dir="${src.dir}" includes="jdk/nashorn/api/**/*.java"/> + <fileset dir="${nashorn.module.src.dir}" includes="jdk/nashorn/api/**/*.java"/> <link href="http://docs.oracle.com/javase/8/docs/api/"/> </javadoc> </target>
--- a/make/nbproject/project.xml Thu Oct 08 15:02:57 2015 +0200 +++ b/make/nbproject/project.xml Fri Oct 16 13:41:24 2015 +0100 @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -20,157 +20,175 @@ 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. ---> -<project xmlns="http://www.netbeans.org/ns/project/1"> - <type>org.netbeans.modules.ant.freeform</type> - <configuration> - <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1"> - <name>nashorn</name> - </general-data> - <general-data xmlns="http://www.netbeans.org/ns/freeform-project/2"> - <!-- Do not use Project Properties customizer when editing this file manually. --> - <name>nashorn</name> - <properties/> - <folders> - <source-folder> - <label>nashorn</label> - <location>.</location> - <encoding>UTF-8</encoding> - </source-folder> - <source-folder> - <label>../test/src</label> - <location>../test/src</location> - </source-folder> - <source-folder> - <label>../buildtools/nasgen/src</label> - <location>../buildtools/nasgen/src</location> - </source-folder> - <source-folder> - <label>../src/jdk.scripting.nashorn/share/classes</label> - <location>../src/jdk.scripting.nashorn/share/classes</location> - </source-folder> - <source-folder> - <label>../test/src</label> - <type>java</type> - <location>../test/src</location> - <encoding>UTF-8</encoding> - </source-folder> - <source-folder> - <label>../buildtools/nasgen/src</label> - <type>java</type> - <location>../buildtools/nasgen/src</location> - <encoding>UTF-8</encoding> - </source-folder> - <source-folder> - <label>../src/jdk.scripting.nashorn/share/classes</label> - <type>java</type> - <location>../src/jdk.scripting.nashorn/share/classes</location> - <encoding>UTF-8</encoding> - </source-folder> - </folders> - <ide-actions> - <action name="build"> - <script>nbproject/nbjdk.xml</script> - <target>jar</target> - </action> - <action name="clean"> - <script>nbproject/nbjdk.xml</script> - <target>clean</target> - </action> - <action name="javadoc"> - <script>nbproject/nbjdk.xml</script> - <target>javadoc</target> - </action> - <action name="test"> - <script>nbproject/nbjdk.xml</script> - <target>test</target> - </action> - <action name="rebuild"> - <script>nbproject/nbjdk.xml</script> - <target>clean</target> - <target>jar</target> - </action> - <action name="run"> - <script>nbproject/nbjdk.xml</script> - <target>run</target> - </action> - <action name="debug"> - <script>nbproject/nbjdk.xml</script> - <target>debug-nb</target> - </action> - <action name="run.single"> - <script>build.xml</script> - <target>test</target> - <context> - <property>test.class</property> - <folder>../test/src</folder> - <pattern>\.java$</pattern> - <format>relative-path-noext</format> - <arity> - <one-file-only/> - </arity> - </context> - </action> - <action name="debug.single"> - <script>nbproject/ide-file-targets.xml</script> - <target>debug-selected-file-in-src</target> - <context> - <property>test.class</property> - <folder>../test/src</folder> - <pattern>\.java$</pattern> - <format>relative-path-noext</format> - <arity> - <one-file-only/> - </arity> - </context> - </action> - </ide-actions> - <view> - <items> - <source-folder style="packages"> - <label>../test/src</label> - <location>../test/src</location> - </source-folder> - <source-folder style="packages"> - <label>../buildtools/nasgen/src</label> - <location>../buildtools/nasgen/src</location> - </source-folder> - <source-folder style="packages"> - <label>../src/jdk.scripting.nashorn/share/classes</label> - <location>../src/jdk.scripting.nashorn/share/classes</location> - </source-folder> - <source-file> - <location>build.xml</location> - </source-file> - </items> - <context-menu> - <ide-action name="build"/> - <ide-action name="rebuild"/> - <ide-action name="clean"/> - <ide-action name="javadoc"/> - <ide-action name="run"/> - <ide-action name="test"/> - <ide-action name="debug"/> - </context-menu> - </view> - <subprojects/> - </general-data> - <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/4"> - <compilation-unit> - <package-root>../test/src</package-root> - <unit-tests/> - <classpath mode="compile">../test/lib/testng.jar:../build/classes:../src/jdk.scripting.nashorn/share/classes</classpath> - <source-level>1.8</source-level> - </compilation-unit> - <compilation-unit> - <package-root>../buildtools/nasgen/src</package-root> - <classpath mode="compile">../build/classes:../src</classpath> - <source-level>1.8</source-level> - </compilation-unit> - <compilation-unit> - <package-root>../src/jdk.scripting.nashorn/share/classes</package-root> - <source-level>1.8</source-level> - </compilation-unit> - </java-data> - </configuration> -</project> +--> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.ant.freeform</type> + <configuration> + <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1"> + <name>nashorn</name> + </general-data> + <general-data xmlns="http://www.netbeans.org/ns/freeform-project/2"> + <!-- Do not use Project Properties customizer when editing this file manually. --> + <name>nashorn</name> + <properties/> + <folders> + <source-folder> + <label>nashorn</label> + <location>.</location> + <encoding>UTF-8</encoding> + </source-folder> + <source-folder> + <label>../test/src</label> + <location>../test/src</location> + </source-folder> + <source-folder> + <label>../buildtools/nasgen/src</label> + <location>../buildtools/nasgen/src</location> + </source-folder> + <source-folder> + <label>../src/jdk.scripting.nashorn/share/classes</label> + <location>../src/jdk.scripting.nashorn/share/classes</location> + </source-folder> + <source-folder> + <label>../test/src</label> + <type>java</type> + <location>../test/src</location> + <encoding>UTF-8</encoding> + </source-folder> + <source-folder> + <label>../buildtools/nasgen/src</label> + <type>java</type> + <location>../buildtools/nasgen/src</location> + <encoding>UTF-8</encoding> + </source-folder> + <source-folder> + <label>../src/jdk.scripting.nashorn/share/classes</label> + <type>java</type> + <location>../src/jdk.scripting.nashorn/share/classes</location> + <encoding>UTF-8</encoding> + </source-folder> + <source-folder> + <label>../src/jdk.scripting.nashorn.shell/share/classes</label> + <type>java</type> + <location>../src/jdk.scripting.nashorn.shell/share/classes</location> + <encoding>UTF-8</encoding> + </source-folder> + <source-folder> + <label>../src/jdk.scripting.nashorn.shell/share/classes</label> + <location>../src/jdk.scripting.nashorn.shell/share/classes</location> + </source-folder> + </folders> + <ide-actions> + <action name="build"> + <script>nbproject/nbjdk.xml</script> + <target>jar</target> + </action> + <action name="clean"> + <script>nbproject/nbjdk.xml</script> + <target>clean</target> + </action> + <action name="javadoc"> + <script>nbproject/nbjdk.xml</script> + <target>javadoc</target> + </action> + <action name="test"> + <script>nbproject/nbjdk.xml</script> + <target>test</target> + </action> + <action name="rebuild"> + <script>nbproject/nbjdk.xml</script> + <target>clean</target> + <target>jar</target> + </action> + <action name="run"> + <script>nbproject/nbjdk.xml</script> + <target>run</target> + </action> + <action name="debug"> + <script>nbproject/nbjdk.xml</script> + <target>debug-nb</target> + </action> + <action name="run.single"> + <script>build.xml</script> + <target>test</target> + <context> + <property>test.class</property> + <folder>../test/src</folder> + <pattern>\.java$</pattern> + <format>relative-path-noext</format> + <arity> + <one-file-only/> + </arity> + </context> + </action> + <action name="debug.single"> + <script>nbproject/ide-file-targets.xml</script> + <target>debug-selected-file-in-src</target> + <context> + <property>test.class</property> + <folder>../test/src</folder> + <pattern>\.java$</pattern> + <format>relative-path-noext</format> + <arity> + <one-file-only/> + </arity> + </context> + </action> + </ide-actions> + <view> + <items> + <source-folder style="packages"> + <label>../test/src</label> + <location>../test/src</location> + </source-folder> + <source-folder style="packages"> + <label>../buildtools/nasgen/src</label> + <location>../buildtools/nasgen/src</location> + </source-folder> + <source-folder style="packages"> + <label>../src/jdk.scripting.nashorn/share/classes</label> + <location>../src/jdk.scripting.nashorn/share/classes</location> + </source-folder> + <source-folder style="packages"> + <label>../src/jdk.scripting.nashorn.shell/share/classes</label> + <location>../src/jdk.scripting.nashorn.shell/share/classes</location> + </source-folder> + <source-file> + <location>build.xml</location> + </source-file> + </items> + <context-menu> + <ide-action name="build"/> + <ide-action name="rebuild"/> + <ide-action name="clean"/> + <ide-action name="javadoc"/> + <ide-action name="run"/> + <ide-action name="test"/> + <ide-action name="debug"/> + </context-menu> + </view> + <subprojects/> + </general-data> + <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/4"> + <compilation-unit> + <package-root>../test/src</package-root> + <unit-tests/> + <classpath mode="compile">../test/lib/testng.jar:../build/classes:../src/jdk.scripting.nashorn/share/classes</classpath> + <source-level>1.8</source-level> + </compilation-unit> + <compilation-unit> + <package-root>../buildtools/nasgen/src</package-root> + <classpath mode="compile">../build/classes:../src</classpath> + <source-level>1.8</source-level> + </compilation-unit> + <compilation-unit> + <package-root>../src/jdk.scripting.nashorn/share/classes</package-root> + <source-level>1.8</source-level> + </compilation-unit> + <compilation-unit> + <package-root>../src/jdk.scripting.nashorn.shell/share/classes</package-root> + <source-level>1.8</source-level> + </compilation-unit> + </java-data> + </configuration> +</project>
--- a/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java Fri Oct 16 13:41:24 2015 +0100 @@ -154,6 +154,10 @@ break; } + if (source == null) { + break; + } + if (source.isEmpty()) { continue; }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java Fri Oct 16 13:41:24 2015 +0100 @@ -103,27 +103,14 @@ * handle is always at the start of the chain. */ public class ChainedCallSite extends AbstractRelinkableCallSite { - private static final MethodHandle PRUNE_CATCHES = - MethodHandles.insertArguments( - Lookup.findOwnSpecial( - MethodHandles.lookup(), - "prune", - MethodHandle.class, - MethodHandle.class, - boolean.class), - 2, - true); - - private static final MethodHandle PRUNE_SWITCHPOINTS = - MethodHandles.insertArguments( - Lookup.findOwnSpecial( - MethodHandles.lookup(), - "prune", - MethodHandle.class, - MethodHandle.class, - boolean.class), - 2, - false); + private static final MethodHandle PRUNE_CATCHES; + private static final MethodHandle PRUNE_SWITCHPOINTS; + static { + final MethodHandle PRUNE = Lookup.findOwnSpecial(MethodHandles.lookup(), "prune", MethodHandle.class, + MethodHandle.class, boolean.class); + PRUNE_CATCHES = MethodHandles.insertArguments(PRUNE, 2, true); + PRUNE_SWITCHPOINTS = MethodHandles.insertArguments(PRUNE, 2, false); + } private final AtomicReference<LinkedList<GuardedInvocation>> invocations = new AtomicReference<>(); @@ -181,8 +168,8 @@ // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger. - final MethodHandle pruneAndInvokeSwitchPoints = makePruneAndInvokeMethod(relink, getPruneSwitchpoints()); - final MethodHandle pruneAndInvokeCatches = makePruneAndInvokeMethod(relink, getPruneCatches()); + final MethodHandle pruneAndInvokeSwitchPoints = makePruneAndInvokeMethod(relink, PRUNE_SWITCHPOINTS); + final MethodHandle pruneAndInvokeCatches = makePruneAndInvokeMethod(relink, PRUNE_CATCHES); // Fold the new chain MethodHandle target = relink; @@ -200,22 +187,6 @@ } /** - * Get the switchpoint pruning function for a chained call site - * @return function that removes invalidated switchpoints tied to callsite guard chain and relinks - */ - protected MethodHandle getPruneSwitchpoints() { - return PRUNE_SWITCHPOINTS; - } - - /** - * Get the catch pruning function for a chained call site - * @return function that removes all catches tied to callsite guard chain and relinks - */ - protected MethodHandle getPruneCatches() { - return PRUNE_CATCHES; - } - - /** * Creates a method that rebuilds our call chain, pruning it of any invalidated switchpoints, and then invokes that * chain. * @param relink the ultimate fallback for the chain (the {@code DynamicLinker}'s relink).
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngine.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/scripting/NashornScriptEngine.java Fri Oct 16 13:41:24 2015 +0100 @@ -140,7 +140,7 @@ this._global_per_engine = nashornContext.getEnv()._global_per_engine; // create new global object - this.global = createNashornGlobal(context); + this.global = createNashornGlobal(); // set the default ENGINE_SCOPE object for the default context context.setBindings(new ScriptObjectMirror(global, global), ScriptContext.ENGINE_SCOPE); } @@ -167,7 +167,7 @@ // We use same 'global' for all Bindings. return new SimpleBindings(); } - return createGlobalMirror(null); + return createGlobalMirror(); } // Compilable methods @@ -317,7 +317,7 @@ // We didn't find associated nashorn global mirror in the Bindings given! // Create new global instance mirror and associate with the Bindings. - final ScriptObjectMirror mirror = createGlobalMirror(ctxt); + final ScriptObjectMirror mirror = createGlobalMirror(); bindings.put(NASHORN_GLOBAL, mirror); return mirror.getHomeGlobal(); } @@ -333,13 +333,13 @@ } // Create a new ScriptObjectMirror wrapping a newly created Nashorn Global object - private ScriptObjectMirror createGlobalMirror(final ScriptContext ctxt) { - final Global newGlobal = createNashornGlobal(ctxt); + private ScriptObjectMirror createGlobalMirror() { + final Global newGlobal = createNashornGlobal(); return new ScriptObjectMirror(newGlobal, newGlobal); } // Create a new Nashorn Global object - private Global createNashornGlobal(final ScriptContext ctxt) { + private Global createNashornGlobal() { final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() { @Override public Global run() { @@ -354,7 +354,7 @@ } }, CREATE_GLOBAL_ACC_CTXT); - nashornContext.initGlobal(newGlobal, this, ctxt); + nashornContext.initGlobal(newGlobal, this); return newGlobal; }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IRTranslator.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IRTranslator.java Fri Oct 16 13:41:24 2015 +0100 @@ -47,7 +47,6 @@ import jdk.nashorn.internal.ir.IfNode; import jdk.nashorn.internal.ir.IndexNode; import jdk.nashorn.internal.ir.LabelNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.ObjectNode; @@ -64,7 +63,7 @@ import jdk.nashorn.internal.ir.VarNode; import jdk.nashorn.internal.ir.WhileNode; import jdk.nashorn.internal.ir.WithNode; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.parser.Lexer; import jdk.nashorn.internal.parser.TokenType; @@ -72,10 +71,9 @@ * This class translates from nashorn IR Node objects * to nashorn parser API Tree objects. */ -final class IRTranslator extends NodeVisitor<LexicalContext> { +final class IRTranslator extends SimpleNodeVisitor { public IRTranslator() { - super(new LexicalContext()); } // currently translated Statement
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ApplySpecialization.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ApplySpecialization.java Fri Oct 16 13:41:24 2015 +0100 @@ -41,9 +41,8 @@ import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.FunctionNode; import jdk.nashorn.internal.ir.IdentNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.Node; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.objects.Global; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.logging.DebugLogger; @@ -81,7 +80,7 @@ */ @Logger(name="apply2call") -public final class ApplySpecialization extends NodeVisitor<LexicalContext> implements Loggable { +public final class ApplySpecialization extends SimpleNodeVisitor implements Loggable { private static final boolean USE_APPLY2CALL = Options.getBooleanProperty("nashorn.apply2call", true); @@ -105,7 +104,6 @@ * @param compiler compiler */ public ApplySpecialization(final Compiler compiler) { - super(new LexicalContext()); this.compiler = compiler; this.log = initLogger(compiler.getContext()); } @@ -138,7 +136,7 @@ private boolean hasApplies(final FunctionNode functionNode) { try { - functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + functionNode.accept(new SimpleNodeVisitor() { @Override public boolean enterFunctionNode(final FunctionNode fn) { return fn == functionNode; @@ -172,7 +170,7 @@ final Deque<Set<Expression>> stack = new ArrayDeque<>(); //ensure that arguments is only passed as arg to apply - functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + functionNode.accept(new SimpleNodeVisitor() { private boolean isCurrentArg(final Expression expr) { return !stack.isEmpty() && stack.peek().contains(expr); //args to current apply call
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/AssignSymbols.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/AssignSymbols.java Fri Oct 16 13:41:24 2015 +0100 @@ -67,7 +67,6 @@ import jdk.nashorn.internal.ir.FunctionNode; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.IndexNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LexicalContextNode; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.Node; @@ -81,7 +80,7 @@ import jdk.nashorn.internal.ir.UnaryNode; import jdk.nashorn.internal.ir.VarNode; import jdk.nashorn.internal.ir.WithNode; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.parser.TokenType; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.ECMAErrors; @@ -102,7 +101,7 @@ * visitor. */ @Logger(name="symbols") -final class AssignSymbols extends NodeVisitor<LexicalContext> implements Loggable { +final class AssignSymbols extends SimpleNodeVisitor implements Loggable { private final DebugLogger log; private final boolean debug; @@ -150,7 +149,6 @@ private final boolean isOnDemand; public AssignSymbols(final Compiler compiler) { - super(new LexicalContext()); this.compiler = compiler; this.log = initLogger(compiler.getContext()); this.debug = log.isEnabled(); @@ -187,7 +185,7 @@ */ private void acceptDeclarations(final FunctionNode functionNode, final Block body) { // This visitor will assign symbol to all declared variables. - body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + body.accept(new SimpleNodeVisitor() { @Override protected boolean enterDefault(final Node node) { // Don't bother visiting expressions; var is a statement, it can't be inside an expression.
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CacheAst.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CacheAst.java Fri Oct 16 13:41:24 2015 +0100 @@ -29,19 +29,17 @@ import java.util.Collections; import java.util.Deque; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.Statement; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData; -class CacheAst extends NodeVisitor<LexicalContext> { +class CacheAst extends SimpleNodeVisitor { private final Deque<RecompilableScriptFunctionData> dataStack = new ArrayDeque<>(); private final Compiler compiler; CacheAst(final Compiler compiler) { - super(new LexicalContext()); this.compiler = compiler; assert !compiler.isOnDemandCompilation(); }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java Fri Oct 16 13:41:24 2015 +0100 @@ -129,7 +129,7 @@ import jdk.nashorn.internal.ir.WhileNode; import jdk.nashorn.internal.ir.WithNode; import jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.objects.Global; import jdk.nashorn.internal.parser.Lexer.RegexToken; import jdk.nashorn.internal.parser.TokenType; @@ -1433,8 +1433,7 @@ final Block currentBlock = lc.getCurrentBlock(); final CodeGeneratorLexicalContext codegenLexicalContext = lc; - function.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { - + function.accept(new SimpleNodeVisitor() { private MethodEmitter sharedScopeCall(final IdentNode identNode, final int flags) { final Symbol symbol = identNode.getSymbol(); final boolean isFastScope = isFastScope(symbol); @@ -2461,7 +2460,7 @@ @Override public Boolean get() { - value.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + value.accept(new SimpleNodeVisitor() { @Override public boolean enterFunctionNode(final FunctionNode functionNode) { return false; @@ -2799,7 +2798,7 @@ boolean contains; @Override public Boolean get() { - rootExpr.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + rootExpr.accept(new SimpleNodeVisitor() { @Override public boolean enterFunctionNode(final FunctionNode functionNode) { return false; @@ -4347,7 +4346,7 @@ * on the stack throughout the store and used at the end to execute it */ - target.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + target.accept(new SimpleNodeVisitor() { @Override public boolean enterIdentNode(final IdentNode node) { if (node.getSymbol().isScope()) { @@ -4446,7 +4445,7 @@ * need to do a conversion on non-equivalent types exists, but is * very rare. See for example test/script/basic/access-specializer.js */ - target.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + target.accept(new SimpleNodeVisitor() { @Override protected boolean enterDefault(final Node node) { throw new AssertionError("Unexpected node " + node + " in store epilogue");
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompilationPhase.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompilationPhase.java Fri Oct 16 13:41:24 2015 +0100 @@ -36,13 +36,13 @@ import jdk.nashorn.internal.codegen.Compiler.CompilationPhases; import jdk.nashorn.internal.ir.Block; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.Symbol; import jdk.nashorn.internal.ir.debug.ASTWriter; import jdk.nashorn.internal.ir.debug.PrintVisitor; import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.runtime.CodeInstaller; import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData; import jdk.nashorn.internal.runtime.ScriptEnvironment; @@ -118,7 +118,7 @@ FunctionNode newFunctionNode; //ensure elementTypes, postsets and presets exist for splitter and arraynodes - newFunctionNode = transformFunction(fn, new NodeVisitor<LexicalContext>(new LexicalContext()) { + newFunctionNode = transformFunction(fn, new SimpleNodeVisitor() { @Override public LiteralNode<?> leaveLiteralNode(final LiteralNode<?> literalNode) { return literalNode.initialize(lc); @@ -222,7 +222,7 @@ // correctness, it's just an optimization -- runtime type calculation is not used when the compilation // is not an on-demand optimistic compilation, so we can skip locals marking then. if (compiler.useOptimisticTypes() && compiler.isOnDemandCompilation()) { - fn.getBody().accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + fn.getBody().accept(new SimpleNodeVisitor() { @Override public boolean enterFunctionNode(final FunctionNode functionNode) { // OTOH, we must not declare symbols from nested functions to be locals. As we're doing on-demand
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java Fri Oct 16 13:41:24 2015 +0100 @@ -39,7 +39,7 @@ import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.Symbol; import jdk.nashorn.internal.ir.WithNode; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData; import jdk.nashorn.internal.runtime.logging.DebugLogger; @@ -53,7 +53,7 @@ * FunctionNode being compiled */ @Logger(name="scopedepths") -final class FindScopeDepths extends NodeVisitor<LexicalContext> implements Loggable { +final class FindScopeDepths extends SimpleNodeVisitor implements Loggable { private final Compiler compiler; private final Map<Integer, Map<Integer, RecompilableScriptFunctionData>> fnIdToNestedFunctions = new HashMap<>(); @@ -66,7 +66,6 @@ private int dynamicScopeCount; FindScopeDepths(final Compiler compiler) { - super(new LexicalContext()); this.compiler = compiler; this.log = initLogger(compiler.getContext()); } @@ -273,7 +272,7 @@ //get all symbols that are referenced inside this function body final Set<Symbol> symbols = new HashSet<>(); - block.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + block.accept(new SimpleNodeVisitor() { @Override public boolean enterIdentNode(final IdentNode identNode) { final Symbol symbol = identNode.getSymbol();
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java Fri Oct 16 13:41:24 2015 +0100 @@ -38,7 +38,6 @@ import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.FunctionNode; import jdk.nashorn.internal.ir.IfNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; import jdk.nashorn.internal.ir.Node; @@ -47,7 +46,7 @@ import jdk.nashorn.internal.ir.TernaryNode; import jdk.nashorn.internal.ir.UnaryNode; import jdk.nashorn.internal.ir.VarNode; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.ScriptRuntime; @@ -59,12 +58,11 @@ * Simple constant folding pass, executed before IR is starting to be lowered. */ @Logger(name="fold") -final class FoldConstants extends NodeVisitor<LexicalContext> implements Loggable { +final class FoldConstants extends SimpleNodeVisitor implements Loggable { private final DebugLogger log; FoldConstants(final Compiler compiler) { - super(new LexicalContext()); this.log = initLogger(compiler.getContext()); } @@ -194,7 +192,7 @@ * initializers removed. */ static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Statement> statements) { - deadCodeRoot.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + deadCodeRoot.accept(new SimpleNodeVisitor() { @Override public boolean enterVarNode(final VarNode varNode) { statements.add(varNode.setInit(null));
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Fri Oct 16 13:41:24 2015 +0100 @@ -87,6 +87,7 @@ import jdk.nashorn.internal.ir.WhileNode; import jdk.nashorn.internal.ir.WithNode; import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.parser.TokenType; /** @@ -105,7 +106,7 @@ * instances of the calculator to be run on nested functions (when not lazy compiling). * */ -final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{ +final class LocalVariableTypesCalculator extends SimpleNodeVisitor { private static class JumpOrigin { final JoinPredecessor node; @@ -425,7 +426,6 @@ private final Deque<Label> catchLabels = new ArrayDeque<>(); LocalVariableTypesCalculator(final Compiler compiler) { - super(new LexicalContext()); this.compiler = compiler; } @@ -1330,7 +1330,7 @@ // Sets the return type of the function and also performs the bottom-up pass of applying type and conversion // information to nodes as well as doing the calculation on nested functions as required. FunctionNode newFunction = functionNode; - final NodeVisitor<LexicalContext> applyChangesVisitor = new NodeVisitor<LexicalContext>(new LexicalContext()) { + final SimpleNodeVisitor applyChangesVisitor = new SimpleNodeVisitor() { private boolean inOuterFunction = true; private final Deque<JoinPredecessor> joinPredecessors = new ArrayDeque<>();
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java Fri Oct 16 13:41:24 2015 +0100 @@ -74,7 +74,7 @@ import jdk.nashorn.internal.ir.WhileNode; import jdk.nashorn.internal.ir.WithNode; import jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.parser.Token; import jdk.nashorn.internal.parser.TokenType; import jdk.nashorn.internal.runtime.Context; @@ -331,7 +331,7 @@ @SuppressWarnings("unchecked") private static <T extends Node> T ensureUniqueNamesIn(final T node) { - return (T)node.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + return (T)node.accept(new SimpleNodeVisitor() { @Override public Node leaveFunctionNode(final FunctionNode functionNode) { final String name = functionNode.getName(); @@ -396,7 +396,7 @@ final Block finallyBlock = createFinallyBlock(finallyBody); final ArrayList<Block> inlinedFinallies = new ArrayList<>(); final FunctionNode fn = lc.getCurrentFunction(); - final TryNode newTryNode = (TryNode)tryNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + final TryNode newTryNode = (TryNode)tryNode.accept(new SimpleNodeVisitor() { @Override public boolean enterFunctionNode(final FunctionNode functionNode) { @@ -539,7 +539,7 @@ final Block catchAll = catchAllBlock(tryNode); final List<ThrowNode> rethrows = new ArrayList<>(1); - catchAll.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + catchAll.accept(new SimpleNodeVisitor() { @Override public boolean enterThrowNode(final ThrowNode throwNode) { rethrows.add(throwNode); @@ -686,7 +686,7 @@ private static boolean controlFlowEscapes(final LexicalContext lex, final Block loopBody) { final List<Node> escapes = new ArrayList<>(); - loopBody.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + loopBody.accept(new SimpleNodeVisitor() { @Override public Node leaveBreakNode(final BreakNode node) { escapes.add(node);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java Fri Oct 16 13:41:24 2015 +0100 @@ -42,7 +42,6 @@ import jdk.nashorn.internal.ir.IfNode; import jdk.nashorn.internal.ir.IndexNode; import jdk.nashorn.internal.ir.JoinPredecessorExpression; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LoopNode; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.Optimistic; @@ -52,7 +51,7 @@ import jdk.nashorn.internal.ir.UnaryNode; import jdk.nashorn.internal.ir.VarNode; import jdk.nashorn.internal.ir.WhileNode; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.parser.TokenType; import jdk.nashorn.internal.runtime.ScriptObject; @@ -61,7 +60,7 @@ * must not ever be marked as optimistic, assigning narrowest non-invalidated types to program points from the * compilation environment, as well as initializing optimistic types of global properties for scripts. */ -final class OptimisticTypesCalculator extends NodeVisitor<LexicalContext> { +final class OptimisticTypesCalculator extends SimpleNodeVisitor { final Compiler compiler; @@ -69,7 +68,6 @@ final Deque<BitSet> neverOptimistic = new ArrayDeque<>(); OptimisticTypesCalculator(final Compiler compiler) { - super(new LexicalContext()); this.compiler = compiler; }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ProgramPoints.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ProgramPoints.java Fri Oct 16 13:41:24 2015 +0100 @@ -37,25 +37,20 @@ import jdk.nashorn.internal.ir.FunctionNode; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.IndexNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.Optimistic; import jdk.nashorn.internal.ir.UnaryNode; import jdk.nashorn.internal.ir.VarNode; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; /** * Find program points in the code that are needed for optimistic assumptions */ -class ProgramPoints extends NodeVisitor<LexicalContext> { +class ProgramPoints extends SimpleNodeVisitor { private final IntDeque nextProgramPoint = new IntDeque(); private final Set<Node> noProgramPoint = new HashSet<>(); - ProgramPoints() { - super(new LexicalContext()); - } - private int next() { final int next = nextProgramPoint.getAndIncrement(); if(next > MAX_PROGRAM_POINT_VALUE) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ReplaceCompileUnits.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ReplaceCompileUnits.java Fri Oct 16 13:41:24 2015 +0100 @@ -27,24 +27,19 @@ import java.util.ArrayList; import java.util.List; - import jdk.nashorn.internal.ir.CompileUnitHolder; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.ObjectNode; import jdk.nashorn.internal.ir.Splittable; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; /** * Base class for a node visitor that replaces {@link CompileUnit}s in {@link CompileUnitHolder}s. */ -abstract class ReplaceCompileUnits extends NodeVisitor<LexicalContext> { - ReplaceCompileUnits() { - super(new LexicalContext()); - } +abstract class ReplaceCompileUnits extends SimpleNodeVisitor { /** * Override to provide a replacement for an old compile unit.
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Splitter.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Splitter.java Fri Oct 16 13:41:24 2015 +0100 @@ -33,7 +33,6 @@ import java.util.Map; import jdk.nashorn.internal.ir.Block; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; import jdk.nashorn.internal.ir.Node; @@ -42,7 +41,7 @@ import jdk.nashorn.internal.ir.SplitNode; import jdk.nashorn.internal.ir.Splittable; import jdk.nashorn.internal.ir.Statement; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.logging.DebugLogger; import jdk.nashorn.internal.runtime.logging.Loggable; @@ -53,7 +52,7 @@ * Split the IR into smaller compile units. */ @Logger(name="splitter") -final class Splitter extends NodeVisitor<LexicalContext> implements Loggable { +final class Splitter extends SimpleNodeVisitor implements Loggable { /** Current compiler. */ private final Compiler compiler; @@ -79,7 +78,6 @@ * @param outermostCompileUnit compile unit for outermost function, if non-lazy this is the script's compile unit */ public Splitter(final Compiler compiler, final FunctionNode functionNode, final CompileUnit outermostCompileUnit) { - super(new LexicalContext()); this.compiler = compiler; this.outermost = functionNode; this.outermostCompileUnit = outermostCompileUnit; @@ -142,7 +140,7 @@ final Block body = functionNode.getBody(); final List<FunctionNode> dc = directChildren(functionNode); - final Block newBody = (Block)body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + final Block newBody = (Block)body.accept(new SimpleNodeVisitor() { @Override public boolean enterFunctionNode(final FunctionNode nestedFunction) { return dc.contains(nestedFunction); @@ -164,7 +162,7 @@ private static List<FunctionNode> directChildren(final FunctionNode functionNode) { final List<FunctionNode> dc = new ArrayList<>(); - functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + functionNode.accept(new SimpleNodeVisitor() { @Override public boolean enterFunctionNode(final FunctionNode child) { if (child == functionNode) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/JSONWriter.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/JSONWriter.java Fri Oct 16 13:41:24 2015 +0100 @@ -49,7 +49,6 @@ import jdk.nashorn.internal.ir.IndexNode; import jdk.nashorn.internal.ir.JoinPredecessorExpression; import jdk.nashorn.internal.ir.LabelNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.ObjectNode; @@ -66,7 +65,7 @@ import jdk.nashorn.internal.ir.VarNode; import jdk.nashorn.internal.ir.WhileNode; import jdk.nashorn.internal.ir.WithNode; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.parser.JSONParser; import jdk.nashorn.internal.parser.Lexer.RegexToken; import jdk.nashorn.internal.parser.Parser; @@ -78,7 +77,7 @@ /** * This IR writer produces a JSON string that represents AST as a JSON string. */ -public final class JSONWriter extends NodeVisitor<LexicalContext> { +public final class JSONWriter extends SimpleNodeVisitor { /** * Returns AST as JSON compatible string. @@ -945,7 +944,6 @@ // Internals below private JSONWriter(final boolean includeLocation) { - super(new LexicalContext()); this.buf = new StringBuilder(); this.includeLocation = includeLocation; }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/PrintVisitor.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/PrintVisitor.java Fri Oct 16 13:41:24 2015 +0100 @@ -41,7 +41,6 @@ import jdk.nashorn.internal.ir.JoinPredecessor; import jdk.nashorn.internal.ir.JoinPredecessorExpression; import jdk.nashorn.internal.ir.LabelNode; -import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LocalVariableConversion; import jdk.nashorn.internal.ir.Node; import jdk.nashorn.internal.ir.SplitNode; @@ -53,7 +52,7 @@ import jdk.nashorn.internal.ir.VarNode; import jdk.nashorn.internal.ir.WhileNode; import jdk.nashorn.internal.ir.WithNode; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; /** * Print out the AST as human readable source code. @@ -61,7 +60,7 @@ * * see the flags --print-parse and --print-lower-parse */ -public final class PrintVisitor extends NodeVisitor<LexicalContext> { +public final class PrintVisitor extends SimpleNodeVisitor { /** Tab width */ private static final int TABWIDTH = 4; @@ -96,7 +95,6 @@ * @param printTypes should we print optimistic and inferred types? */ public PrintVisitor(final boolean printLineNumbers, final boolean printTypes) { - super(new LexicalContext()); this.EOLN = System.lineSeparator(); this.sb = new StringBuilder(); this.printLineNumbers = printLineNumbers;
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/visitor/NodeOperatorVisitor.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/visitor/NodeOperatorVisitor.java Fri Oct 16 13:41:24 2015 +0100 @@ -34,7 +34,7 @@ * Like NodeVisitor but navigating further into operators. * @param <T> Lexical context class for this NodeOperatorVisitor */ -public class NodeOperatorVisitor<T extends LexicalContext> extends NodeVisitor<T> { +public abstract class NodeOperatorVisitor<T extends LexicalContext> extends NodeVisitor<T> { /** * Constructor *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/visitor/SimpleNodeVisitor.java Fri Oct 16 13:41:24 2015 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, 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.ir.visitor; + +import jdk.nashorn.internal.ir.LexicalContext; + +/** + * Convenience base class for a {@link NodeVisitor} with a plain {@link LexicalContext}. + */ +public abstract class SimpleNodeVisitor extends NodeVisitor<LexicalContext> { + + /** + * Creates a new simple node visitor. + */ + public SimpleNodeVisitor() { + super(new LexicalContext()); + } +}
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/Global.java Fri Oct 16 13:41:24 2015 +0100 @@ -928,8 +928,6 @@ private ThreadLocal<ScriptContext> scontext; // current ScriptEngine associated - can be null. private ScriptEngine engine; - // initial ScriptContext - can be null - private volatile ScriptContext initscontext; // ES6 global lexical scope. private final LexicalScope lexicalScope; @@ -957,7 +955,7 @@ private ScriptContext currentContext() { final ScriptContext sc = scontext != null? scontext.get() : null; - return sc == null? initscontext : sc; + return (sc != null)? sc : (engine != null? engine.getContext() : null); } @Override @@ -1067,16 +1065,14 @@ * of the global scope object. * * @param eng ScriptEngine to initialize - * @param ctxt ScriptContext to initialize */ - public void initBuiltinObjects(final ScriptEngine eng, final ScriptContext ctxt) { + public void initBuiltinObjects(final ScriptEngine eng) { if (this.builtinObject != null) { // already initialized, just return return; } this.engine = eng; - this.initscontext = ctxt; if (this.engine != null) { this.scontext = new ThreadLocal<>(); }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJSAdapter.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJSAdapter.java Fri Oct 16 13:41:24 2015 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -52,18 +52,18 @@ import jdk.nashorn.internal.scripts.JO; /** - * This class is the implementation of the Nashorn-specific global object named {@code JSAdapter}. It can be - * thought of as the {@link java.lang.reflect.Proxy} equivalent for JavaScript. NativeJSAdapter calls specially named + * This class is the implementation of the Nashorn-specific global object named {@code JSAdapter}. It can be thought of + * as the {@link java.lang.reflect.Proxy} equivalent for JavaScript. A {@code NativeJSAdapter} calls specially named * JavaScript methods on an adaptee object when property access/update/call/new/delete is attempted on it. Example: *<pre> * var y = { - * __get__ : function (name) { ... } - * __has__ : function (name) { ... } - * __put__ : function (name, value) {...} - * __call__ : function (name, arg1, arg2) {...} - * __new__ : function (arg1, arg2) {...} - * __delete__ : function (name) { ... } - * __getIds__ : function () { ... } + * __get__ : function (name) { ... } + * __has__ : function (name) { ... } + * __put__ : function (name, value) {...} + * __call__ : function (name, arg1, arg2) {...} + * __new__ : function (arg1, arg2) {...} + * __delete__ : function (name) { ... } + * __getKeys__ : function () { ... } * }; * * var x = new JSAdapter(y); @@ -74,17 +74,21 @@ * i in x; // calls y.__has__ * x.p = 10; // calls y.__put__ * delete x.p; // calls y.__delete__ - * for (i in x) { print(i); } // calls y.__getIds__ + * for (i in x) { print(i); } // calls y.__getKeys__ * </pre> * <p> - * JavaScript caller of adapter object is isolated from the fact that the property access/mutation/deletion are really - * calls to JavaScript methods on adaptee. + * The {@code __getKeys__} and {@code __getIds__} properties are mapped to the same operation. Concrete + * {@code JSAdapter} implementations are expected to use only one of these. As {@code __getIds__} exists for + * compatibility reasons only, use of {@code __getKeys__} is recommended. * </p> * <p> - * JSAdapter constructor can optionally receive an "overrides" object. Properties of overrides object is copied to - * JSAdapter instance. When user accessed property is one of these, then adaptee's methods like {@code __get__}, - * {@code __put__} etc. are not called for those. This can be used to make certain "preferred" properties that can be - * accessed in the usual/faster way avoiding proxy mechanism. Example: + * The JavaScript caller of an adapter object is oblivious of the property access/mutation/deletion's being adapted. + * </p> + * <p> + * The {@code JSAdapter} constructor can optionally receive an "overrides" object. The properties of overrides object + * are copied to the {@code JSAdapter} instance. In case user-accessed properties are among these, the adaptee's methods + * like {@code __get__}, {@code __put__} etc. are not called for them. This can be used to make certain "preferred" + * properties that can be accessed in the usual/faster way avoiding the proxy mechanism. Example: * </p> * <pre> * var x = new JSAdapter({ foo: 444, bar: 6546 }) { @@ -95,13 +99,13 @@ * x.bar = 'hello'; // "bar" directly set without __put__ call * x.prop // calls __get__("prop") as 'prop' is not overridden * </pre> - * It is possible to pass a specific prototype for JSAdapter instance by passing three arguments to JSAdapter - * constructor. So exact signature of JSAdapter constructor is as follows: + * It is possible to pass a specific prototype for the {@code JSAdapter} instance by passing three arguments to the + * {@code JSAdapter} constructor. The exact signature of the {@code JSAdapter} constructor is as follows: * <pre> * JSAdapter([proto], [overrides], adaptee); * </pre> - * Both proto and overrides are optional - but adaptee is not. When proto is not passed {@code JSAdapter.prototype} is - * used. + * Both the {@code proto} and {@code overrides} arguments are optional - but {@code adaptee} is not. When {@code proto} + * is not passed, {@code JSAdapter.prototype} is used. */ @ScriptClass("JSAdapter") public final class NativeJSAdapter extends ScriptObject { @@ -113,7 +117,7 @@ public static final String __call__ = "__call__"; /** object new operation */ public static final String __new__ = "__new__"; - /** object getIds operation */ + /** object getIds operation (provided for compatibility reasons; use of getKeys is preferred) */ public static final String __getIds__ = "__getIds__"; /** object getKeys operation */ public static final String __getKeys__ = "__getKeys__"; @@ -142,7 +146,7 @@ private final ScriptObject adaptee; private final boolean overrides; - private static final MethodHandle IS_JSADAPTOR = findOwnMH("isJSAdaptor", boolean.class, Object.class, Object.class, MethodHandle.class, Object.class, ScriptFunction.class); + private static final MethodHandle IS_JSADAPTER = findOwnMH("isJSAdapter", boolean.class, Object.class, Object.class, MethodHandle.class, Object.class, ScriptFunction.class); // initialized by nasgen private static PropertyMap $nasgenmap$; @@ -626,7 +630,7 @@ // to name. Probably not a big deal, but if we can ever make it leaner, it'd be nice. return new GuardedInvocation(MH.dropArguments(MH.constant(Object.class, func.createBound(this, new Object[] { name })), 0, Object.class), - testJSAdaptor(adaptee, null, null, null), + testJSAdapter(adaptee, null, null, null), adaptee.getProtoSwitchPoints(__call__, find.getOwner()), null); } } @@ -697,7 +701,7 @@ if (methodHandle != null) { return new GuardedInvocation( methodHandle, - testJSAdaptor(adaptee, findData.getGetter(Object.class, INVALID_PROGRAM_POINT, null), findData.getOwner(), func), + testJSAdapter(adaptee, findData.getGetter(Object.class, INVALID_PROGRAM_POINT, null), findData.getOwner(), func), adaptee.getProtoSwitchPoints(hook, findData.getOwner()), null); } } @@ -710,16 +714,16 @@ final MethodHandle methodHandle = hook.equals(__put__) ? MH.asType(Lookup.EMPTY_SETTER, type) : Lookup.emptyGetter(type.returnType()); - return new GuardedInvocation(methodHandle, testJSAdaptor(adaptee, null, null, null), adaptee.getProtoSwitchPoints(hook, null), null); + return new GuardedInvocation(methodHandle, testJSAdapter(adaptee, null, null, null), adaptee.getProtoSwitchPoints(hook, null), null); } } - private static MethodHandle testJSAdaptor(final Object adaptee, final MethodHandle getter, final Object where, final ScriptFunction func) { - return MH.insertArguments(IS_JSADAPTOR, 1, adaptee, getter, where, func); + private static MethodHandle testJSAdapter(final Object adaptee, final MethodHandle getter, final Object where, final ScriptFunction func) { + return MH.insertArguments(IS_JSADAPTER, 1, adaptee, getter, where, func); } @SuppressWarnings("unused") - private static boolean isJSAdaptor(final Object self, final Object adaptee, final MethodHandle getter, final Object where, final ScriptFunction func) { + private static boolean isJSAdapter(final Object self, final Object adaptee, final MethodHandle getter, final Object where, final ScriptFunction func) { final boolean res = self instanceof NativeJSAdapter && ((NativeJSAdapter)self).getAdaptee() == adaptee; if (res && getter != null) { try {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java Fri Oct 16 13:41:24 2015 +0100 @@ -141,7 +141,7 @@ private static final LongAdder NAMED_INSTALLED_SCRIPT_COUNT = new LongAdder(); private static final LongAdder ANONYMOUS_INSTALLED_SCRIPT_COUNT = new LongAdder(); - private static final boolean DISABLE_VM_ANONYMOUS_CLASSES = Options.getBooleanProperty("nashorn.disableVmAnonymousClasses"); + /** * Should scripts use only object slots for fields, or dual long/object slots? The default * behaviour is to couple this to optimistic types, using dual representation if optimistic types are enabled @@ -776,7 +776,7 @@ * @return reusable compiled script across many global scopes. */ public MultiGlobalCompiledScript compileScript(final Source source) { - final Class<?> clazz = compile(source, this.errors, this._strict); + final Class<?> clazz = compile(source, this.errors, this._strict, false); final MethodHandle createProgramFunctionHandle = getCreateProgramFunctionHandle(clazz); return new MultiGlobalCompiledScript() { @@ -830,7 +830,7 @@ Class<?> clazz = null; try { - clazz = compile(source, new ThrowErrorManager(), strictFlag); + clazz = compile(source, new ThrowErrorManager(), strictFlag, true); } catch (final ParserException e) { e.throwAsEcmaException(global); return null; @@ -1265,17 +1265,16 @@ * * @param global the global * @param engine the associated ScriptEngine instance, can be null - * @param ctxt the initial ScriptContext, can be null * @return the initialized global scope object. */ - public Global initGlobal(final Global global, final ScriptEngine engine, final ScriptContext ctxt) { + public Global initGlobal(final Global global, final ScriptEngine engine) { // Need only minimal global object, if we are just compiling. if (!env._compile_only) { final Global oldGlobal = Context.getGlobal(); try { Context.setGlobal(global); // initialize global scope with builtin global objects - global.initBuiltinObjects(engine, ctxt); + global.initBuiltinObjects(engine); } finally { Context.setGlobal(oldGlobal); } @@ -1291,7 +1290,7 @@ * @return the initialized global scope object. */ public Global initGlobal(final Global global) { - return initGlobal(global, null, null); + return initGlobal(global, null); } /** @@ -1381,10 +1380,10 @@ } private ScriptFunction compileScript(final Source source, final ScriptObject scope, final ErrorManager errMan) { - return getProgramFunction(compile(source, errMan, this._strict), scope); + return getProgramFunction(compile(source, errMan, this._strict, false), scope); } - private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) { + private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict, final boolean isEval) { // start with no errors, no warnings. errMan.reset(); @@ -1436,7 +1435,7 @@ final URL url = source.getURL(); final CodeSource cs = new CodeSource(url, (CodeSigner[])null); final CodeInstaller installer; - if (DISABLE_VM_ANONYMOUS_CLASSES || env._persistent_cache || !env._lazy_compilation) { + if (!env.useAnonymousClasses(isEval) || env._persistent_cache || !env._lazy_compilation) { // Persistent code cache and eager compilation preclude use of VM anonymous classes final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader; installer = new NamedContextCodeInstaller(this, cs, loader);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/PropertyMap.java Fri Oct 16 13:41:24 2015 +0100 @@ -34,7 +34,9 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.invoke.SwitchPoint; +import java.lang.ref.Reference; import java.lang.ref.SoftReference; +import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.BitSet; import java.util.Collection; @@ -43,6 +45,7 @@ import java.util.NoSuchElementException; import java.util.WeakHashMap; import java.util.concurrent.atomic.LongAdder; +import jdk.nashorn.internal.runtime.options.Options; import jdk.nashorn.internal.scripts.JO; /** @@ -55,6 +58,9 @@ * will return a new map. */ public class PropertyMap implements Iterable<Object>, Serializable { + private static final int INITIAL_SOFT_REFERENCE_DERIVATION_LIMIT = + Math.max(0, Options.getIntProperty("nashorn.propertyMap.softReferenceDerivationLimit", 32)); + /** Used for non extensible PropertyMaps, negative logic as the normal case is extensible. See {@link ScriptObject#preventExtensions()} */ private static final int NOT_EXTENSIBLE = 0b0000_0001; /** Does this map contain valid array keys? */ @@ -78,6 +84,13 @@ /** Structure class name */ private final String className; + /** + * Countdown of number of times this property map has been derived from another property map. When it + * reaches zero, the property map will start using weak references instead of soft references to hold on + * to its history elements. + */ + private final int softReferenceDerivationLimit; + /** A reference to the expected shared prototype property map. If this is set this * property map should only be used if it the same as the actual prototype map. */ private transient SharedPropertyMap sharedProtoMap; @@ -86,7 +99,7 @@ private transient HashMap<String, SwitchPoint> protoSwitches; /** History of maps, used to limit map duplication. */ - private transient WeakHashMap<Property, SoftReference<PropertyMap>> history; + private transient WeakHashMap<Property, Reference<PropertyMap>> history; /** History of prototypes, used to limit map duplication. */ private transient WeakHashMap<ScriptObject, SoftReference<PropertyMap>> protoHistory; @@ -114,6 +127,7 @@ this.fieldMaximum = fieldMaximum; this.spillLength = spillLength; this.flags = flags; + this.softReferenceDerivationLimit = INITIAL_SOFT_REFERENCE_DERIVATION_LIMIT; if (Context.DEBUG) { count.increment(); @@ -126,7 +140,7 @@ * @param propertyMap Existing property map. * @param properties A {@link PropertyHashMap} with a new set of properties. */ - private PropertyMap(final PropertyMap propertyMap, final PropertyHashMap properties, final int flags, final int fieldCount, final int spillLength) { + private PropertyMap(final PropertyMap propertyMap, final PropertyHashMap properties, final int flags, final int fieldCount, final int spillLength, final int softReferenceDerivationLimit) { this.properties = properties; this.flags = flags; this.spillLength = spillLength; @@ -137,6 +151,7 @@ this.listeners = propertyMap.listeners; this.freeSlots = propertyMap.freeSlots; this.sharedProtoMap = propertyMap.sharedProtoMap; + this.softReferenceDerivationLimit = softReferenceDerivationLimit; if (Context.DEBUG) { count.increment(); @@ -150,7 +165,7 @@ * @param propertyMap Existing property map. */ protected PropertyMap(final PropertyMap propertyMap) { - this(propertyMap, propertyMap.properties, propertyMap.flags, propertyMap.fieldCount, propertyMap.spillLength); + this(propertyMap, propertyMap.properties, propertyMap.flags, propertyMap.fieldCount, propertyMap.spillLength, propertyMap.softReferenceDerivationLimit); } private void writeObject(final ObjectOutputStream out) throws IOException { @@ -438,11 +453,7 @@ */ public final PropertyMap addPropertyNoHistory(final Property property) { propertyAdded(property, true); - final PropertyHashMap newProperties = properties.immutableAdd(property); - final PropertyMap newMap = new PropertyMap(this, newProperties, newFlags(property), newFieldCount(property), newSpillLength(property)); - newMap.updateFreeSlots(null, property); - - return newMap; + return addPropertyInternal(property); } /** @@ -457,15 +468,24 @@ PropertyMap newMap = checkHistory(property); if (newMap == null) { - final PropertyHashMap newProperties = properties.immutableAdd(property); - newMap = new PropertyMap(this, newProperties, newFlags(property), newFieldCount(property), newSpillLength(property)); - newMap.updateFreeSlots(null, property); + newMap = addPropertyInternal(property); addToHistory(property, newMap); } return newMap; } + private PropertyMap deriveMap(final PropertyHashMap newProperties, final int newFlags, final int newFieldCount, final int newSpillLength) { + return new PropertyMap(this, newProperties, newFlags, newFieldCount, newSpillLength, softReferenceDerivationLimit == 0 ? 0 : softReferenceDerivationLimit - 1); + } + + private PropertyMap addPropertyInternal(final Property property) { + final PropertyHashMap newProperties = properties.immutableAdd(property); + final PropertyMap newMap = deriveMap(newProperties, newFlags(property), newFieldCount(property), newSpillLength(property)); + newMap.updateFreeSlots(null, property); + return newMap; + } + /** * Remove a property from a map. Cloning or using an existing map if available. * @@ -485,13 +505,13 @@ // If deleted property was last field or spill slot we can make it reusable by reducing field/slot count. // Otherwise mark it as free in free slots bitset. if (isSpill && slot >= 0 && slot == spillLength - 1) { - newMap = new PropertyMap(this, newProperties, flags, fieldCount, spillLength - 1); + newMap = deriveMap(newProperties, flags, fieldCount, spillLength - 1); newMap.freeSlots = freeSlots; } else if (!isSpill && slot >= 0 && slot == fieldCount - 1) { - newMap = new PropertyMap(this, newProperties, flags, fieldCount - 1, spillLength); + newMap = deriveMap(newProperties, flags, fieldCount - 1, spillLength); newMap.freeSlots = freeSlots; } else { - newMap = new PropertyMap(this, newProperties, flags, fieldCount, spillLength); + newMap = deriveMap(newProperties, flags, fieldCount, spillLength); newMap.updateFreeSlots(property, null); } addToHistory(property, newMap); @@ -539,7 +559,7 @@ // Add replaces existing property. final PropertyHashMap newProperties = properties.immutableReplace(oldProperty, newProperty); - final PropertyMap newMap = new PropertyMap(this, newProperties, flags, fieldCount, newSpillLength); + final PropertyMap newMap = deriveMap(newProperties, flags, fieldCount, newSpillLength); if (!sameType) { newMap.updateFreeSlots(oldProperty, newProperty); @@ -584,7 +604,7 @@ final Property[] otherProperties = other.properties.getProperties(); final PropertyHashMap newProperties = properties.immutableAdd(otherProperties); - final PropertyMap newMap = new PropertyMap(this, newProperties, flags, fieldCount, spillLength); + final PropertyMap newMap = deriveMap(newProperties, flags, fieldCount, spillLength); for (final Property property : otherProperties) { // This method is only safe to use with non-slotted, native getter/setter properties assert property.getSlot() == -1; @@ -618,7 +638,7 @@ * @return New map with {@link #NOT_EXTENSIBLE} flag set. */ PropertyMap preventExtensions() { - return new PropertyMap(this, properties, flags | NOT_EXTENSIBLE, fieldCount, spillLength); + return deriveMap(properties, flags | NOT_EXTENSIBLE, fieldCount, spillLength); } /** @@ -634,7 +654,7 @@ newProperties = newProperties.immutableAdd(oldProperty.addFlags(Property.NOT_CONFIGURABLE)); } - return new PropertyMap(this, newProperties, flags | NOT_EXTENSIBLE, fieldCount, spillLength); + return deriveMap(newProperties, flags | NOT_EXTENSIBLE, fieldCount, spillLength); } /** @@ -656,7 +676,7 @@ newProperties = newProperties.immutableAdd(oldProperty.addFlags(propertyFlags)); } - return new PropertyMap(this, newProperties, flags | NOT_EXTENSIBLE, fieldCount, spillLength); + return deriveMap(newProperties, flags | NOT_EXTENSIBLE, fieldCount, spillLength); } /** @@ -743,7 +763,7 @@ history = new WeakHashMap<>(); } - history.put(property, new SoftReference<>(newMap)); + history.put(property, softReferenceDerivationLimit == 0 ? new WeakReference<>(newMap) : new SoftReference<>(newMap)); } /** @@ -756,7 +776,7 @@ private PropertyMap checkHistory(final Property property) { if (history != null) { - final SoftReference<PropertyMap> ref = history.get(property); + final Reference<PropertyMap> ref = history.get(property); final PropertyMap historicMap = ref == null ? null : ref.get(); if (historicMap != null) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Fri Oct 16 13:41:24 2015 +0100 @@ -62,7 +62,7 @@ import jdk.nashorn.internal.ir.SwitchNode; import jdk.nashorn.internal.ir.Symbol; import jdk.nashorn.internal.ir.TryNode; -import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.ir.visitor.SimpleNodeVisitor; import jdk.nashorn.internal.objects.Global; import jdk.nashorn.internal.parser.Parser; import jdk.nashorn.internal.parser.Token; @@ -518,8 +518,7 @@ // don't cache non-split functions from the eager pass); those already cached, or those not split // don't need this step. final Set<Symbol> blockDefinedSymbols = fn.isSplit() && !cached ? Collections.newSetFromMap(new IdentityHashMap<>()) : null; - FunctionNode newFn = (FunctionNode)fn.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { - + FunctionNode newFn = (FunctionNode)fn.accept(new SimpleNodeVisitor() { private Symbol getReplacement(final Symbol original) { if (original == null) { return null; @@ -757,7 +756,7 @@ private FunctionNode extractFunctionFromScript(final FunctionNode script) { final Set<FunctionNode> fns = new HashSet<>(); - script.getBody().accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { + script.getBody().accept(new SimpleNodeVisitor() { @Override public boolean enterFunctionNode(final FunctionNode fn) { fns.add(fn);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptEnvironment.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptEnvironment.java Fri Oct 16 13:41:24 2015 +0100 @@ -213,6 +213,14 @@ /** Timing */ public final Timing _timing; + /** Whether to use anonymous classes. See {@link #useAnonymousClasses(boolean)}. */ + private final AnonymousClasses _anonymousClasses; + private enum AnonymousClasses { + AUTO, + OFF, + ON + } + /** * Constructor * @@ -279,6 +287,18 @@ _version = options.getBoolean("version"); _verify_code = options.getBoolean("verify.code"); + final String anonClasses = options.getString("anonymous.classes"); + if (anonClasses == null || anonClasses.equals("auto")) { + _anonymousClasses = AnonymousClasses.AUTO; + } else if (anonClasses.equals("true")) { + _anonymousClasses = AnonymousClasses.ON; + } else if (anonClasses.equals("false")) { + _anonymousClasses = AnonymousClasses.OFF; + } else { + throw new RuntimeException("Unsupported value for anonymous classes: " + anonClasses); + } + + final String language = options.getString("language"); if (language == null || language.equals("es5")) { _es6 = false; @@ -411,4 +431,13 @@ return _timing != null ? _timing.isEnabled() : false; } + /** + * Returns true if compilation should use anonymous classes. + * @param isEval true if compilation is an eval call. + * @return true if anonymous classes should be used + */ + public boolean useAnonymousClasses(final boolean isEval) { + return _anonymousClasses == AnonymousClasses.ON || (_anonymousClasses == AnonymousClasses.AUTO && isEval); + } + }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java Fri Oct 16 13:41:24 2015 +0100 @@ -710,8 +710,7 @@ final long longIndex = ArrayIndex.toLongIndex(index); final long oldLength = getArray().length(); if (longIndex >= oldLength) { - setArray(getArray().ensure(longIndex)); - doesNotHaveEnsureDelete(longIndex, oldLength, false); + setArray(getArray().ensure(longIndex).safeDelete(oldLength, longIndex - 1, false)); } setArray(getArray().set(index, value, false)); } @@ -2693,11 +2692,7 @@ } if (newLength > arrayLength) { - data = data.ensure(newLength - 1); - if (data.canDelete(arrayLength, newLength - 1, false)) { - data = data.delete(arrayLength, newLength - 1); - } - setArray(data); + setArray(data.ensure(newLength - 1).safeDelete(arrayLength, newLength - 1, false)); return; } @@ -3118,23 +3113,12 @@ return false; } - private void doesNotHaveEnsureDelete(final long longIndex, final long oldLength, final boolean strict) { - if (longIndex > oldLength) { - ArrayData array = getArray(); - if (array.canDelete(oldLength, longIndex - 1, strict)) { - array = array.delete(oldLength, longIndex - 1); - } - setArray(array); - } - } - private void doesNotHave(final int index, final int value, final int callSiteFlags) { final long oldLength = getArray().length(); final long longIndex = ArrayIndex.toLongIndex(index); if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) { final boolean strict = isStrictFlag(callSiteFlags); - setArray(getArray().set(index, value, strict)); - doesNotHaveEnsureDelete(longIndex, oldLength, strict); + setArray(getArray().set(index, value, strict).safeDelete(oldLength, longIndex - 1, strict)); } } @@ -3143,8 +3127,7 @@ final long longIndex = ArrayIndex.toLongIndex(index); if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) { final boolean strict = isStrictFlag(callSiteFlags); - setArray(getArray().set(index, value, strict)); - doesNotHaveEnsureDelete(longIndex, oldLength, strict); + setArray(getArray().set(index, value, strict).safeDelete(oldLength, longIndex - 1, strict)); } } @@ -3153,8 +3136,7 @@ final long longIndex = ArrayIndex.toLongIndex(index); if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) { final boolean strict = isStrictFlag(callSiteFlags); - setArray(getArray().set(index, value, strict)); - doesNotHaveEnsureDelete(longIndex, oldLength, strict); + setArray(getArray().set(index, value, strict).safeDelete(oldLength, longIndex - 1, strict)); } } @@ -3163,8 +3145,7 @@ final long longIndex = ArrayIndex.toLongIndex(index); if (!doesNotHaveCheckArrayKeys(longIndex, value, callSiteFlags) && !doesNotHaveEnsureLength(longIndex, oldLength, callSiteFlags)) { final boolean strict = isStrictFlag(callSiteFlags); - setArray(getArray().set(index, value, strict)); - doesNotHaveEnsureDelete(longIndex, oldLength, strict); + setArray(getArray().set(index, value, strict).safeDelete(oldLength, longIndex - 1, strict)); } }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ArrayData.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ArrayData.java Fri Oct 16 13:41:24 2015 +0100 @@ -258,7 +258,7 @@ * Factory method for unspecified array - start as int * @return ArrayData */ - public final static ArrayData initialArray() { + public static ArrayData initialArray() { return new IntArrayData(); } @@ -278,7 +278,7 @@ * @param size size required * @return size given, always >= size */ - protected final static int alignUp(final int size) { + protected static int alignUp(final int size) { return size + CHUNK_SIZE - 1 & ~(CHUNK_SIZE - 1); } @@ -288,7 +288,7 @@ * @param length the initial length * @return ArrayData */ - public static final ArrayData allocate(final int length) { + public static ArrayData allocate(final int length) { if (length == 0) { return new IntArrayData(); } else if (length >= SparseArrayData.MAX_DENSE_LENGTH) { @@ -304,7 +304,7 @@ * @param array the array * @return ArrayData wrapping this array */ - public static final ArrayData allocate(final Object array) { + public static ArrayData allocate(final Object array) { final Class<?> clazz = array.getClass(); if (clazz == int[].class) { @@ -324,7 +324,7 @@ * @param array the array to use for initial elements * @return the ArrayData */ - public static final ArrayData allocate(final int[] array) { + public static ArrayData allocate(final int[] array) { return new IntArrayData(array, array.length); } @@ -334,7 +334,7 @@ * @param array the array to use for initial elements * @return the ArrayData */ - public static final ArrayData allocate(final long[] array) { + public static ArrayData allocate(final long[] array) { return new LongArrayData(array, array.length); } @@ -344,7 +344,7 @@ * @param array the array to use for initial elements * @return the ArrayData */ - public static final ArrayData allocate(final double[] array) { + public static ArrayData allocate(final double[] array) { return new NumberArrayData(array, array.length); } @@ -354,7 +354,7 @@ * @param array the array to use for initial elements * @return the ArrayData */ - public static final ArrayData allocate(final Object[] array) { + public static ArrayData allocate(final Object[] array) { return new ObjectArrayData(array, array.length); } @@ -364,7 +364,7 @@ * @param buf the nio ByteBuffer to wrap * @return the ArrayData */ - public static final ArrayData allocate(final ByteBuffer buf) { + public static ArrayData allocate(final ByteBuffer buf) { return new ByteBufferArrayData(buf); } @@ -374,7 +374,7 @@ * @param underlying the underlying ArrayData to wrap in the freeze filter * @return the frozen ArrayData */ - public static final ArrayData freeze(final ArrayData underlying) { + public static ArrayData freeze(final ArrayData underlying) { return new FrozenArrayFilter(underlying); } @@ -384,7 +384,7 @@ * @param underlying the underlying ArrayData to wrap in the seal filter * @return the sealed ArrayData */ - public static final ArrayData seal(final ArrayData underlying) { + public static ArrayData seal(final ArrayData underlying) { return new SealedArrayFilter(underlying); } @@ -394,7 +394,7 @@ * @param underlying the underlying ArrayData to wrap in the non extensible filter * @return new array data, filtered */ - public static final ArrayData preventExtension(final ArrayData underlying) { + public static ArrayData preventExtension(final ArrayData underlying) { return new NonExtensibleArrayFilter(underlying); } @@ -404,7 +404,7 @@ * @param underlying the underlying ArrayDAta to wrap in the non extensible filter * @return new array data, filtered */ - public static final ArrayData setIsLengthNotWritable(final ArrayData underlying) { + public static ArrayData setIsLengthNotWritable(final ArrayData underlying) { return new LengthNotWritableFilter(underlying); } @@ -676,19 +676,34 @@ } /** - * Returns if element at specific index range can be deleted or not. + * Returns if element at specific index can be deleted or not. * - * @param fromIndex the start index - * @param toIndex the end index + * @param longIndex the index * @param strict are we in strict mode * * @return true if range can be deleted */ - public boolean canDelete(final long fromIndex, final long toIndex, final boolean strict) { + public boolean canDelete(final long longIndex, final boolean strict) { return true; } /** + * Delete a range from the array if {@code fromIndex} is less than or equal to {@code toIndex} + * and the array supports deletion. + * + * @param fromIndex the start index (inclusive) + * @param toIndex the end index (inclusive) + * @param strict are we in strict mode + * @return an array with the range deleted, or this array if no deletion took place + */ + public final ArrayData safeDelete(final long fromIndex, final long toIndex, final boolean strict) { + if (fromIndex <= toIndex && canDelete(fromIndex, strict)) { + return delete(fromIndex, toIndex); + } + return this; + } + + /** * Returns property descriptor for element at a given index * * @param global the global object
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ByteBufferArrayData.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/ByteBufferArrayData.java Fri Oct 16 13:41:24 2015 +0100 @@ -164,7 +164,7 @@ } @Override - public boolean canDelete(final long fromIndex, final long toIndex, final boolean strict) { + public boolean canDelete(final long longIndex, final boolean strict) { return false; }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SealedArrayFilter.java Fri Oct 16 13:41:24 2015 +0100 @@ -50,15 +50,15 @@ @Override public boolean canDelete(final int index, final boolean strict) { - if (strict) { - throw typeError("cant.delete.property", Integer.toString(index), "sealed array"); - } - return false; + return canDelete(ArrayIndex.toLongIndex(index), strict); } @Override - public boolean canDelete(final long fromIndex, final long toIndex, final boolean strict) { - return canDelete((int) fromIndex, strict); + public boolean canDelete(final long longIndex, final boolean strict) { + if (strict) { + throw typeError("cant.delete.property", Long.toString(longIndex), "sealed array"); + } + return false; } @Override
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Fri Oct 16 13:41:24 2015 +0100 @@ -36,7 +36,7 @@ * Handle arrays where the index is very large. */ class SparseArrayData extends ArrayData { - static final int MAX_DENSE_LENGTH = 8 * 1024 * 1024; + static final int MAX_DENSE_LENGTH = 1024 * 1024; /** Underlying array. */ private ArrayData underlying; @@ -48,7 +48,7 @@ private TreeMap<Long, Object> sparseMap; SparseArrayData(final ArrayData underlying, final long length) { - this(underlying, length, new TreeMap<Long, Object>()); + this(underlying, length, new TreeMap<>()); } SparseArrayData(final ArrayData underlying, final long length, final TreeMap<Long, Object> sparseMap) { @@ -166,8 +166,9 @@ @Override public ArrayData set(final int index, final Object value, final boolean strict) { if (index >= 0 && index < maxDenseLength) { + final long oldLength = underlying.length(); ensure(index); - underlying = underlying.set(index, value, strict); + underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict); setLength(Math.max(underlying.length(), length())); } else { final Long longIndex = indexToKey(index); @@ -181,8 +182,9 @@ @Override public ArrayData set(final int index, final int value, final boolean strict) { if (index >= 0 && index < maxDenseLength) { + final long oldLength = underlying.length(); ensure(index); - underlying = underlying.set(index, value, strict); + underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict); setLength(Math.max(underlying.length(), length())); } else { final Long longIndex = indexToKey(index); @@ -195,8 +197,9 @@ @Override public ArrayData set(final int index, final long value, final boolean strict) { if (index >= 0 && index < maxDenseLength) { + final long oldLength = underlying.length(); ensure(index); - underlying = underlying.set(index, value, strict); + underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict); setLength(Math.max(underlying.length(), length())); } else { final Long longIndex = indexToKey(index); @@ -209,8 +212,9 @@ @Override public ArrayData set(final int index, final double value, final boolean strict) { if (index >= 0 && index < maxDenseLength) { + final long oldLength = underlying.length(); ensure(index); - underlying = underlying.set(index, value, strict); + underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict); setLength(Math.max(underlying.length(), length())); } else { final Long longIndex = indexToKey(index);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/TypedArrayData.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/TypedArrayData.java Fri Oct 16 13:41:24 2015 +0100 @@ -83,7 +83,7 @@ } @Override - public boolean canDelete(final long fromIndex, final long toIndex, final boolean strict) { + public boolean canDelete(final long longIndex, final boolean strict) { return false; }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java Fri Oct 16 13:41:24 2015 +0100 @@ -107,9 +107,10 @@ return null; } - final GuardedInvocation inv; + GuardedInvocation inv; if (jsObjectClass.isInstance(self)) { inv = lookup(desc, request, linkerServices); + inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard()); } else { throw new AssertionError(); // Should never reach here. }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java Fri Oct 16 13:41:24 2015 +0100 @@ -77,9 +77,10 @@ return null; } - final GuardedInvocation inv; + GuardedInvocation inv; if (self instanceof JSObject) { inv = lookup(desc, request, linkerServices); + inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard()); } else if (self instanceof Map || self instanceof Bindings) { // guard to make sure the Map or Bindings does not turn into JSObject later! final GuardedInvocation beanInv = nashornBeansLinker.getGuardedInvocation(request, linkerServices);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java Fri Oct 16 13:41:24 2015 +0100 @@ -64,9 +64,6 @@ private static final String PROFILEFILE = Options.getStringProperty("nashorn.profilefile", "NashornProfile.txt"); private static final MethodHandle INCREASE_MISS_COUNTER = MH.findStatic(MethodHandles.lookup(), LinkerCallSite.class, "increaseMissCount", MH.type(Object.class, String.class, Object.class)); - private static final MethodHandle ON_CATCH_INVALIDATION = MH.findStatic(MethodHandles.lookup(), LinkerCallSite.class, "onCatchInvalidation", MH.type(ChainedCallSite.class, LinkerCallSite.class)); - - private int catchInvalidations; LinkerCallSite(final NashornCallSiteDescriptor descriptor) { super(descriptor); @@ -75,34 +72,6 @@ } } - @Override - protected MethodHandle getPruneCatches() { - return MH.filterArguments(super.getPruneCatches(), 0, ON_CATCH_INVALIDATION); - } - - /** - * Action to perform when a catch guard around a callsite triggers. Increases - * catch invalidation counter - * @param callSite callsite - * @return the callsite, so this can be used as argument filter - */ - @SuppressWarnings("unused") - private static ChainedCallSite onCatchInvalidation(final LinkerCallSite callSite) { - ++callSite.catchInvalidations; - return callSite; - } - - /** - * Get the number of catch invalidations that have happened at this call site so far - * @param callSiteToken call site token, unique to the callsite. - * @return number of catch invalidations, i.e. thrown exceptions caught by the linker - */ - public static int getCatchInvalidationCount(final Object callSiteToken) { - if (callSiteToken instanceof LinkerCallSite) { - return ((LinkerCallSite)callSiteToken).catchInvalidations; - } - return 0; - } /** * Construct a new linker call site. * @param name Name of method.
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/EncodingHelper.java Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/regexp/joni/EncodingHelper.java Fri Oct 16 13:41:24 2015 +0100 @@ -278,8 +278,9 @@ case 0x0d: return true; default: - // true if Unicode separator or BOM - return (1 << Character.getType(code) & CharacterType.SPACE_MASK) != 0 || code == 0xfeff; + // true if Unicode separator or BOM or U+180E (see JDK-8138758) + return (1 << Character.getType(code) & CharacterType.SPACE_MASK) != 0 + || code == 0xfeff || code == 0x180e; } case CharacterType.UPPER: return Character.isUpperCase(code);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Options.properties Thu Oct 08 15:02:57 2015 +0200 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/resources/Options.properties Fri Oct 16 13:41:24 2015 +0100 @@ -380,6 +380,15 @@ enterexit [trace callsite enter/exit], objects [print object properties]." \ } +nashorn.option.anonymous.classes = { \ + name="--anonymous-classes", \ + is_undocumented=true, \ + params=[auto|true|false], \ + default=auto, \ + type=string, \ + desc="Use VM anonymous classes for compiled scripts." \ +} + nashorn.option.verify.code = { \ name="--verify-code", \ is_undocumented=true, \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8137281.js Fri Oct 16 13:41:24 2015 +0100 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, 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-8137281: OutOfMemoryError with large numeric keys in JSON.parse + * + * @test + * @run + */ + +function createObject(startKey, level1, level2) { + var root = {}; + var key = startKey; + for (var i = 0; i < level1; i++) { + var child = {}; + for (var j = 0; j < level2; j++) { + child[key++] = {}; + } + root[key++] = child; + } + return root; +} + +JSON.parse(JSON.stringify(createObject(500000, 20, 20))); +JSON.parse(JSON.stringify(createObject(1000000, 20, 20))); +JSON.parse(JSON.stringify(createObject(2000000, 20, 20))); +JSON.parse(JSON.stringify(createObject(4000000, 20, 20))); +JSON.parse(JSON.stringify(createObject(8000000, 20, 20))); +JSON.parse(JSON.stringify(createObject(16000000, 20, 20)));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8138632.js Fri Oct 16 13:41:24 2015 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015, 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-8138632: Sparse array does not handle growth of underlying dense array + * + * @test + * @run + */ + +var x = []; +x[10000000] = 1; +x[10] = 1; +x[20] = 1; +print(Object.keys(x));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8138632.js.EXPECTED Fri Oct 16 13:41:24 2015 +0100 @@ -0,0 +1,1 @@ +10,20,10000000
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8138758.js Fri Oct 16 13:41:24 2015 +0100 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015, 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-8138758: U+180E not recognized as whitespace by Joni + * + * @test + * @run + */ + + +Assert.assertEquals("\u180e".replace(/\s/, "OK"), "OK"); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/jsadapter-ids.js Fri Oct 16 13:41:24 2015 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, 2015, 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. + */ + +/** + * Verify that JSAdapter __getIds__ works as expected. + * + * @test + * @run + */ + +var obj = new JSAdapter() { + __getIds__: function() { + print("__getIds__ called"); + return [ "foo", "bar" ]; + } +}; + +// calls __getIds__ +for (i in obj) { + print(i); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/jsadapter-ids.js.EXPECTED Fri Oct 16 13:41:24 2015 +0100 @@ -0,0 +1,3 @@ +__getIds__ called +foo +bar
--- a/test/script/basic/jsadapter.js Thu Oct 08 15:02:57 2015 +0200 +++ b/test/script/basic/jsadapter.js Fri Oct 16 13:41:24 2015 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, 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 @@ -45,8 +45,8 @@ print("new with " + arg1 + ", " + arg2); }, - __getIds__: function() { - print("__getIds__ called"); + __getKeys__: function() { + print("__getKeys__ called"); return [ "foo", "bar" ]; }, @@ -78,22 +78,28 @@ // calls __new__ new obj("hey!", "it works!"); +// calls __getKeys__ for (i in obj) { print(i); } +// calls __getValues__ for each (i in obj) { print(i); } +// calls __has__ var x = "foo" in obj; print(x); +// calls __has__ var y = "js" in obj; print(y); +// calls __delete__ print(delete obj.prop); +// call __get__ and __set__ print(obj["js"]); obj["js"] = "javascript"; print(obj["javascript"]);
--- a/test/script/basic/jsadapter.js.EXPECTED Thu Oct 08 15:02:57 2015 +0200 +++ b/test/script/basic/jsadapter.js.EXPECTED Fri Oct 16 13:41:24 2015 +0100 @@ -3,7 +3,7 @@ setter called for 'foo' with 33 method 'func' called with hello, world new with hey!, it works! -__getIds__ called +__getKeys__ called foo bar __getValues__ called
--- a/test/script/nosecurity/JDK-8044798.js Thu Oct 08 15:02:57 2015 +0200 +++ b/test/script/nosecurity/JDK-8044798.js Fri Oct 16 13:41:24 2015 +0100 @@ -127,7 +127,7 @@ // private compile method of Context class var compileMethod = contextCls.getDeclaredMethod("compile", - sourceCls, errorMgrCls, booleanCls); + sourceCls, errorMgrCls, booleanCls, booleanCls); compileMethod.accessible = true; var getContextMethod = contextCls.getMethod("getContext"); @@ -135,7 +135,7 @@ var scriptCls = compileMethod.invoke(getContextMethod.invoke(null), Source.sourceFor("test", "print('hello')"), - new ThrowErrorManager(), false); + new Context.ThrowErrorManager(), false, false); var SCRIPT_CLASS_NAME_PREFIX = "jdk.nashorn.internal.scripts.Script$"; print("script class name pattern satisfied? " +
--- a/test/src/jdk/nashorn/api/scripting/test/PluggableJSObjectTest.java Thu Oct 08 15:02:57 2015 +0200 +++ b/test/src/jdk/nashorn/api/scripting/test/PluggableJSObjectTest.java Fri Oct 16 13:41:24 2015 +0100 @@ -27,6 +27,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.nio.IntBuffer; @@ -34,9 +35,11 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Set; +import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import jdk.nashorn.api.scripting.AbstractJSObject; +import jdk.nashorn.api.scripting.ScriptObjectMirror; import org.testng.annotations.Test; /** @@ -286,4 +289,23 @@ fail(exp.getMessage()); } } + + // @bug 8137258: JSObjectLinker and BrowserJSObjectLinker should not expose internal JS objects + @Test + public void hidingInternalObjectsForJSObjectTest() throws Exception { + final ScriptEngineManager engineManager = new ScriptEngineManager(); + final ScriptEngine e = engineManager.getEngineByName("nashorn"); + + final String code = "function func(obj) { obj.foo = [5, 5]; obj.bar = {} }"; + e.eval(code); + + // call the exposed function but pass user defined JSObject impl as argument + ((Invocable)e).invokeFunction("func", new AbstractJSObject() { + @Override + public void setMember(final String name, final Object value) { + // make sure that wrapped objects are passed (and not internal impl. objects) + assertTrue(value.getClass() == ScriptObjectMirror.class); + } + }); + } }
--- a/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java Thu Oct 08 15:02:57 2015 +0200 +++ b/test/src/jdk/nashorn/api/scripting/test/ScopeTest.java Fri Oct 16 13:41:24 2015 +0100 @@ -30,6 +30,7 @@ import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import javax.script.Bindings; +import javax.script.Invocable; import javax.script.ScriptContext; import javax.script.ScriptEngine; import javax.script.ScriptEngineFactory; @@ -855,4 +856,59 @@ assertTrue(ret, "Expected true in iteration " + i); } } + + // @bug 8138616: invokeFunction fails if function calls a function defined in GLOBAL_SCOPE + @Test + public void invokeFunctionInGlobalScopeTest() throws Exception { + final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); + final ScriptContext ctxt = engine.getContext(); + + // define a function called "func" + engine.eval("func = function() { return 42 }"); + + // move ENGINE_SCOPE Bindings to GLOBAL_SCOPE + ctxt.setBindings(ctxt.getBindings(ScriptContext.ENGINE_SCOPE), ScriptContext.GLOBAL_SCOPE); + + // create a new Bindings and set as ENGINE_SCOPE + ctxt.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE); + + // define new function that calls "func" now in GLOBAL_SCOPE + engine.eval("newfunc = function() { return func() }"); + + // call "newfunc" and check the return value + Object value = ((Invocable)engine).invokeFunction("newfunc"); + assertTrue(((Number)value).intValue() == 42); + } + + + // @bug 8138616: invokeFunction fails if function calls a function defined in GLOBAL_SCOPE + // variant of above that replaces default ScriptContext of the engine with a fresh instance! + @Test + public void invokeFunctionInGlobalScopeTest2() throws Exception { + final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); + + // create a new ScriptContext instance + final ScriptContext ctxt = new SimpleScriptContext(); + // set it as 'default' ScriptContext + engine.setContext(ctxt); + + // create a new Bindings and set as ENGINE_SCOPE + ctxt.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE); + + // define a function called "func" + engine.eval("func = function() { return 42 }"); + + // move ENGINE_SCOPE Bindings to GLOBAL_SCOPE + ctxt.setBindings(ctxt.getBindings(ScriptContext.ENGINE_SCOPE), ScriptContext.GLOBAL_SCOPE); + + // create a new Bindings and set as ENGINE_SCOPE + ctxt.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE); + + // define new function that calls "func" now in GLOBAL_SCOPE + engine.eval("newfunc = function() { return func() }"); + + // call "newfunc" and check the return value + Object value = ((Invocable)engine).invokeFunction("newfunc"); + assertTrue(((Number)value).intValue() == 42); + } }