mirror of
https://github.com/openjdk/jdk.git
synced 2026-06-01 16:22:31 +00:00
8130663: 6 fields can be static fields in Global class
Reviewed-by: hannesw, attila
This commit is contained in:
parent
94d29a19c8
commit
39ea286002
@ -69,7 +69,6 @@ import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
|
||||
import jdk.nashorn.internal.runtime.logging.DebugLogger;
|
||||
import jdk.nashorn.internal.runtime.logging.Loggable;
|
||||
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.
|
||||
|
||||
@ -88,14 +88,14 @@ import jdk.nashorn.tools.ShellFunctions;
|
||||
*/
|
||||
@ScriptClass("Global")
|
||||
public final class Global extends Scope {
|
||||
// Placeholder value used in place of a location property (__FILE__, __DIR__, __LINE__)
|
||||
private static final Object LOCATION_PROPERTY_PLACEHOLDER = new Object();
|
||||
// This special value is used to flag a lazily initialized global property.
|
||||
// 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 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
|
||||
* upon assignment. Overly conservative, but works for now, to avoid
|
||||
@ -182,15 +182,15 @@ public final class Global extends Scope {
|
||||
|
||||
/** Value property NaN of the Global Object - ECMA 15.1.1.1 NaN */
|
||||
@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 */
|
||||
@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 */
|
||||
@Property(attributes = Attribute.NON_ENUMERABLE_CONSTANT)
|
||||
public final Object undefined = UNDEFINED;
|
||||
public static final Object undefined = UNDEFINED;
|
||||
|
||||
/** ECMA 15.1.2.1 eval(x) */
|
||||
@Property(attributes = Attribute.NOT_ENUMERABLE)
|
||||
@ -830,15 +830,15 @@ public final class Global extends Scope {
|
||||
|
||||
/** Nashorn extension: current script's file name */
|
||||
@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 */
|
||||
@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 */
|
||||
@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;
|
||||
|
||||
@ -2020,7 +2020,7 @@ public final class Global extends Scope {
|
||||
* @return true if the value is a placeholder, false otherwise.
|
||||
*/
|
||||
public static boolean isLocationPropertyPlaceholder(final Object placeholder) {
|
||||
return placeholder == LOCATION_PROPERTY_PLACEHOLDER;
|
||||
return placeholder == LAZY_SENTINEL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -907,7 +907,7 @@ final class CompiledFunction {
|
||||
OptimismInfo(final RecompilableScriptFunctionData data, final Map<Integer, Type> invalidatedProgramPoints) {
|
||||
this.data = data;
|
||||
this.log = data.getLogger();
|
||||
this.invalidatedProgramPoints = invalidatedProgramPoints == null ? new TreeMap<Integer, Type>() : invalidatedProgramPoints;
|
||||
this.invalidatedProgramPoints = invalidatedProgramPoints == null ? new TreeMap<>() : invalidatedProgramPoints;
|
||||
newOptimisticAssumptions();
|
||||
}
|
||||
|
||||
|
||||
@ -562,8 +562,8 @@ public abstract class Property implements Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final Class<?> type = getLocalType();
|
||||
return Objects.hashCode(this.key) ^ flags ^ getSlot() ^ (type == null ? 0 : type.hashCode());
|
||||
final Class<?> t = getLocalType();
|
||||
return Objects.hashCode(this.key) ^ flags ^ getSlot() ^ (t == null ? 0 : t.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -588,7 +588,7 @@ public abstract class Property implements Serializable {
|
||||
getKey().equals(otherProperty.getKey());
|
||||
}
|
||||
|
||||
private static final String type(final Class<?> type) {
|
||||
private static String type(final Class<?> type) {
|
||||
if (type == null) {
|
||||
return "undef";
|
||||
} else if (type == int.class) {
|
||||
@ -608,8 +608,8 @@ public abstract class Property implements Serializable {
|
||||
*/
|
||||
public final String toStringShort() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final Class<?> type = getLocalType();
|
||||
sb.append(getKey()).append(" (").append(type(type)).append(')');
|
||||
final Class<?> t = getLocalType();
|
||||
sb.append(getKey()).append(" (").append(type(t)).append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@ -625,7 +625,7 @@ public abstract class Property implements Serializable {
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final Class<?> type = getLocalType();
|
||||
final Class<?> t = getLocalType();
|
||||
|
||||
sb.append(indent(getKey(), 20)).
|
||||
append(" id=").
|
||||
@ -635,7 +635,7 @@ public abstract class Property implements Serializable {
|
||||
append(") ").
|
||||
append(getClass().getSimpleName()).
|
||||
append(" {").
|
||||
append(indent(type(type), 5)).
|
||||
append(indent(type(t), 5)).
|
||||
append('}');
|
||||
|
||||
if (slot != -1) {
|
||||
|
||||
@ -999,10 +999,10 @@ public final class PropertyMap implements Iterable<Object>, Serializable {
|
||||
for (final Property p : map0.getProperties()) {
|
||||
final Property p2 = map1.findProperty(p.getKey());
|
||||
if (p2 == null) {
|
||||
sb.append("FIRST ONLY : [" + p + "]");
|
||||
sb.append("FIRST ONLY : [").append(p).append("]");
|
||||
found = true;
|
||||
} else if (p2 != p) {
|
||||
sb.append("DIFFERENT : [" + p + "] != [" + p2 + "]");
|
||||
sb.append("DIFFERENT : [").append(p).append("] != [").append(p2).append("]");
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
@ -1010,7 +1010,7 @@ public final class PropertyMap implements Iterable<Object>, Serializable {
|
||||
for (final Property p2 : map1.getProperties()) {
|
||||
final Property p1 = map0.findProperty(p2.getKey());
|
||||
if (p1 == null) {
|
||||
sb.append("SECOND ONLY: [" + p2 + "]");
|
||||
sb.append("SECOND ONLY: [").append(p2).append("]");
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user