Tue, 15 Sep 2015 16:17:33 +0530
8055917: jdk.nashorn.internal.codegen.CompilationPhase$N should be renamed to proper classes
Reviewed-by: attila, hannesw, mhaupt
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/samples/exceptionswallow.js Tue Sep 15 16:17:33 2015 +0530 1.3 @@ -0,0 +1,136 @@ 1.4 +#// Usage: jjs exceptionswallow.js -- <directory> 1.5 + 1.6 +/* 1.7 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 1.8 + * 1.9 + * Redistribution and use in source and binary forms, with or without 1.10 + * modification, are permitted provided that the following conditions 1.11 + * are met: 1.12 + * 1.13 + * - Redistributions of source code must retain the above copyright 1.14 + * notice, this list of conditions and the following disclaimer. 1.15 + * 1.16 + * - Redistributions in binary form must reproduce the above copyright 1.17 + * notice, this list of conditions and the following disclaimer in the 1.18 + * documentation and/or other materials provided with the distribution. 1.19 + * 1.20 + * - Neither the name of Oracle nor the names of its 1.21 + * contributors may be used to endorse or promote products derived 1.22 + * from this software without specific prior written permission. 1.23 + * 1.24 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 1.25 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 1.26 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.27 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1.28 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.29 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.30 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.31 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.32 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.33 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.34 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.35 + */ 1.36 + 1.37 +// This example demonstrates Java subclassing by Java.extend 1.38 +// and javac Compiler and Tree API. This example looks for 1.39 +// empty catch blocks ("exception swallow") and reports those. 1.40 + 1.41 +if (arguments.length == 0) { 1.42 + print("Usage: jjs exceptionswallow.js -- <directory>"); 1.43 + exit(1); 1.44 +} 1.45 + 1.46 +// Java types used 1.47 +var File = Java.type("java.io.File"); 1.48 +var Files = Java.type("java.nio.file.Files"); 1.49 +var StringArray = Java.type("java.lang.String[]"); 1.50 +var ToolProvider = Java.type("javax.tools.ToolProvider"); 1.51 +var Tree = Java.type("com.sun.source.tree.Tree"); 1.52 +var EmptyStatementTree = Java.type("com.sun.source.tree.EmptyStatementTree"); 1.53 +var Trees = Java.type("com.sun.source.util.Trees"); 1.54 +var TreeScanner = Java.type("com.sun.source.util.TreeScanner"); 1.55 + 1.56 +// printEmptyCatch 1.57 + 1.58 +function printEmptyCatch() { 1.59 + // get the system compiler tool 1.60 + var compiler = ToolProvider.systemJavaCompiler; 1.61 + // get standard file manager 1.62 + var fileMgr = compiler.getStandardFileManager(null, null, null); 1.63 + // Using Java.to convert script array (arguments) to a Java String[] 1.64 + var compUnits = fileMgr.getJavaFileObjects( 1.65 + Java.to(arguments, StringArray)); 1.66 + // create a new compilation task 1.67 + var task = compiler.getTask(null, fileMgr, null, null, null, compUnits); 1.68 + 1.69 + // SourcePositions object to get positions of AST nodes 1.70 + var sourcePositions = Trees.instance(task).sourcePositions; 1.71 + 1.72 + // subclass SimpleTreeVisitor - to print empty catch 1.73 + var EmptyCatchFinder = Java.extend(TreeScanner); 1.74 + 1.75 + function hasOnlyEmptyStats(stats) { 1.76 + var itr = stats.iterator(); 1.77 + while (itr.hasNext()) { 1.78 + if (! (itr.next() instanceof EmptyStatementTree)) { 1.79 + return false; 1.80 + } 1.81 + } 1.82 + 1.83 + return true; 1.84 + } 1.85 + 1.86 + var visitor = new EmptyCatchFinder() { 1.87 + // current CompilationUnitTree 1.88 + compUnit: null, 1.89 + // current LineMap (pos -> line, column) 1.90 + lineMap: null, 1.91 + // current compilation unit's file name 1.92 + fileName: null, 1.93 + 1.94 + // overrides of TreeScanner methods 1.95 + 1.96 + visitCompilationUnit: function(node, p) { 1.97 + // capture info about current Compilation unit 1.98 + this.compUnit = node; 1.99 + this.lineMap = node.lineMap; 1.100 + this.fileName = node.sourceFile.name; 1.101 + 1.102 + // Using Java.super API to call super class method here 1.103 + return Java.super(visitor).visitCompilationUnit(node, p); 1.104 + }, 1.105 + 1.106 + visitCatch: function (node, p) { 1.107 + var stats = node.block.statements; 1.108 + if (stats.empty || hasOnlyEmptyStats(stats)) { 1.109 + // print information on this empty catch 1.110 + var pos = sourcePositions.getStartPosition(this.compUnit, node); 1.111 + var line = this.lineMap.getLineNumber(pos); 1.112 + var col = this.lineMap.getColumnNumber(pos); 1.113 + print("Exception swallow" + " @ " + this.fileName + ":" + line + ":" + col); 1.114 + // print(node); 1.115 + } 1.116 + } 1.117 + } 1.118 + 1.119 + for each (var cu in task.parse()) { 1.120 + cu.accept(visitor, null); 1.121 + } 1.122 +} 1.123 + 1.124 +// for each ".java" file in directory (recursively) and check it! 1.125 +function main(dir) { 1.126 + Files.walk(dir.toPath()). 1.127 + forEach(function(p) { 1.128 + var name = p.toFile().absolutePath; 1.129 + if (name.endsWith(".java")) { 1.130 + try { 1.131 + printEmptyCatch(p.toFile().getAbsolutePath()); 1.132 + } catch (e) { 1.133 + print(e); 1.134 + } 1.135 + } 1.136 + }); 1.137 +} 1.138 + 1.139 +main(new File(arguments[0]));
2.1 --- a/samples/find_nonfinals2.js Fri Sep 11 21:08:07 2015 +0530 2.2 +++ b/samples/find_nonfinals2.js Tue Sep 15 16:17:33 2015 +0530 2.3 @@ -43,7 +43,6 @@ 2.4 // Java types used 2.5 var File = Java.type("java.io.File"); 2.6 var Files = Java.type("java.nio.file.Files"); 2.7 -var FileVisitOption = Java.type("java.nio.file.FileVisitOption"); 2.8 var StringArray = Java.type("java.lang.String[]"); 2.9 var ToolProvider = Java.type("javax.tools.ToolProvider"); 2.10 var Tree = Java.type("com.sun.source.tree.Tree"); 2.11 @@ -106,7 +105,7 @@ 2.12 // for each ".java" file in directory (recursively). 2.13 function main(dir) { 2.14 var totalCount = 0; 2.15 - Files.walk(dir.toPath(), FileVisitOption.FOLLOW_LINKS). 2.16 + Files.walk(dir.toPath()). 2.17 forEach(function(p) { 2.18 var name = p.toFile().absolutePath; 2.19 if (name.endsWith(".java")) {
3.1 --- a/samples/javafoovars.js Fri Sep 11 21:08:07 2015 +0530 3.2 +++ b/samples/javafoovars.js Tue Sep 15 16:17:33 2015 +0530 3.3 @@ -42,7 +42,6 @@ 3.4 // Java types used 3.5 var File = Java.type("java.io.File"); 3.6 var Files = Java.type("java.nio.file.Files"); 3.7 -var FileVisitOption = Java.type("java.nio.file.FileVisitOption"); 3.8 var StringArray = Java.type("java.lang.String[]"); 3.9 var ToolProvider = Java.type("javax.tools.ToolProvider"); 3.10 var Tree = Java.type("com.sun.source.tree.Tree"); 3.11 @@ -81,7 +80,7 @@ 3.12 // for each ".java" file in directory (recursively) count "foo". 3.13 function main(dir) { 3.14 var totalCount = 0; 3.15 - Files.walk(dir.toPath(), FileVisitOption.FOLLOW_LINKS). 3.16 + Files.walk(dir.toPath()). 3.17 forEach(function(p) { 3.18 var name = p.toFile().absolutePath; 3.19 if (name.endsWith(".java")) {
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/samples/resourcetrysuggester.js Tue Sep 15 16:17:33 2015 +0530 4.3 @@ -0,0 +1,156 @@ 4.4 +#// Usage: jjs resourcetrysuggester.js -- <directory> 4.5 + 4.6 +/* 4.7 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 4.8 + * 4.9 + * Redistribution and use in source and binary forms, with or without 4.10 + * modification, are permitted provided that the following conditions 4.11 + * are met: 4.12 + * 4.13 + * - Redistributions of source code must retain the above copyright 4.14 + * notice, this list of conditions and the following disclaimer. 4.15 + * 4.16 + * - Redistributions in binary form must reproduce the above copyright 4.17 + * notice, this list of conditions and the following disclaimer in the 4.18 + * documentation and/or other materials provided with the distribution. 4.19 + * 4.20 + * - Neither the name of Oracle nor the names of its 4.21 + * contributors may be used to endorse or promote products derived 4.22 + * from this software without specific prior written permission. 4.23 + * 4.24 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 4.25 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 4.26 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4.27 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 4.28 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 4.29 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 4.30 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 4.31 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 4.32 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 4.33 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 4.34 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4.35 + */ 4.36 + 4.37 +// This example demonstrates Java subclassing by Java.extend 4.38 +// and javac Compiler and Tree API. This example looks for 4.39 +// finally clauses with "close" call and suggests "resource try"! 4.40 + 4.41 +if (arguments.length == 0) { 4.42 + print("Usage: jjs resourcetrysuggester.js -- <directory>"); 4.43 + exit(1); 4.44 +} 4.45 + 4.46 +// Java types used 4.47 +var ExpressionStatementTree = Java.type("com.sun.source.tree.ExpressionStatementTree"); 4.48 +var File = Java.type("java.io.File"); 4.49 +var Files = Java.type("java.nio.file.Files"); 4.50 +var MemberSelectTree = Java.type("com.sun.source.tree.MemberSelectTree"); 4.51 +var MethodInvocationTree = Java.type("com.sun.source.tree.MethodInvocationTree"); 4.52 +var StringArray = Java.type("java.lang.String[]"); 4.53 +var ToolProvider = Java.type("javax.tools.ToolProvider"); 4.54 +var Tree = Java.type("com.sun.source.tree.Tree"); 4.55 +var Trees = Java.type("com.sun.source.util.Trees"); 4.56 +var TreeScanner = Java.type("com.sun.source.util.TreeScanner"); 4.57 + 4.58 +// resourceTrySuggestions 4.59 + 4.60 +function resourceTrySuggestions() { 4.61 + // get the system compiler tool 4.62 + var compiler = ToolProvider.systemJavaCompiler; 4.63 + // get standard file manager 4.64 + var fileMgr = compiler.getStandardFileManager(null, null, null); 4.65 + // Using Java.to convert script array (arguments) to a Java String[] 4.66 + var compUnits = fileMgr.getJavaFileObjects( 4.67 + Java.to(arguments, StringArray)); 4.68 + // create a new compilation task 4.69 + var task = compiler.getTask(null, fileMgr, null, null, null, compUnits); 4.70 + 4.71 + // SourcePositions object to get positions of AST nodes 4.72 + var sourcePositions = Trees.instance(task).sourcePositions; 4.73 + 4.74 + // subclass SimpleTreeVisitor - to print resource try suggestions 4.75 + var ResourceTrySuggester = Java.extend(TreeScanner); 4.76 + 4.77 + function hasOnlyEmptyStats(stats) { 4.78 + var itr = stats.iterator(); 4.79 + while (itr.hasNext()) { 4.80 + if (! (itr.next() instanceof EmptyStatementTree)) { 4.81 + return false; 4.82 + } 4.83 + } 4.84 + 4.85 + return true; 4.86 + } 4.87 + 4.88 + // does the given statement list has an expression statement which 4.89 + // calls "close" method (don't worry about types - just crude one will do) 4.90 + function hasCloseCall(stats) { 4.91 + var itr = stats.iterator(); 4.92 + while (itr.hasNext()) { 4.93 + var stat = itr.next(); 4.94 + if (stat instanceof ExpressionStatementTree) { 4.95 + var expr = stat.expression; 4.96 + if (expr instanceof MethodInvocationTree) { 4.97 + var method = expr.methodSelect; 4.98 + if (method instanceof MemberSelectTree) { 4.99 + return method.identifier.toString().equals("close"); 4.100 + } 4.101 + } 4.102 + } 4.103 + } 4.104 + return false; 4.105 + } 4.106 + 4.107 + var visitor = new ResourceTrySuggester() { 4.108 + // current CompilationUnitTree 4.109 + compUnit: null, 4.110 + // current LineMap (pos -> line, column) 4.111 + lineMap: null, 4.112 + // current compilation unit's file name 4.113 + fileName: null, 4.114 + 4.115 + // overrides of TreeScanner methods 4.116 + 4.117 + visitCompilationUnit: function(node, p) { 4.118 + // capture info about current Compilation unit 4.119 + this.compUnit = node; 4.120 + this.lineMap = node.lineMap; 4.121 + this.fileName = node.sourceFile.name; 4.122 + 4.123 + // Using Java.super API to call super class method here 4.124 + return Java.super(visitor).visitCompilationUnit(node, p); 4.125 + }, 4.126 + 4.127 + visitTry: function (node, p) { 4.128 + var finallyBlk = node.finallyBlock; 4.129 + if (finallyBlk != null && hasCloseCall(finallyBlk.statements)) { 4.130 + var pos = sourcePositions.getStartPosition(this.compUnit, node); 4.131 + var line = this.lineMap.getLineNumber(pos); 4.132 + var col = this.lineMap.getColumnNumber(pos); 4.133 + print("Consider resource try statement " + " @ " + this.fileName + ":" + line + ":" + col); 4.134 + // print(node); 4.135 + } 4.136 + } 4.137 + } 4.138 + 4.139 + for each (var cu in task.parse()) { 4.140 + cu.accept(visitor, null); 4.141 + } 4.142 +} 4.143 + 4.144 +// for each ".java" file in directory (recursively) and check it! 4.145 +function main(dir) { 4.146 + Files.walk(dir.toPath()). 4.147 + forEach(function(p) { 4.148 + var name = p.toFile().absolutePath; 4.149 + if (name.endsWith(".java")) { 4.150 + try { 4.151 + resourceTrySuggestions(p.toFile().getAbsolutePath()); 4.152 + } catch (e) { 4.153 + print(e); 4.154 + } 4.155 + } 4.156 + }); 4.157 +} 4.158 + 4.159 +main(new File(arguments[0]));
5.1 --- a/samples/zipfs.js Fri Sep 11 21:08:07 2015 +0530 5.2 +++ b/samples/zipfs.js Tue Sep 15 16:17:33 2015 +0530 5.3 @@ -36,13 +36,12 @@ 5.4 5.5 var Files = Java.type("java.nio.file.Files") 5.6 var FileSystems = Java.type("java.nio.file.FileSystems") 5.7 -var FileVisitOption = Java.type("java.nio.file.FileVisitOption") 5.8 var Paths = Java.type("java.nio.file.Paths") 5.9 5.10 var zipfile = Paths.get(arguments[0]) 5.11 var fs = FileSystems.newFileSystem(zipfile, null) 5.12 var root = fs.rootDirectories[0] 5.13 -Files.walk(root, FileVisitOption.FOLLOW_LINKS).forEach( 5.14 +Files.walk(root).forEach( 5.15 function(p) (print(p), print(Files.readAttributes(p, "zip:*"))) 5.16 ) 5.17 fs.close()
6.1 --- a/src/jdk/nashorn/internal/codegen/ApplySpecialization.java Fri Sep 11 21:08:07 2015 +0530 6.2 +++ b/src/jdk/nashorn/internal/codegen/ApplySpecialization.java Tue Sep 15 16:17:33 2015 +0530 6.3 @@ -40,7 +40,6 @@ 6.4 import jdk.nashorn.internal.ir.CallNode; 6.5 import jdk.nashorn.internal.ir.Expression; 6.6 import jdk.nashorn.internal.ir.FunctionNode; 6.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 6.8 import jdk.nashorn.internal.ir.IdentNode; 6.9 import jdk.nashorn.internal.ir.LexicalContext; 6.10 import jdk.nashorn.internal.ir.Node; 6.11 @@ -375,7 +374,7 @@ 6.12 callSiteTypes.pop(); 6.13 explodedArguments.pop(); 6.14 6.15 - return newFunctionNode.setState(lc, CompilationState.BUILTINS_TRANSFORMED); 6.16 + return newFunctionNode; 6.17 } 6.18 6.19 private static boolean isApply(final CallNode callNode) {
7.1 --- a/src/jdk/nashorn/internal/codegen/AssignSymbols.java Fri Sep 11 21:08:07 2015 +0530 7.2 +++ b/src/jdk/nashorn/internal/codegen/AssignSymbols.java Tue Sep 15 16:17:33 2015 +0530 7.3 @@ -65,7 +65,6 @@ 7.4 import jdk.nashorn.internal.ir.Expression; 7.5 import jdk.nashorn.internal.ir.ForNode; 7.6 import jdk.nashorn.internal.ir.FunctionNode; 7.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 7.8 import jdk.nashorn.internal.ir.IdentNode; 7.9 import jdk.nashorn.internal.ir.IndexNode; 7.10 import jdk.nashorn.internal.ir.LexicalContext; 7.11 @@ -848,7 +847,7 @@ 7.12 lc.applyTopFlags(functionNode)))) 7.13 .setThisProperties(lc, thisProperties.pop().size())); 7.14 } 7.15 - return finalizedFunction.setState(lc, CompilationState.SYMBOLS_ASSIGNED); 7.16 + return finalizedFunction; 7.17 } 7.18 7.19 @Override
8.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java Fri Sep 11 21:08:07 2015 +0530 8.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java Tue Sep 15 16:17:33 2015 +0530 8.3 @@ -93,7 +93,6 @@ 8.4 import jdk.nashorn.internal.ir.ExpressionStatement; 8.5 import jdk.nashorn.internal.ir.ForNode; 8.6 import jdk.nashorn.internal.ir.FunctionNode; 8.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 8.8 import jdk.nashorn.internal.ir.GetSplitState; 8.9 import jdk.nashorn.internal.ir.IdentNode; 8.10 import jdk.nashorn.internal.ir.IfNode; 8.11 @@ -2143,7 +2142,7 @@ 8.12 markOptimistic = false; 8.13 } 8.14 8.15 - FunctionNode newFunctionNode = functionNode.setState(lc, CompilationState.BYTECODE_GENERATED); 8.16 + FunctionNode newFunctionNode = functionNode; 8.17 if (markOptimistic) { 8.18 newFunctionNode = newFunctionNode.setFlag(lc, FunctionNode.IS_DEOPTIMIZABLE); 8.19 }
9.1 --- a/src/jdk/nashorn/internal/codegen/CompilationPhase.java Fri Sep 11 21:08:07 2015 +0530 9.2 +++ b/src/jdk/nashorn/internal/codegen/CompilationPhase.java Tue Sep 15 16:17:33 2015 +0530 9.3 @@ -25,18 +25,6 @@ 9.4 9.5 package jdk.nashorn.internal.codegen; 9.6 9.7 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.BUILTINS_TRANSFORMED; 9.8 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.BYTECODE_GENERATED; 9.9 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.BYTECODE_INSTALLED; 9.10 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.CONSTANT_FOLDED; 9.11 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.INITIALIZED; 9.12 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.LOCAL_VARIABLE_TYPES_CALCULATED; 9.13 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.LOWERED; 9.14 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.OPTIMISTIC_TYPES_ASSIGNED; 9.15 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.PARSED; 9.16 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.SCOPE_DEPTHS_COMPUTED; 9.17 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.SPLIT; 9.18 -import static jdk.nashorn.internal.ir.FunctionNode.CompilationState.SYMBOLS_ASSIGNED; 9.19 import static jdk.nashorn.internal.runtime.logging.DebugLogger.quote; 9.20 9.21 import java.io.PrintWriter; 9.22 @@ -49,7 +37,6 @@ 9.23 import jdk.nashorn.internal.AssertsEnabled; 9.24 import jdk.nashorn.internal.codegen.Compiler.CompilationPhases; 9.25 import jdk.nashorn.internal.ir.FunctionNode; 9.26 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 9.27 import jdk.nashorn.internal.ir.LexicalContext; 9.28 import jdk.nashorn.internal.ir.LiteralNode; 9.29 import jdk.nashorn.internal.ir.Node; 9.30 @@ -65,15 +52,9 @@ 9.31 * A compilation phase is a step in the processes of turning a JavaScript 9.32 * FunctionNode into bytecode. It has an optional return value. 9.33 */ 9.34 -enum CompilationPhase { 9.35 - /** 9.36 - * Constant folding pass Simple constant folding that will make elementary 9.37 - * constructs go away 9.38 - */ 9.39 - CONSTANT_FOLDING_PHASE( 9.40 - EnumSet.of( 9.41 - INITIALIZED, 9.42 - PARSED)) { 9.43 +abstract class CompilationPhase { 9.44 + 9.45 + private static final class ConstantFoldingPhase extends CompilationPhase { 9.46 @Override 9.47 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.48 return transformFunction(fn, new FoldConstants(compiler)); 9.49 @@ -83,20 +64,15 @@ 9.50 public String toString() { 9.51 return "'Constant Folding'"; 9.52 } 9.53 - }, 9.54 + } 9.55 9.56 /** 9.57 - * Lower (Control flow pass) Finalizes the control flow. Clones blocks for 9.58 - * finally constructs and similar things. Establishes termination criteria 9.59 - * for nodes Guarantee return instructions to method making sure control 9.60 - * flow cannot fall off the end. Replacing high level nodes with lower such 9.61 - * as runtime nodes where applicable. 9.62 + * Constant folding pass Simple constant folding that will make elementary 9.63 + * constructs go away 9.64 */ 9.65 - LOWERING_PHASE( 9.66 - EnumSet.of( 9.67 - INITIALIZED, 9.68 - PARSED, 9.69 - CONSTANT_FOLDED)) { 9.70 + static final CompilationPhase CONSTANT_FOLDING_PHASE = new ConstantFoldingPhase(); 9.71 + 9.72 + private static final class LoweringPhase extends CompilationPhase { 9.73 @Override 9.74 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.75 return transformFunction(fn, new Lower(compiler)); 9.76 @@ -106,42 +82,35 @@ 9.77 public String toString() { 9.78 return "'Control Flow Lowering'"; 9.79 } 9.80 - }, 9.81 + } 9.82 9.83 /** 9.84 - * Phase used only when doing optimistic code generation. It assigns all potentially 9.85 - * optimistic ops a program point so that an UnwarrantedException knows from where 9.86 - * a guess went wrong when creating the continuation to roll back this execution 9.87 + * Lower (Control flow pass) Finalizes the control flow. Clones blocks for 9.88 + * finally constructs and similar things. Establishes termination criteria 9.89 + * for nodes Guarantee return instructions to method making sure control 9.90 + * flow cannot fall off the end. Replacing high level nodes with lower such 9.91 + * as runtime nodes where applicable. 9.92 */ 9.93 - TRANSFORM_BUILTINS_PHASE( 9.94 - EnumSet.of( 9.95 - INITIALIZED, 9.96 - PARSED, 9.97 - CONSTANT_FOLDED, 9.98 - LOWERED)) { 9.99 - //we only do this if we have a param type map, otherwise this is not a specialized recompile 9.100 + static final CompilationPhase LOWERING_PHASE = new LoweringPhase(); 9.101 + 9.102 + private static final class ApplySpecializationPhase extends CompilationPhase { 9.103 @Override 9.104 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.105 - return setStates(transformFunction(fn, new ApplySpecialization(compiler)), BUILTINS_TRANSFORMED); 9.106 + return transformFunction(fn, new ApplySpecialization(compiler)); 9.107 } 9.108 9.109 @Override 9.110 public String toString() { 9.111 return "'Builtin Replacement'"; 9.112 } 9.113 - }, 9.114 + }; 9.115 9.116 /** 9.117 - * Splitter Split the AST into several compile units based on a heuristic size calculation. 9.118 - * Split IR can lead to scope information being changed. 9.119 + * Phase used to transform Function.prototype.apply. 9.120 */ 9.121 - SPLITTING_PHASE( 9.122 - EnumSet.of( 9.123 - INITIALIZED, 9.124 - PARSED, 9.125 - CONSTANT_FOLDED, 9.126 - LOWERED, 9.127 - BUILTINS_TRANSFORMED)) { 9.128 + static final CompilationPhase APPLY_SPECIALIZATION_PHASE = new ApplySpecializationPhase(); 9.129 + 9.130 + private static final class SplittingPhase extends CompilationPhase { 9.131 @Override 9.132 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.133 final CompileUnit outermostCompileUnit = compiler.addCompileUnit(0L); 9.134 @@ -168,16 +137,15 @@ 9.135 public String toString() { 9.136 return "'Code Splitting'"; 9.137 } 9.138 - }, 9.139 + }; 9.140 9.141 - PROGRAM_POINT_PHASE( 9.142 - EnumSet.of( 9.143 - INITIALIZED, 9.144 - PARSED, 9.145 - CONSTANT_FOLDED, 9.146 - LOWERED, 9.147 - BUILTINS_TRANSFORMED, 9.148 - SPLIT)) { 9.149 + /** 9.150 + * Splitter Split the AST into several compile units based on a heuristic size calculation. 9.151 + * Split IR can lead to scope information being changed. 9.152 + */ 9.153 + static final CompilationPhase SPLITTING_PHASE = new SplittingPhase(); 9.154 + 9.155 + private static final class ProgramPointPhase extends CompilationPhase { 9.156 @Override 9.157 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.158 return transformFunction(fn, new ProgramPoints()); 9.159 @@ -187,16 +155,11 @@ 9.160 public String toString() { 9.161 return "'Program Point Calculation'"; 9.162 } 9.163 - }, 9.164 + }; 9.165 9.166 - SERIALIZE_SPLIT_PHASE( 9.167 - EnumSet.of( 9.168 - INITIALIZED, 9.169 - PARSED, 9.170 - CONSTANT_FOLDED, 9.171 - LOWERED, 9.172 - BUILTINS_TRANSFORMED, 9.173 - SPLIT)) { 9.174 + static final CompilationPhase PROGRAM_POINT_PHASE = new ProgramPointPhase(); 9.175 + 9.176 + private static final class SerializeSplitPhase extends CompilationPhase { 9.177 @Override 9.178 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.179 return transformFunction(fn, new NodeVisitor<LexicalContext>(new LexicalContext()) { 9.180 @@ -214,16 +177,11 @@ 9.181 public String toString() { 9.182 return "'Serialize Split Functions'"; 9.183 } 9.184 - }, 9.185 + }; 9.186 9.187 - SYMBOL_ASSIGNMENT_PHASE( 9.188 - EnumSet.of( 9.189 - INITIALIZED, 9.190 - PARSED, 9.191 - CONSTANT_FOLDED, 9.192 - LOWERED, 9.193 - BUILTINS_TRANSFORMED, 9.194 - SPLIT)) { 9.195 + static final CompilationPhase SERIALIZE_SPLIT_PHASE = new SerializeSplitPhase(); 9.196 + 9.197 + private static final class SymbolAssignmentPhase extends CompilationPhase { 9.198 @Override 9.199 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.200 return transformFunction(fn, new AssignSymbols(compiler)); 9.201 @@ -233,17 +191,11 @@ 9.202 public String toString() { 9.203 return "'Symbol Assignment'"; 9.204 } 9.205 - }, 9.206 + }; 9.207 9.208 - SCOPE_DEPTH_COMPUTATION_PHASE( 9.209 - EnumSet.of( 9.210 - INITIALIZED, 9.211 - PARSED, 9.212 - CONSTANT_FOLDED, 9.213 - LOWERED, 9.214 - BUILTINS_TRANSFORMED, 9.215 - SPLIT, 9.216 - SYMBOLS_ASSIGNED)) { 9.217 + static final CompilationPhase SYMBOL_ASSIGNMENT_PHASE = new SymbolAssignmentPhase(); 9.218 + 9.219 + private static final class ScopeDepthComputationPhase extends CompilationPhase { 9.220 @Override 9.221 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.222 return transformFunction(fn, new FindScopeDepths(compiler)); 9.223 @@ -253,43 +205,28 @@ 9.224 public String toString() { 9.225 return "'Scope Depth Computation'"; 9.226 } 9.227 - }, 9.228 + }; 9.229 9.230 - OPTIMISTIC_TYPE_ASSIGNMENT_PHASE( 9.231 - EnumSet.of( 9.232 - INITIALIZED, 9.233 - PARSED, 9.234 - CONSTANT_FOLDED, 9.235 - LOWERED, 9.236 - BUILTINS_TRANSFORMED, 9.237 - SPLIT, 9.238 - SYMBOLS_ASSIGNED, 9.239 - SCOPE_DEPTHS_COMPUTED)) { 9.240 + static final CompilationPhase SCOPE_DEPTH_COMPUTATION_PHASE = new ScopeDepthComputationPhase(); 9.241 + 9.242 + private static final class OptimisticTypeAssignmentPhase extends CompilationPhase { 9.243 @Override 9.244 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.245 if (compiler.useOptimisticTypes()) { 9.246 return transformFunction(fn, new OptimisticTypesCalculator(compiler)); 9.247 } 9.248 - return setStates(fn, OPTIMISTIC_TYPES_ASSIGNED); 9.249 + return fn; 9.250 } 9.251 9.252 @Override 9.253 public String toString() { 9.254 return "'Optimistic Type Assignment'"; 9.255 } 9.256 - }, 9.257 + } 9.258 9.259 - LOCAL_VARIABLE_TYPE_CALCULATION_PHASE( 9.260 - EnumSet.of( 9.261 - INITIALIZED, 9.262 - PARSED, 9.263 - CONSTANT_FOLDED, 9.264 - LOWERED, 9.265 - BUILTINS_TRANSFORMED, 9.266 - SPLIT, 9.267 - SYMBOLS_ASSIGNED, 9.268 - SCOPE_DEPTHS_COMPUTED, 9.269 - OPTIMISTIC_TYPES_ASSIGNED)) { 9.270 + static final CompilationPhase OPTIMISTIC_TYPE_ASSIGNMENT_PHASE = new OptimisticTypeAssignmentPhase(); 9.271 + 9.272 + private static final class LocalVariableTypeCalculationPhase extends CompilationPhase { 9.273 @Override 9.274 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.275 final FunctionNode newFunctionNode = transformFunction(fn, new LocalVariableTypesCalculator(compiler)); 9.276 @@ -314,25 +251,11 @@ 9.277 public String toString() { 9.278 return "'Local Variable Type Calculation'"; 9.279 } 9.280 - }, 9.281 + }; 9.282 9.283 + static final CompilationPhase LOCAL_VARIABLE_TYPE_CALCULATION_PHASE = new LocalVariableTypeCalculationPhase(); 9.284 9.285 - /** 9.286 - * Reuse compile units, if they are already present. We are using the same compiler 9.287 - * to recompile stuff 9.288 - */ 9.289 - REUSE_COMPILE_UNITS_PHASE( 9.290 - EnumSet.of( 9.291 - INITIALIZED, 9.292 - PARSED, 9.293 - CONSTANT_FOLDED, 9.294 - LOWERED, 9.295 - BUILTINS_TRANSFORMED, 9.296 - SPLIT, 9.297 - SYMBOLS_ASSIGNED, 9.298 - SCOPE_DEPTHS_COMPUTED, 9.299 - OPTIMISTIC_TYPES_ASSIGNED, 9.300 - LOCAL_VARIABLE_TYPES_CALCULATED)) { 9.301 + private static final class ReuseCompileUnitsPhase extends CompilationPhase { 9.302 @Override 9.303 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.304 assert phases.isRestOfCompilation() : "reuse compile units currently only used for Rest-Of methods"; 9.305 @@ -380,16 +303,15 @@ 9.306 public String toString() { 9.307 return "'Reuse Compile Units'"; 9.308 } 9.309 - }, 9.310 + } 9.311 9.312 - REINITIALIZE_SERIALIZED( 9.313 - EnumSet.of( 9.314 - INITIALIZED, 9.315 - PARSED, 9.316 - CONSTANT_FOLDED, 9.317 - LOWERED, 9.318 - BUILTINS_TRANSFORMED, 9.319 - SPLIT)) { 9.320 + /** 9.321 + * Reuse compile units, if they are already present. We are using the same compiler 9.322 + * to recompile stuff 9.323 + */ 9.324 + static final CompilationPhase REUSE_COMPILE_UNITS_PHASE = new ReuseCompileUnitsPhase(); 9.325 + 9.326 + private static final class ReinitializeSerializedPhase extends CompilationPhase { 9.327 @Override 9.328 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.329 final Set<CompileUnit> unitSet = CompileUnit.createCompileUnitSet(); 9.330 @@ -432,26 +354,11 @@ 9.331 public String toString() { 9.332 return "'Deserialize'"; 9.333 } 9.334 - }, 9.335 + } 9.336 9.337 - /** 9.338 - * Bytecode generation: 9.339 - * 9.340 - * Generate the byte code class(es) resulting from the compiled FunctionNode 9.341 - */ 9.342 - BYTECODE_GENERATION_PHASE( 9.343 - EnumSet.of( 9.344 - INITIALIZED, 9.345 - PARSED, 9.346 - CONSTANT_FOLDED, 9.347 - LOWERED, 9.348 - BUILTINS_TRANSFORMED, 9.349 - SPLIT, 9.350 - SYMBOLS_ASSIGNED, 9.351 - SCOPE_DEPTHS_COMPUTED, 9.352 - OPTIMISTIC_TYPES_ASSIGNED, 9.353 - LOCAL_VARIABLE_TYPES_CALCULATED)) { 9.354 + static final CompilationPhase REINITIALIZE_SERIALIZED = new ReinitializeSerializedPhase(); 9.355 9.356 + private static final class BytecodeGenerationPhase extends CompilationPhase { 9.357 @Override 9.358 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.359 final ScriptEnvironment senv = compiler.getScriptEnvironment(); 9.360 @@ -469,7 +376,7 @@ 9.361 try { 9.362 // Explicitly set BYTECODE_GENERATED here; it can not be set in case of skipping codegen for :program 9.363 // in the lazy + optimistic world. See CodeGenerator.skipFunction(). 9.364 - newFunctionNode = transformFunction(newFunctionNode, codegen).setState(null, BYTECODE_GENERATED); 9.365 + newFunctionNode = transformFunction(newFunctionNode, codegen); 9.366 codegen.generateScopeCalls(); 9.367 } catch (final VerifyError e) { 9.368 if (senv._verify_code || senv._print_code) { 9.369 @@ -517,22 +424,16 @@ 9.370 public String toString() { 9.371 return "'Bytecode Generation'"; 9.372 } 9.373 - }, 9.374 + } 9.375 9.376 - INSTALL_PHASE( 9.377 - EnumSet.of( 9.378 - INITIALIZED, 9.379 - PARSED, 9.380 - CONSTANT_FOLDED, 9.381 - LOWERED, 9.382 - BUILTINS_TRANSFORMED, 9.383 - SPLIT, 9.384 - SYMBOLS_ASSIGNED, 9.385 - SCOPE_DEPTHS_COMPUTED, 9.386 - OPTIMISTIC_TYPES_ASSIGNED, 9.387 - LOCAL_VARIABLE_TYPES_CALCULATED, 9.388 - BYTECODE_GENERATED)) { 9.389 + /** 9.390 + * Bytecode generation: 9.391 + * 9.392 + * Generate the byte code class(es) resulting from the compiled FunctionNode 9.393 + */ 9.394 + static final CompilationPhase BYTECODE_GENERATION_PHASE = new BytecodeGenerationPhase(); 9.395 9.396 + private static final class InstallPhase extends CompilationPhase { 9.397 @Override 9.398 FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { 9.399 final DebugLogger log = compiler.getLogger(); 9.400 @@ -600,18 +501,16 @@ 9.401 log.fine(sb.toString()); 9.402 } 9.403 9.404 - return setStates(fn.setRootClass(null, rootClass), BYTECODE_INSTALLED); 9.405 + return fn.setRootClass(null, rootClass); 9.406 } 9.407 9.408 @Override 9.409 public String toString() { 9.410 return "'Class Installation'"; 9.411 } 9.412 + } 9.413 9.414 - }; 9.415 - 9.416 - /** pre conditions required for function node to which this transform is to be applied */ 9.417 - private final EnumSet<CompilationState> pre; 9.418 + static final CompilationPhase INSTALL_PHASE = new InstallPhase(); 9.419 9.420 /** start time of transform - used for timing, see {@link jdk.nashorn.internal.runtime.Timing} */ 9.421 private long startTime; 9.422 @@ -622,21 +521,7 @@ 9.423 /** boolean that is true upon transform completion */ 9.424 private boolean isFinished; 9.425 9.426 - private CompilationPhase(final EnumSet<CompilationState> pre) { 9.427 - this.pre = pre; 9.428 - } 9.429 - 9.430 - private static FunctionNode setStates(final FunctionNode functionNode, final CompilationState state) { 9.431 - if (!AssertsEnabled.assertsEnabled()) { 9.432 - return functionNode; 9.433 - } 9.434 - return transformFunction(functionNode, new NodeVisitor<LexicalContext>(new LexicalContext()) { 9.435 - @Override 9.436 - public Node leaveFunctionNode(final FunctionNode fn) { 9.437 - return fn.setState(lc, state); 9.438 - } 9.439 - }); 9.440 - } 9.441 + private CompilationPhase() {} 9.442 9.443 /** 9.444 * Start a compilation phase 9.445 @@ -646,23 +531,7 @@ 9.446 */ 9.447 protected FunctionNode begin(final Compiler compiler, final FunctionNode functionNode) { 9.448 compiler.getLogger().indent(); 9.449 - 9.450 - assert pre != null; 9.451 - 9.452 - if (!functionNode.hasState(pre)) { 9.453 - final StringBuilder sb = new StringBuilder("Compilation phase "); 9.454 - sb.append(this). 9.455 - append(" is not applicable to "). 9.456 - append(quote(functionNode.getName())). 9.457 - append("\n\tFunctionNode state = "). 9.458 - append(functionNode.getState()). 9.459 - append("\n\tRequired state = "). 9.460 - append(this.pre); 9.461 - 9.462 - throw new CompilationException(sb.toString()); 9.463 - } 9.464 - 9.465 - startTime = System.nanoTime(); 9.466 + startTime = System.nanoTime(); 9.467 9.468 return functionNode; 9.469 }
10.1 --- a/src/jdk/nashorn/internal/codegen/Compiler.java Fri Sep 11 21:08:07 2015 +0530 10.2 +++ b/src/jdk/nashorn/internal/codegen/Compiler.java Tue Sep 15 16:17:33 2015 +0530 10.3 @@ -174,7 +174,7 @@ 10.4 "Common initial phases", 10.5 CompilationPhase.CONSTANT_FOLDING_PHASE, 10.6 CompilationPhase.LOWERING_PHASE, 10.7 - CompilationPhase.TRANSFORM_BUILTINS_PHASE, 10.8 + CompilationPhase.APPLY_SPECIALIZATION_PHASE, 10.9 CompilationPhase.SPLITTING_PHASE, 10.10 CompilationPhase.PROGRAM_POINT_PHASE, 10.11 CompilationPhase.SERIALIZE_SPLIT_PHASE
11.1 --- a/src/jdk/nashorn/internal/codegen/FindScopeDepths.java Fri Sep 11 21:08:07 2015 +0530 11.2 +++ b/src/jdk/nashorn/internal/codegen/FindScopeDepths.java Tue Sep 15 16:17:33 2015 +0530 11.3 @@ -34,7 +34,6 @@ 11.4 import java.util.Set; 11.5 import jdk.nashorn.internal.ir.Block; 11.6 import jdk.nashorn.internal.ir.FunctionNode; 11.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 11.8 import jdk.nashorn.internal.ir.IdentNode; 11.9 import jdk.nashorn.internal.ir.LexicalContext; 11.10 import jdk.nashorn.internal.ir.Node; 11.11 @@ -182,8 +181,7 @@ 11.12 @Override 11.13 public Node leaveFunctionNode(final FunctionNode functionNode) { 11.14 final String name = functionNode.getName(); 11.15 - FunctionNode newFunctionNode = functionNode.setState(lc, CompilationState.SCOPE_DEPTHS_COMPUTED); 11.16 - 11.17 + FunctionNode newFunctionNode = functionNode; 11.18 if (compiler.isOnDemandCompilation()) { 11.19 final RecompilableScriptFunctionData data = compiler.getScriptFunctionData(newFunctionNode.getId()); 11.20 if (data.inDynamicContext()) {
12.1 --- a/src/jdk/nashorn/internal/codegen/FoldConstants.java Fri Sep 11 21:08:07 2015 +0530 12.2 +++ b/src/jdk/nashorn/internal/codegen/FoldConstants.java Tue Sep 15 16:17:33 2015 +0530 12.3 @@ -37,7 +37,6 @@ 12.4 import jdk.nashorn.internal.ir.EmptyNode; 12.5 import jdk.nashorn.internal.ir.Expression; 12.6 import jdk.nashorn.internal.ir.FunctionNode; 12.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 12.8 import jdk.nashorn.internal.ir.IfNode; 12.9 import jdk.nashorn.internal.ir.LexicalContext; 12.10 import jdk.nashorn.internal.ir.LiteralNode; 12.11 @@ -101,7 +100,7 @@ 12.12 12.13 @Override 12.14 public Node leaveFunctionNode(final FunctionNode functionNode) { 12.15 - return functionNode.setState(lc, CompilationState.CONSTANT_FOLDED); 12.16 + return functionNode; 12.17 } 12.18 12.19 @Override
13.1 --- a/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Fri Sep 11 21:08:07 2015 +0530 13.2 +++ b/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Tue Sep 15 16:17:33 2015 +0530 13.3 @@ -54,7 +54,6 @@ 13.4 import jdk.nashorn.internal.ir.ExpressionStatement; 13.5 import jdk.nashorn.internal.ir.ForNode; 13.6 import jdk.nashorn.internal.ir.FunctionNode; 13.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 13.8 import jdk.nashorn.internal.ir.GetSplitState; 13.9 import jdk.nashorn.internal.ir.IdentNode; 13.10 import jdk.nashorn.internal.ir.IfNode; 13.11 @@ -1478,7 +1477,6 @@ 13.12 newFunction = newFunction.setReturnType(lc, returnType); 13.13 13.14 13.15 - newFunction = newFunction.setState(lc, CompilationState.LOCAL_VARIABLE_TYPES_CALCULATED); 13.16 newFunction = newFunction.setParameters(lc, newFunction.visitParameters(applyChangesVisitor)); 13.17 return newFunction; 13.18 }
14.1 --- a/src/jdk/nashorn/internal/codegen/Lower.java Fri Sep 11 21:08:07 2015 +0530 14.2 +++ b/src/jdk/nashorn/internal/codegen/Lower.java Tue Sep 15 16:17:33 2015 +0530 14.3 @@ -51,7 +51,6 @@ 14.4 import jdk.nashorn.internal.ir.ExpressionStatement; 14.5 import jdk.nashorn.internal.ir.ForNode; 14.6 import jdk.nashorn.internal.ir.FunctionNode; 14.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 14.8 import jdk.nashorn.internal.ir.IdentNode; 14.9 import jdk.nashorn.internal.ir.IfNode; 14.10 import jdk.nashorn.internal.ir.IndexNode; 14.11 @@ -266,7 +265,7 @@ 14.12 @Override 14.13 public Node leaveFunctionNode(final FunctionNode functionNode) { 14.14 log.info("END FunctionNode: ", functionNode.getName()); 14.15 - return functionNode.setState(lc, CompilationState.LOWERED); 14.16 + return functionNode; 14.17 } 14.18 14.19 @Override
15.1 --- a/src/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java Fri Sep 11 21:08:07 2015 +0530 15.2 +++ b/src/jdk/nashorn/internal/codegen/OptimisticTypesCalculator.java Tue Sep 15 16:17:33 2015 +0530 15.3 @@ -38,7 +38,6 @@ 15.4 import jdk.nashorn.internal.ir.ExpressionStatement; 15.5 import jdk.nashorn.internal.ir.ForNode; 15.6 import jdk.nashorn.internal.ir.FunctionNode; 15.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 15.8 import jdk.nashorn.internal.ir.IdentNode; 15.9 import jdk.nashorn.internal.ir.IfNode; 15.10 import jdk.nashorn.internal.ir.IndexNode; 15.11 @@ -208,7 +207,7 @@ 15.12 @Override 15.13 public Node leaveFunctionNode(final FunctionNode functionNode) { 15.14 neverOptimistic.pop(); 15.15 - return functionNode.setState(lc, CompilationState.OPTIMISTIC_TYPES_ASSIGNED); 15.16 + return functionNode; 15.17 } 15.18 15.19 @Override
16.1 --- a/src/jdk/nashorn/internal/codegen/ReplaceCompileUnits.java Fri Sep 11 21:08:07 2015 +0530 16.2 +++ b/src/jdk/nashorn/internal/codegen/ReplaceCompileUnits.java Tue Sep 15 16:17:33 2015 +0530 16.3 @@ -29,7 +29,6 @@ 16.4 import java.util.List; 16.5 import jdk.nashorn.internal.ir.CompileUnitHolder; 16.6 import jdk.nashorn.internal.ir.FunctionNode; 16.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 16.8 import jdk.nashorn.internal.ir.LexicalContext; 16.9 import jdk.nashorn.internal.ir.LiteralNode; 16.10 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; 16.11 @@ -64,7 +63,7 @@ 16.12 16.13 @Override 16.14 public Node leaveFunctionNode(final FunctionNode node) { 16.15 - return node.setCompileUnit(lc, getExistingReplacement(node)).setState(lc, CompilationState.COMPILE_UNITS_REUSED); 16.16 + return node.setCompileUnit(lc, getExistingReplacement(node)); 16.17 } 16.18 16.19 @Override
17.1 --- a/src/jdk/nashorn/internal/codegen/SplitIntoFunctions.java Fri Sep 11 21:08:07 2015 +0530 17.2 +++ b/src/jdk/nashorn/internal/codegen/SplitIntoFunctions.java Tue Sep 15 16:17:33 2015 +0530 17.3 @@ -175,8 +175,7 @@ 17.4 FunctionNode.IS_ANONYMOUS | FunctionNode.USES_ANCESTOR_SCOPE | FunctionNode.IS_SPLIT 17.5 ) 17.6 .setBody(lc, body) 17.7 - .setCompileUnit(lc, splitNode.getCompileUnit()) 17.8 - .copyCompilationState(lc, originalFn); 17.9 + .setCompileUnit(lc, splitNode.getCompileUnit()); 17.10 17.11 // Call the function: 17.12 // either "(function () { ... }).call(this)"
18.1 --- a/src/jdk/nashorn/internal/codegen/Splitter.java Fri Sep 11 21:08:07 2015 +0530 18.2 +++ b/src/jdk/nashorn/internal/codegen/Splitter.java Tue Sep 15 16:17:33 2015 +0530 18.3 @@ -33,7 +33,6 @@ 18.4 import java.util.Map; 18.5 import jdk.nashorn.internal.ir.Block; 18.6 import jdk.nashorn.internal.ir.FunctionNode; 18.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 18.8 import jdk.nashorn.internal.ir.LexicalContext; 18.9 import jdk.nashorn.internal.ir.LiteralNode; 18.10 import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode; 18.11 @@ -158,7 +157,7 @@ 18.12 18.13 assert functionNode.getCompileUnit() != null; 18.14 18.15 - return functionNode.setState(null, CompilationState.SPLIT); 18.16 + return functionNode; 18.17 } 18.18 18.19 private static List<FunctionNode> directChildren(final FunctionNode functionNode) {
19.1 --- a/src/jdk/nashorn/internal/ir/FunctionNode.java Fri Sep 11 21:08:07 2015 +0530 19.2 +++ b/src/jdk/nashorn/internal/ir/FunctionNode.java Tue Sep 15 16:17:33 2015 +0530 19.3 @@ -33,10 +33,8 @@ 19.4 import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_VALUES; 19.5 19.6 import java.util.Collections; 19.7 -import java.util.EnumSet; 19.8 import java.util.Iterator; 19.9 import java.util.List; 19.10 -import jdk.nashorn.internal.AssertsEnabled; 19.11 import jdk.nashorn.internal.codegen.CompileUnit; 19.12 import jdk.nashorn.internal.codegen.Compiler; 19.13 import jdk.nashorn.internal.codegen.CompilerConstants; 19.14 @@ -73,40 +71,6 @@ 19.15 SETTER 19.16 } 19.17 19.18 - /** Compilation states available */ 19.19 - public enum CompilationState { 19.20 - /** compiler is ready */ 19.21 - INITIALIZED, 19.22 - /** method has been parsed */ 19.23 - PARSED, 19.24 - /** method has been parsed */ 19.25 - PARSE_ERROR, 19.26 - /** constant folding pass */ 19.27 - CONSTANT_FOLDED, 19.28 - /** method has been lowered */ 19.29 - LOWERED, 19.30 - /** program points have been assigned to unique locations */ 19.31 - PROGRAM_POINTS_ASSIGNED, 19.32 - /** any transformations of builtins have taken place, e.g. apply=>call */ 19.33 - BUILTINS_TRANSFORMED, 19.34 - /** method has been split */ 19.35 - SPLIT, 19.36 - /** method has had symbols assigned */ 19.37 - SYMBOLS_ASSIGNED, 19.38 - /** computed scope depths for symbols */ 19.39 - SCOPE_DEPTHS_COMPUTED, 19.40 - /** method has had types calculated*/ 19.41 - OPTIMISTIC_TYPES_ASSIGNED, 19.42 - /** method has had types calculated */ 19.43 - LOCAL_VARIABLE_TYPES_CALCULATED, 19.44 - /** compile units reused (optional) */ 19.45 - COMPILE_UNITS_REUSED, 19.46 - /** method has been emitted to bytecode */ 19.47 - BYTECODE_GENERATED, 19.48 - /** method has been installed */ 19.49 - BYTECODE_INSTALLED 19.50 - } 19.51 - 19.52 /** Source of entity. */ 19.53 private transient final Source source; 19.54 19.55 @@ -144,10 +108,6 @@ 19.56 /** Method's namespace. */ 19.57 private transient final Namespace namespace; 19.58 19.59 - /** Current compilation state */ 19.60 - @Ignore 19.61 - private final EnumSet<CompilationState> compilationState; 19.62 - 19.63 /** Number of properties of "this" object assigned in this function */ 19.64 @Ignore 19.65 private final int thisProperties; 19.66 @@ -322,7 +282,6 @@ 19.67 this.firstToken = firstToken; 19.68 this.lastToken = token; 19.69 this.namespace = namespace; 19.70 - this.compilationState = EnumSet.of(CompilationState.INITIALIZED); 19.71 this.flags = flags; 19.72 this.compileUnit = null; 19.73 this.body = null; 19.74 @@ -339,7 +298,6 @@ 19.75 final String name, 19.76 final Type returnType, 19.77 final CompileUnit compileUnit, 19.78 - final EnumSet<CompilationState> compilationState, 19.79 final Block body, 19.80 final List<IdentNode> parameters, 19.81 final int thisProperties, 19.82 @@ -354,7 +312,6 @@ 19.83 this.returnType = returnType; 19.84 this.compileUnit = compileUnit; 19.85 this.lastToken = lastToken; 19.86 - this.compilationState = compilationState; 19.87 this.body = body; 19.88 this.parameters = parameters; 19.89 this.thisProperties = thisProperties; 19.90 @@ -454,7 +411,6 @@ 19.91 name, 19.92 returnType, 19.93 compileUnit, 19.94 - compilationState, 19.95 body, 19.96 parameters, 19.97 thisProperties, 19.98 @@ -530,80 +486,6 @@ 19.99 } 19.100 19.101 /** 19.102 - * Get the compilation state of this function 19.103 - * @return the compilation state 19.104 - */ 19.105 - public EnumSet<CompilationState> getState() { 19.106 - return compilationState; 19.107 - } 19.108 - 19.109 - /** 19.110 - * Check whether this FunctionNode has reached a give CompilationState. 19.111 - * 19.112 - * @param state the state to check for 19.113 - * @return true of the node is in the given state 19.114 - */ 19.115 - public boolean hasState(final EnumSet<CompilationState> state) { 19.116 - return !AssertsEnabled.assertsEnabled() || compilationState.containsAll(state); 19.117 - } 19.118 - 19.119 - /** 19.120 - * Add a state to the total CompilationState of this node, e.g. if 19.121 - * FunctionNode has been lowered, the compiler will add 19.122 - * {@code CompilationState#LOWERED} to the state vector 19.123 - * 19.124 - * @param lc lexical context 19.125 - * @param state {@link CompilationState} to add 19.126 - * @return function node or a new one if state was changed 19.127 - */ 19.128 - public FunctionNode setState(final LexicalContext lc, final CompilationState state) { 19.129 - if (!AssertsEnabled.assertsEnabled() || this.compilationState.contains(state)) { 19.130 - return this; 19.131 - } 19.132 - final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState); 19.133 - newState.add(state); 19.134 - return setCompilationState(lc, newState); 19.135 - } 19.136 - 19.137 - /** 19.138 - * Copy a compilation state from an original function to this function. Used when creating synthetic 19.139 - * function nodes by the splitter. 19.140 - * 19.141 - * @param lc lexical context 19.142 - * @param original the original function node to copy compilation state from 19.143 - * @return function node or a new one if state was changed 19.144 - */ 19.145 - public FunctionNode copyCompilationState(final LexicalContext lc, final FunctionNode original) { 19.146 - final EnumSet<CompilationState> origState = original.compilationState; 19.147 - if (!AssertsEnabled.assertsEnabled() || this.compilationState.containsAll(origState)) { 19.148 - return this; 19.149 - } 19.150 - final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState); 19.151 - newState.addAll(origState); 19.152 - return setCompilationState(lc, newState); 19.153 - } 19.154 - 19.155 - private FunctionNode setCompilationState(final LexicalContext lc, final EnumSet<CompilationState> compilationState) { 19.156 - return Node.replaceInLexicalContext( 19.157 - lc, 19.158 - this, 19.159 - new FunctionNode( 19.160 - this, 19.161 - lastToken, 19.162 - endParserState, 19.163 - flags, 19.164 - name, 19.165 - returnType, 19.166 - compileUnit, 19.167 - compilationState, 19.168 - body, 19.169 - parameters, 19.170 - thisProperties, 19.171 - rootClass, source, namespace)); 19.172 - } 19.173 - 19.174 - 19.175 - /** 19.176 * Create a unique name in the namespace of this FunctionNode 19.177 * @param base prefix for name 19.178 * @return base if no collision exists, otherwise a name prefix with base 19.179 @@ -668,7 +550,6 @@ 19.180 name, 19.181 returnType, 19.182 compileUnit, 19.183 - compilationState, 19.184 body, 19.185 parameters, 19.186 thisProperties, 19.187 @@ -809,7 +690,6 @@ 19.188 name, 19.189 returnType, 19.190 compileUnit, 19.191 - compilationState, 19.192 body, 19.193 parameters, 19.194 thisProperties, 19.195 @@ -905,7 +785,6 @@ 19.196 name, 19.197 returnType, 19.198 compileUnit, 19.199 - compilationState, 19.200 body, 19.201 parameters, 19.202 thisProperties, 19.203 @@ -966,7 +845,6 @@ 19.204 name, 19.205 returnType, 19.206 compileUnit, 19.207 - compilationState, 19.208 body, 19.209 parameters, 19.210 thisProperties, 19.211 @@ -1002,7 +880,6 @@ 19.212 name, 19.213 returnType, 19.214 compileUnit, 19.215 - compilationState, 19.216 body, 19.217 parameters, 19.218 thisProperties, 19.219 @@ -1040,7 +917,6 @@ 19.220 name, 19.221 returnType, 19.222 compileUnit, 19.223 - compilationState, 19.224 body, 19.225 parameters, 19.226 thisProperties, 19.227 @@ -1116,7 +992,6 @@ 19.228 name, 19.229 returnType, 19.230 compileUnit, 19.231 - compilationState, 19.232 body, 19.233 parameters, 19.234 thisProperties, 19.235 @@ -1204,7 +1079,6 @@ 19.236 name, 19.237 type, 19.238 compileUnit, 19.239 - compilationState, 19.240 body, 19.241 parameters, 19.242 thisProperties, 19.243 @@ -1252,7 +1126,6 @@ 19.244 name, 19.245 returnType, 19.246 compileUnit, 19.247 - compilationState, 19.248 body, 19.249 parameters, 19.250 thisProperties, 19.251 @@ -1308,7 +1181,6 @@ 19.252 name, 19.253 returnType, 19.254 compileUnit, 19.255 - compilationState, 19.256 body, 19.257 parameters, 19.258 thisProperties,
20.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Fri Sep 11 21:08:07 2015 +0530 20.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Tue Sep 15 16:17:33 2015 +0530 20.3 @@ -84,7 +84,6 @@ 20.4 import jdk.nashorn.internal.ir.ExpressionStatement; 20.5 import jdk.nashorn.internal.ir.ForNode; 20.6 import jdk.nashorn.internal.ir.FunctionNode; 20.7 -import jdk.nashorn.internal.ir.FunctionNode.CompilationState; 20.8 import jdk.nashorn.internal.ir.IdentNode; 20.9 import jdk.nashorn.internal.ir.IfNode; 20.10 import jdk.nashorn.internal.ir.IndexNode; 20.11 @@ -513,8 +512,7 @@ 20.12 20.13 return lc.pop(functionNode). 20.14 setBody(lc, newBody). 20.15 - setLastToken(lc, lastToken). 20.16 - setState(lc, errors.hasErrors() ? CompilationState.PARSE_ERROR : CompilationState.PARSED); 20.17 + setLastToken(lc, lastToken); 20.18 } 20.19 20.20 /**
21.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Fri Sep 11 21:08:07 2015 +0530 21.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Tue Sep 15 16:17:33 2015 +0530 21.3 @@ -591,7 +591,7 @@ 21.4 * 21.5 * @param newPrototype new prototype object 21.6 */ 21.7 - public final void setPrototype(Object newPrototype) { 21.8 + public final void setPrototype(final Object newPrototype) { 21.9 if (newPrototype instanceof ScriptObject && newPrototype != this.prototype && allocatorMap != null) { 21.10 // Replace our current allocator map with one that is associated with the new prototype. 21.11 allocatorMap = allocatorMap.changeProto((ScriptObject) newPrototype);