提交 8a82836a 编写于 作者: S sundar

8130663: 6 fields can be static fields in Global class

Reviewed-by: hannesw, attila
上级 60db28fa
...@@ -69,7 +69,6 @@ import jdk.nashorn.internal.runtime.UnwarrantedOptimismException; ...@@ -69,7 +69,6 @@ import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
import jdk.nashorn.internal.runtime.logging.DebugLogger; import jdk.nashorn.internal.runtime.logging.DebugLogger;
import jdk.nashorn.internal.runtime.logging.Loggable; import jdk.nashorn.internal.runtime.logging.Loggable;
import jdk.nashorn.internal.runtime.logging.Logger; import jdk.nashorn.internal.runtime.logging.Logger;
import jdk.nashorn.internal.runtime.options.Options;
/** /**
* Generates the ScriptObject subclass structure with fields for a user objects. * Generates the ScriptObject subclass structure with fields for a user objects.
......
...@@ -88,14 +88,14 @@ import jdk.nashorn.tools.ShellFunctions; ...@@ -88,14 +88,14 @@ import jdk.nashorn.tools.ShellFunctions;
*/ */
@ScriptClass("Global") @ScriptClass("Global")
public final class Global extends Scope { public final class Global extends Scope {
// Placeholder value used in place of a location property (__FILE__, __DIR__, __LINE__) // This special value is used to flag a lazily initialized global property.
private static final Object LOCATION_PROPERTY_PLACEHOLDER = new Object(); // This also serves as placeholder value used in place of a location property
// (__FILE__, __DIR__, __LINE__)
private static final Object LAZY_SENTINEL = new Object();
private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class);
private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class);
// placeholder value for lazily initialized global objects
private static final Object LAZY_SENTINEL = new Object();
/** /**
* Optimistic builtin names that require switchpoint invalidation * Optimistic builtin names that require switchpoint invalidation
* upon assignment. Overly conservative, but works for now, to avoid * upon assignment. Overly conservative, but works for now, to avoid
...@@ -182,15 +182,15 @@ public final class Global extends Scope { ...@@ -182,15 +182,15 @@ public final class Global extends Scope {
/** Value property NaN of the Global Object - ECMA 15.1.1.1 NaN */ /** Value property NaN of the Global Object - ECMA 15.1.1.1 NaN */
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public final double NaN = Double.NaN; public static final double NaN = Double.NaN;
/** Value property Infinity of the Global Object - ECMA 15.1.1.2 Infinity */ /** Value property Infinity of the Global Object - ECMA 15.1.1.2 Infinity */
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public final double Infinity = Double.POSITIVE_INFINITY; public static final double Infinity = Double.POSITIVE_INFINITY;
/** Value property Undefined of the Global Object - ECMA 15.1.1.3 Undefined */ /** Value property Undefined of the Global Object - ECMA 15.1.1.3 Undefined */
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT) @Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public final Object undefined = UNDEFINED; public static final Object undefined = UNDEFINED;
/** ECMA 15.1.2.1 eval(x) */ /** ECMA 15.1.2.1 eval(x) */
@Property(attributes = Attribute.NOT_ENUMERABLE) @Property(attributes = Attribute.NOT_ENUMERABLE)
...@@ -830,15 +830,15 @@ public final class Global extends Scope { ...@@ -830,15 +830,15 @@ public final class Global extends Scope {
/** Nashorn extension: current script's file name */ /** Nashorn extension: current script's file name */
@Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) @Property(name = "__FILE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public final Object __FILE__ = LOCATION_PROPERTY_PLACEHOLDER; public static final Object __FILE__ = LAZY_SENTINEL;
/** Nashorn extension: current script's directory */ /** Nashorn extension: current script's directory */
@Property(name = "__DIR__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) @Property(name = "__DIR__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public final Object __DIR__ = LOCATION_PROPERTY_PLACEHOLDER; public static final Object __DIR__ = LAZY_SENTINEL;
/** Nashorn extension: current source line number being executed */ /** Nashorn extension: current source line number being executed */
@Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT) @Property(name = "__LINE__", attributes = Attribute.NON_ENUMERABLE_CONSTANT)
public final Object __LINE__ = LOCATION_PROPERTY_PLACEHOLDER; public static final Object __LINE__ = LAZY_SENTINEL;
private volatile NativeDate DEFAULT_DATE; private volatile NativeDate DEFAULT_DATE;
...@@ -2020,7 +2020,7 @@ public final class Global extends Scope { ...@@ -2020,7 +2020,7 @@ public final class Global extends Scope {
* @return true if the value is a placeholder, false otherwise. * @return true if the value is a placeholder, false otherwise.
*/ */
public static boolean isLocationPropertyPlaceholder(final Object placeholder) { public static boolean isLocationPropertyPlaceholder(final Object placeholder) {
return placeholder == LOCATION_PROPERTY_PLACEHOLDER; return placeholder == LAZY_SENTINEL;
} }
/** /**
......
...@@ -907,7 +907,7 @@ final class CompiledFunction { ...@@ -907,7 +907,7 @@ final class CompiledFunction {
OptimismInfo(final RecompilableScriptFunctionData data, final Map<Integer, Type> invalidatedProgramPoints) { OptimismInfo(final RecompilableScriptFunctionData data, final Map<Integer, Type> invalidatedProgramPoints) {
this.data = data; this.data = data;
this.log = data.getLogger(); this.log = data.getLogger();
this.invalidatedProgramPoints = invalidatedProgramPoints == null ? new TreeMap<Integer, Type>() : invalidatedProgramPoints; this.invalidatedProgramPoints = invalidatedProgramPoints == null ? new TreeMap<>() : invalidatedProgramPoints;
newOptimisticAssumptions(); newOptimisticAssumptions();
} }
......
...@@ -562,8 +562,8 @@ public abstract class Property implements Serializable { ...@@ -562,8 +562,8 @@ public abstract class Property implements Serializable {
@Override @Override
public int hashCode() { public int hashCode() {
final Class<?> type = getLocalType(); final Class<?> t = getLocalType();
return Objects.hashCode(this.key) ^ flags ^ getSlot() ^ (type == null ? 0 : type.hashCode()); return Objects.hashCode(this.key) ^ flags ^ getSlot() ^ (t == null ? 0 : t.hashCode());
} }
@Override @Override
...@@ -588,7 +588,7 @@ public abstract class Property implements Serializable { ...@@ -588,7 +588,7 @@ public abstract class Property implements Serializable {
getKey().equals(otherProperty.getKey()); getKey().equals(otherProperty.getKey());
} }
private static final String type(final Class<?> type) { private static String type(final Class<?> type) {
if (type == null) { if (type == null) {
return "undef"; return "undef";
} else if (type == int.class) { } else if (type == int.class) {
...@@ -608,8 +608,8 @@ public abstract class Property implements Serializable { ...@@ -608,8 +608,8 @@ public abstract class Property implements Serializable {
*/ */
public final String toStringShort() { public final String toStringShort() {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
final Class<?> type = getLocalType(); final Class<?> t = getLocalType();
sb.append(getKey()).append(" (").append(type(type)).append(')'); sb.append(getKey()).append(" (").append(type(t)).append(')');
return sb.toString(); return sb.toString();
} }
...@@ -625,7 +625,7 @@ public abstract class Property implements Serializable { ...@@ -625,7 +625,7 @@ public abstract class Property implements Serializable {
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
final Class<?> type = getLocalType(); final Class<?> t = getLocalType();
sb.append(indent(getKey(), 20)). sb.append(indent(getKey(), 20)).
append(" id="). append(" id=").
...@@ -635,7 +635,7 @@ public abstract class Property implements Serializable { ...@@ -635,7 +635,7 @@ public abstract class Property implements Serializable {
append(") "). append(") ").
append(getClass().getSimpleName()). append(getClass().getSimpleName()).
append(" {"). append(" {").
append(indent(type(type), 5)). append(indent(type(t), 5)).
append('}'); append('}');
if (slot != -1) { if (slot != -1) {
......
...@@ -999,10 +999,10 @@ public final class PropertyMap implements Iterable<Object>, Serializable { ...@@ -999,10 +999,10 @@ public final class PropertyMap implements Iterable<Object>, Serializable {
for (final Property p : map0.getProperties()) { for (final Property p : map0.getProperties()) {
final Property p2 = map1.findProperty(p.getKey()); final Property p2 = map1.findProperty(p.getKey());
if (p2 == null) { if (p2 == null) {
sb.append("FIRST ONLY : [" + p + "]"); sb.append("FIRST ONLY : [").append(p).append("]");
found = true; found = true;
} else if (p2 != p) { } else if (p2 != p) {
sb.append("DIFFERENT : [" + p + "] != [" + p2 + "]"); sb.append("DIFFERENT : [").append(p).append("] != [").append(p2).append("]");
found = true; found = true;
} }
} }
...@@ -1010,7 +1010,7 @@ public final class PropertyMap implements Iterable<Object>, Serializable { ...@@ -1010,7 +1010,7 @@ public final class PropertyMap implements Iterable<Object>, Serializable {
for (final Property p2 : map1.getProperties()) { for (final Property p2 : map1.getProperties()) {
final Property p1 = map0.findProperty(p2.getKey()); final Property p1 = map0.findProperty(p2.getKey());
if (p1 == null) { if (p1 == null) {
sb.append("SECOND ONLY: [" + p2 + "]"); sb.append("SECOND ONLY: [").append(p2).append("]");
found = true; found = true;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册