aboutsummaryrefslogtreecommitdiff
path: root/src/jdk/nashorn/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/jdk/nashorn/internal')
-rw-r--r--src/jdk/nashorn/internal/lookup/Lookup.java38
-rw-r--r--src/jdk/nashorn/internal/objects/ArrayBufferView.java9
-rw-r--r--src/jdk/nashorn/internal/objects/Global.java51
-rw-r--r--src/jdk/nashorn/internal/objects/NativeArguments.java12
-rw-r--r--src/jdk/nashorn/internal/objects/NativeBoolean.java1
-rw-r--r--src/jdk/nashorn/internal/objects/NativeDebug.java14
-rw-r--r--src/jdk/nashorn/internal/objects/NativeError.java1
-rw-r--r--src/jdk/nashorn/internal/objects/NativeJSAdapter.java1
-rw-r--r--src/jdk/nashorn/internal/objects/NativeJSON.java1
-rw-r--r--src/jdk/nashorn/internal/objects/NativeMath.java1
-rw-r--r--src/jdk/nashorn/internal/objects/NativeStrictArguments.java11
-rw-r--r--src/jdk/nashorn/internal/objects/PrototypeObject.java10
-rw-r--r--src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java35
-rw-r--r--src/jdk/nashorn/internal/runtime/AccessorProperty.java14
-rw-r--r--src/jdk/nashorn/internal/runtime/Context.java8
-rw-r--r--src/jdk/nashorn/internal/runtime/PropertyListenerManager.java10
-rw-r--r--src/jdk/nashorn/internal/runtime/PropertyMap.java117
-rw-r--r--src/jdk/nashorn/internal/runtime/ScriptEnvironment.java8
-rw-r--r--src/jdk/nashorn/internal/runtime/ScriptObject.java2
-rw-r--r--src/jdk/nashorn/internal/runtime/resources/Options.properties16
-rw-r--r--src/jdk/nashorn/internal/scripts/JO.java2
21 files changed, 224 insertions, 138 deletions
diff --git a/src/jdk/nashorn/internal/lookup/Lookup.java b/src/jdk/nashorn/internal/lookup/Lookup.java
index a454527a..e874cfd7 100644
--- a/src/jdk/nashorn/internal/lookup/Lookup.java
+++ b/src/jdk/nashorn/internal/lookup/Lookup.java
@@ -125,44 +125,6 @@ public final class Lookup {
}
/**
- * Create a new {@link Property}
- *
- * @param map property map
- * @param key property key
- * @param flags property flags
- * @param propertyGetter getter for property if available, null otherwise
- * @param propertySetter setter for property if available, null otherwise
- *
- * @return new property map, representing {@code PropertyMap} with the new property added to it
- */
- @SuppressWarnings("fallthrough")
- public static PropertyMap newProperty(final PropertyMap map, final String key, final int flags, final MethodHandle propertyGetter, final MethodHandle propertySetter) {
- MethodHandle getter = propertyGetter;
- MethodHandle setter = propertySetter;
-
- // TODO: this is temporary code. This code exists to support reflective
- // field reader/writer handles generated by "unreflect" lookup.
-
- switch (getter.type().parameterCount()) {
- case 0:
- // A static field reader, so drop the 'self' argument.
- getter = MH.dropArguments(getter, 0, Object.class);
- if (setter != null) {
- setter = MH.dropArguments(setter, 0, Object.class);
- }
- // fall through
- case 1:
- // standard getter that accepts 'self'.
- break;
- default:
- // Huh!! something wrong..
- throw new IllegalArgumentException("getter/setter has wrong arguments");
- }
-
- return map.newProperty(key, flags, -1, getter, setter);
- }
-
- /**
* This method filters primitive return types using JavaScript semantics. For example,
* an (int) cast of a double in Java land is not the same thing as invoking toInt32 on it.
* If you are returning values to JavaScript that have to be of a specific type, this is
diff --git a/src/jdk/nashorn/internal/objects/ArrayBufferView.java b/src/jdk/nashorn/internal/objects/ArrayBufferView.java
index 60da65a1..73969fa5 100644
--- a/src/jdk/nashorn/internal/objects/ArrayBufferView.java
+++ b/src/jdk/nashorn/internal/objects/ArrayBufferView.java
@@ -46,14 +46,17 @@ abstract class ArrayBufferView extends ScriptObject {
return $nasgenmap$;
}
- ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength) {
+ private ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength, final Global global) {
+ super(global.getArrayBufferViewMap());
checkConstructorArgs(buffer, byteOffset, elementLength);
- final Global global = Global.instance();
- this.setMap(global.getArrayBufferViewMap());
this.setProto(getPrototype(global));
this.setArray(factory().createArrayData(buffer, byteOffset, elementLength));
}
+ ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength) {
+ this(buffer, byteOffset, elementLength, Global.instance());
+ }
+
private void checkConstructorArgs(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength) {
if (byteOffset < 0 || elementLength < 0) {
throw new RuntimeException("byteOffset or length must not be negative");
diff --git a/src/jdk/nashorn/internal/objects/Global.java b/src/jdk/nashorn/internal/objects/Global.java
index a92de8e1..e54fbb45 100644
--- a/src/jdk/nashorn/internal/objects/Global.java
+++ b/src/jdk/nashorn/internal/objects/Global.java
@@ -43,7 +43,6 @@ import java.util.List;
import java.util.Map;
import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.LinkRequest;
-import jdk.nashorn.internal.lookup.MethodHandleFactory;
import jdk.nashorn.internal.objects.annotations.Attribute;
import jdk.nashorn.internal.objects.annotations.Property;
import jdk.nashorn.internal.objects.annotations.ScriptClass;
@@ -389,6 +388,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
private PropertyMap prototypeObjectMap;
private PropertyMap objectMap;
private PropertyMap functionMap;
+ private PropertyMap anonymousFunctionMap;
private PropertyMap strictFunctionMap;
private PropertyMap boundFunctionMap;
@@ -409,7 +409,6 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
private static final MethodHandle EXIT = findOwnMH("exit", Object.class, Object.class, Object.class);
// initialized by nasgen
- @SuppressWarnings("unused")
private static PropertyMap $nasgenmap$;
/**
@@ -418,14 +417,14 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
* @param context the context
*/
public Global(final Context context) {
- this.setContext(context);
- this.setIsScope();
/*
* Duplicate global's map and use it. This way the initial Map filled
* by nasgen (referenced from static field in this class) is retained
- * 'as is'. This allows multiple globals to be used within a context.
+ * 'as is' (as that one is process wide singleton.
*/
- this.setMap(getMap().duplicate());
+ super($nasgenmap$.duplicate());
+ this.setContext(context);
+ this.setIsScope();
final int cacheSize = context.getEnv()._class_cache_size;
if (cacheSize > 0) {
@@ -1018,6 +1017,10 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
return functionMap;
}
+ PropertyMap getAnonymousFunctionMap() {
+ return anonymousFunctionMap;
+ }
+
PropertyMap getStrictFunctionMap() {
return strictFunctionMap;
}
@@ -1538,7 +1541,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
final ScriptEnvironment env = getContext().getEnv();
// duplicate PropertyMaps of Native* classes
- copyInitialMaps();
+ copyInitialMaps(env);
// initialize Function and Object constructor
initFunctionAndObject();
@@ -1599,12 +1602,16 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
initErrorObjects();
// java access
- initJavaAccess();
+ if (! env._no_java) {
+ initJavaAccess();
+ }
- initTypedArray();
+ if (! env._no_typed_arrays) {
+ initTypedArray();
+ }
if (env._scripting) {
- initScripting();
+ initScripting(env);
}
if (Context.DEBUG && System.getSecurityManager() == null) {
@@ -1685,7 +1692,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
this.builtinJavaApi = initConstructor("Java");
}
- private void initScripting() {
+ private void initScripting(final ScriptEnvironment scriptEnv) {
Object value;
value = ScriptFunctionImpl.makeFunction("readLine", ScriptingFunctions.READLINE);
addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value);
@@ -1704,7 +1711,6 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
// Nashorn extension: global.$OPTIONS (scripting-mode-only)
final ScriptObject options = newObject();
- final ScriptEnvironment scriptEnv = getContext().getEnv();
copyOptions(options, scriptEnv);
addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);
@@ -1857,20 +1863,17 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
}
}
- private void copyInitialMaps() {
+ private void copyInitialMaps(final ScriptEnvironment env) {
this.accessorPropertyDescriptorMap = AccessorPropertyDescriptor.getInitialMap().duplicate();
- this.arrayBufferViewMap = ArrayBufferView.getInitialMap().duplicate();
this.dataPropertyDescriptorMap = DataPropertyDescriptor.getInitialMap().duplicate();
this.genericPropertyDescriptorMap = GenericPropertyDescriptor.getInitialMap().duplicate();
this.nativeArgumentsMap = NativeArguments.getInitialMap().duplicate();
this.nativeArrayMap = NativeArray.getInitialMap().duplicate();
- this.nativeArrayBufferMap = NativeArrayBuffer.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.nativeJavaImporterMap = NativeJavaImporter.getInitialMap().duplicate();
this.nativeNumberMap = NativeNumber.getInitialMap().duplicate();
this.nativeRangeErrorMap = NativeRangeError.getInitialMap().duplicate();
this.nativeReferenceErrorMap = NativeReferenceError.getInitialMap().duplicate();
@@ -1883,9 +1886,21 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
this.nativeURIErrorMap = NativeURIError.getInitialMap().duplicate();
this.prototypeObjectMap = PrototypeObject.getInitialMap().duplicate();
this.objectMap = JO.getInitialMap().duplicate();
- this.functionMap = ScriptFunctionImpl.getInitialMap();
+ 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,
@@ -1899,7 +1914,7 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
this.builtinFunction = (ScriptFunction)initConstructor("Function");
// create global anonymous function
- final ScriptFunction anon = ScriptFunctionImpl.newAnonymousFunction();
+ final ScriptFunction anon = ScriptFunctionImpl.newAnonymousFunction(this);
// need to copy over members of Function.prototype to anon function
anon.addBoundProperties(getFunctionPrototype());
diff --git a/src/jdk/nashorn/internal/objects/NativeArguments.java b/src/jdk/nashorn/internal/objects/NativeArguments.java
index 4a5b5986..3bd74d52 100644
--- a/src/jdk/nashorn/internal/objects/NativeArguments.java
+++ b/src/jdk/nashorn/internal/objects/NativeArguments.java
@@ -31,8 +31,10 @@ import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
+import jdk.nashorn.internal.runtime.AccessorProperty;
import jdk.nashorn.internal.runtime.Property;
import jdk.nashorn.internal.runtime.PropertyDescriptor;
import jdk.nashorn.internal.runtime.PropertyMap;
@@ -41,8 +43,6 @@ import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
import jdk.nashorn.internal.runtime.arrays.ArrayData;
import jdk.nashorn.internal.runtime.arrays.ArrayIndex;
-import jdk.nashorn.internal.lookup.Lookup;
-import jdk.nashorn.internal.lookup.MethodHandleFactory;
/**
* ECMA 10.6 Arguments Object.
@@ -64,10 +64,10 @@ public final class NativeArguments extends ScriptObject {
private static final PropertyMap map$;
static {
- PropertyMap map = PropertyMap.newMap();
- map = Lookup.newProperty(map, "length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH);
- map = Lookup.newProperty(map, "callee", Property.NOT_ENUMERABLE, G$CALLEE, S$CALLEE);
- map$ = map;
+ 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();
}
static PropertyMap getInitialMap() {
diff --git a/src/jdk/nashorn/internal/objects/NativeBoolean.java b/src/jdk/nashorn/internal/objects/NativeBoolean.java
index 962086c4..bb57cc71 100644
--- a/src/jdk/nashorn/internal/objects/NativeBoolean.java
+++ b/src/jdk/nashorn/internal/objects/NativeBoolean.java
@@ -40,7 +40,6 @@ import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
-import jdk.nashorn.internal.lookup.MethodHandleFactory;
import jdk.nashorn.internal.runtime.linker.PrimitiveLookup;
/**
diff --git a/src/jdk/nashorn/internal/objects/NativeDebug.java b/src/jdk/nashorn/internal/objects/NativeDebug.java
index 43106eeb..30a42289 100644
--- a/src/jdk/nashorn/internal/objects/NativeDebug.java
+++ b/src/jdk/nashorn/internal/objects/NativeDebug.java
@@ -49,6 +49,7 @@ import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
public final class NativeDebug extends ScriptObject {
// initialized by nasgen
+ @SuppressWarnings("unused")
private static PropertyMap $nasgenmap$;
private NativeDebug() {
@@ -144,7 +145,7 @@ public final class NativeDebug extends ScriptObject {
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object equals(final Object self, final Object obj1, final Object obj2) {
- return (obj1 != null) ? obj1.equals(obj2) : false;
+ return Objects.equals(obj1, obj2);
}
/**
@@ -177,6 +178,15 @@ public final class NativeDebug extends ScriptObject {
}
/**
+ * Returns the property listener count for a script object
+ * @return listener count
+ */
+ @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;
+ }
+
+ /**
* Dump all Nashorn debug mode counters. Calling this may be better if
* you want to print all counters. This way you can avoid too many callsites
* due to counter access itself!!
@@ -197,6 +207,8 @@ public final class NativeDebug extends ScriptObject {
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());
out.println("PropertyMap proto history hit " + PropertyMap.getProtoHistoryHit());
diff --git a/src/jdk/nashorn/internal/objects/NativeError.java b/src/jdk/nashorn/internal/objects/NativeError.java
index 0f233f18..dc6aef90 100644
--- a/src/jdk/nashorn/internal/objects/NativeError.java
+++ b/src/jdk/nashorn/internal/objects/NativeError.java
@@ -31,7 +31,6 @@ import static jdk.nashorn.internal.lookup.Lookup.MH;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import jdk.nashorn.api.scripting.NashornException;
-import jdk.nashorn.internal.lookup.MethodHandleFactory;
import jdk.nashorn.internal.objects.annotations.Attribute;
import jdk.nashorn.internal.objects.annotations.Constructor;
import jdk.nashorn.internal.objects.annotations.Function;
diff --git a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java
index 8e98f4e1..1fda3767 100644
--- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java
+++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java
@@ -48,7 +48,6 @@ import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.ScriptRuntime;
import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator;
import jdk.nashorn.internal.lookup.Lookup;
-import jdk.nashorn.internal.lookup.MethodHandleFactory;
import jdk.nashorn.internal.scripts.JO;
/**
diff --git a/src/jdk/nashorn/internal/objects/NativeJSON.java b/src/jdk/nashorn/internal/objects/NativeJSON.java
index 0fdb170f..863d531b 100644
--- a/src/jdk/nashorn/internal/objects/NativeJSON.java
+++ b/src/jdk/nashorn/internal/objects/NativeJSON.java
@@ -60,6 +60,7 @@ public final class NativeJSON extends ScriptObject {
ScriptFunction.class, ScriptObject.class, Object.class, Object.class);
// initialized by nasgen
+ @SuppressWarnings("unused")
private static PropertyMap $nasgenmap$;
private NativeJSON() {
diff --git a/src/jdk/nashorn/internal/objects/NativeMath.java b/src/jdk/nashorn/internal/objects/NativeMath.java
index c952bd1d..cc50fbb4 100644
--- a/src/jdk/nashorn/internal/objects/NativeMath.java
+++ b/src/jdk/nashorn/internal/objects/NativeMath.java
@@ -43,6 +43,7 @@ import jdk.nashorn.internal.runtime.ScriptObject;
public final class NativeMath extends ScriptObject {
// initialized by nasgen
+ @SuppressWarnings("unused")
private static PropertyMap $nasgenmap$;
private NativeMath() {
diff --git a/src/jdk/nashorn/internal/objects/NativeStrictArguments.java b/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
index df2d17dd..de6e4b51 100644
--- a/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
+++ b/src/jdk/nashorn/internal/objects/NativeStrictArguments.java
@@ -30,14 +30,14 @@ import static jdk.nashorn.internal.lookup.Lookup.MH;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
import java.util.Arrays;
+import jdk.nashorn.internal.runtime.AccessorProperty;
import jdk.nashorn.internal.runtime.Property;
import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
import jdk.nashorn.internal.runtime.arrays.ArrayData;
-import jdk.nashorn.internal.lookup.Lookup;
-import jdk.nashorn.internal.lookup.MethodHandleFactory;
/**
* ECMA 10.6 Arguments Object.
@@ -54,14 +54,15 @@ public final class NativeStrictArguments extends ScriptObject {
private static final PropertyMap map$;
static {
- PropertyMap map = PropertyMap.newMap();
- map = Lookup.newProperty(map, "length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH);
+ final ArrayList<Property> properties = new ArrayList<>(1);
+ properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH));
+ PropertyMap map = PropertyMap.newMap(properties);
// 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;
+ map$ = map.setIsShared();
}
static PropertyMap getInitialMap() {
diff --git a/src/jdk/nashorn/internal/objects/PrototypeObject.java b/src/jdk/nashorn/internal/objects/PrototypeObject.java
index 64af4215..837fee8b 100644
--- a/src/jdk/nashorn/internal/objects/PrototypeObject.java
+++ b/src/jdk/nashorn/internal/objects/PrototypeObject.java
@@ -30,12 +30,12 @@ import static jdk.nashorn.internal.lookup.Lookup.MH;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import jdk.nashorn.internal.runtime.AccessorProperty;
import jdk.nashorn.internal.runtime.Property;
import jdk.nashorn.internal.runtime.PropertyMap;
import jdk.nashorn.internal.runtime.ScriptFunction;
import jdk.nashorn.internal.runtime.ScriptObject;
-import jdk.nashorn.internal.lookup.Lookup;
-import jdk.nashorn.internal.lookup.MethodHandleFactory;
/**
* Instances of this class serve as "prototype" object for script functions.
@@ -52,9 +52,9 @@ public class PrototypeObject extends ScriptObject {
private static final MethodHandle SET_CONSTRUCTOR = findOwnMH("setConstructor", void.class, Object.class, Object.class);
static {
- PropertyMap map = PropertyMap.newMap();
- map = Lookup.newProperty(map, "constructor", Property.NOT_ENUMERABLE, GET_CONSTRUCTOR, SET_CONSTRUCTOR);
- map$ = map;
+ final ArrayList<Property> properties = new ArrayList<>(1);
+ properties.add(AccessorProperty.create("constructor", Property.NOT_ENUMERABLE, GET_CONSTRUCTOR, SET_CONSTRUCTOR));
+ map$ = PropertyMap.newMap(properties).setIsShared();
}
static PropertyMap getInitialMap() {
diff --git a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
index 921073d4..643d9acd 100644
--- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
+++ b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java
@@ -28,6 +28,7 @@ package jdk.nashorn.internal.objects;
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
import java.lang.invoke.MethodHandle;
+import java.util.ArrayList;
import jdk.nashorn.internal.runtime.GlobalFunctions;
import jdk.nashorn.internal.runtime.Property;
import jdk.nashorn.internal.runtime.PropertyMap;
@@ -36,6 +37,7 @@ 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;
/**
* Concrete implementation of ScriptFunction. This sets correct map for the
@@ -57,6 +59,10 @@ public class ScriptFunctionImpl extends ScriptFunction {
return map$;
}
+ static PropertyMap getInitialAnonymousMap() {
+ return AnonymousFunction.getInitialMap();
+ }
+
static PropertyMap getInitialStrictMap() {
return strictmodemap$;
}
@@ -149,13 +155,18 @@ public class ScriptFunctionImpl extends ScriptFunction {
}
static {
- PropertyMap map = PropertyMap.newMap();
- map = Lookup.newProperty(map, "prototype", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE, G$PROTOTYPE, S$PROTOTYPE);
- map = Lookup.newProperty(map, "length", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$LENGTH, null);
- map = Lookup.newProperty(map, "name", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$NAME, null);
- map$ = map;
+ final ArrayList<Property> properties = new ArrayList<>(3);
+ properties.add(AccessorProperty.create("prototype", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE, G$PROTOTYPE, S$PROTOTYPE));
+ properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$LENGTH, null));
+ properties.add(AccessorProperty.create("name", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$NAME, null));
+ 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();
}
// function object representing TypeErrorThrower
@@ -201,15 +212,19 @@ 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 nasgenmap$$ = PropertyMap.newMap();
+ private static final PropertyMap map$ = PropertyMap.newMap().setIsShared();
+
+ static PropertyMap getInitialMap() {
+ return map$;
+ }
- AnonymousFunction() {
- super("", GlobalFunctions.ANONYMOUS, nasgenmap$$, null);
+ AnonymousFunction(final Global global) {
+ super("", GlobalFunctions.ANONYMOUS, global.getAnonymousFunctionMap(), null);
}
}
- static ScriptFunctionImpl newAnonymousFunction() {
- return new AnonymousFunction();
+ static ScriptFunctionImpl newAnonymousFunction(final Global global) {
+ return new AnonymousFunction(global);
}
/**
diff --git a/src/jdk/nashorn/internal/runtime/AccessorProperty.java b/src/jdk/nashorn/internal/runtime/AccessorProperty.java
index 6840d458..f7ece9df 100644
--- a/src/jdk/nashorn/internal/runtime/AccessorProperty.java
+++ b/src/jdk/nashorn/internal/runtime/AccessorProperty.java
@@ -107,6 +107,20 @@ public class AccessorProperty extends Property {
SPILL_ELEMENT_SETTER = MH.filterArguments(MH.arrayElementSetter(Object[].class), 0, spillGetter);
}
+ /**
+ * Create a new accessor property. Factory method used by nasgen generated code.
+ *
+ * @param key {@link Property} key.
+ * @param propertyFlags {@link Property} flags.
+ * @param getter {@link Property} get accessor method.
+ * @param setter {@link Property} set accessor method.
+ *
+ * @return New {@link AccessorProperty} created.
+ */
+ public static AccessorProperty create(final String key, final int propertyFlags, final MethodHandle getter, final MethodHandle setter) {
+ return new AccessorProperty(key, propertyFlags, -1, getter, setter);
+ }
+
/** Seed getter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */
private MethodHandle primitiveGetter;
diff --git a/src/jdk/nashorn/internal/runtime/Context.java b/src/jdk/nashorn/internal/runtime/Context.java
index 218be74e..8f00d521 100644
--- a/src/jdk/nashorn/internal/runtime/Context.java
+++ b/src/jdk/nashorn/internal/runtime/Context.java
@@ -253,13 +253,7 @@ public final class Context {
this.env = new ScriptEnvironment(options, out, err);
this._strict = env._strict;
this.appLoader = appLoader;
- this.scriptLoader = (ScriptLoader)AccessController.doPrivileged(
- new PrivilegedAction<ClassLoader>() {
- @Override
- public ClassLoader run() {
- return new ScriptLoader(sharedLoader, Context.this);
- }
- });
+ this.scriptLoader = env._loader_per_compile? null : createNewLoader();
this.errors = errors;
// if user passed -classpath option, make a class loader with that and set it as
diff --git a/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java b/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java
index 34db0cb3..1ce18b63 100644
--- a/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java
+++ b/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java
@@ -41,6 +41,7 @@ public class PropertyListenerManager implements PropertyListener {
private static int listenersRemoved;
/**
+ * Return aggregate listeners added to all PropertyListenerManagers
* @return the listenersAdded
*/
public static int getListenersAdded() {
@@ -48,12 +49,21 @@ public class PropertyListenerManager implements PropertyListener {
}
/**
+ * 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
/**
diff --git a/src/jdk/nashorn/internal/runtime/PropertyMap.java b/src/jdk/nashorn/internal/runtime/PropertyMap.java
index f8d9b437..05e8dc78 100644
--- a/src/jdk/nashorn/internal/runtime/PropertyMap.java
+++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java
@@ -25,11 +25,8 @@
package jdk.nashorn.internal.runtime;
-import jdk.nashorn.internal.scripts.JO;
-
import static jdk.nashorn.internal.runtime.PropertyHashMap.EMPTY_HASHMAP;
-import java.lang.invoke.MethodHandle;
import java.lang.invoke.SwitchPoint;
import java.lang.ref.WeakReference;
import java.util.Arrays;
@@ -57,9 +54,8 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
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;
-
- /** Empty map used for seed map for JO$ objects */
- private static final PropertyMap EMPTY_MAP = new PropertyMap(EMPTY_HASHMAP);
+ /** 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;
@@ -145,16 +141,17 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
- * Duplicates this PropertyMap instance. This is used by nasgen generated
- * prototype and constructor classes. {@link PropertyMap} used for singletons
- * like these (and global instance) are duplicated using this method and used.
- * The original filled map referenced by static fields of prototype and
- * constructor classes are not touched. This allows multiple independent global
- * instances to be used within a single context instance.
+ * Duplicates this PropertyMap instance. This is used to duplicate 'shared'
+ * maps {@link PropertyMap} used as process wide singletons. Shared maps are
+ * duplicated for every global scope object. That way listeners, proto and property
+ * histories are scoped within a global scope.
*
* @return Duplicated {@link PropertyMap}.
*/
public PropertyMap duplicate() {
+ if (Context.DEBUG) {
+ duplicatedCount++;
+ }
return new PropertyMap(this.properties);
}
@@ -173,6 +170,15 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
+ * Public property map allocator. Used by nasgen generated code.
+ * @param properties Collection of initial properties.
+ * @return New {@link PropertyMap}.
+ */
+ public static PropertyMap newMap(final Collection<Property> properties) {
+ return (properties == null || properties.isEmpty())? newMap() : newMap(properties, 0, 0, 0);
+ }
+
+ /**
* Return a sharable empty map.
*
* @return New empty {@link PropertyMap}.
@@ -199,6 +205,8 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
* @return A shared {@link SwitchPoint} for the property.
*/
public SwitchPoint getProtoGetSwitchPoint(final ScriptObject proto, final String key) {
+ assert !isShared() : "proto SwitchPoint from a shared PropertyMap";
+
if (proto == null) {
return null;
}
@@ -227,6 +235,8 @@ 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";
+
if (protoGetSwitches != null) {
final String key = property.getKey();
final SwitchPoint sp = protoGetSwitches.get(key);
@@ -241,17 +251,6 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
- * Add a property to the map.
- *
- * @param property {@link Property} being added.
- *
- * @return New {@link PropertyMap} with {@link Property} added.
- */
- public PropertyMap newProperty(final Property property) {
- return addProperty(property);
- }
-
- /**
* Add a property to the map, re-binding its getters and setters,
* if available, to a given receiver. This is typically the global scope. See
* {@link ScriptObject#addBoundProperties(ScriptObject)}
@@ -261,23 +260,8 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
*
* @return New {@link PropertyMap} with {@link Property} added.
*/
- PropertyMap newPropertyBind(final AccessorProperty property, final ScriptObject bindTo) {
- return newProperty(new AccessorProperty(property, bindTo));
- }
-
- /**
- * Add a new accessor property to the map.
- *
- * @param key {@link Property} key.
- * @param propertyFlags {@link Property} flags.
- * @param slot {@link Property} slot.
- * @param getter {@link Property} get accessor method.
- * @param setter {@link Property} set accessor method.
- *
- * @return New {@link PropertyMap} with {@link AccessorProperty} added.
- */
- public PropertyMap newProperty(final String key, final int propertyFlags, final int slot, final MethodHandle getter, final MethodHandle setter) {
- return newProperty(new AccessorProperty(key, propertyFlags, slot, getter, setter));
+ PropertyMap addPropertyBind(final AccessorProperty property, final ScriptObject bindTo) {
+ return addProperty(new AccessorProperty(property, bindTo));
}
/**
@@ -479,6 +463,28 @@ 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.
@@ -544,6 +550,8 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
* @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";
+
if (protoHistory == null) {
protoHistory = new WeakHashMap<>();
}
@@ -558,6 +566,8 @@ 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<>();
@@ -683,6 +693,15 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
}
/**
+ * 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.
@@ -745,6 +764,8 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
* @return New {@link PropertyMap} with prototype changed.
*/
PropertyMap changeProto(final ScriptObject oldProto, final ScriptObject newProto) {
+ assert !isShared() : "proto associated with a shared PropertyMap";
+
if (oldProto == newProto) {
return this;
}
@@ -860,6 +881,8 @@ public final class PropertyMap implements Iterable<Object>, PropertyListener {
// 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;
private static int protoHistoryHit;
@@ -880,6 +903,20 @@ 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() {
+ return duplicatedCount;
+ }
+
+ /**
* @return The number of times history was successfully used.
*/
public static int getHistoryHit() {
diff --git a/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java b/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
index f04dedf0..a2f1f4a0 100644
--- a/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
+++ b/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java
@@ -119,9 +119,15 @@ public final class ScriptEnvironment {
/** Create a new class loaded for each compilation */
public final boolean _loader_per_compile;
+ /** Do not support Java support extensions. */
+ public final boolean _no_java;
+
/** Do not support non-standard syntax extensions. */
public final boolean _no_syntax_extensions;
+ /** Do not support typed arrays. */
+ public final boolean _no_typed_arrays;
+
/** Package to which generated class files are added */
public final String _package;
@@ -207,7 +213,9 @@ public final class ScriptEnvironment {
_fx = options.getBoolean("fx");
_lazy_compilation = options.getBoolean("lazy.compilation");
_loader_per_compile = options.getBoolean("loader.per.compile");
+ _no_java = options.getBoolean("no.java");
_no_syntax_extensions = options.getBoolean("no.syntax.extensions");
+ _no_typed_arrays = options.getBoolean("no.typed.arrays");
_package = options.getString("package");
_parse_only = options.getBoolean("parse.only");
_print_ast = options.getBoolean("print.ast");
diff --git a/src/jdk/nashorn/internal/runtime/ScriptObject.java b/src/jdk/nashorn/internal/runtime/ScriptObject.java
index e4eaf77e..c56c32c7 100644
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java
+++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java
@@ -213,7 +213,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source));
newMap = newMap.addProperty(prop);
} else {
- newMap = newMap.newPropertyBind((AccessorProperty)property, source);
+ newMap = newMap.addPropertyBind((AccessorProperty)property, source);
}
}
}
diff --git a/src/jdk/nashorn/internal/runtime/resources/Options.properties b/src/jdk/nashorn/internal/runtime/resources/Options.properties
index 4d7be62b..452ae88c 100644
--- a/src/jdk/nashorn/internal/runtime/resources/Options.properties
+++ b/src/jdk/nashorn/internal/runtime/resources/Options.properties
@@ -192,6 +192,14 @@ nashorn.option.loader.per.compile = { \
default=true \
}
+nashorn.option.no.java = { \
+ name="--no-java", \
+ short_name="-nj", \
+ is_undocumented=true, \
+ desc="No Java support", \
+ default=false \
+}
+
nashorn.option.no.syntax.extensions = { \
name="--no-syntax-extensions", \
short_name="-nse", \
@@ -200,6 +208,14 @@ nashorn.option.no.syntax.extensions = { \
default=false \
}
+nashorn.option.no.typed.arrays = { \
+ name="--no-typed-arrays", \
+ short_name="-nta", \
+ is_undocumented=true, \
+ desc="No Typed arrays support", \
+ default=false \
+}
+
nashorn.option.package = { \
name="--package", \
is_undocumented=true, \
diff --git a/src/jdk/nashorn/internal/scripts/JO.java b/src/jdk/nashorn/internal/scripts/JO.java
index d6173918..f2f00062 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();
+ private static final PropertyMap map$ = PropertyMap.newMap().setIsShared();
/**
* Returns the initial property map to be used.