aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannesw <none@none>2014-03-03 15:23:01 +0100
committerhannesw <none@none>2014-03-03 15:23:01 +0100
commit29a489a0e7ea64249200f420c8e5466822acc702 (patch)
treea1c1df7e851b92c5bd7cfc2476fd0dc22df3639d /src
parent05b944f823cb1b4a5c92908faa84b9d957d8aeef (diff)
downloadnashorn-29a489a0e7ea64249200f420c8e5466822acc702.tar.gz
8035948: Redesign property listeners for shared classes
Reviewed-by: sundar, lagergren
Diffstat (limited to 'src')
-rw-r--r--src/jdk/nashorn/internal/codegen/ConstantData.java49
-rw-r--r--src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java2
-rw-r--r--src/jdk/nashorn/internal/objects/ArrayBufferView.java2
-rw-r--r--src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java2
-rw-r--r--src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java2
-rw-r--r--src/jdk/nashorn/internal/objects/Global.java210
-rw-r--r--src/jdk/nashorn/internal/objects/NativeArguments.java6
-rw-r--r--src/jdk/nashorn/internal/objects/NativeArray.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeArrayBuffer.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeBoolean.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeDate.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeDebug.java9
-rw-r--r--src/jdk/nashorn/internal/objects/NativeError.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeEvalError.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeJSAdapter.java10
-rw-r--r--src/jdk/nashorn/internal/objects/NativeJavaImporter.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeNumber.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeRangeError.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeReferenceError.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeRegExp.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeStrictArguments.java6
-rw-r--r--src/jdk/nashorn/internal/objects/NativeString.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeSyntaxError.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeTypeError.java2
-rw-r--r--src/jdk/nashorn/internal/objects/NativeURIError.java2
-rw-r--r--src/jdk/nashorn/internal/objects/PrototypeObject.java5
-rw-r--r--src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java32
-rw-r--r--src/jdk/nashorn/internal/runtime/PropertyListener.java66
-rw-r--r--src/jdk/nashorn/internal/runtime/PropertyListenerManager.java179
-rw-r--r--src/jdk/nashorn/internal/runtime/PropertyListeners.java222
-rw-r--r--src/jdk/nashorn/internal/runtime/PropertyMap.java365
-rw-r--r--src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java9
-rw-r--r--src/jdk/nashorn/internal/runtime/ScriptFunction.java10
-rw-r--r--src/jdk/nashorn/internal/runtime/ScriptFunctionData.java13
-rw-r--r--src/jdk/nashorn/internal/runtime/ScriptObject.java113
-rw-r--r--src/jdk/nashorn/internal/runtime/SetMethodCreator.java7
-rw-r--r--src/jdk/nashorn/internal/runtime/WithObject.java16
-rw-r--r--src/jdk/nashorn/internal/runtime/linker/NashornGuards.java19
-rw-r--r--src/jdk/nashorn/internal/scripts/JO.java2
40 files changed, 590 insertions, 798 deletions
diff --git a/src/jdk/nashorn/internal/codegen/ConstantData.java b/src/jdk/nashorn/internal/codegen/ConstantData.java
index 631cdb3e..292f1678 100644
--- a/src/jdk/nashorn/internal/codegen/ConstantData.java
+++ b/src/jdk/nashorn/internal/codegen/ConstantData.java
@@ -25,6 +25,9 @@
package jdk.nashorn.internal.codegen;
+import jdk.nashorn.internal.runtime.Property;
+import jdk.nashorn.internal.runtime.PropertyMap;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -110,6 +113,43 @@ class ConstantData {
}
/**
+ * {@link PropertyMap} wrapper class that provides implementations for the {@code hashCode} and {@code equals}
+ * methods that are based on the map layout. {@code PropertyMap} itself inherits the identity based implementations
+ * from {@code java.lang.Object}.
+ */
+ private static class PropertyMapWrapper {
+ private final PropertyMap propertyMap;
+ private final int hashCode;
+
+ public PropertyMapWrapper(final PropertyMap map) {
+ int hash = 0;
+ for (final Property property : map.getProperties()) {
+ hash = hash << 7 ^ hash >> 7;
+ hash ^= property.hashCode();
+ }
+ this.hashCode = hash;
+ this.propertyMap = map;
+ }
+
+ @Override
+ public int hashCode() {
+ return hashCode;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (!(other instanceof PropertyMapWrapper)) {
+ return false;
+ }
+
+ final Property[] ownProperties = propertyMap.getProperties();
+ final Property[] otherProperties = ((PropertyMapWrapper) other).propertyMap.getProperties();
+
+ return Arrays.equals(ownProperties, otherProperties);
+ }
+ }
+
+ /**
* Constructor
*/
ConstantData() {
@@ -145,7 +185,14 @@ class ConstantData {
* @return the index in the constant pool that the object was given
*/
public int add(final Object object) {
- final Object entry = object.getClass().isArray() ? new ArrayWrapper(object) : object;
+ final Object entry;
+ if (object.getClass().isArray()) {
+ entry = new ArrayWrapper(object);
+ } else if (object instanceof PropertyMap) {
+ entry = new PropertyMapWrapper((PropertyMap) object);
+ } else {
+ entry = object;
+ }
final Integer value = objectMap.get(entry);
if (value != null) {
diff --git a/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java b/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java
index 4d3fd43d..b3388eb0 100644
--- a/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java
+++ b/src/jdk/nashorn/internal/objects/AccessorPropertyDescriptor.java
@@ -72,7 +72,7 @@ public final class AccessorPropertyDescriptor extends ScriptObject implements Pr
}
AccessorPropertyDescriptor(final boolean configurable, final boolean enumerable, final Object get, final Object set, final Global global) {
- super(global.getObjectPrototype(), global.getAccessorPropertyDescriptorMap());
+ super(global.getObjectPrototype(), getInitialMap());
this.configurable = configurable;
this.enumerable = enumerable;
this.get = get;
diff --git a/src/jdk/nashorn/internal/objects/ArrayBufferView.java b/src/jdk/nashorn/internal/objects/ArrayBufferView.java
index ecf8bec8..a7252fcc 100644
--- a/src/jdk/nashorn/internal/objects/ArrayBufferView.java
+++ b/src/jdk/nashorn/internal/objects/ArrayBufferView.java
@@ -47,7 +47,7 @@ abstract class ArrayBufferView extends ScriptObject {
}
private ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength, final Global global) {
- super(global.getArrayBufferViewMap());
+ super(getInitialMap());
checkConstructorArgs(buffer, byteOffset, elementLength);
this.setProto(getPrototype(global));
this.setArray(factory().createArrayData(buffer, byteOffset, elementLength));
diff --git a/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java b/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java
index 39325627..9f7d2e4f 100644
--- a/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java
+++ b/src/jdk/nashorn/internal/objects/DataPropertyDescriptor.java
@@ -69,7 +69,7 @@ public final class DataPropertyDescriptor extends ScriptObject implements Proper
}
DataPropertyDescriptor(final boolean configurable, final boolean enumerable, final boolean writable, final Object value, final Global global) {
- super(global.getObjectPrototype(), global.getDataPropertyDescriptorMap());
+ super(global.getObjectPrototype(), getInitialMap());
this.configurable = configurable;
this.enumerable = enumerable;
this.writable = writable;
diff --git a/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java b/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java
index 221fe002..bfa06cb3 100644
--- a/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java
+++ b/src/jdk/nashorn/internal/objects/GenericPropertyDescriptor.java
@@ -60,7 +60,7 @@ public final class GenericPropertyDescriptor extends ScriptObject implements Pro
}
GenericPropertyDescriptor(final boolean configurable, final boolean enumerable, final Global global) {
- super(global.getObjectPrototype(), global.getGenericPropertyDescriptorMap());
+ super(global.getObjectPrototype(), getInitialMap());
this.configurable = configurable;
this.enumerable = enumerable;
}
diff --git a/src/jdk/nashorn/internal/objects/Global.java b/src/jdk/nashorn/internal/objects/Global.java
index 819095c0..e8b12cb8 100644
--- a/src/jdk/nashorn/internal/objects/Global.java
+++ b/src/jdk/nashorn/internal/objects/Global.java
@@ -370,36 +370,6 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
*/
private ScriptFunction typeErrorThrower;
- private PropertyMap accessorPropertyDescriptorMap;
- private PropertyMap arrayBufferViewMap;
- private PropertyMap dataPropertyDescriptorMap;
- private PropertyMap genericPropertyDescriptorMap;
- private PropertyMap nativeArgumentsMap;
- private PropertyMap nativeArrayMap;
- private PropertyMap nativeArrayBufferMap;
- private PropertyMap nativeBooleanMap;
- private PropertyMap nativeDateMap;
- private PropertyMap nativeErrorMap;
- private PropertyMap nativeEvalErrorMap;
- private PropertyMap nativeJSAdapterMap;
- private PropertyMap nativeJavaImporterMap;
- private PropertyMap nativeNumberMap;
- private PropertyMap nativeRangeErrorMap;
- private PropertyMap nativeReferenceErrorMap;
- private PropertyMap nativeRegExpMap;
- private PropertyMap nativeRegExpExecResultMap;
- private PropertyMap nativeStrictArgumentsMap;
- private PropertyMap nativeStringMap;
- private PropertyMap nativeSyntaxErrorMap;
- private PropertyMap nativeTypeErrorMap;
- private PropertyMap nativeURIErrorMap;
- private PropertyMap prototypeObjectMap;
- private PropertyMap objectMap;
- private PropertyMap functionMap;
- private PropertyMap anonymousFunctionMap;
- private PropertyMap strictFunctionMap;
- private PropertyMap boundFunctionMap;
-
// Flag to indicate that a split method issued a return statement
private int splitState = -1;
@@ -557,7 +527,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
@Override
public ScriptObject newObject() {
- return new JO(getObjectPrototype(), getObjectMap());
+ return new JO(getObjectPrototype(), JO.getInitialMap());
}
@Override
@@ -999,123 +969,6 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
return ScriptFunction.getPrototype(builtinFloat64Array);
}
- // Builtin PropertyMap accessors
- PropertyMap getAccessorPropertyDescriptorMap() {
- return accessorPropertyDescriptorMap;
- }
-
- PropertyMap getArrayBufferViewMap() {
- return arrayBufferViewMap;
- }
-
- PropertyMap getDataPropertyDescriptorMap() {
- return dataPropertyDescriptorMap;
- }
-
- PropertyMap getGenericPropertyDescriptorMap() {
- return genericPropertyDescriptorMap;
- }
-
- PropertyMap getArgumentsMap() {
- return nativeArgumentsMap;
- }
-
- PropertyMap getArrayMap() {
- return nativeArrayMap;
- }
-
- PropertyMap getArrayBufferMap() {
- return nativeArrayBufferMap;
- }
-
- PropertyMap getBooleanMap() {
- return nativeBooleanMap;
- }
-
- PropertyMap getDateMap() {
- return nativeDateMap;
- }
-
- PropertyMap getErrorMap() {
- return nativeErrorMap;
- }
-
- PropertyMap getEvalErrorMap() {
- return nativeEvalErrorMap;
- }
-
- PropertyMap getJSAdapterMap() {
- return nativeJSAdapterMap;
- }
-
- PropertyMap getJavaImporterMap() {
- return nativeJavaImporterMap;
- }
-
- PropertyMap getNumberMap() {
- return nativeNumberMap;
- }
-
- PropertyMap getRangeErrorMap() {
- return nativeRangeErrorMap;
- }
-
- PropertyMap getReferenceErrorMap() {
- return nativeReferenceErrorMap;
- }
-
- PropertyMap getRegExpMap() {
- return nativeRegExpMap;
- }
-
- PropertyMap getRegExpExecResultMap() {
- return nativeRegExpExecResultMap;
- }
-
- PropertyMap getStrictArgumentsMap() {
- return nativeStrictArgumentsMap;
- }
-
- PropertyMap getStringMap() {
- return nativeStringMap;
- }
-
- PropertyMap getSyntaxErrorMap() {
- return nativeSyntaxErrorMap;
- }
-
- PropertyMap getTypeErrorMap() {
- return nativeTypeErrorMap;
- }
-
- PropertyMap getURIErrorMap() {
- return nativeURIErrorMap;
- }
-
- PropertyMap getPrototypeObjectMap() {
- return prototypeObjectMap;
- }
-
- PropertyMap getObjectMap() {
- return objectMap;
- }
-
- PropertyMap getFunctionMap() {
- return functionMap;
- }
-
- PropertyMap getAnonymousFunctionMap() {
- return anonymousFunctionMap;
- }
-
- PropertyMap getStrictFunctionMap() {
- return strictFunctionMap;
- }
-
- PropertyMap getBoundFunctionMap() {
- return boundFunctionMap;
- }
-
private ScriptFunction getBuiltinArray() {
return builtinArray;
}
@@ -1631,14 +1484,11 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
final ScriptEnvironment env = getContext().getEnv();
- // duplicate PropertyMaps of Native* classes
- copyInitialMaps(env);
-
// initialize Function and Object constructor
initFunctionAndObject();
// Now fix Global's own proto.
- this.setProto(getObjectPrototype());
+ this.setInitialProto(getObjectPrototype());
// initialize global function properties
this.eval = this.builtinEval = ScriptFunctionImpl.makeFunction("eval", EVAL);
@@ -1783,7 +1633,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
final ScriptObject prototype = ScriptFunction.getPrototype(cons);
prototype.set(NativeError.NAME, name, false);
prototype.set(NativeError.MESSAGE, "", false);
- prototype.setProto(errorProto);
+ prototype.setInitialProto(errorProto);
return (ScriptFunction)cons;
}
@@ -1955,7 +1805,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
}
if (res.getProto() == null) {
- res.setProto(getObjectPrototype());
+ res.setInitialProto(getObjectPrototype());
}
return res;
@@ -1965,46 +1815,6 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
}
}
- private void copyInitialMaps(final ScriptEnvironment env) {
- this.accessorPropertyDescriptorMap = AccessorPropertyDescriptor.getInitialMap().duplicate();
- this.dataPropertyDescriptorMap = DataPropertyDescriptor.getInitialMap().duplicate();
- this.genericPropertyDescriptorMap = GenericPropertyDescriptor.getInitialMap().duplicate();
- this.nativeArgumentsMap = NativeArguments.getInitialMap().duplicate();
- this.nativeArrayMap = NativeArray.getInitialMap().duplicate();
- this.nativeBooleanMap = NativeBoolean.getInitialMap().duplicate();
- this.nativeDateMap = NativeDate.getInitialMap().duplicate();
- this.nativeErrorMap = NativeError.getInitialMap().duplicate();
- this.nativeEvalErrorMap = NativeEvalError.getInitialMap().duplicate();
- this.nativeJSAdapterMap = NativeJSAdapter.getInitialMap().duplicate();
- this.nativeNumberMap = NativeNumber.getInitialMap().duplicate();
- this.nativeRangeErrorMap = NativeRangeError.getInitialMap().duplicate();
- this.nativeReferenceErrorMap = NativeReferenceError.getInitialMap().duplicate();
- this.nativeRegExpMap = NativeRegExp.getInitialMap().duplicate();
- this.nativeRegExpExecResultMap = NativeRegExpExecResult.getInitialMap().duplicate();
- this.nativeStrictArgumentsMap = NativeStrictArguments.getInitialMap().duplicate();
- this.nativeStringMap = NativeString.getInitialMap().duplicate();
- this.nativeSyntaxErrorMap = NativeSyntaxError.getInitialMap().duplicate();
- this.nativeTypeErrorMap = NativeTypeError.getInitialMap().duplicate();
- this.nativeURIErrorMap = NativeURIError.getInitialMap().duplicate();
- this.prototypeObjectMap = PrototypeObject.getInitialMap().duplicate();
- this.objectMap = JO.getInitialMap().duplicate();
- this.functionMap = ScriptFunctionImpl.getInitialMap().duplicate();
- this.anonymousFunctionMap = ScriptFunctionImpl.getInitialAnonymousMap().duplicate();
- this.strictFunctionMap = ScriptFunctionImpl.getInitialStrictMap().duplicate();
- this.boundFunctionMap = ScriptFunctionImpl.getInitialBoundMap().duplicate();
-
- // java
- if (! env._no_java) {
- this.nativeJavaImporterMap = NativeJavaImporter.getInitialMap().duplicate();
- }
-
- // typed arrays
- if (! env._no_typed_arrays) {
- this.arrayBufferViewMap = ArrayBufferView.getInitialMap().duplicate();
- this.nativeArrayBufferMap = NativeArrayBuffer.getInitialMap().duplicate();
- }
- }
-
// Function and Object constructors are inter-dependent. Also,
// Function.prototype
// functions are not properly initialized. We fix the references here.
@@ -2022,7 +1832,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
// Function.prototype === Object.getPrototypeOf(Function) ===
// <anon-function>
- builtinFunction.setProto(anon);
+ builtinFunction.setInitialProto(anon);
builtinFunction.setPrototype(anon);
anon.set("constructor", builtinFunction, false);
anon.deleteOwnProperty(anon.getMap().findProperty("prototype"));
@@ -2038,7 +1848,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
this.builtinObject = (ScriptFunction)initConstructor("Object");
final ScriptObject ObjectPrototype = getObjectPrototype();
// Object.getPrototypeOf(Function.prototype) === Object.prototype
- anon.setProto(ObjectPrototype);
+ anon.setInitialProto(ObjectPrototype);
// Function valued properties of Function.prototype were not properly
// initialized. Because, these were created before global.function and
@@ -2050,10 +1860,10 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
if (value instanceof ScriptFunction && value != anon) {
final ScriptFunction func = (ScriptFunction)value;
- func.setProto(getFunctionPrototype());
+ func.setInitialProto(getFunctionPrototype());
final ScriptObject prototype = ScriptFunction.getPrototype(func);
if (prototype != null) {
- prototype.setProto(ObjectPrototype);
+ prototype.setInitialProto(ObjectPrototype);
}
}
}
@@ -2068,7 +1878,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
final ScriptFunction func = (ScriptFunction)value;
final ScriptObject prototype = ScriptFunction.getPrototype(func);
if (prototype != null) {
- prototype.setProto(ObjectPrototype);
+ prototype.setInitialProto(ObjectPrototype);
}
}
}
@@ -2086,7 +1896,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
final ScriptFunction func = (ScriptFunction)value;
final ScriptObject prototype = ScriptFunction.getPrototype(func);
if (prototype != null) {
- prototype.setProto(ObjectPrototype);
+ prototype.setInitialProto(ObjectPrototype);
}
}
}
diff --git a/src/jdk/nashorn/internal/objects/NativeArguments.java b/src/jdk/nashorn/internal/objects/NativeArguments.java
index f8535732..03f68bf6 100644
--- a/src/jdk/nashorn/internal/objects/NativeArguments.java
+++ b/src/jdk/nashorn/internal/objects/NativeArguments.java
@@ -68,7 +68,7 @@ public final class NativeArguments extends ScriptObject {
final ArrayList<Property> properties = new ArrayList<>(2);
properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH));
properties.add(AccessorProperty.create("callee", Property.NOT_ENUMERABLE, G$CALLEE, S$CALLEE));
- map$ = PropertyMap.newMap(properties).setIsShared();
+ map$ = PropertyMap.newMap(properties);
}
static PropertyMap getInitialMap() {
@@ -267,9 +267,9 @@ public final class NativeArguments extends ScriptObject {
final Global global = Global.instance();
final ScriptObject proto = global.getObjectPrototype();
if (isStrict) {
- return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap());
+ return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap());
}
- return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap());
+ return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap());
}
/**
diff --git a/src/jdk/nashorn/internal/objects/NativeArray.java b/src/jdk/nashorn/internal/objects/NativeArray.java
index 67b9f1f1..cc62d23c 100644
--- a/src/jdk/nashorn/internal/objects/NativeArray.java
+++ b/src/jdk/nashorn/internal/objects/NativeArray.java
@@ -208,7 +208,7 @@ public final class NativeArray extends ScriptObject {
}
NativeArray(final ArrayData arrayData, final Global global) {
- super(global.getArrayPrototype(), global.getArrayMap());
+ super(global.getArrayPrototype(), getInitialMap());
this.setArray(arrayData);
this.setIsArray();
}
diff --git a/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java b/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java
index d75a2129..dbc1b24b 100644
--- a/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java
+++ b/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java
@@ -57,7 +57,7 @@ final class NativeArrayBuffer extends ScriptObject {
}
protected NativeArrayBuffer(final byte[] byteArray, final Global global) {
- super(global.getArrayBufferPrototype(), global.getArrayBufferMap());
+ super(global.getArrayBufferPrototype(), getInitialMap());
this.buffer = byteArray;
}
diff --git a/src/jdk/nashorn/internal/objects/NativeBoolean.java b/src/jdk/nashorn/internal/objects/NativeBoolean.java
index bb57cc71..bd955079 100644
--- a/src/jdk/nashorn/internal/objects/NativeBoolean.java
+++ b/src/jdk/nashorn/internal/objects/NativeBoolean.java
@@ -65,7 +65,7 @@ public final class NativeBoolean extends ScriptObject {
}
NativeBoolean(final boolean flag, final Global global) {
- this(flag, global.getBooleanPrototype(), global.getBooleanMap());
+ this(flag, global.getBooleanPrototype(), getInitialMap());
}
NativeBoolean(final boolean flag) {
diff --git a/src/jdk/nashorn/internal/objects/NativeDate.java b/src/jdk/nashorn/internal/objects/NativeDate.java
index 935285f0..b0d12022 100644
--- a/src/jdk/nashorn/internal/objects/NativeDate.java
+++ b/src/jdk/nashorn/internal/objects/NativeDate.java
@@ -127,7 +127,7 @@ public final class NativeDate extends ScriptObject {
}
NativeDate(final double time, final Global global) {
- this(time, global.getDatePrototype(), global.getDateMap());
+ this(time, global.getDatePrototype(), getInitialMap());
}
private NativeDate (final double time) {
diff --git a/src/jdk/nashorn/internal/objects/NativeDebug.java b/src/jdk/nashorn/internal/objects/NativeDebug.java
index 9ee7c99a..59b7b2fe 100644
--- a/src/jdk/nashorn/internal/objects/NativeDebug.java
+++ b/src/jdk/nashorn/internal/objects/NativeDebug.java
@@ -34,7 +34,7 @@ import jdk.nashorn.internal.objects.annotations.Function;
import jdk.nashorn.internal.objects.annotations.ScriptClass;
import jdk.nashorn.internal.objects.annotations.Where;
import jdk.nashorn.internal.runtime.Context;
-import jdk.nashorn.internal.runtime.PropertyListenerManager;
+import jdk.nashorn.internal.runtime.PropertyListeners;
import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
@@ -186,7 +186,7 @@ public final class NativeDebug extends ScriptObject {
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getListenerCount(final Object self, final Object obj) {
- return (obj instanceof ScriptObject)? ((ScriptObject)obj).getListenerCount() : 0;
+ return (obj instanceof ScriptObject) ? PropertyListeners.getListenerCount((ScriptObject) obj) : 0;
}
/**
@@ -203,14 +203,13 @@ public final class NativeDebug extends ScriptObject {
out.println("ScriptObject count " + ScriptObject.getCount());
out.println("Scope count " + ScriptObject.getScopeCount());
- out.println("ScriptObject listeners added " + PropertyListenerManager.getListenersAdded());
- out.println("ScriptObject listeners removed " + PropertyListenerManager.getListenersRemoved());
+ out.println("ScriptObject listeners added " + PropertyListeners.getListenersAdded());
+ out.println("ScriptObject listeners removed " + PropertyListeners.getListenersRemoved());
out.println("ScriptFunction constructor calls " + ScriptFunction.getConstructorCount());
out.println("ScriptFunction invokes " + ScriptFunction.getInvokes());
out.println("ScriptFunction allocations " + ScriptFunction.getAllocations());
out.println("PropertyMap count " + PropertyMap.getCount());
out.println("PropertyMap cloned " + PropertyMap.getClonedCount());
- out.println("PropertyMap shared " + PropertyMap.getSharedCount());
out.println("PropertyMap duplicated " + PropertyMap.getDuplicatedCount());
out.println("PropertyMap history hit " + PropertyMap.getHistoryHit());
out.println("PropertyMap proto invalidations " + PropertyMap.getProtoInvalidations());
diff --git a/src/jdk/nashorn/internal/objects/NativeError.java b/src/jdk/nashorn/internal/objects/NativeError.java
index 0541084d..e1a4730d 100644
--- a/src/jdk/nashorn/internal/objects/NativeError.java
+++ b/src/jdk/nashorn/internal/objects/NativeError.java
@@ -108,7 +108,7 @@ public final class NativeError extends ScriptObject {
}
NativeError(final Object msg, final Global global) {
- this(msg, global.getErrorPrototype(), global.getErrorMap());
+ this(msg, global.getErrorPrototype(), getInitialMap());
}
private NativeError(final Object msg) {
diff --git a/src/jdk/nashorn/internal/objects/NativeEvalError.java b/src/jdk/nashorn/internal/objects/NativeEvalError.java
index df8164c1..bb11ef6c 100644
--- a/src/jdk/nashorn/internal/objects/NativeEvalError.java
+++ b/src/jdk/nashorn/internal/objects/NativeEvalError.java
@@ -78,7 +78,7 @@ public final class NativeEvalError extends ScriptObject {
}
NativeEvalError(final Object msg, final Global global) {
- this(msg, global.getEvalErrorPrototype(), global.getEvalErrorMap());
+ this(msg, global.getEvalErrorPrototype(), getInitialMap());
}
private NativeEvalError(final Object msg) {
diff --git a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java
index 668ca8cd..c77b2fe0 100644
--- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java
+++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java
@@ -163,7 +163,7 @@ public final class NativeJSAdapter extends ScriptObject {
}
private static ScriptObject wrapAdaptee(final ScriptObject adaptee) {
- return new JO(adaptee, Global.instance().getObjectMap());
+ return new JO(adaptee, JO.getInitialMap());
}
@Override
@@ -577,7 +577,7 @@ public final class NativeJSAdapter extends ScriptObject {
proto = global.getJSAdapterPrototype();
}
- return new NativeJSAdapter(overrides, (ScriptObject)adaptee, (ScriptObject)proto, global.getJSAdapterMap());
+ return new NativeJSAdapter(overrides, (ScriptObject)adaptee, (ScriptObject)proto, getInitialMap());
}
@Override
@@ -629,7 +629,7 @@ public final class NativeJSAdapter extends ScriptObject {
// to name. Probably not a big deal, but if we can ever make it leaner, it'd be nice.
return new GuardedInvocation(MH.dropArguments(MH.constant(Object.class,
func.makeBoundFunction(this, new Object[] { name })), 0, Object.class),
- adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), __call__),
+ adaptee.getProtoSwitchPoint(__call__, find.getOwner()),
testJSAdaptor(adaptee, null, null, null));
}
}
@@ -700,7 +700,7 @@ public final class NativeJSAdapter extends ScriptObject {
if (methodHandle != null) {
return new GuardedInvocation(
methodHandle,
- adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), hook),
+ adaptee.getProtoSwitchPoint(hook, findData.getOwner()),
testJSAdaptor(adaptee, findData.getGetter(Object.class), findData.getOwner(), func));
}
}
@@ -713,7 +713,7 @@ public final class NativeJSAdapter extends ScriptObject {
final MethodHandle methodHandle = hook.equals(__put__) ?
MH.asType(Lookup.EMPTY_SETTER, type) :
Lookup.emptyGetter(type.returnType());
- return new GuardedInvocation(methodHandle, adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), hook), testJSAdaptor(adaptee, null, null, null));
+ return new GuardedInvocation(methodHandle, adaptee.getProtoSwitchPoint(hook, null), testJSAdaptor(adaptee, null, null, null));
}
}
diff --git a/src/jdk/nashorn/internal/objects/NativeJavaImporter.java b/src/jdk/nashorn/internal/objects/NativeJavaImporter.java
index 56baf66d..c86f3053 100644
--- a/src/jdk/nashorn/internal/objects/NativeJavaImporter.java
+++ b/src/jdk/nashorn/internal/objects/NativeJavaImporter.java
@@ -70,7 +70,7 @@ public final class NativeJavaImporter extends ScriptObject {
}
private NativeJavaImporter(final Object[] args, final Global global) {
- this(args, global.getJavaImporterPrototype(), global.getJavaImporterMap());
+ this(args, global.getJavaImporterPrototype(), getInitialMap());
}
private NativeJavaImporter(final Object[] args) {
diff --git a/src/jdk/nashorn/internal/objects/NativeNumber.java b/src/jdk/nashorn/internal/objects/NativeNumber.java
index d9d568b7..09289a01 100644
--- a/src/jdk/nashorn/internal/objects/NativeNumber.java
+++ b/src/jdk/nashorn/internal/objects/NativeNumber.java
@@ -98,7 +98,7 @@ public final class NativeNumber extends ScriptObject {
}
NativeNumber(final double value, final Global global) {
- this(value, global.getNumberPrototype(), global.getNumberMap());
+ this(value, global.getNumberPrototype(), getInitialMap());
}
private NativeNumber(final double value) {
diff --git a/src/jdk/nashorn/internal/objects/NativeRangeError.java b/src/jdk/nashorn/internal/objects/NativeRangeError.java
index a71b28b1..6e0d954b 100644
--- a/src/jdk/nashorn/internal/objects/NativeRangeError.java
+++ b/src/jdk/nashorn/internal/objects/NativeRangeError.java
@@ -78,7 +78,7 @@ public final class NativeRangeError extends ScriptObject {
}
NativeRangeError(final Object msg, final Global global) {
- this(msg, global.getRangeErrorPrototype(), global.getRangeErrorMap());
+ this(msg, global.getRangeErrorPrototype(), getInitialMap());
}
private NativeRangeError(final Object msg) {
diff --git a/src/jdk/nashorn/internal/objects/NativeReferenceError.java b/src/jdk/nashorn/internal/objects/NativeReferenceError.java
index d02a3250..052950c6 100644
--- a/src/jdk/nashorn/internal/objects/NativeReferenceError.java
+++ b/src/jdk/nashorn/internal/objects/NativeReferenceError.java
@@ -78,7 +78,7 @@ public final class NativeReferenceError extends ScriptObject {
}
NativeReferenceError(final Object msg, final Global global) {
- this(msg, global.getReferenceErrorPrototype(), global.getReferenceErrorMap());
+ this(msg, global.getReferenceErrorPrototype(), getInitialMap());
}
private NativeReferenceError(final Object msg) {
diff --git a/src/jdk/nashorn/internal/objects/NativeRegExp.java b/src/jdk/nashorn/internal/objects/NativeRegExp.java
index 318ca2a0..abc3366d 100644
--- a/src/jdk/nashorn/internal/objects/NativeRegExp.java
+++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java
@@ -75,7 +75,7 @@ public final class NativeRegExp extends ScriptObject {
}
private NativeRegExp(final Global global) {
- super(global.getRegExpPrototype(), global.getRegExpMap());
+ super(global.getRegExpPrototype(), getInitialMap());
this.globalObject = global;
}
diff --git a/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java b/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java
index 3508e5f6..5d79699e 100644
--- a/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java
+++ b/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java
@@ -58,7 +58,7 @@ public final class NativeRegExpExecResult extends ScriptObject {
}
NativeRegExpExecResult(final RegExpResult result, final Global global) {
- super(global.getArrayPrototype(), global.getRegExpExecResultMap());
+ super(global.getArrayPrototype(), getInitialMap());
setIsArray();
this.setArray(ArrayData.allocate(result.getGroups().clone()));
this.index = result.getIndex();
diff --git a/src/jdk/nashorn/internal/objects/NativeStrictArguments.java b/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
index b81cc2af..dd2c2816 100644
--- a/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
+++ b/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
@@ -60,9 +60,9 @@ public final class NativeStrictArguments extends ScriptObject {
// In strict mode, the caller and callee properties should throw TypeError
// Need to add properties directly to map since slots are assigned speculatively by newUserAccessors.
final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
- map = map.addProperty(map.newUserAccessors("caller", flags));
- map = map.addProperty(map.newUserAccessors("callee", flags));
- map$ = map.setIsShared();
+ map = map.addPropertyNoHistory(map.newUserAccessors("caller", flags));
+ map = map.addPropertyNoHistory(map.newUserAccessors("callee", flags));
+ map$ = map;
}
static PropertyMap getInitialMap() {
diff --git a/src/jdk/nashorn/internal/objects/NativeString.java b/src/jdk/nashorn/internal/objects/NativeString.java
index 95af71a6..2370f514 100644
--- a/src/jdk/nashorn/internal/objects/NativeString.java
+++ b/src/jdk/nashorn/internal/objects/NativeString.java
@@ -83,7 +83,7 @@ public final class NativeString extends ScriptObject {
}
NativeString(final CharSequence value, final Global global) {
- this(value, global.getStringPrototype(), global.getStringMap());
+ this(value, global.getStringPrototype(), getInitialMap());
}
private NativeString(final CharSequence value, final ScriptObject proto, final PropertyMap map) {
diff --git a/src/jdk/nashorn/internal/objects/NativeSyntaxError.java b/src/jdk/nashorn/internal/objects/NativeSyntaxError.java
index 5d71ade7..ffe1b0a7 100644
--- a/src/jdk/nashorn/internal/objects/NativeSyntaxError.java
+++ b/src/jdk/nashorn/internal/objects/NativeSyntaxError.java
@@ -68,7 +68,7 @@ public final class NativeSyntaxError extends ScriptObject {
@SuppressWarnings("LeakingThisInConstructor")
NativeSyntaxError(final Object msg, final Global global) {
- super(global.getSyntaxErrorPrototype(), global.getSyntaxErrorMap());
+ super(global.getSyntaxErrorPrototype(), getInitialMap());
if (msg != UNDEFINED) {
this.instMessage = JSType.toString(msg);
} else {
diff --git a/src/jdk/nashorn/internal/objects/NativeTypeError.java b/src/jdk/nashorn/internal/objects/NativeTypeError.java
index 8857da71..067139cd 100644
--- a/src/jdk/nashorn/internal/objects/NativeTypeError.java
+++ b/src/jdk/nashorn/internal/objects/NativeTypeError.java
@@ -68,7 +68,7 @@ public final class NativeTypeError extends ScriptObject {
@SuppressWarnings("LeakingThisInConstructor")
NativeTypeError(final Object msg, final Global global) {
- super(global.getTypeErrorPrototype(), global.getTypeErrorMap());
+ super(global.getTypeErrorPrototype(), getInitialMap());
if (msg != UNDEFINED) {
this.instMessage = JSType.toString(msg);
} else {
diff --git a/src/jdk/nashorn/internal/objects/NativeURIError.java b/src/jdk/nashorn/internal/objects/NativeURIError.java
index 7ff6c196..382e23f4 100644
--- a/src/jdk/nashorn/internal/objects/NativeURIError.java
+++ b/src/jdk/nashorn/internal/objects/NativeURIError.java
@@ -67,7 +67,7 @@ public final class NativeURIError extends ScriptObject {
@SuppressWarnings("LeakingThisInConstructor")
NativeURIError(final Object msg, final Global global) {
- super(global.getURIErrorPrototype(), global.getURIErrorMap());
+ super(global.getURIErrorPrototype(), getInitialMap());
if (msg != UNDEFINED) {
this.instMessage = JSType.toString(msg);
} else {
diff --git a/src/jdk/nashorn/internal/objects/PrototypeObject.java b/src/jdk/nashorn/internal/objects/PrototypeObject.java
index 4610afc2..1fd4f60d 100644
--- a/src/jdk/nashorn/internal/objects/PrototypeObject.java
+++ b/src/jdk/nashorn/internal/objects/PrototypeObject.java
@@ -54,7 +54,7 @@ public class PrototypeObject extends ScriptObject {
static {
final ArrayList<Property> properties = new ArrayList<>(1);
properties.add(AccessorProperty.create("constructor", Property.NOT_ENUMERABLE, GET_CONSTRUCTOR, SET_CONSTRUCTOR));
- map$ = PropertyMap.newMap(properties).setIsShared();
+ map$ = PropertyMap.newMap(properties);
}
static PropertyMap getInitialMap() {
@@ -62,8 +62,7 @@ public class PrototypeObject extends ScriptObject {
}
private PrototypeObject(final Global global, final PropertyMap map) {
- super(map != map$? map.addAll(global.getPrototypeObjectMap()) : global.getPrototypeObjectMap());
- setProto(global.getObjectPrototype());
+ super(global.getObjectPrototype(), map != map$? map.addAll(map$) : map$);
}
PrototypeObject() {
diff --git a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
index f0bea3a6..9852c962 100644
--- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
+++ b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
@@ -37,7 +37,6 @@ import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptFunctionData;
import jdk.nashorn.internal.runtime.ScriptObject;
-import jdk.nashorn.internal.lookup.Lookup;
import jdk.nashorn.internal.runtime.AccessorProperty;
/**
@@ -76,7 +75,7 @@ public class ScriptFunctionImpl extends ScriptFunction {
private static final Object LAZY_PROTOTYPE = new Object();
private ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final MethodHandle[] specs, final Global global) {
- super(name, invokeHandle, global.getFunctionMap(), null, specs, false, true, true);
+ super(name, invokeHandle, getInitialMap(), null, specs, false, true, true);
init(global);
}
@@ -93,7 +92,7 @@ public class ScriptFunctionImpl extends ScriptFunction {
}
private ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final PropertyMap map, final MethodHandle[] specs, final Global global) {
- super(name, invokeHandle, map.addAll(global.getFunctionMap()), null, specs, false, true, true);
+ super(name, invokeHandle, map.addAll(getInitialMap()), null, specs, false, true, true);
init(global);
}
@@ -151,7 +150,7 @@ public class ScriptFunctionImpl extends ScriptFunction {
* @param global the global object
*/
ScriptFunctionImpl(final ScriptFunctionData data, final Global global) {
- super(data, global.getBoundFunctionMap(), null);
+ super(data, getInitialBoundMap(), null);
init(global);
}
@@ -163,25 +162,20 @@ public class ScriptFunctionImpl extends ScriptFunction {
map$ = PropertyMap.newMap(properties);
strictmodemap$ = createStrictModeMap(map$);
boundfunctionmap$ = createBoundFunctionMap(strictmodemap$);
- // There are order dependencies between normal map, struct map and bound map
- // We can make these 'shared' only after initialization of all three.
- map$.setIsShared();
- strictmodemap$.setIsShared();
- boundfunctionmap$.setIsShared();
}
private static PropertyMap createStrictModeMap(final PropertyMap map) {
final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE;
PropertyMap newMap = map;
// Need to add properties directly to map since slots are assigned speculatively by newUserAccessors.
- newMap = newMap.addProperty(map.newUserAccessors("arguments", flags));
- newMap = newMap.addProperty(map.newUserAccessors("caller", flags));
+ newMap = newMap.addPropertyNoHistory(map.newUserAccessors("arguments", flags));
+ newMap = newMap.addPropertyNoHistory(map.newUserAccessors("caller", flags));
return newMap;
}
// Choose the map based on strict mode!
private static PropertyMap getMap(final Global global, final boolean strict) {
- return strict ? global.getStrictFunctionMap() : global.getFunctionMap();
+ return strict ? getInitialStrictMap() : getInitialMap();
}
private static PropertyMap createBoundFunctionMap(final PropertyMap strictModeMap) {
@@ -193,14 +187,14 @@ public class ScriptFunctionImpl extends ScriptFunction {
// Instance of this class is used as global anonymous function which
// serves as Function.prototype object.
private static class AnonymousFunction extends ScriptFunctionImpl {
- private static final PropertyMap anonmap$ = PropertyMap.newMap().setIsShared();
+ private static final PropertyMap anonmap$ = PropertyMap.newMap();
static PropertyMap getInitialMap() {
return anonmap$;
}
AnonymousFunction(final Global global) {
- super("", GlobalFunctions.ANONYMOUS, global.getAnonymousFunctionMap(), null);
+ super("", GlobalFunctions.ANONYMOUS, getInitialAnonymousMap(), null);
}
}
@@ -281,13 +275,17 @@ public class ScriptFunctionImpl extends ScriptFunction {
}
@Override
- public final void setPrototype(final Object prototype) {
- this.prototype = prototype;
+ public final void setPrototype(final Object newProto) {
+ if (newProto instanceof ScriptObject && newProto != this.prototype && allocatorMap != null) {
+ // Replace our current allocator map with one that is associated with the new prototype.
+ allocatorMap = allocatorMap.changeProto((ScriptObject)newProto);
+ }
+ this.prototype = newProto;
}
// Internals below..
private void init(final Global global) {
- this.setProto(global.getFunctionPrototype());
+ this.setInitialProto(global.getFunctionPrototype());
this.prototype = LAZY_PROTOTYPE;
// We have to fill user accessor functions late as these are stored
diff --git a/src/jdk/nashorn/internal/runtime/PropertyListener.java b/src/jdk/nashorn/internal/runtime/PropertyListener.java
deleted file mode 100644
index 307d58b4..00000000
--- a/src/jdk/nashorn/internal/runtime/PropertyListener.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.nashorn.internal.runtime;
-
-/**
- * Property change listener gets notified whenever properties are added/deleted/modified.
- */
-public interface PropertyListener {
- /**
- * A new property is being added.
- *
- * @param object The ScriptObject to which property was added.
- * @param prop The new Property added.
- */
- public void propertyAdded(ScriptObject object, Property prop);
-
- /**
- * An existing property is being deleted.
- *
- * @param object The ScriptObject whose property is being deleted.
- * @param prop The property being deleted.
- */
- public void propertyDeleted(ScriptObject object, Property prop);
-
- /**
- * An existing Property is being replaced with a new Property.
- *
- * @param object The ScriptObject whose property is being modified.
- * @param oldProp The old property that is being replaced.
- * @param newProp The new property that replaces the old property.
- *
- */
- public void propertyModified(ScriptObject object, Property oldProp, Property newProp);
-
- /**
- * Given object's __proto__ has changed.
- *
- * @param object object whose __proto__ has changed.
- * @param oldProto old __proto__
- * @param newProto new __proto__
- */
- public void protoChanged(ScriptObject object, ScriptObject oldProto, ScriptObject newProto);
-}
diff --git a/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java b/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java
deleted file mode 100644
index 27ec2c97..00000000
--- a/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.nashorn.internal.runtime;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-
-/**
- * Helper class to manage property listeners and notification.
- */
-public class PropertyListenerManager implements PropertyListener {
- PropertyListenerManager() {}
-
- /** property listeners for this object. */
- private Map<PropertyListener,Boolean> listeners;
-
- // These counters are updated in debug mode
- private static int listenersAdded;
- private static int listenersRemoved;
-
- /**
- * Return aggregate listeners added to all PropertyListenerManagers
- * @return the listenersAdded
- */
- public static int getListenersAdded() {
- return listenersAdded;
- }
-
- /**
- * Return aggregate listeners removed from all PropertyListenerManagers
- * @return the listenersRemoved
- */
- public static int getListenersRemoved() {
- return listenersRemoved;
- }
-
- /**
- * Return listeners added to this PropertyListenerManager.
- * @return the listener count
- */
- public final int getListenerCount() {
- return listeners != null? listeners.size() : 0;
- }
-
- // Property listener management methods
-
- /**
- * Add a property listener to this object.
- *
- * @param listener The property listener that is added.
- */
- public synchronized final void addPropertyListener(final PropertyListener listener) {
- if (listeners == null) {
- listeners = new WeakHashMap<>();
- }
-
- if (Context.DEBUG) {
- listenersAdded++;
- }
- listeners.put(listener, Boolean.TRUE);
- }
-
- /**
- * Remove a property listener from this object.
- *
- * @param listener The property listener that is removed.
- */
- public synchronized final void removePropertyListener(final PropertyListener listener) {
- if (listeners != null) {
- if (Context.DEBUG) {
- listenersRemoved++;
- }
- listeners.remove(listener);
- }
- }
-
- /**
- * This method can be called to notify property addition to this object's listeners.
- *
- * @param object The ScriptObject to which property was added.
- * @param prop The property being added.
- */
- protected synchronized final void notifyPropertyAdded(final ScriptObject object, final Property prop) {
- if (listeners != null) {
- for (PropertyListener listener : listeners.keySet()) {
- listener.propertyAdded(object, prop);
- }
- }
- }
-
- /**
- * This method can be called to notify property deletion to this object's listeners.
- *
- * @param object The ScriptObject from which property was deleted.
- * @param prop The property being deleted.
- */
- protected synchronized final void notifyPropertyDeleted(final ScriptObject object, final Property prop) {
- if (listeners != null) {
- for (PropertyListener listener : listeners.keySet()) {
- listener.propertyDeleted(object, prop);
- }
- }
- }
-
- /**
- * This method can be called to notify property modification to this object's listeners.
- *
- * @param object The ScriptObject to which property was modified.
- * @param oldProp The old property being replaced.
- * @param newProp The new property that replaces the old property.
- */
- protected synchronized final void notifyPropertyModified(final ScriptObject object, final Property oldProp, final Property newProp) {
- if (listeners != null) {
- for (PropertyListener listener : listeners.keySet()) {
- listener.propertyModified(object, oldProp, newProp);
- }
- }
- }
-
- /**
- * This method can be called to notify __proto__ modification to this object's listeners.
- *
- * @param object The ScriptObject whose __proto__ was changed.
- * @param oldProto old __proto__
- * @param newProto new __proto__
- */
- protected synchronized final void notifyProtoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) {
- if (listeners != null) {
- for (PropertyListener listener : listeners.keySet()) {
- listener.protoChanged(object, oldProto, newProto);
- }
- }
- }
-
- // PropertyListener methods
-
- @Override
- public final void propertyAdded(final ScriptObject object, final Property prop) {
- notifyPropertyAdded(object, prop);
- }
-
- @Override
- public final void propertyDeleted(final ScriptObject object, final Property prop) {
- notifyPropertyDeleted(object, prop);
- }
-
- @Override
- public final void propertyModified(final ScriptObject object, final Property oldProp, final Property newProp) {
- notifyPropertyModified(object, oldProp, newProp);
- }
-
- @Override
- public final void protoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) {
- notifyProtoChanged(object, oldProto, newProto);
- }
-}
diff --git a/src/jdk/nashorn/internal/runtime/PropertyListeners.java b/src/jdk/nashorn/internal/runtime/PropertyListeners.java
new file mode 100644
index 00000000..532969cc
--- /dev/null
+++ b/src/jdk/nashorn/internal/runtime/PropertyListeners.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package jdk.nashorn.internal.runtime;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+/**
+ * Helper class to manage property listeners and notification.
+ */
+public class PropertyListeners {
+
+ private Map<String, WeakPropertyMapSet> listeners;
+
+ // These counters are updated in debug mode
+ private static int listenersAdded;
+ private static int listenersRemoved;
+
+ /**
+ * Copy constructor
+ * @param listener listener to copy
+ */
+ PropertyListeners(final PropertyListeners listener) {
+ if (listener != null && listener.listeners != null) {
+ this.listeners = new WeakHashMap<>(listener.listeners);
+ }
+ }
+
+ /**
+ * Return aggregate listeners added to all PropertyListenerManagers
+ * @return the listenersAdded
+ */
+ public static int getListenersAdded() {
+ return listenersAdded;
+ }
+
+ /**
+ * Return aggregate listeners removed from all PropertyListenerManagers
+ * @return the listenersRemoved
+ */
+ public static int getListenersRemoved() {
+ return listenersRemoved;
+ }
+
+ /**
+ * Return listeners added to this ScriptObject.
+ * @param obj the object
+ * @return the listener count
+ */
+ public static int getListenerCount(final ScriptObject obj) {
+ final PropertyListeners propertyListeners = obj.getMap().getListeners();
+ if (propertyListeners != null) {
+ return propertyListeners.listeners == null ? 0 : propertyListeners.listeners.size();
+ }
+ return 0;
+ }
+
+ // Property listener management methods
+
+ /**
+ * Add {@code propertyMap} as property listener to {@code listeners} using key {@code key} by
+ * creating and returning a new {@code PropertyListeners} instance.
+ *
+ * @param listeners the original property listeners instance, may be null
+ * @param key the property key
+ * @param propertyMap the property map
+ * @return the new property map
+ */
+ public static PropertyListeners addListener(final PropertyListeners listeners, final String key, final PropertyMap propertyMap) {
+ final PropertyListeners newListeners;
+ if (listeners == null || !listeners.containsListener(key, propertyMap)) {
+ newListeners = new PropertyListeners(listeners);
+ newListeners.addListener(key, propertyMap);
+ return newListeners;
+ }
+ return listeners;
+ }
+
+ /**
+ * Checks whether {@code propertyMap} is registered as listener with {@code key}.
+ *
+ * @param key the property key
+ * @param propertyMap the property map
+ * @return true if property map is registered with property key
+ */
+ synchronized boolean containsListener(final String key, final PropertyMap propertyMap) {
+ if (listeners == null) {
+ return false;
+ }
+ WeakPropertyMapSet set = listeners.get(key);
+ return set != null && set.contains(propertyMap);
+ }
+
+ /**
+ * Add a property listener to this object.
+ *
+ * @param propertyMap The property listener that is added.
+ */
+ synchronized final void addListener(final String key, final PropertyMap propertyMap) {
+ if (Context.DEBUG) {
+ listenersAdded++;
+ }
+ if (listeners == null) {
+ listeners = new WeakHashMap<>();
+ }
+
+ WeakPropertyMapSet set = listeners.get(key);
+ if (set == null) {
+ set = new WeakPropertyMapSet();
+ listeners.put(key, set);
+ }
+ if (!set.contains(propertyMap)) {
+ set.add(propertyMap);
+ }
+ }
+
+ /**
+ * A new property is being added.
+ *
+ * @param prop The new Property added.
+ */
+ public synchronized void propertyAdded(final Property prop) {
+ if (listeners != null) {
+ WeakPropertyMapSet set = listeners.get(prop.getKey());
+ if (set != null) {
+ for (PropertyMap propertyMap : set.elements()) {
+ propertyMap.propertyAdded(prop);
+ }
+ listeners.remove(prop.getKey());
+ }
+ }
+ }
+
+ /**
+ * An existing property is being deleted.
+ *
+ * @param prop The property being deleted.
+ */
+ public synchronized void propertyDeleted(final Property prop) {
+ if (listeners != null) {
+ WeakPropertyMapSet set = listeners.get(prop.getKey());
+ if (set != null) {
+ for (PropertyMap propertyMap : set.elements()) {
+ propertyMap.propertyDeleted(prop);
+ }
+ listeners.remove(prop.getKey());
+ }
+ }
+ }
+
+ /**
+ * An existing Property is being replaced with a new Property.
+ *
+ * @param oldProp The old property that is being replaced.
+ * @param newProp The new property that replaces the old property.
+ *
+ */
+ public synchronized void propertyModified(final Property oldProp, final Property newProp) {
+ if (listeners != null) {
+ WeakPropertyMapSet set = listeners.get(oldProp.getKey());
+ if (set != null) {
+ for (PropertyMap propertyMap : set.elements()) {
+ propertyMap.propertyModified(oldProp, newProp);
+ }
+ listeners.remove(oldProp.getKey());
+ }
+ }
+ }
+
+ public synchronized void protoChanged() {
+ if (listeners != null) {
+ for (WeakPropertyMapSet set : listeners.values()) {
+ for (PropertyMap propertyMap : set.elements()) {
+ propertyMap.protoChanged();
+ }
+ }
+ listeners.clear();
+ }
+ }
+
+ private static class WeakPropertyMapSet {
+
+ private WeakHashMap<PropertyMap, Boolean> map = new WeakHashMap<>();
+
+ void add(final PropertyMap propertyMap) {
+ map.put(propertyMap, Boolean.TRUE);
+ }
+
+ boolean contains(final PropertyMap propertyMap) {
+ return map.containsKey(propertyMap);
+ }
+
+ Set<PropertyMap> elements() {
+ return map.keySet();
+ }
+
+ }
+}
diff --git a/src/jdk/nashorn/internal/runtime/PropertyMap.java b/src/jdk/nashorn/internal/runtime/PropertyMap.java
index 03c4978a..77bcc83f 100644
--- a/src/jdk/nashorn/internal/runtime/PropertyMap.java
+++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java
@@ -30,13 +30,11 @@ import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndex;
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
import java.lang.invoke.SwitchPoint;
-import java.lang.ref.WeakReference;
+import java.lang.ref.SoftReference;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
import java.util.NoSuchElementException;
import java.util.WeakHashMap;
@@ -49,17 +47,11 @@ import java.util.WeakHashMap;
* All property maps are immutable. If a property is added, modified or removed, the mutator
* will return a new map.
*/
-public final class PropertyMap implements Iterable<Object>, PropertyListener {
+public final class PropertyMap implements Iterable<Object> {
/** Used for non extensible PropertyMaps, negative logic as the normal case is extensible. See {@link ScriptObject#preventExtensions()} */
public static final int NOT_EXTENSIBLE = 0b0000_0001;
/** Does this map contain valid array keys? */
public static final int CONTAINS_ARRAY_KEYS = 0b0000_0010;
- /** This mask is used to preserve certain flags when cloning the PropertyMap. Others should not be copied */
- private static final int CLONEABLE_FLAGS_MASK = 0b0000_1111;
- /** Has a listener been added to this property map. This flag is not copied when cloning a map. See {@link PropertyListener} */
- public static final int IS_LISTENER_ADDED = 0b0001_0000;
- /** Is this process wide "shared" map?. This flag is not copied when cloning a map */
- public static final int IS_SHARED = 0b0010_0000;
/** Map status flags. */
private int flags;
@@ -77,16 +69,16 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
private int spillLength;
/** {@link SwitchPoint}s for gets on inherited properties. */
- private Map<String, SwitchPoint> protoGetSwitches;
+ private HashMap<String, SwitchPoint> protoGetSwitches;
/** History of maps, used to limit map duplication. */
- private HashMap<Property, PropertyMap> history;
+ private WeakHashMap<Property, SoftReference<PropertyMap>> history;
/** History of prototypes, used to limit map duplication. */
- private WeakHashMap<ScriptObject, WeakReference<PropertyMap>> protoHistory;
+ private WeakHashMap<PropertyMap, SoftReference<PropertyMap>> protoHistory;
- /** Cache for hashCode */
- private int hashCode;
+ /** property listeners */
+ private PropertyListeners listeners;
/**
* Constructor.
@@ -119,10 +111,12 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
*/
private PropertyMap(final PropertyMap propertyMap, final PropertyHashMap properties) {
this.properties = properties;
- this.flags = propertyMap.getClonedFlags();
+ this.flags = propertyMap.flags;
this.spillLength = propertyMap.spillLength;
this.fieldCount = propertyMap.fieldCount;
this.fieldMaximum = propertyMap.fieldMaximum;
+ // We inherit the parent property listeners instance. It will be cloned when a new listener is added.
+ this.listeners = propertyMap.listeners;
if (Context.DEBUG) {
count++;
@@ -203,35 +197,92 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
- * Return a SwitchPoint used to track changes of a property in a prototype.
+ * Get the listeners of this map, or null if none exists
*
- * @param proto Object prototype.
- * @param key {@link Property} key.
+ * @return the listeners
+ */
+ public PropertyListeners getListeners() {
+ return listeners;
+ }
+
+ /**
+ * Add {@code listenerMap} as a listener to this property map for the given {@code key}.
*
- * @return A shared {@link SwitchPoint} for the property.
+ * @param key the property name
+ * @param listenerMap the listener map
*/
- public SwitchPoint getProtoGetSwitchPoint(final ScriptObject proto, final String key) {
- assert !isShared() : "proto SwitchPoint from a shared PropertyMap";
+ public void addListener(final String key, final PropertyMap listenerMap) {
+ if (listenerMap != this) {
+ // We need to clone listener instance when adding a new listener since we share
+ // the listeners instance with our parent maps that don't need to see the new listener.
+ listeners = PropertyListeners.addListener(listeners, key, listenerMap);
+ }
+ }
- if (proto == null) {
- return null;
+ /**
+ * A new property is being added.
+ *
+ * @param property The new Property added.
+ */
+ public void propertyAdded(final Property property) {
+ invalidateProtoGetSwitchPoint(property);
+ if (listeners != null) {
+ listeners.propertyAdded(property);
}
+ }
+ /**
+ * An existing property is being deleted.
+ *
+ * @param property The property being deleted.
+ */
+ public void propertyDeleted(final Property property) {
+ invalidateProtoGetSwitchPoint(property);
+ if (listeners != null) {
+ listeners.propertyDeleted(property);
+ }
+ }
+
+ /**
+ * An existing property is being redefined.
+ *
+ * @param oldProperty The old property
+ * @param newProperty The new property
+ */
+ public void propertyModified(final Property oldProperty, final Property newProperty) {
+ invalidateProtoGetSwitchPoint(oldProperty);
+ if (listeners != null) {
+ listeners.propertyModified(oldProperty, newProperty);
+ }
+ }
+
+ /**
+ * The prototype of an object associated with this {@link PropertyMap} is changed.
+ */
+ public void protoChanged() {
+ invalidateAllProtoGetSwitchPoints();
+ if (listeners != null) {
+ listeners.protoChanged();
+ }
+ }
+
+ /**
+ * Return a SwitchPoint used to track changes of a property in a prototype.
+ *
+ * @param key Property key.
+ * @return A shared {@link SwitchPoint} for the property.
+ */
+ public synchronized SwitchPoint getSwitchPoint(final String key) {
if (protoGetSwitches == null) {
protoGetSwitches = new HashMap<>();
- if (! isListenerAdded()) {
- proto.addPropertyListener(this);
- setIsListenerAdded();
- }
}
- if (protoGetSwitches.containsKey(key)) {
- return protoGetSwitches.get(key);
+ SwitchPoint switchPoint = protoGetSwitches.get(key);
+ if (switchPoint == null) {
+ switchPoint = new SwitchPoint();
+ protoGetSwitches.put(key, switchPoint);
}
- final SwitchPoint switchPoint = new SwitchPoint();
- protoGetSwitches.put(key, switchPoint);
-
return switchPoint;
}
@@ -240,14 +291,13 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
*
* @param property {@link Property} to invalidate.
*/
- private void invalidateProtoGetSwitchPoint(final Property property) {
- assert !isShared() : "proto invalidation on a shared PropertyMap";
-
+ synchronized void invalidateProtoGetSwitchPoint(final Property property) {
if (protoGetSwitches != null) {
+
final String key = property.getKey();
final SwitchPoint sp = protoGetSwitches.get(key);
if (sp != null) {
- protoGetSwitches.put(key, new SwitchPoint());
+ protoGetSwitches.remove(key);
if (Context.DEBUG) {
protoInvalidations++;
}
@@ -257,14 +307,15 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
- * Indicate that proto itself has changed in hierachy somewhere.
+ * Indicate that proto itself has changed in hierarchy somewhere.
*/
- private void invalidateAllProtoGetSwitchPoints() {
- assert !isShared() : "proto invalidation on a shared PropertyMap";
-
- if (protoGetSwitches != null) {
- final Collection<SwitchPoint> sws = protoGetSwitches.values();
- SwitchPoint.invalidateAll(sws.toArray(new SwitchPoint[sws.size()]));
+ synchronized void invalidateAllProtoGetSwitchPoints() {
+ if (protoGetSwitches != null && !protoGetSwitches.isEmpty()) {
+ if (Context.DEBUG) {
+ protoInvalidations += protoGetSwitches.size();
+ }
+ SwitchPoint.invalidateAll(protoGetSwitches.values().toArray(new SwitchPoint[protoGetSwitches.values().size()]));
+ protoGetSwitches.clear();
}
}
@@ -279,7 +330,33 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
* @return New {@link PropertyMap} with {@link Property} added.
*/
PropertyMap addPropertyBind(final AccessorProperty property, final Object bindTo) {
- return addProperty(new AccessorProperty(property, bindTo));
+ // No need to store bound property in the history as bound properties can't be reused.
+ return addPropertyNoHistory(new AccessorProperty(property, bindTo));
+ }
+
+ /**
+ * Add a property to the map without adding it to the history. This should be used for properties that
+ * can't be shared such as bound properties, or properties that are expected to be added only once.
+ *
+ * @param property {@link Property} being added.
+ * @return New {@link PropertyMap} with {@link Property} added.
+ */
+ public PropertyMap addPropertyNoHistory(final Property property) {
+ if (listeners != null) {
+ listeners.propertyAdded(property);
+ }
+ final PropertyHashMap newProperties = properties.immutableAdd(property);
+ final PropertyMap newMap = new PropertyMap(this, newProperties);
+
+ if(!property.isSpill()) {
+ newMap.fieldCount = Math.max(newMap.fieldCount, property.getSlot() + 1);
+ }
+ if (isValidArrayIndex(getArrayIndex(property.getKey()))) {
+ newMap.setContainsArrayKeys();
+ }
+
+ newMap.spillLength += property.getSpillCount();
+ return newMap;
}
/**
@@ -290,6 +367,9 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
* @return New {@link PropertyMap} with {@link Property} added.
*/
public PropertyMap addProperty(final Property property) {
+ if (listeners != null) {
+ listeners.propertyAdded(property);
+ }
PropertyMap newMap = checkHistory(property);
if (newMap == null) {
@@ -318,6 +398,9 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
* @return New {@link PropertyMap} with {@link Property} removed or {@code null} if not found.
*/
public PropertyMap deleteProperty(final Property property) {
+ if (listeners != null) {
+ listeners.propertyDeleted(property);
+ }
PropertyMap newMap = checkHistory(property);
final String key = property.getKey();
@@ -339,6 +422,9 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
* @return New {@link PropertyMap} with {@link Property} replaced.
*/
PropertyMap replaceProperty(final Property oldProperty, final Property newProperty) {
+ if (listeners != null) {
+ listeners.propertyModified(oldProperty, newProperty);
+ }
// Add replaces existing property.
final PropertyHashMap newProperties = properties.immutableAdd(newProperty);
final PropertyMap newMap = new PropertyMap(this, newProperties);
@@ -363,7 +449,7 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
(oldProperty instanceof AccessorProperty &&
newProperty instanceof UserAccessorProperty) : "arbitrary replaceProperty attempted";
- newMap.flags = getClonedFlags();
+ newMap.flags = flags;
/*
* spillLength remains same in case (1) and (2) because of slot reuse. Only for case (3), we need
@@ -491,28 +577,6 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
- * Make this property map 'shared' one. Shared property map instances are
- * process wide singleton objects. A shaped map should never be added as a listener
- * to a proto object. Nor it should have history or proto history. A shared map
- * is just a template that is meant to be duplicated before use. All nasgen initialized
- * property maps are shared.
- *
- * @return this map after making it as shared
- */
- public PropertyMap setIsShared() {
- assert !isListenerAdded() : "making PropertyMap shared after listener added";
- assert protoHistory == null : "making PropertyMap shared after associating a proto with it";
- if (Context.DEBUG) {
- sharedCount++;
- }
-
- flags |= IS_SHARED;
- // clear any history on this PropertyMap, won't be used.
- history = null;
- return this;
- }
-
- /**
* Check for any configurable properties.
*
* @return {@code true} if any configurable.
@@ -551,14 +615,14 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
/**
* Check prototype history for an existing property map with specified prototype.
*
- * @param newProto New prototype object.
+ * @param parentMap New prototype object.
*
* @return Existing {@link PropertyMap} or {@code null} if not found.
*/
- private PropertyMap checkProtoHistory(final ScriptObject newProto) {
+ private PropertyMap checkProtoHistory(final PropertyMap parentMap) {
final PropertyMap cachedMap;
if (protoHistory != null) {
- final WeakReference<PropertyMap> weakMap = protoHistory.get(newProto);
+ final SoftReference<PropertyMap> weakMap = protoHistory.get(parentMap);
cachedMap = (weakMap != null ? weakMap.get() : null);
} else {
cachedMap = null;
@@ -574,17 +638,15 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
/**
* Add a map to the prototype history.
*
- * @param newProto Prototype to add (key.)
+ * @param parentMap Prototype to add (key.)
* @param newMap {@link PropertyMap} associated with prototype.
*/
- private void addToProtoHistory(final ScriptObject newProto, final PropertyMap newMap) {
- assert !isShared() : "proto history modified on a shared PropertyMap";
-
+ private void addToProtoHistory(final PropertyMap parentMap, final PropertyMap newMap) {
if (protoHistory == null) {
protoHistory = new WeakHashMap<>();
}
- protoHistory.put(newProto, new WeakReference<>(newMap));
+ protoHistory.put(parentMap, new SoftReference<>(newMap));
}
/**
@@ -594,14 +656,12 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
* @param newMap Modified {@link PropertyMap}.
*/
private void addToHistory(final Property property, final PropertyMap newMap) {
- assert !isShared() : "history modified on a shared PropertyMap";
-
if (!properties.isEmpty()) {
if (history == null) {
- history = new LinkedHashMap<>();
+ history = new WeakHashMap<>();
}
- history.put(property, newMap);
+ history.put(property, new SoftReference<>(newMap));
}
}
@@ -613,8 +673,10 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
* @return Existing map or {@code null} if not found.
*/
private PropertyMap checkHistory(final Property property) {
+
if (history != null) {
- PropertyMap historicMap = history.get(property);
+ SoftReference<PropertyMap> ref = history.get(property);
+ final PropertyMap historicMap = ref == null ? null : ref.get();
if (historicMap != null) {
if (Context.DEBUG) {
@@ -628,54 +690,6 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
return null;
}
- /**
- * Calculate the hash code for the map.
- *
- * @return Computed hash code.
- */
- private int computeHashCode() {
- int hash = 0;
-
- for (final Property property : getProperties()) {
- hash = hash << 7 ^ hash >> 7;
- hash ^= property.hashCode();
- }
-
- return hash;
- }
-
- @Override
- public int hashCode() {
- if (hashCode == 0 && !properties.isEmpty()) {
- hashCode = computeHashCode();
- }
- return hashCode;
- }
-
- @Override
- public boolean equals(final Object other) {
- if (!(other instanceof PropertyMap)) {
- return false;
- }
-
- final PropertyMap otherMap = (PropertyMap)other;
-
- if (properties.size() != otherMap.properties.size()) {
- return false;
- }
-
- final Iterator<Property> iter = properties.values().iterator();
- final Iterator<Property> otherIter = otherMap.properties.values().iterator();
-
- while (iter.hasNext() && otherIter.hasNext()) {
- if (!iter.next().equals(otherIter.next())) {
- return false;
- }
- }
-
- return true;
- }
-
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
@@ -728,24 +742,6 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
- * Check whether a {@link PropertyListener} has been added to this map.
- *
- * @return {@code true} if {@link PropertyListener} exists
- */
- public boolean isListenerAdded() {
- return (flags & IS_LISTENER_ADDED) != 0;
- }
-
- /**
- * Check if this map shared or not.
- *
- * @return true if this map is shared.
- */
- public boolean isShared() {
- return (flags & IS_SHARED) != 0;
- }
-
- /**
* Test to see if {@link PropertyMap} is extensible.
*
* @return {@code true} if {@link PropertyMap} can be added to.
@@ -800,50 +796,29 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
- * Change the prototype of objects associated with this {@link PropertyMap}.
+ * Return a property map with the same layout that is associated with the new prototype object.
*
- * @param oldProto Current prototype object.
* @param newProto New prototype object to replace oldProto.
- *
* @return New {@link PropertyMap} with prototype changed.
*/
- PropertyMap changeProto(final ScriptObject oldProto, final ScriptObject newProto) {
- assert !isShared() : "proto associated with a shared PropertyMap";
+ public PropertyMap changeProto(final ScriptObject newProto) {
- if (oldProto == newProto) {
- return this;
- }
-
- final PropertyMap nextMap = checkProtoHistory(newProto);
+ final PropertyMap parentMap = newProto == null ? null : newProto.getMap();
+ final PropertyMap nextMap = checkProtoHistory(parentMap);
if (nextMap != null) {
return nextMap;
}
if (Context.DEBUG) {
- incrementSetProtoNewMapCount();
+ setProtoNewMapCount++;
}
final PropertyMap newMap = new PropertyMap(this);
- addToProtoHistory(newProto, newMap);
+ addToProtoHistory(parentMap, newMap);
return newMap;
}
- /**
- * Indicate that the map has listeners.
- */
- private void setIsListenerAdded() {
- flags |= IS_LISTENER_ADDED;
- }
-
- /**
- * Return only the flags that should be copied during cloning.
- *
- * @return Subset of flags that should be copied.
- */
- private int getClonedFlags() {
- return flags & CLONEABLE_FLAGS_MASK;
- }
/**
* {@link PropertyMap} iterator.
@@ -900,41 +875,12 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/*
- * PropertyListener implementation.
- */
-
- @Override
- public void propertyAdded(final ScriptObject object, final Property prop) {
- invalidateProtoGetSwitchPoint(prop);
- }
-
- @Override
- public void propertyDeleted(final ScriptObject object, final Property prop) {
- invalidateProtoGetSwitchPoint(prop);
- }
-
- @Override
- public void propertyModified(final ScriptObject object, final Property oldProp, final Property newProp) {
- invalidateProtoGetSwitchPoint(oldProp);
- }
-
- @Override
- public void protoChanged(final ScriptObject object, final ScriptObject oldProto, final ScriptObject newProto) {
- // We may walk and invalidate SwitchPoints for properties inherited
- // from 'object' or it's old proto chain. But, it may not be worth it.
- // For example, a new proto may have a user defined getter/setter for
- // a data property down the chain. So, invalidating all is better.
- invalidateAllProtoGetSwitchPoints();
- }
-
- /*
* Debugging and statistics.
*/
// counters updated only in debug mode
private static int count;
private static int clonedCount;
- private static int sharedCount;
private static int duplicatedCount;
private static int historyHit;
private static int protoInvalidations;
@@ -956,13 +902,6 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
- * @return The number of maps that are shared.
- */
- public static int getSharedCount() {
- return sharedCount;
- }
-
- /**
* @return The number of maps that are duplicated.
*/
public static int getDuplicatedCount() {
@@ -997,10 +936,4 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
return setProtoNewMapCount;
}
- /**
- * Increment the prototype set count.
- */
- private static void incrementSetProtoNewMapCount() {
- setProtoNewMapCount++;
- }
}
diff --git a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java
index e5ca3c9a..2b18cbc8 100644
--- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java
+++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java
@@ -160,10 +160,10 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData {
}
@Override
- ScriptObject allocate() {
+ ScriptObject allocate(final PropertyMap map) {
try {
ensureHasAllocator(); //if allocatorClass name is set to null (e.g. for bound functions) we don't even try
- return allocator == null ? null : (ScriptObject)allocator.invokeExact(allocatorMap);
+ return allocator == null ? null : (ScriptObject)allocator.invokeExact(map);
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
@@ -178,6 +178,11 @@ public final class RecompilableScriptFunctionData extends ScriptFunctionData {
}
@Override
+ PropertyMap getAllocatorMap() {
+ return allocatorMap;
+ }
+
+ @Override
protected synchronized void ensureCodeGenerated() {
if (!code.isEmpty()) {
return; // nothing to do, we have code, at least some.
diff --git a/src/jdk/nashorn/internal/runtime/ScriptFunction.java b/src/jdk/nashorn/internal/runtime/ScriptFunction.java
index d0669d70..0f5174ea 100644
--- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java
+++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java
@@ -80,6 +80,9 @@ public abstract class ScriptFunction extends ScriptObject {
private final ScriptFunctionData data;
+ /** The property map used for newly allocated object when function is used as constructor. */
+ protected PropertyMap allocatorMap;
+
/**
* Constructor
*
@@ -125,6 +128,7 @@ public abstract class ScriptFunction extends ScriptObject {
this.data = data;
this.scope = scope;
+ this.allocatorMap = data.getAllocatorMap();
}
@Override
@@ -229,16 +233,16 @@ public abstract class ScriptFunction extends ScriptObject {
}
assert !isBoundFunction(); // allocate never invoked on bound functions
- final ScriptObject object = data.allocate();
+ final ScriptObject object = data.allocate(allocatorMap);
if (object != null) {
Object prototype = getPrototype();
if (prototype instanceof ScriptObject) {
- object.setProto((ScriptObject)prototype);
+ object.setInitialProto((ScriptObject)prototype);
}
if (object.getProto() == null) {
- object.setProto(getObjectPrototype());
+ object.setInitialProto(getObjectPrototype());
}
}
diff --git a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java
index 4dbbfba9..f0569937 100644
--- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java
+++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java
@@ -229,9 +229,20 @@ public abstract class ScriptFunctionData {
/**
* Allocates an object using this function's allocator.
+ *
+ * @param map the property map for the allocated object.
* @return the object allocated using this function's allocator, or null if the function doesn't have an allocator.
*/
- ScriptObject allocate() {
+ ScriptObject allocate(final PropertyMap map) {
+ return null;
+ }
+
+ /**
+ * Get the property map to use for objects allocated by this function.
+ *
+ * @return the property map for allocated objects.
+ */
+ PropertyMap getAllocatorMap() {
return null;
}
diff --git a/src/jdk/nashorn/internal/runtime/ScriptObject.java b/src/jdk/nashorn/internal/runtime/ScriptObject.java
index 4b3bb939..b7f9c4c1 100644
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java
+++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java
@@ -43,6 +43,7 @@ import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
+import java.lang.invoke.SwitchPoint;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
@@ -88,7 +89,7 @@ import jdk.nashorn.internal.runtime.linker.NashornGuards;
* </ul>
*/
-public abstract class ScriptObject extends PropertyListenerManager implements PropertyAccess {
+public abstract class ScriptObject implements PropertyAccess {
/** __proto__ special property name */
public static final String PROTO_PROPERTY_NAME = "__proto__";
@@ -107,9 +108,6 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
/** Per ScriptObject flag - is this an arguments object? */
public static final int IS_ARGUMENTS = 0b0000_0100;
- /** Is this a prototype PropertyMap? */
- public static final int IS_PROTOTYPE = 0b0000_1000;
-
/** Is length property not-writable? */
public static final int IS_LENGTH_NOT_WRITABLE = 0b0001_0000;
@@ -155,7 +153,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
public static final Call GET_PROTO = virtualCallNoLookup(ScriptObject.class, "getProto", ScriptObject.class);
/** Method handle for setting the proto of a ScriptObject */
- public static final Call SET_PROTO = virtualCallNoLookup(ScriptObject.class, "setProto", void.class, ScriptObject.class);
+ public static final Call SET_PROTO = virtualCallNoLookup(ScriptObject.class, "setInitialProto", void.class, ScriptObject.class);
/** Method handle for setting the proto of a ScriptObject after checking argument */
public static final Call SET_PROTO_CHECK = virtualCallNoLookup(ScriptObject.class, "setProtoCheck", void.class, Object.class);
@@ -201,10 +199,6 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
this.arrayData = ArrayData.EMPTY_ARRAY;
this.setMap(map == null ? PropertyMap.newMap() : map);
this.proto = proto;
-
- if (proto != null) {
- proto.setIsPrototype();
- }
}
/**
@@ -232,7 +226,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
if (oldProp == null) {
if (property instanceof UserAccessorProperty) {
final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source));
- newMap = newMap.addProperty(prop);
+ newMap = newMap.addPropertyNoHistory(prop);
} else {
newMap = newMap.addPropertyBind((AccessorProperty)property, source);
}
@@ -875,8 +869,6 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
newProperty = newUserAccessors(oldProperty.getKey(), propertyFlags, getter, setter);
}
- notifyPropertyModified(this, oldProperty, newProperty);
-
return modifyOwnProperty(oldProperty, newProperty);
}
@@ -1120,29 +1112,33 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
*/
public synchronized final void setProto(final ScriptObject newProto) {
final ScriptObject oldProto = proto;
- map = map.changeProto(oldProto, newProto);
- if (newProto != null) {
- newProto.setIsPrototype();
- }
-
- proto = newProto;
-
- if (isPrototype()) {
- // tell listeners that my __proto__ has been changed
- notifyProtoChanged(this, oldProto, newProto);
-
- if (oldProto != null) {
- oldProto.removePropertyListener(this);
- }
+ if (oldProto != newProto) {
+ proto = newProto;
- if (newProto != null) {
- newProto.addPropertyListener(this);
+ // Let current listeners know that the protototype has changed and set our map
+ final PropertyListeners listeners = getMap().getListeners();
+ if (listeners != null) {
+ listeners.protoChanged();
}
+ // Replace our current allocator map with one that is associated with the new prototype.
+ setMap(getMap().changeProto(newProto));
}
}
/**
+ * Set the initial __proto__ of this object. This should be used instead of
+ * {@link #setProto} if it is known that the current property map will not be
+ * used on a new object with any other parent property map, so we can pass over
+ * property map invalidation/evolution.
+ *
+ * @param initialProto the initial __proto__ to set.
+ */
+ public void setInitialProto(final ScriptObject initialProto) {
+ this.proto = initialProto;
+ }
+
+ /**
* Set the __proto__ of an object with checks.
* @param newProto Prototype to set.
*/
@@ -1332,25 +1328,6 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
}
/**
- * Check if this object is a prototype
- *
- * @return {@code true} if is prototype
- */
- public final boolean isPrototype() {
- return (flags & IS_PROTOTYPE) != 0;
- }
-
- /**
- * Flag this object as having a prototype.
- */
- public final void setIsPrototype() {
- if (proto != null && !isPrototype()) {
- proto.addPropertyListener(this);
- }
- flags |= IS_PROTOTYPE;
- }
-
- /**
* Check if this object has non-writable length property
*
* @return {@code true} if 'length' property is non-writable
@@ -1791,6 +1768,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
final boolean noGuard = ObjectClassGenerator.OBJECT_FIELDS_ONLY && NashornCallSiteDescriptor.isFastScope(desc) && !property.canChangeType();
// getMap() is fine as we have the prototype switchpoint depending on where the property was found
final MethodHandle guard = noGuard ? null : NashornGuards.getMapGuard(getMap());
+ final ScriptObject owner = find.getOwner();
if (methodHandle != null) {
assert methodHandle.type().returnType().equals(returnType);
@@ -1798,18 +1776,18 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
return new GuardedInvocation(methodHandle, guard);
}
- if (!property.hasGetterFunction(find.getOwner())) {
+ if (!property.hasGetterFunction(owner)) {
// If not a scope bind to actual prototype as changing prototype will change the property map.
// For scopes we install a filter that replaces the self object with the prototype owning the property.
methodHandle = isScope() ?
addProtoFilter(methodHandle, find.getProtoChainLength()) :
- bindTo(methodHandle, find.getOwner());
+ bindTo(methodHandle, owner);
}
- return new GuardedInvocation(methodHandle, noGuard ? null : getMap().getProtoGetSwitchPoint(proto, name), guard);
+ return new GuardedInvocation(methodHandle, noGuard ? null : getProtoSwitchPoint(name, owner), guard);
}
assert !NashornCallSiteDescriptor.isFastScope(desc);
- return new GuardedInvocation(Lookup.emptyGetter(returnType), getMap().getProtoGetSwitchPoint(proto, name), guard);
+ return new GuardedInvocation(Lookup.emptyGetter(returnType), getProtoSwitchPoint(name, owner), guard);
}
private static GuardedInvocation findMegaMorphicGetMethod(final CallSiteDescriptor desc, final String name, final boolean isMethod) {
@@ -1866,6 +1844,28 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
}
/**
+ * Get a switch point for a property with the given {@code name} that will be invalidated when
+ * the property definition is changed in this object's prototype chain. Returns {@code null} if
+ * the property is defined in this object itself.
+ *
+ * @param name the property name
+ * @param owner the property owner, null if property is not defined
+ * @return a SwitchPoint or null
+ */
+ public final SwitchPoint getProtoSwitchPoint(final String name, final ScriptObject owner) {
+ if (owner == this || getProto() == null) {
+ return null;
+ }
+
+ for (ScriptObject obj = this; obj != owner && obj.getProto() != null; obj = obj.getProto()) {
+ ScriptObject parent = obj.getProto();
+ parent.getMap().addListener(name, obj.getMap());
+ }
+
+ return getMap().getSwitchPoint(name);
+ }
+
+ /**
* Find the appropriate SET method for an invoke dynamic call.
*
* @param desc the call site descriptor
@@ -1921,8 +1921,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
throw typeError(strictErrorMessage, name, ScriptRuntime.safeToString((this)));
}
assert canBeFastScope || !NashornCallSiteDescriptor.isFastScope(desc);
- final PropertyMap myMap = getMap();
- return new GuardedInvocation(Lookup.EMPTY_SETTER, myMap.getProtoGetSwitchPoint(proto, name), NashornGuards.getMapGuard(myMap));
+ return new GuardedInvocation(Lookup.EMPTY_SETTER, getProtoSwitchPoint(name, null), NashornGuards.getMapGuard(getMap()));
}
@SuppressWarnings("unused")
@@ -2082,7 +2081,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
methodHandle = bindTo(methodHandle, UNDEFINED);
}
return new GuardedInvocation(methodHandle,
- find.isInherited()? getMap().getProtoGetSwitchPoint(proto, NO_SUCH_PROPERTY_NAME) : null,
+ getProtoSwitchPoint(NO_SUCH_PROPERTY_NAME, find.getOwner()),
getKnownFunctionPropertyGuard(getMap(), find.getGetter(Object.class), find.getOwner(), func));
}
}
@@ -2134,7 +2133,8 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
}
private GuardedInvocation createEmptyGetter(final CallSiteDescriptor desc, final String name) {
- return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()), getMap().getProtoGetSwitchPoint(proto, name), NashornGuards.getMapGuard(getMap()));
+ return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()),
+ getProtoSwitchPoint(name, null), NashornGuards.getMapGuard(getMap()));
}
private abstract static class ScriptObjectIterator <T extends Object> implements Iterator<T> {
@@ -2215,12 +2215,10 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
if (fieldCount < fieldMaximum) {
property = new AccessorProperty(key, propertyFlags & ~Property.IS_SPILL, getClass(), fieldCount);
- notifyPropertyAdded(this, property);
property = addOwnProperty(property);
} else {
int i = getMap().getSpillLength();
property = new AccessorProperty(key, propertyFlags | Property.IS_SPILL, i);
- notifyPropertyAdded(this, property);
property = addOwnProperty(property);
i = property.getSlot();
@@ -3274,7 +3272,6 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
}
final Property prop = find.getProperty();
- notifyPropertyDeleted(this, prop);
deleteOwnProperty(prop);
return true;
diff --git a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java
index 7390aadd..bdbc8ec8 100644
--- a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java
+++ b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java
@@ -80,7 +80,7 @@ final class SetMethodCreator {
}
/**
- * This class encapsulates the results of looking up a setter method; it's basically a triple of a method hanle,
+ * This class encapsulates the results of looking up a setter method; it's basically a triple of a method handle,
* a Property object, and flags for invocation.
*
*/
@@ -170,7 +170,10 @@ final class SetMethodCreator {
private SetMethod createNewPropertySetter() {
final SetMethod sm = map.getFieldCount() < map.getFieldMaximum() ? createNewFieldSetter() : createNewSpillPropertySetter();
- sobj.notifyPropertyAdded(sobj, sm.property);
+ final PropertyListeners listeners = map.getListeners();
+ if (listeners != null) {
+ listeners.propertyAdded(sm.property);
+ }
return sm;
}
diff --git a/src/jdk/nashorn/internal/runtime/WithObject.java b/src/jdk/nashorn/internal/runtime/WithObject.java
index 6e03dc60..d4a28cd7 100644
--- a/src/jdk/nashorn/internal/runtime/WithObject.java
+++ b/src/jdk/nashorn/internal/runtime/WithObject.java
@@ -36,6 +36,7 @@ import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
+import jdk.nashorn.internal.runtime.linker.NashornGuards;
/**
* This class supports the handling of scope in a with body.
@@ -123,7 +124,7 @@ public final class WithObject extends ScriptObject implements Scope {
}
if (find != null) {
- return fixScopeCallSite(scope.lookup(desc, request), name);
+ return fixScopeCallSite(scope.lookup(desc, request), name, find.getOwner());
}
// the property is not found - now check for
@@ -175,7 +176,7 @@ public final class WithObject extends ScriptObject implements Scope {
link = scope.lookup(desc, request);
if (link != null) {
- return fixScopeCallSite(link, name);
+ return fixScopeCallSite(link, name, null);
}
return null;
@@ -252,13 +253,10 @@ public final class WithObject extends ScriptObject implements Scope {
filterGuard(link, WITHEXPRESSIONFILTER));
}
- private GuardedInvocation fixScopeCallSite(final GuardedInvocation link, final String name) {
+ private GuardedInvocation fixScopeCallSite(final GuardedInvocation link, final String name, final ScriptObject owner) {
final GuardedInvocation newLink = fixReceiverType(link, WITHSCOPEFILTER);
return link.replaceMethods(filter(newLink.getInvocation(), WITHSCOPEFILTER),
- MH.guardWithTest(
- expressionGuard(name),
- filterGuard(newLink, WITHSCOPEFILTER),
- MH.dropArguments(MH.constant(boolean.class, false), 0, Object.class)));
+ NashornGuards.combineGuards(expressionGuard(name, owner), filterGuard(newLink, WITHSCOPEFILTER)));
}
private static MethodHandle filterGuard(final GuardedInvocation link, final MethodHandle filter) {
@@ -288,9 +286,9 @@ public final class WithObject extends ScriptObject implements Scope {
return fn.makeBoundFunction(withFilterExpression(receiver), new Object[0]);
}
- private MethodHandle expressionGuard(final String name) {
+ private MethodHandle expressionGuard(final String name, final ScriptObject owner) {
final PropertyMap map = expression.getMap();
- final SwitchPoint sp = map.getProtoGetSwitchPoint(expression.getProto(), name);
+ final SwitchPoint sp = expression.getProtoSwitchPoint(name, owner);
return MH.insertArguments(WITHEXPRESSIONGUARD, 1, map, sp);
}
diff --git a/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java b/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java
index a8e79184..0b720be2 100644
--- a/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java
+++ b/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java
@@ -37,10 +37,10 @@ import jdk.nashorn.internal.runtime.ScriptObject;
* Constructor of method handles used to guard call sites.
*/
public final class NashornGuards {
- private static final MethodHandle IS_SCRIPTOBJECT = findOwnMH("isScriptObject", boolean.class, Object.class);
- private static final MethodHandle IS_SCRIPTFUNCTION = findOwnMH("isScriptFunction", boolean.class, Object.class);
- private static final MethodHandle IS_MAP = findOwnMH("isMap", boolean.class, Object.class, PropertyMap.class);
- private static final MethodHandle IS_INSTANCEOF_2 = findOwnMH("isInstanceOf2", boolean.class, Object.class, Class.class, Class.class);
+ private static final MethodHandle IS_SCRIPTOBJECT = findOwnMH("isScriptObject", boolean.class, Object.class);
+ private static final MethodHandle IS_SCRIPTFUNCTION = findOwnMH("isScriptFunction", boolean.class, Object.class);
+ private static final MethodHandle IS_MAP = findOwnMH("isMap", boolean.class, Object.class, PropertyMap.class);
+ private static final MethodHandle IS_INSTANCEOF_2 = findOwnMH("isInstanceOf2", boolean.class, Object.class, Class.class, Class.class);
// don't create me!
private NashornGuards() {
@@ -85,6 +85,17 @@ public final class NashornGuards {
return MH.insertArguments(IS_INSTANCEOF_2, 1, class1, class2);
}
+ /**
+ * Combine two method handles of type {@code (Object)boolean} using logical AND.
+ *
+ * @param guard1 the first guard
+ * @param guard2 the second guard, only invoked if guard1 returns true
+ * @return true if both guard1 and guard2 returned true
+ */
+ public static MethodHandle combineGuards(final MethodHandle guard1, final MethodHandle guard2) {
+ return MH.guardWithTest(guard1, guard2, MH.dropArguments(MH.constant(boolean.class, false), 0, Object.class));
+ }
+
@SuppressWarnings("unused")
private static boolean isScriptObject(final Object self) {
return self instanceof ScriptObject;
diff --git a/src/jdk/nashorn/internal/scripts/JO.java b/src/jdk/nashorn/internal/scripts/JO.java
index f2f00062..d6173918 100644
--- a/src/jdk/nashorn/internal/scripts/JO.java
+++ b/src/jdk/nashorn/internal/scripts/JO.java
@@ -33,7 +33,7 @@ import jdk.nashorn.internal.runtime.ScriptObject;
*/
public class JO extends ScriptObject {
- private static final PropertyMap map$ = PropertyMap.newMap().setIsShared();
+ private static final PropertyMap map$ = PropertyMap.newMap();
/**
* Returns the initial property map to be used.