提交 3c64d163 编写于 作者: S sundar

Merge

...@@ -26,7 +26,7 @@ if [ -z $ITERS ]; then ...@@ -26,7 +26,7 @@ if [ -z $ITERS ]; then
ITERS=7 ITERS=7
fi fi
NASHORN_JAR=dist/nashorn.jar NASHORN_JAR=dist/nashorn.jar
JVM_FLAGS="-XX:+UnlockDiagnosticVMOptions -Dnashorn.unstable.relink.threshold=8 -Xms2G -Xmx2G -XX:+TieredCompilation -server -jar ${NASHORN_JAR}" JVM_FLAGS="-Djava.ext.dirs=`dirname $0`/../dist:$JAVA_HOME/jre/lib/ext -XX:+UnlockDiagnosticVMOptions -Dnashorn.unstable.relink.threshold=8 -Xms2G -Xmx2G -XX:+TieredCompilation -server -jar ${NASHORN_JAR}"
JVM_FLAGS7="-Xbootclasspath/p:${NASHORN_JAR} ${JVM_FLAGS}" JVM_FLAGS7="-Xbootclasspath/p:${NASHORN_JAR} ${JVM_FLAGS}"
OCTANE_ARGS="--verbose --iterations ${ITERS}" OCTANE_ARGS="--verbose --iterations ${ITERS}"
......
...@@ -397,10 +397,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C ...@@ -397,10 +397,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
} }
setContextVariables(ctxt); setContextVariables(ctxt);
final Object val = ctxt.getAttribute(ScriptEngine.FILENAME); return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(ScriptRuntime.apply(script, ctxtGlobal), ctxtGlobal));
final String fileName = (val != null) ? val.toString() : "<eval>";
Object res = ScriptRuntime.apply(script, ctxtGlobal);
return ScriptObjectMirror.translateUndefined(ScriptObjectMirror.wrap(res, ctxtGlobal));
} catch (final Exception e) { } catch (final Exception e) {
throwAsScriptException(e); throwAsScriptException(e);
throw new AssertionError("should not reach here"); throw new AssertionError("should not reach here");
......
...@@ -58,12 +58,14 @@ import java.util.Arrays; ...@@ -58,12 +58,14 @@ import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import jdk.internal.org.objectweb.asm.ClassReader; import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter; import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.MethodVisitor; import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.util.TraceClassVisitor; import jdk.internal.org.objectweb.asm.util.TraceClassVisitor;
import jdk.nashorn.internal.codegen.types.Type; import jdk.nashorn.internal.codegen.types.Type;
import jdk.nashorn.internal.ir.FunctionNode; import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.SplitNode;
import jdk.nashorn.internal.runtime.PropertyMap; import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.ScriptEnvironment; import jdk.nashorn.internal.runtime.ScriptEnvironment;
import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptObject;
...@@ -219,14 +221,14 @@ public class ClassEmitter implements Emitter { ...@@ -219,14 +221,14 @@ public class ClassEmitter implements Emitter {
private void defineCommonStatics(final boolean strictMode) { private void defineCommonStatics(final boolean strictMode) {
// source - used to store the source data (text) for this script. Shared across // source - used to store the source data (text) for this script. Shared across
// compile units. Set externally by the compiler. // compile units. Set externally by the compiler.
field(EnumSet.of(Flag.PRIVATE, Flag.STATIC), SOURCE.tag(), Source.class); field(EnumSet.of(Flag.PRIVATE, Flag.STATIC), SOURCE.symbolName(), Source.class);
// constants - used to the constants array for this script. Shared across // constants - used to the constants array for this script. Shared across
// compile units. Set externally by the compiler. // compile units. Set externally by the compiler.
field(EnumSet.of(Flag.PRIVATE, Flag.STATIC), CONSTANTS.tag(), Object[].class); field(EnumSet.of(Flag.PRIVATE, Flag.STATIC), CONSTANTS.symbolName(), Object[].class);
// strictMode - was this script compiled in strict mode. Set externally by the compiler. // strictMode - was this script compiled in strict mode. Set externally by the compiler.
field(EnumSet.of(Flag.PUBLIC, Flag.STATIC, Flag.FINAL), STRICT_MODE.tag(), boolean.class, strictMode); field(EnumSet.of(Flag.PUBLIC, Flag.STATIC, Flag.FINAL), STRICT_MODE.symbolName(), boolean.class, strictMode);
} }
/** /**
...@@ -238,9 +240,9 @@ public class ClassEmitter implements Emitter { ...@@ -238,9 +240,9 @@ public class ClassEmitter implements Emitter {
if (constantMethodNeeded.contains(String.class)) { if (constantMethodNeeded.contains(String.class)) {
// $getString - get the ith entry from the constants table and cast to String. // $getString - get the ith entry from the constants table and cast to String.
final MethodEmitter getStringMethod = method(EnumSet.of(Flag.PRIVATE, Flag.STATIC), GET_STRING.tag(), String.class, int.class); final MethodEmitter getStringMethod = method(EnumSet.of(Flag.PRIVATE, Flag.STATIC), GET_STRING.symbolName(), String.class, int.class);
getStringMethod.begin(); getStringMethod.begin();
getStringMethod.getStatic(unitClassName, CONSTANTS.tag(), CONSTANTS.descriptor()) getStringMethod.getStatic(unitClassName, CONSTANTS.symbolName(), CONSTANTS.descriptor())
.load(Type.INT, 0) .load(Type.INT, 0)
.arrayload() .arrayload()
.checkcast(String.class) .checkcast(String.class)
...@@ -250,7 +252,7 @@ public class ClassEmitter implements Emitter { ...@@ -250,7 +252,7 @@ public class ClassEmitter implements Emitter {
if (constantMethodNeeded.contains(PropertyMap.class)) { if (constantMethodNeeded.contains(PropertyMap.class)) {
// $getMap - get the ith entry from the constants table and cast to PropertyMap. // $getMap - get the ith entry from the constants table and cast to PropertyMap.
final MethodEmitter getMapMethod = method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), GET_MAP.tag(), PropertyMap.class, int.class); final MethodEmitter getMapMethod = method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), GET_MAP.symbolName(), PropertyMap.class, int.class);
getMapMethod.begin(); getMapMethod.begin();
getMapMethod.loadConstants() getMapMethod.loadConstants()
.load(Type.INT, 0) .load(Type.INT, 0)
...@@ -260,7 +262,7 @@ public class ClassEmitter implements Emitter { ...@@ -260,7 +262,7 @@ public class ClassEmitter implements Emitter {
getMapMethod.end(); getMapMethod.end();
// $setMap - overwrite an existing map. // $setMap - overwrite an existing map.
final MethodEmitter setMapMethod = method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), SET_MAP.tag(), void.class, int.class, PropertyMap.class); final MethodEmitter setMapMethod = method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), SET_MAP.symbolName(), void.class, int.class, PropertyMap.class);
setMapMethod.begin(); setMapMethod.begin();
setMapMethod.loadConstants() setMapMethod.loadConstants()
.load(Type.INT, 0) .load(Type.INT, 0)
...@@ -289,7 +291,7 @@ public class ClassEmitter implements Emitter { ...@@ -289,7 +291,7 @@ public class ClassEmitter implements Emitter {
final MethodEmitter getArrayMethod = method(EnumSet.of(Flag.PRIVATE, Flag.STATIC), methodName, cls, int.class); final MethodEmitter getArrayMethod = method(EnumSet.of(Flag.PRIVATE, Flag.STATIC), methodName, cls, int.class);
getArrayMethod.begin(); getArrayMethod.begin();
getArrayMethod.getStatic(unitClassName, CONSTANTS.tag(), CONSTANTS.descriptor()) getArrayMethod.getStatic(unitClassName, CONSTANTS.symbolName(), CONSTANTS.descriptor())
.load(Type.INT, 0) .load(Type.INT, 0)
.arrayload() .arrayload()
.checkcast(cls) .checkcast(cls)
...@@ -307,7 +309,7 @@ public class ClassEmitter implements Emitter { ...@@ -307,7 +309,7 @@ public class ClassEmitter implements Emitter {
*/ */
static String getArrayMethodName(final Class<?> cls) { static String getArrayMethodName(final Class<?> cls) {
assert cls.isArray(); assert cls.isArray();
return GET_ARRAY_PREFIX.tag() + cls.getComponentType().getSimpleName() + GET_ARRAY_SUFFIX.tag(); return GET_ARRAY_PREFIX.symbolName() + cls.getComponentType().getSimpleName() + GET_ARRAY_SUFFIX.symbolName();
} }
/** /**
...@@ -409,6 +411,10 @@ public class ClassEmitter implements Emitter { ...@@ -409,6 +411,10 @@ public class ClassEmitter implements Emitter {
methodsStarted.remove(method); methodsStarted.remove(method);
} }
SplitMethodEmitter method(final SplitNode splitNode, final String methodName, final Class<?> rtype, final Class<?>... ptypes) {
return new SplitMethodEmitter(this, methodVisitor(EnumSet.of(Flag.PUBLIC, Flag.STATIC), methodName, rtype, ptypes), splitNode);
}
/** /**
* Add a new method to the class - defaults to public method * Add a new method to the class - defaults to public method
* *
...@@ -433,7 +439,7 @@ public class ClassEmitter implements Emitter { ...@@ -433,7 +439,7 @@ public class ClassEmitter implements Emitter {
* @return method emitter to use for weaving this method * @return method emitter to use for weaving this method
*/ */
MethodEmitter method(final EnumSet<Flag> methodFlags, final String methodName, final Class<?> rtype, final Class<?>... ptypes) { MethodEmitter method(final EnumSet<Flag> methodFlags, final String methodName, final Class<?> rtype, final Class<?>... ptypes) {
return new MethodEmitter(this, cw.visitMethod(Flag.getValue(methodFlags), methodName, methodDescriptor(rtype, ptypes), null, null)); return new MethodEmitter(this, methodVisitor(methodFlags, methodName, rtype, ptypes));
} }
/** /**
...@@ -484,7 +490,7 @@ public class ClassEmitter implements Emitter { ...@@ -484,7 +490,7 @@ public class ClassEmitter implements Emitter {
* @return method emitter to use for weaving <clinit> * @return method emitter to use for weaving <clinit>
*/ */
MethodEmitter clinit() { MethodEmitter clinit() {
return method(EnumSet.of(Flag.STATIC), CLINIT.tag(), void.class); return method(EnumSet.of(Flag.STATIC), CLINIT.symbolName(), void.class);
} }
/** /**
...@@ -493,7 +499,7 @@ public class ClassEmitter implements Emitter { ...@@ -493,7 +499,7 @@ public class ClassEmitter implements Emitter {
* @return method emitter to use for weaving <init>()V * @return method emitter to use for weaving <init>()V
*/ */
MethodEmitter init() { MethodEmitter init() {
return method(INIT.tag(), void.class); return method(INIT.symbolName(), void.class);
} }
/** /**
...@@ -503,7 +509,7 @@ public class ClassEmitter implements Emitter { ...@@ -503,7 +509,7 @@ public class ClassEmitter implements Emitter {
* @return method emitter to use for weaving <init>()V * @return method emitter to use for weaving <init>()V
*/ */
MethodEmitter init(final Class<?>... ptypes) { MethodEmitter init(final Class<?>... ptypes) {
return method(INIT.tag(), void.class, ptypes); return method(INIT.symbolName(), void.class, ptypes);
} }
/** /**
...@@ -515,7 +521,7 @@ public class ClassEmitter implements Emitter { ...@@ -515,7 +521,7 @@ public class ClassEmitter implements Emitter {
* @return method emitter to use for weaving <init>(...)V * @return method emitter to use for weaving <init>(...)V
*/ */
MethodEmitter init(final EnumSet<Flag> flags, final Class<?>... ptypes) { MethodEmitter init(final EnumSet<Flag> flags, final Class<?>... ptypes) {
return method(flags, INIT.tag(), void.class, ptypes); return method(flags, INIT.symbolName(), void.class, ptypes);
} }
/** /**
...@@ -628,4 +634,9 @@ public class ClassEmitter implements Emitter { ...@@ -628,4 +634,9 @@ public class ClassEmitter implements Emitter {
return v; return v;
} }
} }
private MethodVisitor methodVisitor(EnumSet<Flag> flags, final String methodName, final Class<?> rtype, final Class<?>... ptypes) {
return cw.visitMethod(Flag.getValue(flags), methodName, methodDescriptor(rtype, ptypes), null, null);
}
} }
...@@ -25,12 +25,16 @@ ...@@ -25,12 +25,16 @@
package jdk.nashorn.internal.codegen; package jdk.nashorn.internal.codegen;
import static jdk.nashorn.internal.codegen.CompilerConstants.ARGUMENTS;
import static jdk.nashorn.internal.codegen.CompilerConstants.CALLEE;
import static jdk.nashorn.internal.codegen.CompilerConstants.CONSTANTS; import static jdk.nashorn.internal.codegen.CompilerConstants.CONSTANTS;
import static jdk.nashorn.internal.codegen.CompilerConstants.DEFAULT_SCRIPT_NAME; import static jdk.nashorn.internal.codegen.CompilerConstants.DEFAULT_SCRIPT_NAME;
import static jdk.nashorn.internal.codegen.CompilerConstants.LAZY; import static jdk.nashorn.internal.codegen.CompilerConstants.LAZY;
import static jdk.nashorn.internal.codegen.CompilerConstants.RETURN;
import static jdk.nashorn.internal.codegen.CompilerConstants.SCOPE; import static jdk.nashorn.internal.codegen.CompilerConstants.SCOPE;
import static jdk.nashorn.internal.codegen.CompilerConstants.SOURCE; import static jdk.nashorn.internal.codegen.CompilerConstants.SOURCE;
import static jdk.nashorn.internal.codegen.CompilerConstants.THIS; import static jdk.nashorn.internal.codegen.CompilerConstants.THIS;
import static jdk.nashorn.internal.codegen.CompilerConstants.VARARGS;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
...@@ -46,13 +50,12 @@ import java.util.Map; ...@@ -46,13 +50,12 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import jdk.internal.dynalink.support.NameCodec; import jdk.internal.dynalink.support.NameCodec;
import jdk.nashorn.internal.codegen.ClassEmitter.Flag; import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
import jdk.nashorn.internal.codegen.types.Type; import jdk.nashorn.internal.codegen.types.Type;
import jdk.nashorn.internal.ir.FunctionNode; import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.FunctionNode.CompilationState; import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
import jdk.nashorn.internal.ir.Node;
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
import jdk.nashorn.internal.runtime.CodeInstaller; import jdk.nashorn.internal.runtime.CodeInstaller;
import jdk.nashorn.internal.runtime.DebugLogger; import jdk.nashorn.internal.runtime.DebugLogger;
import jdk.nashorn.internal.runtime.ScriptEnvironment; import jdk.nashorn.internal.runtime.ScriptEnvironment;
...@@ -80,8 +83,6 @@ public final class Compiler { ...@@ -80,8 +83,6 @@ public final class Compiler {
private final ConstantData constantData; private final ConstantData constantData;
private final FunctionNode functionNode;
private final CompilationSequence sequence; private final CompilationSequence sequence;
private final ScriptEnvironment env; private final ScriptEnvironment env;
...@@ -90,6 +91,8 @@ public final class Compiler { ...@@ -90,6 +91,8 @@ public final class Compiler {
private boolean strict; private boolean strict;
private FunctionNode functionNode;
private CodeInstaller<ScriptEnvironment> installer; private CodeInstaller<ScriptEnvironment> installer;
/** logger for compiler, trampolines, splits and related code generation events /** logger for compiler, trampolines, splits and related code generation events
...@@ -103,8 +106,12 @@ public final class Compiler { ...@@ -103,8 +106,12 @@ public final class Compiler {
* during a compile. * during a compile.
*/ */
private static String[] RESERVED_NAMES = { private static String[] RESERVED_NAMES = {
SCOPE.tag(), SCOPE.symbolName(),
THIS.tag() THIS.symbolName(),
RETURN.symbolName(),
CALLEE.symbolName(),
VARARGS.symbolName(),
ARGUMENTS.symbolName()
}; };
/** /**
...@@ -186,7 +193,7 @@ public final class Compiler { ...@@ -186,7 +193,7 @@ public final class Compiler {
private static String lazyTag(final FunctionNode functionNode) { private static String lazyTag(final FunctionNode functionNode) {
if (functionNode.isLazy()) { if (functionNode.isLazy()) {
return '$' + LAZY.tag() + '$' + functionNode.getName(); return '$' + LAZY.symbolName() + '$' + functionNode.getName();
} }
return ""; return "";
} }
...@@ -205,13 +212,13 @@ public final class Compiler { ...@@ -205,13 +212,13 @@ public final class Compiler {
this.functionNode = functionNode; this.functionNode = functionNode;
this.sequence = sequence; this.sequence = sequence;
this.installer = installer; this.installer = installer;
this.strict = strict || functionNode.isStrictMode(); this.strict = strict || functionNode.isStrict();
this.constantData = new ConstantData(); this.constantData = new ConstantData();
this.compileUnits = new HashSet<>(); this.compileUnits = new HashSet<>();
this.bytecode = new HashMap<>(); this.bytecode = new HashMap<>();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(functionNode.uniqueName(DEFAULT_SCRIPT_NAME.tag() + lazyTag(functionNode))). sb.append(functionNode.uniqueName(DEFAULT_SCRIPT_NAME.symbolName() + lazyTag(functionNode))).
append('$'). append('$').
append(safeSourceName(functionNode.getSource())); append(safeSourceName(functionNode.getSource()));
...@@ -253,9 +260,9 @@ public final class Compiler { ...@@ -253,9 +260,9 @@ public final class Compiler {
* Execute the compilation this Compiler was created with * Execute the compilation this Compiler was created with
* @params param types if known, for specialization * @params param types if known, for specialization
* @throws CompilationException if something goes wrong * @throws CompilationException if something goes wrong
* @return this compiler, for possible chaining * @return function node that results from code transforms
*/ */
public Compiler compile() throws CompilationException { public FunctionNode compile() throws CompilationException {
return compile(null); return compile(null);
} }
...@@ -263,9 +270,9 @@ public final class Compiler { ...@@ -263,9 +270,9 @@ public final class Compiler {
* Execute the compilation this Compiler was created with * Execute the compilation this Compiler was created with
* @param paramTypes param types if known, for specialization * @param paramTypes param types if known, for specialization
* @throws CompilationException if something goes wrong * @throws CompilationException if something goes wrong
* @return this compiler, for possible chaining * @return function node that results from code transforms
*/ */
public Compiler compile(final Class<?> paramTypes) throws CompilationException { public FunctionNode compile(final Class<?> paramTypes) throws CompilationException {
for (final String reservedName : RESERVED_NAMES) { for (final String reservedName : RESERVED_NAMES) {
functionNode.uniqueName(reservedName); functionNode.uniqueName(reservedName);
} }
...@@ -276,7 +283,7 @@ public final class Compiler { ...@@ -276,7 +283,7 @@ public final class Compiler {
long time = 0L; long time = 0L;
for (final CompilationPhase phase : sequence) { for (final CompilationPhase phase : sequence) {
phase.apply(this, functionNode); this.functionNode = phase.apply(this, functionNode);
final long duration = Timing.isEnabled() ? (phase.getEndTime() - phase.getStartTime()) : 0L; final long duration = Timing.isEnabled() ? (phase.getEndTime() - phase.getStartTime()) : 0L;
time += duration; time += duration;
...@@ -295,7 +302,7 @@ public final class Compiler { ...@@ -295,7 +302,7 @@ public final class Compiler {
append(" ms "); append(" ms ");
} }
LOG.fine(sb.toString()); LOG.fine(sb);
} }
} }
...@@ -311,14 +318,14 @@ public final class Compiler { ...@@ -311,14 +318,14 @@ public final class Compiler {
append(" ms"); append(" ms");
} }
LOG.info(sb.toString()); LOG.info(sb);
} }
return this; return functionNode;
} }
private Class<?> install(final String className, final byte[] code) { private Class<?> install(final String className, final byte[] code) {
LOG.fine("Installing class " + className); LOG.fine("Installing class ", className);
final Class<?> clazz = installer.install(Compiler.binaryName(className), code); final Class<?> clazz = installer.install(Compiler.binaryName(className), code);
...@@ -330,8 +337,8 @@ public final class Compiler { ...@@ -330,8 +337,8 @@ public final class Compiler {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
//use reflection to write source and constants table to installed classes //use reflection to write source and constants table to installed classes
final Field sourceField = clazz.getDeclaredField(SOURCE.tag()); final Field sourceField = clazz.getDeclaredField(SOURCE.symbolName());
final Field constantsField = clazz.getDeclaredField(CONSTANTS.tag()); final Field constantsField = clazz.getDeclaredField(CONSTANTS.symbolName());
sourceField.setAccessible(true); sourceField.setAccessible(true);
constantsField.setAccessible(true); constantsField.setAccessible(true);
sourceField.set(null, source); sourceField.set(null, source);
...@@ -380,17 +387,6 @@ public final class Compiler { ...@@ -380,17 +387,6 @@ public final class Compiler {
unit.setCode(installedClasses.get(unit.getUnitClassName())); unit.setCode(installedClasses.get(unit.getUnitClassName()));
} }
functionNode.accept(new NodeVisitor() {
@Override
public Node enterFunctionNode(final FunctionNode node) {
if (node.isLazy()) {
return null;
}
node.setState(CompilationState.INSTALLED);
return node;
}
});
final StringBuilder sb; final StringBuilder sb;
if (LOG.isEnabled()) { if (LOG.isEnabled()) {
sb = new StringBuilder(); sb = new StringBuilder();
...@@ -416,7 +412,7 @@ public final class Compiler { ...@@ -416,7 +412,7 @@ public final class Compiler {
} }
if (sb != null) { if (sb != null) {
LOG.info(sb.toString()); LOG.info(sb);
} }
return rootClass; return rootClass;
...@@ -495,7 +491,7 @@ public final class Compiler { ...@@ -495,7 +491,7 @@ public final class Compiler {
private CompileUnit addCompileUnit(final String unitClassName, final long initialWeight) { private CompileUnit addCompileUnit(final String unitClassName, final long initialWeight) {
final CompileUnit compileUnit = initCompileUnit(unitClassName, initialWeight); final CompileUnit compileUnit = initCompileUnit(unitClassName, initialWeight);
compileUnits.add(compileUnit); compileUnits.add(compileUnit);
LOG.fine("Added compile unit " + compileUnit); LOG.fine("Added compile unit ", compileUnit);
return compileUnit; return compileUnit;
} }
......
...@@ -52,9 +52,6 @@ public enum CompilerConstants { ...@@ -52,9 +52,6 @@ public enum CompilerConstants {
/** lazy prefix for classes of jitted methods */ /** lazy prefix for classes of jitted methods */
LAZY("Lazy"), LAZY("Lazy"),
/** leaf tag used for functions that require no scope */
LEAF("__leaf__"),
/** constructor name */ /** constructor name */
INIT("<init>"), INIT("<init>"),
...@@ -96,7 +93,7 @@ public enum CompilerConstants { ...@@ -96,7 +93,7 @@ public enum CompilerConstants {
SCOPE("__scope__", ScriptObject.class, 2), SCOPE("__scope__", ScriptObject.class, 2),
/** the return value variable name were intermediate results are stored for scripts */ /** the return value variable name were intermediate results are stored for scripts */
SCRIPT_RETURN("__return__"), RETURN("__return__"),
/** the callee value variable when necessary */ /** the callee value variable when necessary */
CALLEE("__callee__", ScriptFunction.class), CALLEE("__callee__", ScriptFunction.class),
...@@ -167,30 +164,30 @@ public enum CompilerConstants { ...@@ -167,30 +164,30 @@ public enum CompilerConstants {
/** get array suffix */ /** get array suffix */
GET_ARRAY_SUFFIX("$array"); GET_ARRAY_SUFFIX("$array");
private final String tag; private final String symbolName;
private final Class<?> type; private final Class<?> type;
private final int slot; private final int slot;
private CompilerConstants() { private CompilerConstants() {
this.tag = name(); this.symbolName = name();
this.type = null; this.type = null;
this.slot = -1; this.slot = -1;
} }
private CompilerConstants(final String tag) { private CompilerConstants(final String symbolName) {
this(tag, -1); this(symbolName, -1);
} }
private CompilerConstants(final String tag, final int slot) { private CompilerConstants(final String symbolName, final int slot) {
this(tag, null, slot); this(symbolName, null, slot);
} }
private CompilerConstants(final String tag, final Class<?> type) { private CompilerConstants(final String symbolName, final Class<?> type) {
this(tag, type, -1); this(symbolName, type, -1);
} }
private CompilerConstants(final String tag, final Class<?> type, final int slot) { private CompilerConstants(final String symbolName, final Class<?> type, final int slot) {
this.tag = tag; this.symbolName = symbolName;
this.type = type; this.type = type;
this.slot = slot; this.slot = slot;
} }
...@@ -202,8 +199,8 @@ public enum CompilerConstants { ...@@ -202,8 +199,8 @@ public enum CompilerConstants {
* *
* @return the tag * @return the tag
*/ */
public final String tag() { public final String symbolName() {
return tag; return symbolName;
} }
/** /**
...@@ -277,7 +274,7 @@ public enum CompilerConstants { ...@@ -277,7 +274,7 @@ public enum CompilerConstants {
* @return Call representing void constructor for type * @return Call representing void constructor for type
*/ */
public static Call constructorNoLookup(final Class<?> clazz) { public static Call constructorNoLookup(final Class<?> clazz) {
return specialCallNoLookup(clazz, INIT.tag(), void.class); return specialCallNoLookup(clazz, INIT.symbolName(), void.class);
} }
/** /**
...@@ -290,7 +287,7 @@ public enum CompilerConstants { ...@@ -290,7 +287,7 @@ public enum CompilerConstants {
* @return Call representing constructor for type * @return Call representing constructor for type
*/ */
public static Call constructorNoLookup(final String className, final Class<?>... ptypes) { public static Call constructorNoLookup(final String className, final Class<?>... ptypes) {
return specialCallNoLookup(className, INIT.tag(), methodDescriptor(void.class, ptypes)); return specialCallNoLookup(className, INIT.symbolName(), methodDescriptor(void.class, ptypes));
} }
/** /**
...@@ -303,7 +300,7 @@ public enum CompilerConstants { ...@@ -303,7 +300,7 @@ public enum CompilerConstants {
* @return Call representing constructor for type * @return Call representing constructor for type
*/ */
public static Call constructorNoLookup(final Class<?> clazz, final Class<?>... ptypes) { public static Call constructorNoLookup(final Class<?> clazz, final Class<?>... ptypes) {
return specialCallNoLookup(clazz, INIT.tag(), void.class, ptypes); return specialCallNoLookup(clazz, INIT.symbolName(), void.class, ptypes);
} }
/** /**
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
package jdk.nashorn.internal.codegen; package jdk.nashorn.internal.codegen;
import static jdk.nashorn.internal.codegen.CompilerConstants.ARGUMENTS; import static jdk.nashorn.internal.codegen.CompilerConstants.ARGUMENTS;
import static jdk.nashorn.internal.codegen.CompilerConstants.SCOPE;
import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup; import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup;
import static jdk.nashorn.internal.codegen.CompilerConstants.typeDescriptor; import static jdk.nashorn.internal.codegen.CompilerConstants.typeDescriptor;
import static jdk.nashorn.internal.codegen.types.Type.OBJECT; import static jdk.nashorn.internal.codegen.types.Type.OBJECT;
...@@ -86,7 +87,7 @@ public abstract class FieldObjectCreator<T> extends ObjectCreator { ...@@ -86,7 +87,7 @@ public abstract class FieldObjectCreator<T> extends ObjectCreator {
* @param method the method emitter to use * @param method the method emitter to use
*/ */
protected void loadScope(final MethodEmitter method) { protected void loadScope(final MethodEmitter method) {
method.loadScope(); method.loadCompilerConstant(SCOPE);
} }
/** /**
...@@ -105,7 +106,7 @@ public abstract class FieldObjectCreator<T> extends ObjectCreator { ...@@ -105,7 +106,7 @@ public abstract class FieldObjectCreator<T> extends ObjectCreator {
loadScope(method); loadScope(method);
if (hasArguments()) { if (hasArguments()) {
method.loadArguments(); method.loadCompilerConstant(ARGUMENTS);
method.invoke(constructorNoLookup(getClassName(), PropertyMap.class, ScriptObject.class, ARGUMENTS.type())); method.invoke(constructorNoLookup(getClassName(), PropertyMap.class, ScriptObject.class, ARGUMENTS.type()));
} else { } else {
method.invoke(constructorNoLookup(getClassName(), PropertyMap.class, ScriptObject.class)); method.invoke(constructorNoLookup(getClassName(), PropertyMap.class, ScriptObject.class));
......
...@@ -57,7 +57,7 @@ final class FoldConstants extends NodeVisitor { ...@@ -57,7 +57,7 @@ final class FoldConstants extends NodeVisitor {
public Node leaveUnaryNode(final UnaryNode unaryNode) { public Node leaveUnaryNode(final UnaryNode unaryNode) {
final LiteralNode<?> literalNode = new UnaryNodeConstantEvaluator(unaryNode).eval(); final LiteralNode<?> literalNode = new UnaryNodeConstantEvaluator(unaryNode).eval();
if (literalNode != null) { if (literalNode != null) {
LOG.info("Unary constant folded " + unaryNode + " to " + literalNode); LOG.info("Unary constant folded ", unaryNode, " to ", literalNode);
return literalNode; return literalNode;
} }
return unaryNode; return unaryNode;
...@@ -67,24 +67,20 @@ final class FoldConstants extends NodeVisitor { ...@@ -67,24 +67,20 @@ final class FoldConstants extends NodeVisitor {
public Node leaveBinaryNode(final BinaryNode binaryNode) { public Node leaveBinaryNode(final BinaryNode binaryNode) {
final LiteralNode<?> literalNode = new BinaryNodeConstantEvaluator(binaryNode).eval(); final LiteralNode<?> literalNode = new BinaryNodeConstantEvaluator(binaryNode).eval();
if (literalNode != null) { if (literalNode != null) {
LOG.info("Binary constant folded " + binaryNode + " to " + literalNode); LOG.info("Binary constant folded ", binaryNode, " to ", literalNode);
return literalNode; return literalNode;
} }
return binaryNode; return binaryNode;
} }
@Override @Override
public Node enterFunctionNode(final FunctionNode functionNode) { public boolean enterFunctionNode(final FunctionNode functionNode) {
if (functionNode.isLazy()) { return !functionNode.isLazy();
return null;
}
return functionNode;
} }
@Override @Override
public Node leaveFunctionNode(final FunctionNode functionNode) { public Node leaveFunctionNode(final FunctionNode functionNode) {
functionNode.setState(CompilationState.CONSTANT_FOLDED); return functionNode.setState(getLexicalContext(), CompilationState.CONSTANT_FOLDED);
return functionNode;
} }
@Override @Override
......
此差异已折叠。
...@@ -53,7 +53,7 @@ public class Namespace { ...@@ -53,7 +53,7 @@ public class Namespace {
*/ */
public Namespace(final Namespace parent) { public Namespace(final Namespace parent) {
this.parent = parent; this.parent = parent;
directory = new HashMap<>(); this.directory = new HashMap<>();
} }
/** /**
...@@ -65,10 +65,6 @@ public class Namespace { ...@@ -65,10 +65,6 @@ public class Namespace {
return parent; return parent;
} }
private HashMap<String, Integer> getDirectory() {
return directory;
}
/** /**
* Create a uniqueName name in the namespace in the form base$n where n varies * Create a uniqueName name in the namespace in the form base$n where n varies
* . * .
...@@ -78,7 +74,7 @@ public class Namespace { ...@@ -78,7 +74,7 @@ public class Namespace {
*/ */
public String uniqueName(final String base) { public String uniqueName(final String base) {
for (Namespace namespace = this; namespace != null; namespace = namespace.getParent()) { for (Namespace namespace = this; namespace != null; namespace = namespace.getParent()) {
final HashMap<String, Integer> namespaceDirectory = namespace.getDirectory(); final HashMap<String, Integer> namespaceDirectory = namespace.directory;
final Integer counter = namespaceDirectory.get(base); final Integer counter = namespaceDirectory.get(base);
if (counter != null) { if (counter != null) {
......
...@@ -204,8 +204,8 @@ public final class ObjectClassGenerator { ...@@ -204,8 +204,8 @@ public final class ObjectClassGenerator {
* @return The class name. * @return The class name.
*/ */
public static String getClassName(final int fieldCount) { public static String getClassName(final int fieldCount) {
return fieldCount != 0 ? SCRIPTS_PACKAGE + '/' + JS_OBJECT_PREFIX.tag() + fieldCount : return fieldCount != 0 ? SCRIPTS_PACKAGE + '/' + JS_OBJECT_PREFIX.symbolName() + fieldCount :
SCRIPTS_PACKAGE + '/' + JS_OBJECT_PREFIX.tag(); SCRIPTS_PACKAGE + '/' + JS_OBJECT_PREFIX.symbolName();
} }
/** /**
...@@ -218,7 +218,7 @@ public final class ObjectClassGenerator { ...@@ -218,7 +218,7 @@ public final class ObjectClassGenerator {
* @return The class name. * @return The class name.
*/ */
public static String getClassName(final int fieldCount, final int paramCount) { public static String getClassName(final int fieldCount, final int paramCount) {
return SCRIPTS_PACKAGE + '/' + JS_OBJECT_PREFIX.tag() + fieldCount + SCOPE_MARKER + paramCount; return SCRIPTS_PACKAGE + '/' + JS_OBJECT_PREFIX.symbolName() + fieldCount + SCOPE_MARKER + paramCount;
} }
/** /**
...@@ -449,7 +449,7 @@ public final class ObjectClassGenerator { ...@@ -449,7 +449,7 @@ public final class ObjectClassGenerator {
* @param className Name of JavaScript class. * @param className Name of JavaScript class.
*/ */
private static void newAllocate(final ClassEmitter classEmitter, final String className) { private static void newAllocate(final ClassEmitter classEmitter, final String className) {
final MethodEmitter allocate = classEmitter.method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), ALLOCATE.tag(), ScriptObject.class, PropertyMap.class); final MethodEmitter allocate = classEmitter.method(EnumSet.of(Flag.PUBLIC, Flag.STATIC), ALLOCATE.symbolName(), ScriptObject.class, PropertyMap.class);
allocate.begin(); allocate.begin();
allocate._new(className); allocate._new(className);
allocate.dup(); allocate.dup();
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
...@@ -148,11 +148,7 @@ public final class NativeJSAdapter extends ScriptObject { ...@@ -148,11 +148,7 @@ public final class NativeJSAdapter extends ScriptObject {
if (overrides instanceof ScriptObject) { if (overrides instanceof ScriptObject) {
this.overrides = true; this.overrides = true;
final ScriptObject sobj = (ScriptObject)overrides; final ScriptObject sobj = (ScriptObject)overrides;
final Iterator<String> iter = sobj.propertyIterator(); this.addBoundProperties(sobj);
while (iter.hasNext()) {
final String prop = iter.next();
super.set(prop, sobj.get(prop), false);
}
} else { } else {
this.overrides = false; this.overrides = false;
} }
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册