diff --git a/nashorn/samples/EvalWithArbitraryThis.java.orig b/nashorn/samples/EvalWithArbitraryThis.java.orig deleted file mode 100644 index 4b9c0c76b73..00000000000 --- a/nashorn/samples/EvalWithArbitraryThis.java.orig +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of Oracle nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import javax.script.*; -import jdk.nashorn.api.scripting.*; - -// Simple nashorn demo that evals a script with arbitrary script -// object bound as "this" for the evaluated script. - -public class EvalWithArbitraryThis { - public static void main(String[] args) throws Exception { - ScriptEngineManager m = new ScriptEngineManager(); - ScriptEngine e = m.getEngineByName("nashorn"); - Object sobj = e.eval("( { foo: 343, bar: 'hello' } )"); - - // "this" bound to sobj in this eval. - // so it prints sobj.foo and sobj.bar. - ((ScriptObjectMirror)sobj).eval("print(this.foo); print(this.bar)"); - } -} diff --git a/nashorn/samples/exceptionswallow.js b/nashorn/samples/exceptionswallow.js new file mode 100644 index 00000000000..82f4e2d71fd --- /dev/null +++ b/nashorn/samples/exceptionswallow.js @@ -0,0 +1,136 @@ +#// Usage: jjs exceptionswallow.js -- + +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Oracle nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This example demonstrates Java subclassing by Java.extend +// and javac Compiler and Tree API. This example looks for +// empty catch blocks ("exception swallow") and reports those. + +if (arguments.length == 0) { + print("Usage: jjs exceptionswallow.js -- "); + exit(1); +} + +// Java types used +var File = Java.type("java.io.File"); +var Files = Java.type("java.nio.file.Files"); +var StringArray = Java.type("java.lang.String[]"); +var ToolProvider = Java.type("javax.tools.ToolProvider"); +var Tree = Java.type("com.sun.source.tree.Tree"); +var EmptyStatementTree = Java.type("com.sun.source.tree.EmptyStatementTree"); +var Trees = Java.type("com.sun.source.util.Trees"); +var TreeScanner = Java.type("com.sun.source.util.TreeScanner"); + +// printEmptyCatch + +function printEmptyCatch() { + // get the system compiler tool + var compiler = ToolProvider.systemJavaCompiler; + // get standard file manager + var fileMgr = compiler.getStandardFileManager(null, null, null); + // Using Java.to convert script array (arguments) to a Java String[] + var compUnits = fileMgr.getJavaFileObjects( + Java.to(arguments, StringArray)); + // create a new compilation task + var task = compiler.getTask(null, fileMgr, null, null, null, compUnits); + + // SourcePositions object to get positions of AST nodes + var sourcePositions = Trees.instance(task).sourcePositions; + + // subclass SimpleTreeVisitor - to print empty catch + var EmptyCatchFinder = Java.extend(TreeScanner); + + function hasOnlyEmptyStats(stats) { + var itr = stats.iterator(); + while (itr.hasNext()) { + if (! (itr.next() instanceof EmptyStatementTree)) { + return false; + } + } + + return true; + } + + var visitor = new EmptyCatchFinder() { + // current CompilationUnitTree + compUnit: null, + // current LineMap (pos -> line, column) + lineMap: null, + // current compilation unit's file name + fileName: null, + + // overrides of TreeScanner methods + + visitCompilationUnit: function(node, p) { + // capture info about current Compilation unit + this.compUnit = node; + this.lineMap = node.lineMap; + this.fileName = node.sourceFile.name; + + // Using Java.super API to call super class method here + return Java.super(visitor).visitCompilationUnit(node, p); + }, + + visitCatch: function (node, p) { + var stats = node.block.statements; + if (stats.empty || hasOnlyEmptyStats(stats)) { + // print information on this empty catch + var pos = sourcePositions.getStartPosition(this.compUnit, node); + var line = this.lineMap.getLineNumber(pos); + var col = this.lineMap.getColumnNumber(pos); + print("Exception swallow" + " @ " + this.fileName + ":" + line + ":" + col); + // print(node); + } + } + } + + for each (var cu in task.parse()) { + cu.accept(visitor, null); + } +} + +// for each ".java" file in directory (recursively) and check it! +function main(dir) { + Files.walk(dir.toPath()). + forEach(function(p) { + var name = p.toFile().absolutePath; + if (name.endsWith(".java")) { + try { + printEmptyCatch(p.toFile().getAbsolutePath()); + } catch (e) { + print(e); + } + } + }); +} + +main(new File(arguments[0])); diff --git a/nashorn/samples/find_nonfinals2.js b/nashorn/samples/find_nonfinals2.js index 75fde6246c9..cd003034759 100644 --- a/nashorn/samples/find_nonfinals2.js +++ b/nashorn/samples/find_nonfinals2.js @@ -43,7 +43,6 @@ if (arguments.length == 0) { // Java types used var File = Java.type("java.io.File"); var Files = Java.type("java.nio.file.Files"); -var FileVisitOption = Java.type("java.nio.file.FileVisitOption"); var StringArray = Java.type("java.lang.String[]"); var ToolProvider = Java.type("javax.tools.ToolProvider"); var Tree = Java.type("com.sun.source.tree.Tree"); @@ -106,7 +105,7 @@ function checkNonFinalParams(p) { // for each ".java" file in directory (recursively). function main(dir) { var totalCount = 0; - Files.walk(dir.toPath(), FileVisitOption.FOLLOW_LINKS). + Files.walk(dir.toPath()). forEach(function(p) { var name = p.toFile().absolutePath; if (name.endsWith(".java")) { diff --git a/nashorn/samples/javafoovars.js b/nashorn/samples/javafoovars.js index 037c2bf5461..31fc5ba828a 100644 --- a/nashorn/samples/javafoovars.js +++ b/nashorn/samples/javafoovars.js @@ -42,7 +42,6 @@ if (arguments.length == 0) { // Java types used var File = Java.type("java.io.File"); var Files = Java.type("java.nio.file.Files"); -var FileVisitOption = Java.type("java.nio.file.FileVisitOption"); var StringArray = Java.type("java.lang.String[]"); var ToolProvider = Java.type("javax.tools.ToolProvider"); var Tree = Java.type("com.sun.source.tree.Tree"); @@ -81,7 +80,7 @@ function countFoo() { // for each ".java" file in directory (recursively) count "foo". function main(dir) { var totalCount = 0; - Files.walk(dir.toPath(), FileVisitOption.FOLLOW_LINKS). + Files.walk(dir.toPath()). forEach(function(p) { var name = p.toFile().absolutePath; if (name.endsWith(".java")) { diff --git a/nashorn/samples/resourcetrysuggester.js b/nashorn/samples/resourcetrysuggester.js new file mode 100644 index 00000000000..d21276c12ec --- /dev/null +++ b/nashorn/samples/resourcetrysuggester.js @@ -0,0 +1,156 @@ +#// Usage: jjs resourcetrysuggester.js -- + +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Oracle nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This example demonstrates Java subclassing by Java.extend +// and javac Compiler and Tree API. This example looks for +// finally clauses with "close" call and suggests "resource try"! + +if (arguments.length == 0) { + print("Usage: jjs resourcetrysuggester.js -- "); + exit(1); +} + +// Java types used +var ExpressionStatementTree = Java.type("com.sun.source.tree.ExpressionStatementTree"); +var File = Java.type("java.io.File"); +var Files = Java.type("java.nio.file.Files"); +var MemberSelectTree = Java.type("com.sun.source.tree.MemberSelectTree"); +var MethodInvocationTree = Java.type("com.sun.source.tree.MethodInvocationTree"); +var StringArray = Java.type("java.lang.String[]"); +var ToolProvider = Java.type("javax.tools.ToolProvider"); +var Tree = Java.type("com.sun.source.tree.Tree"); +var Trees = Java.type("com.sun.source.util.Trees"); +var TreeScanner = Java.type("com.sun.source.util.TreeScanner"); + +// resourceTrySuggestions + +function resourceTrySuggestions() { + // get the system compiler tool + var compiler = ToolProvider.systemJavaCompiler; + // get standard file manager + var fileMgr = compiler.getStandardFileManager(null, null, null); + // Using Java.to convert script array (arguments) to a Java String[] + var compUnits = fileMgr.getJavaFileObjects( + Java.to(arguments, StringArray)); + // create a new compilation task + var task = compiler.getTask(null, fileMgr, null, null, null, compUnits); + + // SourcePositions object to get positions of AST nodes + var sourcePositions = Trees.instance(task).sourcePositions; + + // subclass SimpleTreeVisitor - to print resource try suggestions + var ResourceTrySuggester = Java.extend(TreeScanner); + + function hasOnlyEmptyStats(stats) { + var itr = stats.iterator(); + while (itr.hasNext()) { + if (! (itr.next() instanceof EmptyStatementTree)) { + return false; + } + } + + return true; + } + + // does the given statement list has an expression statement which + // calls "close" method (don't worry about types - just crude one will do) + function hasCloseCall(stats) { + var itr = stats.iterator(); + while (itr.hasNext()) { + var stat = itr.next(); + if (stat instanceof ExpressionStatementTree) { + var expr = stat.expression; + if (expr instanceof MethodInvocationTree) { + var method = expr.methodSelect; + if (method instanceof MemberSelectTree) { + return method.identifier.toString().equals("close"); + } + } + } + } + return false; + } + + var visitor = new ResourceTrySuggester() { + // current CompilationUnitTree + compUnit: null, + // current LineMap (pos -> line, column) + lineMap: null, + // current compilation unit's file name + fileName: null, + + // overrides of TreeScanner methods + + visitCompilationUnit: function(node, p) { + // capture info about current Compilation unit + this.compUnit = node; + this.lineMap = node.lineMap; + this.fileName = node.sourceFile.name; + + // Using Java.super API to call super class method here + return Java.super(visitor).visitCompilationUnit(node, p); + }, + + visitTry: function (node, p) { + var finallyBlk = node.finallyBlock; + if (finallyBlk != null && hasCloseCall(finallyBlk.statements)) { + var pos = sourcePositions.getStartPosition(this.compUnit, node); + var line = this.lineMap.getLineNumber(pos); + var col = this.lineMap.getColumnNumber(pos); + print("Consider resource try statement " + " @ " + this.fileName + ":" + line + ":" + col); + // print(node); + } + } + } + + for each (var cu in task.parse()) { + cu.accept(visitor, null); + } +} + +// for each ".java" file in directory (recursively) and check it! +function main(dir) { + Files.walk(dir.toPath()). + forEach(function(p) { + var name = p.toFile().absolutePath; + if (name.endsWith(".java")) { + try { + resourceTrySuggestions(p.toFile().getAbsolutePath()); + } catch (e) { + print(e); + } + } + }); +} + +main(new File(arguments[0])); diff --git a/nashorn/samples/zipfs.js b/nashorn/samples/zipfs.js index ecb6f61a54b..fba5f15dac3 100644 --- a/nashorn/samples/zipfs.js +++ b/nashorn/samples/zipfs.js @@ -36,13 +36,12 @@ if (arguments.length == 0) { var Files = Java.type("java.nio.file.Files") var FileSystems = Java.type("java.nio.file.FileSystems") -var FileVisitOption = Java.type("java.nio.file.FileVisitOption") var Paths = Java.type("java.nio.file.Paths") var zipfile = Paths.get(arguments[0]) var fs = FileSystems.newFileSystem(zipfile, null) var root = fs.rootDirectories[0] -Files.walk(root, FileVisitOption.FOLLOW_LINKS).forEach( +Files.walk(root).forEach( function(p) (print(p), print(Files.readAttributes(p, "zip:*"))) ) fs.close() diff --git a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/EditPad.java b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/EditPad.java index 9dbe2a89cfc..66500353fe3 100644 --- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/EditPad.java +++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/EditPad.java @@ -49,8 +49,8 @@ final class EditPad extends JFrame implements Runnable { private final boolean[] closeLock; private final Consumer saveHandler; - EditPad(Consumer errorHandler, String initialText, - boolean[] closeLock, Consumer saveHandler) { + EditPad(final Consumer errorHandler, final String initialText, + final boolean[] closeLock, final Consumer saveHandler) { super("Edit Pad (Experimental)"); this.errorHandler = errorHandler; this.initialText = initialText; @@ -62,7 +62,7 @@ final class EditPad extends JFrame implements Runnable { public void run() { addWindowListener(new WindowAdapter() { @Override - public void windowClosing(WindowEvent e) { + public void windowClosing(final WindowEvent e) { EditPad.this.dispose(); notifyClose(); } @@ -77,7 +77,7 @@ final class EditPad extends JFrame implements Runnable { setVisible(true); } - private JPanel buttons(JTextArea textArea) { + private JPanel buttons(final JTextArea textArea) { FlowLayout flow = new FlowLayout(); flow.setHgap(35); JPanel buttons = new JPanel(flow); @@ -118,8 +118,8 @@ final class EditPad extends JFrame implements Runnable { } } - static void edit(Consumer errorHandler, String initialText, - Consumer saveHandler) { + static void edit(final Consumer errorHandler, final String initialText, + final Consumer saveHandler) { boolean[] closeLock = new boolean[1]; SwingUtilities.invokeLater( new EditPad(errorHandler, initialText, closeLock, saveHandler)); @@ -127,7 +127,7 @@ final class EditPad extends JFrame implements Runnable { while (!closeLock[0]) { try { closeLock.wait(); - } catch (InterruptedException ex) { + } catch (final InterruptedException ex) { // ignore and loop } } diff --git a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/ExternalEditor.java b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/ExternalEditor.java index d67add1f740..c046a350aa9 100644 --- a/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/ExternalEditor.java +++ b/nashorn/src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/ExternalEditor.java @@ -49,13 +49,13 @@ final class ExternalEditor { private Path dir; private Path tmpfile; - ExternalEditor(Consumer errorHandler, Consumer saveHandler, Console input) { + ExternalEditor(final Consumer errorHandler, final Consumer saveHandler, final Console input) { this.errorHandler = errorHandler; this.saveHandler = saveHandler; this.input = input; } - private void edit(String cmd, String initialText) { + private void edit(final String cmd, final String initialText) { try { setupWatch(initialText); launch(cmd); @@ -67,7 +67,7 @@ final class ExternalEditor { /** * Creates a WatchService and registers the given directory */ - private void setupWatch(String initialText) throws IOException { + private void setupWatch(final String initialText) throws IOException { this.watcher = FileSystems.getDefault().newWatchService(); this.dir = Files.createTempDirectory("REPL"); this.tmpfile = Files.createTempFile(dir, null, ".js"); @@ -81,9 +81,9 @@ final class ExternalEditor { WatchKey key; try { key = watcher.take(); - } catch (ClosedWatchServiceException ex) { + } catch (final ClosedWatchServiceException ex) { break; - } catch (InterruptedException ex) { + } catch (final InterruptedException ex) { continue; // tolerate an intrupt } @@ -103,7 +103,7 @@ final class ExternalEditor { watchedThread.start(); } - private void launch(String cmd) throws IOException { + private void launch(final String cmd) throws IOException { ProcessBuilder pb = new ProcessBuilder(cmd, tmpfile.toString()); pb = pb.inheritIO(); @@ -111,9 +111,9 @@ final class ExternalEditor { input.suspend(); Process process = pb.start(); process.waitFor(); - } catch (IOException ex) { + } catch (final IOException ex) { errorHandler.accept("process IO failure: " + ex.getMessage()); - } catch (InterruptedException ex) { + } catch (final InterruptedException ex) { errorHandler.accept("process interrupt: " + ex.getMessage()); } finally { try { @@ -132,7 +132,7 @@ final class ExternalEditor { List lines; try { lines = Files.readAllLines(tmpfile); - } catch (IOException ex) { + } catch (final IOException ex) { errorHandler.accept("Failure read edit file: " + ex.getMessage()); return ; } @@ -144,8 +144,8 @@ final class ExternalEditor { saveHandler.accept(sb.toString()); } - static void edit(String cmd, Consumer errorHandler, String initialText, - Consumer saveHandler, Console input) { + static void edit(final String cmd, final Consumer errorHandler, final String initialText, + final Consumer saveHandler, final Console input) { ExternalEditor ed = new ExternalEditor(errorHandler, saveHandler, input); ed.edit(cmd, initialText); } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ApplySpecialization.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ApplySpecialization.java index abeb2846477..7616c08a2fc 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ApplySpecialization.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ApplySpecialization.java @@ -40,7 +40,6 @@ import jdk.nashorn.internal.ir.AccessNode; import jdk.nashorn.internal.ir.CallNode; import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.Node; @@ -384,7 +383,7 @@ public final class ApplySpecialization extends NodeVisitor imple callSiteTypes.pop(); explodedArguments.pop(); - return newFunctionNode.setState(lc, CompilationState.BUILTINS_TRANSFORMED); + return newFunctionNode; } private static boolean isApply(final CallNode callNode) { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/AssignSymbols.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/AssignSymbols.java index e0894d1965d..67b74c2ac58 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/AssignSymbols.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/AssignSymbols.java @@ -65,7 +65,6 @@ import jdk.nashorn.internal.ir.CatchNode; import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.ForNode; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.IndexNode; import jdk.nashorn.internal.ir.LexicalContext; @@ -828,7 +827,7 @@ final class AssignSymbols extends NodeVisitor implements Loggabl lc.applyTopFlags(functionNode)))) .setThisProperties(lc, thisProperties.pop().size())); } - return finalizedFunction.setState(lc, CompilationState.SYMBOLS_ASSIGNED); + return finalizedFunction; } @Override diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java index df3423e8d0d..a7fbdb12e02 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java @@ -93,7 +93,6 @@ import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.ExpressionStatement; import jdk.nashorn.internal.ir.ForNode; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.GetSplitState; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.IfNode; @@ -2142,7 +2141,7 @@ final class CodeGenerator extends NodeOperatorVisitor unitSet = CompileUnit.createCompileUnitSet(); @@ -480,26 +398,11 @@ enum CompilationPhase { public String toString() { return "'Reinitialize cached'"; } - }, + } - /** - * Bytecode generation: - * - * Generate the byte code class(es) resulting from the compiled FunctionNode - */ - BYTECODE_GENERATION_PHASE( - EnumSet.of( - INITIALIZED, - PARSED, - CONSTANT_FOLDED, - LOWERED, - BUILTINS_TRANSFORMED, - SPLIT, - SYMBOLS_ASSIGNED, - SCOPE_DEPTHS_COMPUTED, - OPTIMISTIC_TYPES_ASSIGNED, - LOCAL_VARIABLE_TYPES_CALCULATED)) { + static final CompilationPhase REINITIALIZE_CACHED = new ReinitializeCachedPhase(); + private static final class BytecodeGenerationPhase extends CompilationPhase { @Override FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { final ScriptEnvironment senv = compiler.getScriptEnvironment(); @@ -517,7 +420,7 @@ enum CompilationPhase { try { // Explicitly set BYTECODE_GENERATED here; it can not be set in case of skipping codegen for :program // in the lazy + optimistic world. See CodeGenerator.skipFunction(). - newFunctionNode = transformFunction(newFunctionNode, codegen).setState(null, BYTECODE_GENERATED); + newFunctionNode = transformFunction(newFunctionNode, codegen); codegen.generateScopeCalls(); } catch (final VerifyError e) { if (senv._verify_code || senv._print_code) { @@ -565,22 +468,16 @@ enum CompilationPhase { public String toString() { return "'Bytecode Generation'"; } - }, + } - INSTALL_PHASE( - EnumSet.of( - INITIALIZED, - PARSED, - CONSTANT_FOLDED, - LOWERED, - BUILTINS_TRANSFORMED, - SPLIT, - SYMBOLS_ASSIGNED, - SCOPE_DEPTHS_COMPUTED, - OPTIMISTIC_TYPES_ASSIGNED, - LOCAL_VARIABLE_TYPES_CALCULATED, - BYTECODE_GENERATED)) { + /** + * Bytecode generation: + * + * Generate the byte code class(es) resulting from the compiled FunctionNode + */ + static final CompilationPhase BYTECODE_GENERATION_PHASE = new BytecodeGenerationPhase(); + private static final class InstallPhase extends CompilationPhase { @Override FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { final DebugLogger log = compiler.getLogger(); @@ -648,18 +545,16 @@ enum CompilationPhase { log.fine(sb.toString()); } - return setStates(fn.setRootClass(null, rootClass), BYTECODE_INSTALLED); + return fn.setRootClass(null, rootClass); } @Override public String toString() { return "'Class Installation'"; } + } - }; - - /** pre conditions required for function node to which this transform is to be applied */ - private final EnumSet pre; + static final CompilationPhase INSTALL_PHASE = new InstallPhase(); /** start time of transform - used for timing, see {@link jdk.nashorn.internal.runtime.Timing} */ private long startTime; @@ -670,21 +565,7 @@ enum CompilationPhase { /** boolean that is true upon transform completion */ private boolean isFinished; - private CompilationPhase(final EnumSet pre) { - this.pre = pre; - } - - private static FunctionNode setStates(final FunctionNode functionNode, final CompilationState state) { - if (!AssertsEnabled.assertsEnabled()) { - return functionNode; - } - return transformFunction(functionNode, new NodeVisitor(new LexicalContext()) { - @Override - public Node leaveFunctionNode(final FunctionNode fn) { - return fn.setState(lc, state); - } - }); - } + private CompilationPhase() {} /** * Start a compilation phase @@ -694,23 +575,7 @@ enum CompilationPhase { */ protected FunctionNode begin(final Compiler compiler, final FunctionNode functionNode) { compiler.getLogger().indent(); - - assert pre != null; - - if (!functionNode.hasState(pre)) { - final StringBuilder sb = new StringBuilder("Compilation phase "); - sb.append(this). - append(" is not applicable to "). - append(quote(functionNode.getName())). - append("\n\tFunctionNode state = "). - append(functionNode.getState()). - append("\n\tRequired state = "). - append(this.pre); - - throw new CompilationException(sb.toString()); - } - - startTime = System.nanoTime(); + startTime = System.nanoTime(); return functionNode; } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Compiler.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Compiler.java index 24511c54d5b..6d606fd0e37 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Compiler.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Compiler.java @@ -172,17 +172,17 @@ public final class Compiler implements Loggable { "Common initial phases", CompilationPhase.CONSTANT_FOLDING_PHASE, CompilationPhase.LOWERING_PHASE, - CompilationPhase.TRANSFORM_BUILTINS_PHASE, + CompilationPhase.APPLY_SPECIALIZATION_PHASE, CompilationPhase.SPLITTING_PHASE, CompilationPhase.PROGRAM_POINT_PHASE, CompilationPhase.SYMBOL_ASSIGNMENT_PHASE, CompilationPhase.SCOPE_DEPTH_COMPUTATION_PHASE, - CompilationPhase.CACHE_AST + CompilationPhase.CACHE_AST_PHASE ); private final static CompilationPhases COMPILE_CACHED_UPTO_BYTECODE = new CompilationPhases( "After common phases, before bytecode generator", - CompilationPhase.DECLARE_LOCAL_SYMBOLS_TO_COMPILER, + CompilationPhase.DECLARE_LOCAL_SYMBOLS_PHASE, CompilationPhase.OPTIMISTIC_TYPE_ASSIGNMENT_PHASE, CompilationPhase.LOCAL_VARIABLE_TYPE_CALCULATION_PHASE ); diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java index cbc5780e60a..6f962ce0644 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FindScopeDepths.java @@ -34,7 +34,6 @@ import java.util.Map; import java.util.Set; import jdk.nashorn.internal.ir.Block; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.Node; @@ -180,8 +179,7 @@ final class FindScopeDepths extends NodeVisitor implements Logga @Override public Node leaveFunctionNode(final FunctionNode functionNode) { final String name = functionNode.getName(); - FunctionNode newFunctionNode = functionNode.setState(lc, CompilationState.SCOPE_DEPTHS_COMPUTED); - + FunctionNode newFunctionNode = functionNode; if (compiler.isOnDemandCompilation()) { final RecompilableScriptFunctionData data = compiler.getScriptFunctionData(newFunctionNode.getId()); if (data.inDynamicContext()) { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java index 7c8852f2b09..47535e59ac4 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java @@ -37,7 +37,6 @@ import jdk.nashorn.internal.ir.CaseNode; import jdk.nashorn.internal.ir.EmptyNode; import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.IfNode; import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LiteralNode; @@ -101,7 +100,7 @@ final class FoldConstants extends NodeVisitor implements Loggabl @Override public Node leaveFunctionNode(final FunctionNode functionNode) { - return functionNode.setState(lc, CompilationState.CONSTANT_FOLDED); + return functionNode; } @Override diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java index c17edcc0f16..afafd3e88ba 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java @@ -54,7 +54,6 @@ import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.ExpressionStatement; import jdk.nashorn.internal.ir.ForNode; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.GetSplitState; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.IfNode; @@ -1478,7 +1477,6 @@ final class LocalVariableTypesCalculator extends NodeVisitor{ newFunction = newFunction.setReturnType(lc, returnType); - newFunction = newFunction.setState(lc, CompilationState.LOCAL_VARIABLE_TYPES_CALCULATED); newFunction = newFunction.setParameters(lc, newFunction.visitParameters(applyChangesVisitor)); return newFunction; } diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java index c72e94b9e0c..6e0cc49bf41 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java @@ -52,7 +52,6 @@ import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.ExpressionStatement; import jdk.nashorn.internal.ir.ForNode; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.IfNode; import jdk.nashorn.internal.ir.IndexNode; @@ -276,7 +275,7 @@ final class Lower extends NodeOperatorVisitor implements Lo @Override public Node leaveFunctionNode(final FunctionNode functionNode) { log.info("END FunctionNode: ", functionNode.getName()); - return functionNode.setState(lc, CompilationState.LOWERED); + return functionNode; } @Override diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java index c8029070a8a..2ac57041d11 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java @@ -38,7 +38,6 @@ import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.ExpressionStatement; import jdk.nashorn.internal.ir.ForNode; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.IfNode; import jdk.nashorn.internal.ir.IndexNode; @@ -208,7 +207,7 @@ final class OptimisticTypesCalculator extends NodeVisitor { @Override public Node leaveFunctionNode(final FunctionNode functionNode) { neverOptimistic.pop(); - return functionNode.setState(lc, CompilationState.OPTIMISTIC_TYPES_ASSIGNED); + return functionNode; } @Override diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ReplaceCompileUnits.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ReplaceCompileUnits.java index 57f9e681dc5..616dde75437 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ReplaceCompileUnits.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ReplaceCompileUnits.java @@ -29,7 +29,6 @@ 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.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; @@ -64,7 +63,7 @@ abstract class ReplaceCompileUnits extends NodeVisitor { @Override public Node leaveFunctionNode(final FunctionNode node) { - return node.setCompileUnit(lc, getExistingReplacement(node)).setState(lc, CompilationState.COMPILE_UNITS_REUSED); + return node.setCompileUnit(lc, getExistingReplacement(node)); } @Override diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SplitIntoFunctions.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SplitIntoFunctions.java index 4ec70466b03..65e8b602752 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SplitIntoFunctions.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SplitIntoFunctions.java @@ -47,7 +47,6 @@ import jdk.nashorn.internal.ir.ContinueNode; import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.ExpressionStatement; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.GetSplitState; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.IfNode; @@ -176,11 +175,9 @@ final class SplitIntoFunctions extends NodeVisitor { // we still use IS_SPLIT as the criteria in CompilationPhase.SERIALIZE_SPLIT_PHASE. FunctionNode.IS_ANONYMOUS | FunctionNode.USES_ANCESTOR_SCOPE | FunctionNode.IS_SPLIT, body, - CompilationState.INITIALIZED, null ) - .setCompileUnit(lc, splitNode.getCompileUnit()) - .copyCompilationState(lc, originalFn); + .setCompileUnit(lc, splitNode.getCompileUnit()); // Call the function: // either "(function () { ... }).call(this)" diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Splitter.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Splitter.java index 929e954d5a6..6b818898eb0 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Splitter.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Splitter.java @@ -33,7 +33,6 @@ import java.util.List; import java.util.Map; import jdk.nashorn.internal.ir.Block; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.LexicalContext; import jdk.nashorn.internal.ir.LiteralNode; import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; @@ -158,7 +157,7 @@ final class Splitter extends NodeVisitor implements Loggable { assert functionNode.getCompileUnit() != null; - return functionNode.setState(null, CompilationState.SPLIT); + return functionNode; } private static List directChildren(final FunctionNode functionNode) { diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java index 6ae4e402f02..4c5611a115b 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java @@ -33,10 +33,8 @@ import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALL import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_VALUES; import java.util.Collections; -import java.util.EnumSet; import java.util.Iterator; import java.util.List; -import jdk.nashorn.internal.AssertsEnabled; import jdk.nashorn.internal.codegen.CompileUnit; import jdk.nashorn.internal.codegen.Compiler; import jdk.nashorn.internal.codegen.CompilerConstants; @@ -74,40 +72,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag SETTER } - /** Compilation states available */ - public enum CompilationState { - /** compiler is ready */ - INITIALIZED, - /** method has been parsed */ - PARSED, - /** method has been parsed */ - PARSE_ERROR, - /** constant folding pass */ - CONSTANT_FOLDED, - /** method has been lowered */ - LOWERED, - /** program points have been assigned to unique locations */ - PROGRAM_POINTS_ASSIGNED, - /** any transformations of builtins have taken place, e.g. apply=>call */ - BUILTINS_TRANSFORMED, - /** method has been split */ - SPLIT, - /** method has had symbols assigned */ - SYMBOLS_ASSIGNED, - /** computed scope depths for symbols */ - SCOPE_DEPTHS_COMPUTED, - /** method has had types calculated*/ - OPTIMISTIC_TYPES_ASSIGNED, - /** method has had types calculated */ - LOCAL_VARIABLE_TYPES_CALCULATED, - /** compile units reused (optional) */ - COMPILE_UNITS_REUSED, - /** method has been emitted to bytecode */ - BYTECODE_GENERATED, - /** method has been installed */ - BYTECODE_INSTALLED - } - /** Source of entity. */ private transient final Source source; @@ -145,10 +109,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag /** Method's namespace. */ private transient final Namespace namespace; - /** Current compilation state */ - @Ignore - private final EnumSet compilationState; - /** Number of properties of "this" object assigned in this function */ @Ignore private final int thisProperties; @@ -306,7 +266,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag * @param kind kind of function as in {@link FunctionNode.Kind} * @param flags initial flags * @param body body of the function - * @param state The initial state from the parser. Must be one of {@link CompilationState#PARSED} and {@link CompilationState#PARSE_ERROR} * @param endParserState The parser state at the end of the parsing. */ public FunctionNode( @@ -323,7 +282,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag final FunctionNode.Kind kind, final int flags, final Block body, - final CompilationState state, final Object endParserState) { super(token, finish); @@ -336,7 +294,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag this.firstToken = firstToken; this.lastToken = lastToken; this.namespace = namespace; - this.compilationState = EnumSet.of(CompilationState.INITIALIZED, state); this.flags = flags; this.compileUnit = null; this.body = body; @@ -353,7 +310,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag final String name, final Type returnType, final CompileUnit compileUnit, - final EnumSet compilationState, final Block body, final List parameters, final int thisProperties, @@ -368,7 +324,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag this.returnType = returnType; this.compileUnit = compileUnit; this.lastToken = lastToken; - this.compilationState = compilationState; this.body = body; this.parameters = parameters; this.thisProperties = thisProperties; @@ -468,7 +423,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag name, returnType, compileUnit, - compilationState, body, parameters, thisProperties, @@ -543,80 +497,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag return lineNumber; } - /** - * Get the compilation state of this function - * @return the compilation state - */ - public EnumSet getState() { - return compilationState; - } - - /** - * Check whether this FunctionNode has reached a give CompilationState. - * - * @param state the state to check for - * @return true of the node is in the given state - */ - public boolean hasState(final EnumSet state) { - return !AssertsEnabled.assertsEnabled() || compilationState.containsAll(state); - } - - /** - * Add a state to the total CompilationState of this node, e.g. if - * FunctionNode has been lowered, the compiler will add - * {@code CompilationState#LOWERED} to the state vector - * - * @param lc lexical context - * @param state {@link CompilationState} to add - * @return function node or a new one if state was changed - */ - public FunctionNode setState(final LexicalContext lc, final CompilationState state) { - if (!AssertsEnabled.assertsEnabled() || this.compilationState.contains(state)) { - return this; - } - final EnumSet newState = EnumSet.copyOf(this.compilationState); - newState.add(state); - return setCompilationState(lc, newState); - } - - /** - * Copy a compilation state from an original function to this function. Used when creating synthetic - * function nodes by the splitter. - * - * @param lc lexical context - * @param original the original function node to copy compilation state from - * @return function node or a new one if state was changed - */ - public FunctionNode copyCompilationState(final LexicalContext lc, final FunctionNode original) { - final EnumSet origState = original.compilationState; - if (!AssertsEnabled.assertsEnabled() || this.compilationState.containsAll(origState)) { - return this; - } - final EnumSet newState = EnumSet.copyOf(this.compilationState); - newState.addAll(origState); - return setCompilationState(lc, newState); - } - - private FunctionNode setCompilationState(final LexicalContext lc, final EnumSet compilationState) { - return Node.replaceInLexicalContext( - lc, - this, - new FunctionNode( - this, - lastToken, - endParserState, - flags, - name, - returnType, - compileUnit, - compilationState, - body, - parameters, - thisProperties, - rootClass, source, namespace)); - } - - /** * Create a unique name in the namespace of this FunctionNode * @param base prefix for name @@ -682,7 +562,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag name, returnType, compileUnit, - compilationState, body, parameters, thisProperties, @@ -823,7 +702,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag name, returnType, compileUnit, - compilationState, body, parameters, thisProperties, @@ -919,7 +797,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag name, returnType, compileUnit, - compilationState, body, parameters, thisProperties, @@ -996,7 +873,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag name, returnType, compileUnit, - compilationState, body, parameters, thisProperties, @@ -1070,7 +946,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag name, returnType, compileUnit, - compilationState, body, parameters, thisProperties, @@ -1158,7 +1033,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag name, type, compileUnit, - compilationState, body, parameters, thisProperties, @@ -1224,7 +1098,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag name, returnType, compileUnit, - compilationState, body, parameters, thisProperties, @@ -1280,7 +1153,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag name, returnType, compileUnit, - compilationState, body, parameters, thisProperties, diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java index c11d38b70ad..292d59d75b6 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java @@ -84,7 +84,6 @@ import jdk.nashorn.internal.ir.Expression; import jdk.nashorn.internal.ir.ExpressionStatement; import jdk.nashorn.internal.ir.ForNode; import jdk.nashorn.internal.ir.FunctionNode; -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.IdentNode; import jdk.nashorn.internal.ir.IfNode; import jdk.nashorn.internal.ir.IndexNode; @@ -487,7 +486,6 @@ loop: } private FunctionNode createFunctionNode(final ParserContextFunctionNode function, final long startToken, final IdentNode ident, final List parameters, final FunctionNode.Kind kind, final int functionLine, final Block body){ - final CompilationState state = errors.hasErrors() ? CompilationState.PARSE_ERROR : CompilationState.PARSED; // Start new block. final FunctionNode functionNode = new FunctionNode( @@ -504,7 +502,6 @@ loop: kind, function.getFlags(), body, - state, function.getEndParserState()); printAST(functionNode); diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java index a99b7dafbc2..0224bf77724 100644 --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java @@ -591,7 +591,7 @@ public class ScriptFunction extends ScriptObject { * * @param newPrototype new prototype object */ - public final void setPrototype(Object newPrototype) { + public final void setPrototype(final Object newPrototype) { if (newPrototype instanceof ScriptObject && newPrototype != this.prototype && allocatorMap != null) { // Replace our current allocator map with one that is associated with the new prototype. allocatorMap = allocatorMap.changeProto((ScriptObject) newPrototype);