Mon, 08 Jul 2013 16:33:50 +0530
8020015: shared PropertyMaps should not be used without duplication
Reviewed-by: hannesw, attila
1.1 --- a/buildtools/nasgen/build.xml Fri Jul 05 19:35:39 2013 +0200 1.2 +++ b/buildtools/nasgen/build.xml Mon Jul 08 16:33:50 2013 +0530 1.3 @@ -42,7 +42,8 @@ 1.4 destdir="${build.classes.dir}" 1.5 classpath="${javac.classpath}" 1.6 debug="${javac.debug}" 1.7 - includeantruntime="false"> 1.8 + includeantruntime="false" fork="true"> 1.9 + <compilerarg value="-J-Djava.ext.dirs="/> 1.10 <compilerarg value="-Xlint:unchecked"/> 1.11 <compilerarg value="-Xlint:deprecation"/> 1.12 <compilerarg value="-XDignore.symbol.file"/>
2.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java Fri Jul 05 19:35:39 2013 +0200 2.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java Mon Jul 08 16:33:50 2013 +0530 2.3 @@ -37,14 +37,24 @@ 2.4 import static jdk.nashorn.internal.tools.nasgen.StringConstants.GET_CLASS_NAME; 2.5 import static jdk.nashorn.internal.tools.nasgen.StringConstants.GET_CLASS_NAME_DESC; 2.6 import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT; 2.7 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.LOOKUP_NEWPROPERTY; 2.8 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.LOOKUP_NEWPROPERTY_DESC; 2.9 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.LOOKUP_TYPE; 2.10 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_DESC; 2.11 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_FIELD_NAME; 2.12 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_NEWMAP; 2.13 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_NEWMAP_DESC; 2.14 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_TYPE; 2.15 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.ACCESSORPROPERTY_CREATE; 2.16 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.ACCESSORPROPERTY_CREATE_DESC; 2.17 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.ACCESSORPROPERTY_TYPE; 2.18 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.LIST_DESC; 2.19 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.ARRAYLIST_TYPE; 2.20 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.ARRAYLIST_INIT_DESC; 2.21 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTION_TYPE; 2.22 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTION_ADD; 2.23 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTION_ADD_DESC; 2.24 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTIONS_TYPE; 2.25 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTIONS_EMPTY_LIST; 2.26 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC; 2.27 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME; 2.28 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_SETISSHARED; 2.29 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_SETISSHARED_DESC; 2.30 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP; 2.31 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP_DESC; 2.32 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE; 2.33 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC; 2.34 import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION; 2.35 import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION_DESC; 2.36 @@ -161,17 +171,30 @@ 2.37 return new MethodGenerator(mv, access, name, desc); 2.38 } 2.39 2.40 - static void emitStaticInitPrefix(final MethodGenerator mi, final String className) { 2.41 + static void emitStaticInitPrefix(final MethodGenerator mi, final String className, final int memberCount) { 2.42 mi.visitCode(); 2.43 - mi.pushNull(); 2.44 - mi.putStatic(className, MAP_FIELD_NAME, MAP_DESC); 2.45 - mi.invokeStatic(MAP_TYPE, MAP_NEWMAP, MAP_NEWMAP_DESC); 2.46 - // stack: PropertyMap 2.47 + if (memberCount > 0) { 2.48 + // new ArrayList(int) 2.49 + mi.newObject(ARRAYLIST_TYPE); 2.50 + mi.dup(); 2.51 + mi.push(memberCount); 2.52 + mi.invokeSpecial(ARRAYLIST_TYPE, INIT, ARRAYLIST_INIT_DESC); 2.53 + // stack: ArrayList 2.54 + } else { 2.55 + // java.util.Collections.EMPTY_LIST 2.56 + mi.getStatic(COLLECTIONS_TYPE, COLLECTIONS_EMPTY_LIST, LIST_DESC); 2.57 + // stack List 2.58 + } 2.59 } 2.60 2.61 static void emitStaticInitSuffix(final MethodGenerator mi, final String className) { 2.62 - // stack: PropertyMap 2.63 - mi.putStatic(className, MAP_FIELD_NAME, MAP_DESC); 2.64 + // stack: Collection 2.65 + // pmap = PropertyMap.newMap(Collection<Property>); 2.66 + mi.invokeStatic(PROPERTYMAP_TYPE, PROPERTYMAP_NEWMAP, PROPERTYMAP_NEWMAP_DESC); 2.67 + // pmap.setIsShared(); 2.68 + mi.invokeVirtual(PROPERTYMAP_TYPE, PROPERTYMAP_SETISSHARED, PROPERTYMAP_SETISSHARED_DESC); 2.69 + // $nasgenmap$ = pmap; 2.70 + mi.putStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC); 2.71 mi.returnVoid(); 2.72 mi.computeMaxs(); 2.73 mi.visitEnd(); 2.74 @@ -235,9 +258,9 @@ 2.75 } 2.76 2.77 static void addMapField(final ClassVisitor cv) { 2.78 - // add a MAP static field 2.79 + // add a PropertyMap static field 2.80 final FieldVisitor fv = cv.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, 2.81 - MAP_FIELD_NAME, MAP_DESC, null, null); 2.82 + PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC, null, null); 2.83 if (fv != null) { 2.84 fv.visitEnd(); 2.85 } 2.86 @@ -278,7 +301,11 @@ 2.87 2.88 static void linkerAddGetterSetter(final MethodGenerator mi, final String className, final MemberInfo memInfo) { 2.89 final String propertyName = memInfo.getName(); 2.90 - // stack: PropertyMap 2.91 + // stack: Collection 2.92 + // dup of Collection instance 2.93 + mi.dup(); 2.94 + 2.95 + // property = AccessorProperty.create(key, flags, getter, setter); 2.96 mi.loadLiteral(propertyName); 2.97 // setup flags 2.98 mi.push(memInfo.getAttributes()); 2.99 @@ -292,13 +319,21 @@ 2.100 javaName = SETTER_PREFIX + memInfo.getJavaName(); 2.101 mi.visitLdcInsn(new Handle(H_INVOKEVIRTUAL, className, javaName, setterDesc(memInfo))); 2.102 } 2.103 - mi.invokeStatic(LOOKUP_TYPE, LOOKUP_NEWPROPERTY, LOOKUP_NEWPROPERTY_DESC); 2.104 - // stack: PropertyMap 2.105 + mi.invokeStatic(ACCESSORPROPERTY_TYPE, ACCESSORPROPERTY_CREATE, ACCESSORPROPERTY_CREATE_DESC); 2.106 + // boolean Collection.add(property) 2.107 + mi.invokeInterface(COLLECTION_TYPE, COLLECTION_ADD, COLLECTION_ADD_DESC); 2.108 + // pop return value of Collection.add 2.109 + mi.pop(); 2.110 + // stack: Collection 2.111 } 2.112 2.113 static void linkerAddGetterSetter(final MethodGenerator mi, final String className, final MemberInfo getter, final MemberInfo setter) { 2.114 final String propertyName = getter.getName(); 2.115 - // stack: PropertyMap 2.116 + // stack: Collection 2.117 + // dup of Collection instance 2.118 + mi.dup(); 2.119 + 2.120 + // property = AccessorProperty.create(key, flags, getter, setter); 2.121 mi.loadLiteral(propertyName); 2.122 // setup flags 2.123 mi.push(getter.getAttributes()); 2.124 @@ -312,8 +347,12 @@ 2.125 mi.visitLdcInsn(new Handle(H_INVOKESTATIC, className, 2.126 setter.getJavaName(), setter.getJavaDesc())); 2.127 } 2.128 - mi.invokeStatic(LOOKUP_TYPE, LOOKUP_NEWPROPERTY, LOOKUP_NEWPROPERTY_DESC); 2.129 - // stack: PropertyMap 2.130 + mi.invokeStatic(ACCESSORPROPERTY_TYPE, ACCESSORPROPERTY_CREATE, ACCESSORPROPERTY_CREATE_DESC); 2.131 + // boolean Collection.add(property) 2.132 + mi.invokeInterface(COLLECTION_TYPE, COLLECTION_ADD, COLLECTION_ADD_DESC); 2.133 + // pop return value of Collection.add 2.134 + mi.pop(); 2.135 + // stack: Collection 2.136 } 2.137 2.138 static ScriptClassInfo getScriptClassInfo(final String fileName) throws IOException {
3.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java Fri Jul 05 19:35:39 2013 +0200 3.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java Mon Jul 08 16:33:50 2013 +0530 3.3 @@ -32,11 +32,11 @@ 3.4 import static jdk.nashorn.internal.tools.nasgen.StringConstants.CONSTRUCTOR_SUFFIX; 3.5 import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC; 3.6 import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT; 3.7 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_DESC; 3.8 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_DUPLICATE; 3.9 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_DUPLICATE_DESC; 3.10 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_FIELD_NAME; 3.11 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_TYPE; 3.12 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC; 3.13 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE; 3.14 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE_DESC; 3.15 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME; 3.16 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE; 3.17 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC; 3.18 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR; 3.19 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC; 3.20 @@ -129,7 +129,7 @@ 3.21 3.22 private void emitStaticInitializer() { 3.23 final MethodGenerator mi = makeStaticInitializer(); 3.24 - emitStaticInitPrefix(mi, className); 3.25 + emitStaticInitPrefix(mi, className, memberCount); 3.26 3.27 for (final MemberInfo memInfo : scriptClassInfo.getMembers()) { 3.28 if (memInfo.isConstructorFunction() || memInfo.isConstructorProperty()) { 3.29 @@ -170,10 +170,10 @@ 3.30 3.31 private void loadMap(final MethodGenerator mi) { 3.32 if (memberCount > 0) { 3.33 - mi.getStatic(className, MAP_FIELD_NAME, MAP_DESC); 3.34 + mi.getStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC); 3.35 // make sure we use duplicated PropertyMap so that original map 3.36 - // stays intact and so can be used for many globals in same context 3.37 - mi.invokeVirtual(MAP_TYPE, MAP_DUPLICATE, MAP_DUPLICATE_DESC); 3.38 + // stays intact and so can be used for many globals. 3.39 + mi.invokeVirtual(PROPERTYMAP_TYPE, PROPERTYMAP_DUPLICATE, PROPERTYMAP_DUPLICATE_DESC); 3.40 } 3.41 } 3.42
4.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MethodGenerator.java Fri Jul 05 19:35:39 2013 +0200 4.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/MethodGenerator.java Mon Jul 08 16:33:50 2013 +0530 4.3 @@ -57,6 +57,7 @@ 4.4 import static jdk.internal.org.objectweb.asm.Opcodes.IASTORE; 4.5 import static jdk.internal.org.objectweb.asm.Opcodes.ICONST_0; 4.6 import static jdk.internal.org.objectweb.asm.Opcodes.ILOAD; 4.7 +import static jdk.internal.org.objectweb.asm.Opcodes.INVOKEINTERFACE; 4.8 import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESPECIAL; 4.9 import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESTATIC; 4.10 import static jdk.internal.org.objectweb.asm.Opcodes.INVOKEVIRTUAL; 4.11 @@ -347,6 +348,10 @@ 4.12 } 4.13 4.14 // invokes, field get/sets 4.15 + void invokeInterface(final String owner, final String method, final String desc) { 4.16 + super.visitMethodInsn(INVOKEINTERFACE, owner, method, desc); 4.17 + } 4.18 + 4.19 void invokeVirtual(final String owner, final String method, final String desc) { 4.20 super.visitMethodInsn(INVOKEVIRTUAL, owner, method, desc); 4.21 }
5.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java Fri Jul 05 19:35:39 2013 +0200 5.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/PrototypeGenerator.java Mon Jul 08 16:33:50 2013 +0530 5.3 @@ -30,11 +30,11 @@ 5.4 import static jdk.internal.org.objectweb.asm.Opcodes.V1_7; 5.5 import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC; 5.6 import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT; 5.7 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_DESC; 5.8 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_DUPLICATE; 5.9 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_DUPLICATE_DESC; 5.10 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_FIELD_NAME; 5.11 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_TYPE; 5.12 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC; 5.13 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE; 5.14 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DUPLICATE_DESC; 5.15 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME; 5.16 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE; 5.17 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC; 5.18 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_TYPE; 5.19 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPE_SUFFIX; 5.20 @@ -67,6 +67,7 @@ 5.21 // add <clinit> 5.22 emitStaticInitializer(); 5.23 } 5.24 + 5.25 // add <init> 5.26 emitConstructor(); 5.27 5.28 @@ -106,7 +107,7 @@ 5.29 5.30 private void emitStaticInitializer() { 5.31 final MethodGenerator mi = makeStaticInitializer(); 5.32 - emitStaticInitPrefix(mi, className); 5.33 + emitStaticInitPrefix(mi, className, memberCount); 5.34 for (final MemberInfo memInfo : scriptClassInfo.getMembers()) { 5.35 if (memInfo.isPrototypeFunction() || memInfo.isPrototypeProperty()) { 5.36 linkerAddGetterSetter(mi, className, memInfo); 5.37 @@ -124,10 +125,10 @@ 5.38 mi.loadThis(); 5.39 if (memberCount > 0) { 5.40 // call "super(map$)" 5.41 - mi.getStatic(className, MAP_FIELD_NAME, MAP_DESC); 5.42 + mi.getStatic(className, PROPERTYMAP_FIELD_NAME, PROPERTYMAP_DESC); 5.43 // make sure we use duplicated PropertyMap so that original map 5.44 - // stays intact and so can be used for many globals in same context 5.45 - mi.invokeVirtual(MAP_TYPE, MAP_DUPLICATE, MAP_DUPLICATE_DESC); 5.46 + // stays intact and so can be used for many global. 5.47 + mi.invokeVirtual(PROPERTYMAP_TYPE, PROPERTYMAP_DUPLICATE, PROPERTYMAP_DUPLICATE_DESC); 5.48 mi.invokeSpecial(PROTOTYPEOBJECT_TYPE, INIT, SCRIPTOBJECT_INIT_DESC); 5.49 // initialize Function type fields 5.50 initFunctionFields(mi);
6.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInstrumentor.java Fri Jul 05 19:35:39 2013 +0200 6.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ScriptClassInstrumentor.java Mon Jul 08 16:33:50 2013 +0530 6.3 @@ -37,10 +37,7 @@ 6.4 import static jdk.nashorn.internal.tools.nasgen.StringConstants.CLINIT; 6.5 import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC; 6.6 import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT; 6.7 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_DESC; 6.8 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.MAP_FIELD_NAME; 6.9 import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC; 6.10 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTOBJECT_INIT_DESC; 6.11 import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTOBJECT_TYPE; 6.12 6.13 import java.io.BufferedInputStream; 6.14 @@ -159,14 +156,7 @@ 6.15 public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc) { 6.16 if (isConstructor && opcode == INVOKESPECIAL && 6.17 INIT.equals(name) && SCRIPTOBJECT_TYPE.equals(owner)) { 6.18 - 6.19 - // replace call to empty super-constructor with one passing PropertyMap argument 6.20 - if (DEFAULT_INIT_DESC.equals(desc)) { 6.21 - super.visitFieldInsn(GETSTATIC, scriptClassInfo.getJavaName(), MAP_FIELD_NAME, MAP_DESC); 6.22 - super.visitMethodInsn(INVOKESPECIAL, SCRIPTOBJECT_TYPE, INIT, SCRIPTOBJECT_INIT_DESC); 6.23 - } else { 6.24 - super.visitMethodInsn(opcode, owner, name, desc); 6.25 - } 6.26 + super.visitMethodInsn(opcode, owner, name, desc); 6.27 6.28 if (memberCount > 0) { 6.29 // initialize @Property fields if needed 6.30 @@ -256,7 +246,7 @@ 6.31 } 6.32 // Now generate $clinit$ 6.33 final MethodGenerator mi = ClassGenerator.makeStaticInitializer(this, $CLINIT$); 6.34 - ClassGenerator.emitStaticInitPrefix(mi, className); 6.35 + ClassGenerator.emitStaticInitPrefix(mi, className, memberCount); 6.36 if (memberCount > 0) { 6.37 for (final MemberInfo memInfo : scriptClassInfo.getMembers()) { 6.38 if (memInfo.isInstanceProperty() || memInfo.isInstanceFunction()) {
7.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java Fri Jul 05 19:35:39 2013 +0200 7.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java Mon Jul 08 16:33:50 2013 +0530 7.3 @@ -27,10 +27,14 @@ 7.4 7.5 import java.lang.invoke.MethodHandle; 7.6 import java.lang.reflect.Method; 7.7 +import java.util.Collection; 7.8 +import java.util.ArrayList; 7.9 +import java.util.Collections; 7.10 +import java.util.List; 7.11 import jdk.internal.org.objectweb.asm.Type; 7.12 -import jdk.nashorn.internal.lookup.Lookup; 7.13 import jdk.nashorn.internal.objects.PrototypeObject; 7.14 import jdk.nashorn.internal.objects.ScriptFunctionImpl; 7.15 +import jdk.nashorn.internal.runtime.AccessorProperty; 7.16 import jdk.nashorn.internal.runtime.PropertyMap; 7.17 import jdk.nashorn.internal.runtime.ScriptFunction; 7.18 import jdk.nashorn.internal.runtime.ScriptObject; 7.19 @@ -40,15 +44,41 @@ 7.20 */ 7.21 @SuppressWarnings("javadoc") 7.22 public interface StringConstants { 7.23 + // standard jdk types, methods 7.24 static final Type TYPE_METHOD = Type.getType(Method.class); 7.25 static final Type TYPE_METHODHANDLE = Type.getType(MethodHandle.class); 7.26 static final Type TYPE_METHODHANDLE_ARRAY = Type.getType(MethodHandle[].class); 7.27 static final Type TYPE_OBJECT = Type.getType(Object.class); 7.28 static final Type TYPE_CLASS = Type.getType(Class.class); 7.29 static final Type TYPE_STRING = Type.getType(String.class); 7.30 + static final Type TYPE_COLLECTION = Type.getType(Collection.class); 7.31 + static final Type TYPE_COLLECTIONS = Type.getType(Collections.class); 7.32 + static final Type TYPE_ARRAYLIST = Type.getType(ArrayList.class); 7.33 + static final Type TYPE_LIST = Type.getType(List.class); 7.34 7.35 - // Nashorn types 7.36 - static final Type TYPE_LOOKUP = Type.getType(Lookup.class); 7.37 + static final String CLINIT = "<clinit>"; 7.38 + static final String INIT = "<init>"; 7.39 + static final String DEFAULT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE); 7.40 + 7.41 + static final String METHODHANDLE_TYPE = TYPE_METHODHANDLE.getInternalName(); 7.42 + static final String OBJECT_TYPE = TYPE_OBJECT.getInternalName(); 7.43 + static final String OBJECT_DESC = TYPE_OBJECT.getDescriptor(); 7.44 + static final String OBJECT_ARRAY_DESC = Type.getDescriptor(Object[].class); 7.45 + static final String ARRAYLIST_TYPE = TYPE_ARRAYLIST.getInternalName(); 7.46 + static final String COLLECTION_TYPE = TYPE_COLLECTION.getInternalName(); 7.47 + static final String COLLECTIONS_TYPE = TYPE_COLLECTIONS.getInternalName(); 7.48 + 7.49 + // java.util.Collection.add(Object) 7.50 + static final String COLLECTION_ADD = "add"; 7.51 + static final String COLLECTION_ADD_DESC = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, TYPE_OBJECT); 7.52 + // java.util.ArrayList.<init>(int) 7.53 + static final String ARRAYLIST_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE); 7.54 + // java.util.Collections.EMPTY_LIST 7.55 + static final String COLLECTIONS_EMPTY_LIST = "EMPTY_LIST"; 7.56 + static final String LIST_DESC = TYPE_LIST.getDescriptor(); 7.57 + 7.58 + // Nashorn types, methods 7.59 + static final Type TYPE_ACCESSORPROPERTY = Type.getType(AccessorProperty.class); 7.60 static final Type TYPE_PROPERTYMAP = Type.getType(PropertyMap.class); 7.61 static final Type TYPE_PROTOTYPEOBJECT = Type.getType(PrototypeObject.class); 7.62 static final Type TYPE_SCRIPTFUNCTION = Type.getType(ScriptFunction.class); 7.63 @@ -57,52 +87,56 @@ 7.64 7.65 static final String PROTOTYPE_SUFFIX = "$Prototype"; 7.66 static final String CONSTRUCTOR_SUFFIX = "$Constructor"; 7.67 + 7.68 // This field name is known to Nashorn runtime (Context). 7.69 // Synchronize the name change, if needed at all. 7.70 - static final String MAP_FIELD_NAME = "$nasgenmap$"; 7.71 + static final String PROPERTYMAP_FIELD_NAME = "$nasgenmap$"; 7.72 static final String $CLINIT$ = "$clinit$"; 7.73 - static final String CLINIT = "<clinit>"; 7.74 - static final String INIT = "<init>"; 7.75 - static final String DEFAULT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE); 7.76 7.77 - static final String SCRIPTOBJECT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_PROPERTYMAP); 7.78 + // AccessorProperty 7.79 + static final String ACCESSORPROPERTY_TYPE = TYPE_ACCESSORPROPERTY.getInternalName(); 7.80 + static final String ACCESSORPROPERTY_CREATE = "create"; 7.81 + static final String ACCESSORPROPERTY_CREATE_DESC = 7.82 + Type.getMethodDescriptor(TYPE_ACCESSORPROPERTY, TYPE_STRING, Type.INT_TYPE, TYPE_METHODHANDLE, TYPE_METHODHANDLE); 7.83 7.84 - static final String METHODHANDLE_TYPE = TYPE_METHODHANDLE.getInternalName(); 7.85 + // PropertyMap 7.86 + static final String PROPERTYMAP_TYPE = TYPE_PROPERTYMAP.getInternalName(); 7.87 + static final String PROPERTYMAP_DESC = TYPE_PROPERTYMAP.getDescriptor(); 7.88 + static final String PROPERTYMAP_NEWMAP = "newMap"; 7.89 + static final String PROPERTYMAP_NEWMAP_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP, TYPE_COLLECTION); 7.90 + static final String PROPERTYMAP_DUPLICATE = "duplicate"; 7.91 + static final String PROPERTYMAP_DUPLICATE_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP); 7.92 + static final String PROPERTYMAP_SETISSHARED = "setIsShared"; 7.93 + static final String PROPERTYMAP_SETISSHARED_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP); 7.94 7.95 - static final String OBJECT_TYPE = TYPE_OBJECT.getInternalName(); 7.96 - static final String OBJECT_DESC = TYPE_OBJECT.getDescriptor(); 7.97 - static final String OBJECT_ARRAY_DESC = Type.getDescriptor(Object[].class); 7.98 + // PrototypeObject 7.99 + static final String PROTOTYPEOBJECT_TYPE = TYPE_PROTOTYPEOBJECT.getInternalName(); 7.100 + static final String PROTOTYPEOBJECT_SETCONSTRUCTOR = "setConstructor"; 7.101 + static final String PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_OBJECT, TYPE_OBJECT); 7.102 7.103 + // ScriptFunction 7.104 static final String SCRIPTFUNCTION_TYPE = TYPE_SCRIPTFUNCTION.getInternalName(); 7.105 + static final String SCRIPTFUNCTION_SETARITY = "setArity"; 7.106 + static final String SCRIPTFUNCTION_SETARITY_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE); 7.107 + static final String SCRIPTFUNCTION_SETPROTOTYPE = "setPrototype"; 7.108 + static final String SCRIPTFUNCTION_SETPROTOTYPE_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_OBJECT); 7.109 + 7.110 + // ScriptFunctionImpl 7.111 static final String SCRIPTFUNCTIONIMPL_TYPE = TYPE_SCRIPTFUNCTIONIMPL.getInternalName(); 7.112 static final String SCRIPTFUNCTIONIMPL_MAKEFUNCTION = "makeFunction"; 7.113 static final String SCRIPTFUNCTIONIMPL_MAKEFUNCTION_DESC = 7.114 Type.getMethodDescriptor(TYPE_SCRIPTFUNCTION, TYPE_STRING, TYPE_METHODHANDLE); 7.115 static final String SCRIPTFUNCTIONIMPL_MAKEFUNCTION_SPECS_DESC = 7.116 Type.getMethodDescriptor(TYPE_SCRIPTFUNCTION, TYPE_STRING, TYPE_METHODHANDLE, TYPE_METHODHANDLE_ARRAY); 7.117 - 7.118 static final String SCRIPTFUNCTIONIMPL_INIT_DESC3 = 7.119 Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_METHODHANDLE, TYPE_METHODHANDLE_ARRAY); 7.120 static final String SCRIPTFUNCTIONIMPL_INIT_DESC4 = 7.121 Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_METHODHANDLE, TYPE_PROPERTYMAP, TYPE_METHODHANDLE_ARRAY); 7.122 - static final String SCRIPTFUNCTION_SETARITY = "setArity"; 7.123 - static final String SCRIPTFUNCTION_SETARITY_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE); 7.124 - static final String SCRIPTFUNCTION_SETPROTOTYPE = "setPrototype"; 7.125 - static final String SCRIPTFUNCTION_SETPROTOTYPE_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_OBJECT); 7.126 - static final String PROTOTYPEOBJECT_TYPE = TYPE_PROTOTYPEOBJECT.getInternalName(); 7.127 - static final String PROTOTYPEOBJECT_SETCONSTRUCTOR = "setConstructor"; 7.128 - static final String PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_OBJECT, TYPE_OBJECT); 7.129 + 7.130 + // ScriptObject 7.131 static final String SCRIPTOBJECT_TYPE = TYPE_SCRIPTOBJECT.getInternalName(); 7.132 - static final String MAP_TYPE = TYPE_PROPERTYMAP.getInternalName(); 7.133 - static final String MAP_DESC = TYPE_PROPERTYMAP.getDescriptor(); 7.134 - static final String MAP_NEWMAP = "newMap"; 7.135 - static final String MAP_NEWMAP_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP); 7.136 - static final String MAP_DUPLICATE = "duplicate"; 7.137 - static final String MAP_DUPLICATE_DESC = Type.getMethodDescriptor(TYPE_PROPERTYMAP); 7.138 - static final String LOOKUP_TYPE = TYPE_LOOKUP.getInternalName(); 7.139 - static final String LOOKUP_NEWPROPERTY = "newProperty"; 7.140 - static final String LOOKUP_NEWPROPERTY_DESC = 7.141 - Type.getMethodDescriptor(TYPE_PROPERTYMAP, TYPE_PROPERTYMAP, TYPE_STRING, Type.INT_TYPE, TYPE_METHODHANDLE, TYPE_METHODHANDLE); 7.142 + static final String SCRIPTOBJECT_INIT_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_PROPERTYMAP); 7.143 + 7.144 static final String GETTER_PREFIX = "G$"; 7.145 static final String SETTER_PREFIX = "S$"; 7.146
8.1 --- a/make/code_coverage.xml Fri Jul 05 19:35:39 2013 +0200 8.2 +++ b/make/code_coverage.xml Mon Jul 08 16:33:50 2013 +0530 8.3 @@ -60,16 +60,8 @@ 8.4 <copy todir="${build.dir}/to_be_instrumented"> 8.5 <fileset dir="${build.classes.dir}"> 8.6 <include name="**/*.class"/> 8.7 - <include name="**/*.clazz"/> 8.8 </fileset> 8.9 </copy> 8.10 - 8.11 - <move todir="${build.dir}/to_be_instrumented/jdk/nashorn/internal/objects"> 8.12 - <fileset dir="${build.dir}/to_be_instrumented/jdk/nashorn/internal/objects"> 8.13 - <include name="**/*.clazz"/> 8.14 - </fileset> 8.15 - <mapper type="glob" from="*.clazz" to="*.class"/> 8.16 - </move> 8.17 </target> 8.18 8.19 <target name="generate-cc-template" depends="prepare-to-be-instrumented" description="Generates code coverage template for dynamic CC" if="cc.generate.template">
9.1 --- a/make/project.properties Fri Jul 05 19:35:39 2013 +0200 9.2 +++ b/make/project.properties Mon Jul 08 16:33:50 2013 +0530 9.3 @@ -200,6 +200,9 @@ 9.4 9.5 # test262 test frameworks 9.6 test262-test-sys-prop.test.js.framework=\ 9.7 + --class-cache-size=0 \ 9.8 + --no-java \ 9.9 + --no-typed-arrays \ 9.10 -timezone=PST \ 9.11 ${test.script.dir}/test262.js \ 9.12 ${test262.dir}/test/harness/framework.js \
10.1 --- a/src/jdk/nashorn/internal/lookup/Lookup.java Fri Jul 05 19:35:39 2013 +0200 10.2 +++ b/src/jdk/nashorn/internal/lookup/Lookup.java Mon Jul 08 16:33:50 2013 +0530 10.3 @@ -125,44 +125,6 @@ 10.4 } 10.5 10.6 /** 10.7 - * Create a new {@link Property} 10.8 - * 10.9 - * @param map property map 10.10 - * @param key property key 10.11 - * @param flags property flags 10.12 - * @param propertyGetter getter for property if available, null otherwise 10.13 - * @param propertySetter setter for property if available, null otherwise 10.14 - * 10.15 - * @return new property map, representing {@code PropertyMap} with the new property added to it 10.16 - */ 10.17 - @SuppressWarnings("fallthrough") 10.18 - public static PropertyMap newProperty(final PropertyMap map, final String key, final int flags, final MethodHandle propertyGetter, final MethodHandle propertySetter) { 10.19 - MethodHandle getter = propertyGetter; 10.20 - MethodHandle setter = propertySetter; 10.21 - 10.22 - // TODO: this is temporary code. This code exists to support reflective 10.23 - // field reader/writer handles generated by "unreflect" lookup. 10.24 - 10.25 - switch (getter.type().parameterCount()) { 10.26 - case 0: 10.27 - // A static field reader, so drop the 'self' argument. 10.28 - getter = MH.dropArguments(getter, 0, Object.class); 10.29 - if (setter != null) { 10.30 - setter = MH.dropArguments(setter, 0, Object.class); 10.31 - } 10.32 - // fall through 10.33 - case 1: 10.34 - // standard getter that accepts 'self'. 10.35 - break; 10.36 - default: 10.37 - // Huh!! something wrong.. 10.38 - throw new IllegalArgumentException("getter/setter has wrong arguments"); 10.39 - } 10.40 - 10.41 - return map.newProperty(key, flags, -1, getter, setter); 10.42 - } 10.43 - 10.44 - /** 10.45 * This method filters primitive return types using JavaScript semantics. For example, 10.46 * an (int) cast of a double in Java land is not the same thing as invoking toInt32 on it. 10.47 * If you are returning values to JavaScript that have to be of a specific type, this is
11.1 --- a/src/jdk/nashorn/internal/objects/ArrayBufferView.java Fri Jul 05 19:35:39 2013 +0200 11.2 +++ b/src/jdk/nashorn/internal/objects/ArrayBufferView.java Mon Jul 08 16:33:50 2013 +0530 11.3 @@ -46,14 +46,17 @@ 11.4 return $nasgenmap$; 11.5 } 11.6 11.7 - ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength) { 11.8 + private ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength, final Global global) { 11.9 + super(global.getArrayBufferViewMap()); 11.10 checkConstructorArgs(buffer, byteOffset, elementLength); 11.11 - final Global global = Global.instance(); 11.12 - this.setMap(global.getArrayBufferViewMap()); 11.13 this.setProto(getPrototype(global)); 11.14 this.setArray(factory().createArrayData(buffer, byteOffset, elementLength)); 11.15 } 11.16 11.17 + ArrayBufferView(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength) { 11.18 + this(buffer, byteOffset, elementLength, Global.instance()); 11.19 + } 11.20 + 11.21 private void checkConstructorArgs(final NativeArrayBuffer buffer, final int byteOffset, final int elementLength) { 11.22 if (byteOffset < 0 || elementLength < 0) { 11.23 throw new RuntimeException("byteOffset or length must not be negative");
12.1 --- a/src/jdk/nashorn/internal/objects/Global.java Fri Jul 05 19:35:39 2013 +0200 12.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Mon Jul 08 16:33:50 2013 +0530 12.3 @@ -43,7 +43,6 @@ 12.4 import java.util.Map; 12.5 import jdk.internal.dynalink.linker.GuardedInvocation; 12.6 import jdk.internal.dynalink.linker.LinkRequest; 12.7 -import jdk.nashorn.internal.lookup.MethodHandleFactory; 12.8 import jdk.nashorn.internal.objects.annotations.Attribute; 12.9 import jdk.nashorn.internal.objects.annotations.Property; 12.10 import jdk.nashorn.internal.objects.annotations.ScriptClass; 12.11 @@ -389,6 +388,7 @@ 12.12 private PropertyMap prototypeObjectMap; 12.13 private PropertyMap objectMap; 12.14 private PropertyMap functionMap; 12.15 + private PropertyMap anonymousFunctionMap; 12.16 private PropertyMap strictFunctionMap; 12.17 private PropertyMap boundFunctionMap; 12.18 12.19 @@ -409,7 +409,6 @@ 12.20 private static final MethodHandle EXIT = findOwnMH("exit", Object.class, Object.class, Object.class); 12.21 12.22 // initialized by nasgen 12.23 - @SuppressWarnings("unused") 12.24 private static PropertyMap $nasgenmap$; 12.25 12.26 /** 12.27 @@ -418,14 +417,14 @@ 12.28 * @param context the context 12.29 */ 12.30 public Global(final Context context) { 12.31 - this.setContext(context); 12.32 - this.setIsScope(); 12.33 /* 12.34 * Duplicate global's map and use it. This way the initial Map filled 12.35 * by nasgen (referenced from static field in this class) is retained 12.36 - * 'as is'. This allows multiple globals to be used within a context. 12.37 + * 'as is' (as that one is process wide singleton. 12.38 */ 12.39 - this.setMap(getMap().duplicate()); 12.40 + super($nasgenmap$.duplicate()); 12.41 + this.setContext(context); 12.42 + this.setIsScope(); 12.43 12.44 final int cacheSize = context.getEnv()._class_cache_size; 12.45 if (cacheSize > 0) { 12.46 @@ -1018,6 +1017,10 @@ 12.47 return functionMap; 12.48 } 12.49 12.50 + PropertyMap getAnonymousFunctionMap() { 12.51 + return anonymousFunctionMap; 12.52 + } 12.53 + 12.54 PropertyMap getStrictFunctionMap() { 12.55 return strictFunctionMap; 12.56 } 12.57 @@ -1538,7 +1541,7 @@ 12.58 final ScriptEnvironment env = getContext().getEnv(); 12.59 12.60 // duplicate PropertyMaps of Native* classes 12.61 - copyInitialMaps(); 12.62 + copyInitialMaps(env); 12.63 12.64 // initialize Function and Object constructor 12.65 initFunctionAndObject(); 12.66 @@ -1599,12 +1602,16 @@ 12.67 initErrorObjects(); 12.68 12.69 // java access 12.70 - initJavaAccess(); 12.71 + if (! env._no_java) { 12.72 + initJavaAccess(); 12.73 + } 12.74 12.75 - initTypedArray(); 12.76 + if (! env._no_typed_arrays) { 12.77 + initTypedArray(); 12.78 + } 12.79 12.80 if (env._scripting) { 12.81 - initScripting(); 12.82 + initScripting(env); 12.83 } 12.84 12.85 if (Context.DEBUG && System.getSecurityManager() == null) { 12.86 @@ -1685,7 +1692,7 @@ 12.87 this.builtinJavaApi = initConstructor("Java"); 12.88 } 12.89 12.90 - private void initScripting() { 12.91 + private void initScripting(final ScriptEnvironment scriptEnv) { 12.92 Object value; 12.93 value = ScriptFunctionImpl.makeFunction("readLine", ScriptingFunctions.READLINE); 12.94 addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value); 12.95 @@ -1704,7 +1711,6 @@ 12.96 12.97 // Nashorn extension: global.$OPTIONS (scripting-mode-only) 12.98 final ScriptObject options = newObject(); 12.99 - final ScriptEnvironment scriptEnv = getContext().getEnv(); 12.100 copyOptions(options, scriptEnv); 12.101 addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options); 12.102 12.103 @@ -1857,20 +1863,17 @@ 12.104 } 12.105 } 12.106 12.107 - private void copyInitialMaps() { 12.108 + private void copyInitialMaps(final ScriptEnvironment env) { 12.109 this.accessorPropertyDescriptorMap = AccessorPropertyDescriptor.getInitialMap().duplicate(); 12.110 - this.arrayBufferViewMap = ArrayBufferView.getInitialMap().duplicate(); 12.111 this.dataPropertyDescriptorMap = DataPropertyDescriptor.getInitialMap().duplicate(); 12.112 this.genericPropertyDescriptorMap = GenericPropertyDescriptor.getInitialMap().duplicate(); 12.113 this.nativeArgumentsMap = NativeArguments.getInitialMap().duplicate(); 12.114 this.nativeArrayMap = NativeArray.getInitialMap().duplicate(); 12.115 - this.nativeArrayBufferMap = NativeArrayBuffer.getInitialMap().duplicate(); 12.116 this.nativeBooleanMap = NativeBoolean.getInitialMap().duplicate(); 12.117 this.nativeDateMap = NativeDate.getInitialMap().duplicate(); 12.118 this.nativeErrorMap = NativeError.getInitialMap().duplicate(); 12.119 this.nativeEvalErrorMap = NativeEvalError.getInitialMap().duplicate(); 12.120 this.nativeJSAdapterMap = NativeJSAdapter.getInitialMap().duplicate(); 12.121 - this.nativeJavaImporterMap = NativeJavaImporter.getInitialMap().duplicate(); 12.122 this.nativeNumberMap = NativeNumber.getInitialMap().duplicate(); 12.123 this.nativeRangeErrorMap = NativeRangeError.getInitialMap().duplicate(); 12.124 this.nativeReferenceErrorMap = NativeReferenceError.getInitialMap().duplicate(); 12.125 @@ -1883,9 +1886,21 @@ 12.126 this.nativeURIErrorMap = NativeURIError.getInitialMap().duplicate(); 12.127 this.prototypeObjectMap = PrototypeObject.getInitialMap().duplicate(); 12.128 this.objectMap = JO.getInitialMap().duplicate(); 12.129 - this.functionMap = ScriptFunctionImpl.getInitialMap(); 12.130 + this.functionMap = ScriptFunctionImpl.getInitialMap().duplicate(); 12.131 + this.anonymousFunctionMap = ScriptFunctionImpl.getInitialAnonymousMap().duplicate(); 12.132 this.strictFunctionMap = ScriptFunctionImpl.getInitialStrictMap().duplicate(); 12.133 this.boundFunctionMap = ScriptFunctionImpl.getInitialBoundMap().duplicate(); 12.134 + 12.135 + // java 12.136 + if (! env._no_java) { 12.137 + this.nativeJavaImporterMap = NativeJavaImporter.getInitialMap().duplicate(); 12.138 + } 12.139 + 12.140 + // typed arrays 12.141 + if (! env._no_typed_arrays) { 12.142 + this.arrayBufferViewMap = ArrayBufferView.getInitialMap().duplicate(); 12.143 + this.nativeArrayBufferMap = NativeArrayBuffer.getInitialMap().duplicate(); 12.144 + } 12.145 } 12.146 12.147 // Function and Object constructors are inter-dependent. Also, 12.148 @@ -1899,7 +1914,7 @@ 12.149 this.builtinFunction = (ScriptFunction)initConstructor("Function"); 12.150 12.151 // create global anonymous function 12.152 - final ScriptFunction anon = ScriptFunctionImpl.newAnonymousFunction(); 12.153 + final ScriptFunction anon = ScriptFunctionImpl.newAnonymousFunction(this); 12.154 // need to copy over members of Function.prototype to anon function 12.155 anon.addBoundProperties(getFunctionPrototype()); 12.156
13.1 --- a/src/jdk/nashorn/internal/objects/NativeArguments.java Fri Jul 05 19:35:39 2013 +0200 13.2 +++ b/src/jdk/nashorn/internal/objects/NativeArguments.java Mon Jul 08 16:33:50 2013 +0530 13.3 @@ -31,8 +31,10 @@ 13.4 13.5 import java.lang.invoke.MethodHandle; 13.6 import java.lang.invoke.MethodHandles; 13.7 +import java.util.ArrayList; 13.8 import java.util.Arrays; 13.9 import java.util.BitSet; 13.10 +import jdk.nashorn.internal.runtime.AccessorProperty; 13.11 import jdk.nashorn.internal.runtime.Property; 13.12 import jdk.nashorn.internal.runtime.PropertyDescriptor; 13.13 import jdk.nashorn.internal.runtime.PropertyMap; 13.14 @@ -41,8 +43,6 @@ 13.15 import jdk.nashorn.internal.runtime.ScriptRuntime; 13.16 import jdk.nashorn.internal.runtime.arrays.ArrayData; 13.17 import jdk.nashorn.internal.runtime.arrays.ArrayIndex; 13.18 -import jdk.nashorn.internal.lookup.Lookup; 13.19 -import jdk.nashorn.internal.lookup.MethodHandleFactory; 13.20 13.21 /** 13.22 * ECMA 10.6 Arguments Object. 13.23 @@ -64,10 +64,10 @@ 13.24 private static final PropertyMap map$; 13.25 13.26 static { 13.27 - PropertyMap map = PropertyMap.newMap(); 13.28 - map = Lookup.newProperty(map, "length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH); 13.29 - map = Lookup.newProperty(map, "callee", Property.NOT_ENUMERABLE, G$CALLEE, S$CALLEE); 13.30 - map$ = map; 13.31 + final ArrayList<Property> properties = new ArrayList<>(2); 13.32 + properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH)); 13.33 + properties.add(AccessorProperty.create("callee", Property.NOT_ENUMERABLE, G$CALLEE, S$CALLEE)); 13.34 + map$ = PropertyMap.newMap(properties).setIsShared(); 13.35 } 13.36 13.37 static PropertyMap getInitialMap() {
14.1 --- a/src/jdk/nashorn/internal/objects/NativeBoolean.java Fri Jul 05 19:35:39 2013 +0200 14.2 +++ b/src/jdk/nashorn/internal/objects/NativeBoolean.java Mon Jul 08 16:33:50 2013 +0530 14.3 @@ -40,7 +40,6 @@ 14.4 import jdk.nashorn.internal.runtime.PropertyMap; 14.5 import jdk.nashorn.internal.runtime.ScriptObject; 14.6 import jdk.nashorn.internal.runtime.ScriptRuntime; 14.7 -import jdk.nashorn.internal.lookup.MethodHandleFactory; 14.8 import jdk.nashorn.internal.runtime.linker.PrimitiveLookup; 14.9 14.10 /**
15.1 --- a/src/jdk/nashorn/internal/objects/NativeDebug.java Fri Jul 05 19:35:39 2013 +0200 15.2 +++ b/src/jdk/nashorn/internal/objects/NativeDebug.java Mon Jul 08 16:33:50 2013 +0530 15.3 @@ -49,6 +49,7 @@ 15.4 public final class NativeDebug extends ScriptObject { 15.5 15.6 // initialized by nasgen 15.7 + @SuppressWarnings("unused") 15.8 private static PropertyMap $nasgenmap$; 15.9 15.10 private NativeDebug() { 15.11 @@ -144,7 +145,7 @@ 15.12 */ 15.13 @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 15.14 public static Object equals(final Object self, final Object obj1, final Object obj2) { 15.15 - return (obj1 != null) ? obj1.equals(obj2) : false; 15.16 + return Objects.equals(obj1, obj2); 15.17 } 15.18 15.19 /** 15.20 @@ -177,6 +178,15 @@ 15.21 } 15.22 15.23 /** 15.24 + * Returns the property listener count for a script object 15.25 + * @return listener count 15.26 + */ 15.27 + @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 15.28 + public static Object getListenerCount(final Object self, final Object obj) { 15.29 + return (obj instanceof ScriptObject)? ((ScriptObject)obj).getListenerCount() : 0; 15.30 + } 15.31 + 15.32 + /** 15.33 * Dump all Nashorn debug mode counters. Calling this may be better if 15.34 * you want to print all counters. This way you can avoid too many callsites 15.35 * due to counter access itself!! 15.36 @@ -197,6 +207,8 @@ 15.37 out.println("ScriptFunction allocations " + ScriptFunction.getAllocations()); 15.38 out.println("PropertyMap count " + PropertyMap.getCount()); 15.39 out.println("PropertyMap cloned " + PropertyMap.getClonedCount()); 15.40 + out.println("PropertyMap shared " + PropertyMap.getSharedCount()); 15.41 + out.println("PropertyMap duplicated " + PropertyMap.getDuplicatedCount()); 15.42 out.println("PropertyMap history hit " + PropertyMap.getHistoryHit()); 15.43 out.println("PropertyMap proto invalidations " + PropertyMap.getProtoInvalidations()); 15.44 out.println("PropertyMap proto history hit " + PropertyMap.getProtoHistoryHit());
16.1 --- a/src/jdk/nashorn/internal/objects/NativeError.java Fri Jul 05 19:35:39 2013 +0200 16.2 +++ b/src/jdk/nashorn/internal/objects/NativeError.java Mon Jul 08 16:33:50 2013 +0530 16.3 @@ -31,7 +31,6 @@ 16.4 import java.lang.invoke.MethodHandle; 16.5 import java.lang.invoke.MethodHandles; 16.6 import jdk.nashorn.api.scripting.NashornException; 16.7 -import jdk.nashorn.internal.lookup.MethodHandleFactory; 16.8 import jdk.nashorn.internal.objects.annotations.Attribute; 16.9 import jdk.nashorn.internal.objects.annotations.Constructor; 16.10 import jdk.nashorn.internal.objects.annotations.Function;
17.1 --- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Fri Jul 05 19:35:39 2013 +0200 17.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Mon Jul 08 16:33:50 2013 +0530 17.3 @@ -48,7 +48,6 @@ 17.4 import jdk.nashorn.internal.runtime.ScriptRuntime; 17.5 import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator; 17.6 import jdk.nashorn.internal.lookup.Lookup; 17.7 -import jdk.nashorn.internal.lookup.MethodHandleFactory; 17.8 import jdk.nashorn.internal.scripts.JO; 17.9 17.10 /**
18.1 --- a/src/jdk/nashorn/internal/objects/NativeJSON.java Fri Jul 05 19:35:39 2013 +0200 18.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSON.java Mon Jul 08 16:33:50 2013 +0530 18.3 @@ -60,6 +60,7 @@ 18.4 ScriptFunction.class, ScriptObject.class, Object.class, Object.class); 18.5 18.6 // initialized by nasgen 18.7 + @SuppressWarnings("unused") 18.8 private static PropertyMap $nasgenmap$; 18.9 18.10 private NativeJSON() {
19.1 --- a/src/jdk/nashorn/internal/objects/NativeMath.java Fri Jul 05 19:35:39 2013 +0200 19.2 +++ b/src/jdk/nashorn/internal/objects/NativeMath.java Mon Jul 08 16:33:50 2013 +0530 19.3 @@ -43,6 +43,7 @@ 19.4 public final class NativeMath extends ScriptObject { 19.5 19.6 // initialized by nasgen 19.7 + @SuppressWarnings("unused") 19.8 private static PropertyMap $nasgenmap$; 19.9 19.10 private NativeMath() {
20.1 --- a/src/jdk/nashorn/internal/objects/NativeStrictArguments.java Fri Jul 05 19:35:39 2013 +0200 20.2 +++ b/src/jdk/nashorn/internal/objects/NativeStrictArguments.java Mon Jul 08 16:33:50 2013 +0530 20.3 @@ -30,14 +30,14 @@ 20.4 20.5 import java.lang.invoke.MethodHandle; 20.6 import java.lang.invoke.MethodHandles; 20.7 +import java.util.ArrayList; 20.8 import java.util.Arrays; 20.9 +import jdk.nashorn.internal.runtime.AccessorProperty; 20.10 import jdk.nashorn.internal.runtime.Property; 20.11 import jdk.nashorn.internal.runtime.PropertyMap; 20.12 import jdk.nashorn.internal.runtime.ScriptFunction; 20.13 import jdk.nashorn.internal.runtime.ScriptObject; 20.14 import jdk.nashorn.internal.runtime.arrays.ArrayData; 20.15 -import jdk.nashorn.internal.lookup.Lookup; 20.16 -import jdk.nashorn.internal.lookup.MethodHandleFactory; 20.17 20.18 /** 20.19 * ECMA 10.6 Arguments Object. 20.20 @@ -54,14 +54,15 @@ 20.21 private static final PropertyMap map$; 20.22 20.23 static { 20.24 - PropertyMap map = PropertyMap.newMap(); 20.25 - map = Lookup.newProperty(map, "length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH); 20.26 + final ArrayList<Property> properties = new ArrayList<>(1); 20.27 + properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE, G$LENGTH, S$LENGTH)); 20.28 + PropertyMap map = PropertyMap.newMap(properties); 20.29 // In strict mode, the caller and callee properties should throw TypeError 20.30 // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors. 20.31 final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; 20.32 map = map.addProperty(map.newUserAccessors("caller", flags)); 20.33 map = map.addProperty(map.newUserAccessors("callee", flags)); 20.34 - map$ = map; 20.35 + map$ = map.setIsShared(); 20.36 } 20.37 20.38 static PropertyMap getInitialMap() {
21.1 --- a/src/jdk/nashorn/internal/objects/PrototypeObject.java Fri Jul 05 19:35:39 2013 +0200 21.2 +++ b/src/jdk/nashorn/internal/objects/PrototypeObject.java Mon Jul 08 16:33:50 2013 +0530 21.3 @@ -30,12 +30,12 @@ 21.4 21.5 import java.lang.invoke.MethodHandle; 21.6 import java.lang.invoke.MethodHandles; 21.7 +import java.util.ArrayList; 21.8 +import jdk.nashorn.internal.runtime.AccessorProperty; 21.9 import jdk.nashorn.internal.runtime.Property; 21.10 import jdk.nashorn.internal.runtime.PropertyMap; 21.11 import jdk.nashorn.internal.runtime.ScriptFunction; 21.12 import jdk.nashorn.internal.runtime.ScriptObject; 21.13 -import jdk.nashorn.internal.lookup.Lookup; 21.14 -import jdk.nashorn.internal.lookup.MethodHandleFactory; 21.15 21.16 /** 21.17 * Instances of this class serve as "prototype" object for script functions. 21.18 @@ -52,9 +52,9 @@ 21.19 private static final MethodHandle SET_CONSTRUCTOR = findOwnMH("setConstructor", void.class, Object.class, Object.class); 21.20 21.21 static { 21.22 - PropertyMap map = PropertyMap.newMap(); 21.23 - map = Lookup.newProperty(map, "constructor", Property.NOT_ENUMERABLE, GET_CONSTRUCTOR, SET_CONSTRUCTOR); 21.24 - map$ = map; 21.25 + final ArrayList<Property> properties = new ArrayList<>(1); 21.26 + properties.add(AccessorProperty.create("constructor", Property.NOT_ENUMERABLE, GET_CONSTRUCTOR, SET_CONSTRUCTOR)); 21.27 + map$ = PropertyMap.newMap(properties).setIsShared(); 21.28 } 21.29 21.30 static PropertyMap getInitialMap() {
22.1 --- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java Fri Jul 05 19:35:39 2013 +0200 22.2 +++ b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java Mon Jul 08 16:33:50 2013 +0530 22.3 @@ -28,6 +28,7 @@ 22.4 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 22.5 22.6 import java.lang.invoke.MethodHandle; 22.7 +import java.util.ArrayList; 22.8 import jdk.nashorn.internal.runtime.GlobalFunctions; 22.9 import jdk.nashorn.internal.runtime.Property; 22.10 import jdk.nashorn.internal.runtime.PropertyMap; 22.11 @@ -36,6 +37,7 @@ 22.12 import jdk.nashorn.internal.runtime.ScriptFunctionData; 22.13 import jdk.nashorn.internal.runtime.ScriptObject; 22.14 import jdk.nashorn.internal.lookup.Lookup; 22.15 +import jdk.nashorn.internal.runtime.AccessorProperty; 22.16 22.17 /** 22.18 * Concrete implementation of ScriptFunction. This sets correct map for the 22.19 @@ -57,6 +59,10 @@ 22.20 return map$; 22.21 } 22.22 22.23 + static PropertyMap getInitialAnonymousMap() { 22.24 + return AnonymousFunction.getInitialMap(); 22.25 + } 22.26 + 22.27 static PropertyMap getInitialStrictMap() { 22.28 return strictmodemap$; 22.29 } 22.30 @@ -149,13 +155,18 @@ 22.31 } 22.32 22.33 static { 22.34 - PropertyMap map = PropertyMap.newMap(); 22.35 - map = Lookup.newProperty(map, "prototype", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE, G$PROTOTYPE, S$PROTOTYPE); 22.36 - map = Lookup.newProperty(map, "length", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$LENGTH, null); 22.37 - map = Lookup.newProperty(map, "name", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$NAME, null); 22.38 - map$ = map; 22.39 + final ArrayList<Property> properties = new ArrayList<>(3); 22.40 + properties.add(AccessorProperty.create("prototype", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE, G$PROTOTYPE, S$PROTOTYPE)); 22.41 + properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$LENGTH, null)); 22.42 + properties.add(AccessorProperty.create("name", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$NAME, null)); 22.43 + map$ = PropertyMap.newMap(properties); 22.44 strictmodemap$ = createStrictModeMap(map$); 22.45 boundfunctionmap$ = createBoundFunctionMap(strictmodemap$); 22.46 + // There are order dependencies between normal map, struct map and bound map 22.47 + // We can make these 'shared' only after initialization of all three. 22.48 + map$.setIsShared(); 22.49 + strictmodemap$.setIsShared(); 22.50 + boundfunctionmap$.setIsShared(); 22.51 } 22.52 22.53 // function object representing TypeErrorThrower 22.54 @@ -201,15 +212,19 @@ 22.55 // Instance of this class is used as global anonymous function which 22.56 // serves as Function.prototype object. 22.57 private static class AnonymousFunction extends ScriptFunctionImpl { 22.58 - private static final PropertyMap nasgenmap$$ = PropertyMap.newMap(); 22.59 + private static final PropertyMap map$ = PropertyMap.newMap().setIsShared(); 22.60 22.61 - AnonymousFunction() { 22.62 - super("", GlobalFunctions.ANONYMOUS, nasgenmap$$, null); 22.63 + static PropertyMap getInitialMap() { 22.64 + return map$; 22.65 + } 22.66 + 22.67 + AnonymousFunction(final Global global) { 22.68 + super("", GlobalFunctions.ANONYMOUS, global.getAnonymousFunctionMap(), null); 22.69 } 22.70 } 22.71 22.72 - static ScriptFunctionImpl newAnonymousFunction() { 22.73 - return new AnonymousFunction(); 22.74 + static ScriptFunctionImpl newAnonymousFunction(final Global global) { 22.75 + return new AnonymousFunction(global); 22.76 } 22.77 22.78 /**
23.1 --- a/src/jdk/nashorn/internal/runtime/AccessorProperty.java Fri Jul 05 19:35:39 2013 +0200 23.2 +++ b/src/jdk/nashorn/internal/runtime/AccessorProperty.java Mon Jul 08 16:33:50 2013 +0530 23.3 @@ -107,6 +107,20 @@ 23.4 SPILL_ELEMENT_SETTER = MH.filterArguments(MH.arrayElementSetter(Object[].class), 0, spillGetter); 23.5 } 23.6 23.7 + /** 23.8 + * Create a new accessor property. Factory method used by nasgen generated code. 23.9 + * 23.10 + * @param key {@link Property} key. 23.11 + * @param propertyFlags {@link Property} flags. 23.12 + * @param getter {@link Property} get accessor method. 23.13 + * @param setter {@link Property} set accessor method. 23.14 + * 23.15 + * @return New {@link AccessorProperty} created. 23.16 + */ 23.17 + public static AccessorProperty create(final String key, final int propertyFlags, final MethodHandle getter, final MethodHandle setter) { 23.18 + return new AccessorProperty(key, propertyFlags, -1, getter, setter); 23.19 + } 23.20 + 23.21 /** Seed getter for the primitive version of this field (in -Dnashorn.fields.dual=true mode) */ 23.22 private MethodHandle primitiveGetter; 23.23
24.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Fri Jul 05 19:35:39 2013 +0200 24.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Mon Jul 08 16:33:50 2013 +0530 24.3 @@ -253,13 +253,7 @@ 24.4 this.env = new ScriptEnvironment(options, out, err); 24.5 this._strict = env._strict; 24.6 this.appLoader = appLoader; 24.7 - this.scriptLoader = (ScriptLoader)AccessController.doPrivileged( 24.8 - new PrivilegedAction<ClassLoader>() { 24.9 - @Override 24.10 - public ClassLoader run() { 24.11 - return new ScriptLoader(sharedLoader, Context.this); 24.12 - } 24.13 - }); 24.14 + this.scriptLoader = env._loader_per_compile? null : createNewLoader(); 24.15 this.errors = errors; 24.16 24.17 // if user passed -classpath option, make a class loader with that and set it as
25.1 --- a/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java Fri Jul 05 19:35:39 2013 +0200 25.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyListenerManager.java Mon Jul 08 16:33:50 2013 +0530 25.3 @@ -41,6 +41,7 @@ 25.4 private static int listenersRemoved; 25.5 25.6 /** 25.7 + * Return aggregate listeners added to all PropertyListenerManagers 25.8 * @return the listenersAdded 25.9 */ 25.10 public static int getListenersAdded() { 25.11 @@ -48,12 +49,21 @@ 25.12 } 25.13 25.14 /** 25.15 + * Return aggregate listeners removed from all PropertyListenerManagers 25.16 * @return the listenersRemoved 25.17 */ 25.18 public static int getListenersRemoved() { 25.19 return listenersRemoved; 25.20 } 25.21 25.22 + /** 25.23 + * Return listeners added to this PropertyListenerManager. 25.24 + * @return the listener count 25.25 + */ 25.26 + public final int getListenerCount() { 25.27 + return listeners != null? listeners.size() : 0; 25.28 + } 25.29 + 25.30 // Property listener management methods 25.31 25.32 /**
26.1 --- a/src/jdk/nashorn/internal/runtime/PropertyMap.java Fri Jul 05 19:35:39 2013 +0200 26.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java Mon Jul 08 16:33:50 2013 +0530 26.3 @@ -25,11 +25,8 @@ 26.4 26.5 package jdk.nashorn.internal.runtime; 26.6 26.7 -import jdk.nashorn.internal.scripts.JO; 26.8 - 26.9 import static jdk.nashorn.internal.runtime.PropertyHashMap.EMPTY_HASHMAP; 26.10 26.11 -import java.lang.invoke.MethodHandle; 26.12 import java.lang.invoke.SwitchPoint; 26.13 import java.lang.ref.WeakReference; 26.14 import java.util.Arrays; 26.15 @@ -57,9 +54,8 @@ 26.16 private static final int CLONEABLE_FLAGS_MASK = 0b0000_1111; 26.17 /** Has a listener been added to this property map. This flag is not copied when cloning a map. See {@link PropertyListener} */ 26.18 public static final int IS_LISTENER_ADDED = 0b0001_0000; 26.19 - 26.20 - /** Empty map used for seed map for JO$ objects */ 26.21 - private static final PropertyMap EMPTY_MAP = new PropertyMap(EMPTY_HASHMAP); 26.22 + /** Is this process wide "shared" map?. This flag is not copied when cloning a map */ 26.23 + public static final int IS_SHARED = 0b0010_0000; 26.24 26.25 /** Map status flags. */ 26.26 private int flags; 26.27 @@ -145,16 +141,17 @@ 26.28 } 26.29 26.30 /** 26.31 - * Duplicates this PropertyMap instance. This is used by nasgen generated 26.32 - * prototype and constructor classes. {@link PropertyMap} used for singletons 26.33 - * like these (and global instance) are duplicated using this method and used. 26.34 - * The original filled map referenced by static fields of prototype and 26.35 - * constructor classes are not touched. This allows multiple independent global 26.36 - * instances to be used within a single context instance. 26.37 + * Duplicates this PropertyMap instance. This is used to duplicate 'shared' 26.38 + * maps {@link PropertyMap} used as process wide singletons. Shared maps are 26.39 + * duplicated for every global scope object. That way listeners, proto and property 26.40 + * histories are scoped within a global scope. 26.41 * 26.42 * @return Duplicated {@link PropertyMap}. 26.43 */ 26.44 public PropertyMap duplicate() { 26.45 + if (Context.DEBUG) { 26.46 + duplicatedCount++; 26.47 + } 26.48 return new PropertyMap(this.properties); 26.49 } 26.50 26.51 @@ -173,6 +170,15 @@ 26.52 } 26.53 26.54 /** 26.55 + * Public property map allocator. Used by nasgen generated code. 26.56 + * @param properties Collection of initial properties. 26.57 + * @return New {@link PropertyMap}. 26.58 + */ 26.59 + public static PropertyMap newMap(final Collection<Property> properties) { 26.60 + return (properties == null || properties.isEmpty())? newMap() : newMap(properties, 0, 0, 0); 26.61 + } 26.62 + 26.63 + /** 26.64 * Return a sharable empty map. 26.65 * 26.66 * @return New empty {@link PropertyMap}. 26.67 @@ -199,6 +205,8 @@ 26.68 * @return A shared {@link SwitchPoint} for the property. 26.69 */ 26.70 public SwitchPoint getProtoGetSwitchPoint(final ScriptObject proto, final String key) { 26.71 + assert !isShared() : "proto SwitchPoint from a shared PropertyMap"; 26.72 + 26.73 if (proto == null) { 26.74 return null; 26.75 } 26.76 @@ -227,6 +235,8 @@ 26.77 * @param property {@link Property} to invalidate. 26.78 */ 26.79 private void invalidateProtoGetSwitchPoint(final Property property) { 26.80 + assert !isShared() : "proto invalidation on a shared PropertyMap"; 26.81 + 26.82 if (protoGetSwitches != null) { 26.83 final String key = property.getKey(); 26.84 final SwitchPoint sp = protoGetSwitches.get(key); 26.85 @@ -241,17 +251,6 @@ 26.86 } 26.87 26.88 /** 26.89 - * Add a property to the map. 26.90 - * 26.91 - * @param property {@link Property} being added. 26.92 - * 26.93 - * @return New {@link PropertyMap} with {@link Property} added. 26.94 - */ 26.95 - public PropertyMap newProperty(final Property property) { 26.96 - return addProperty(property); 26.97 - } 26.98 - 26.99 - /** 26.100 * Add a property to the map, re-binding its getters and setters, 26.101 * if available, to a given receiver. This is typically the global scope. See 26.102 * {@link ScriptObject#addBoundProperties(ScriptObject)} 26.103 @@ -261,23 +260,8 @@ 26.104 * 26.105 * @return New {@link PropertyMap} with {@link Property} added. 26.106 */ 26.107 - PropertyMap newPropertyBind(final AccessorProperty property, final ScriptObject bindTo) { 26.108 - return newProperty(new AccessorProperty(property, bindTo)); 26.109 - } 26.110 - 26.111 - /** 26.112 - * Add a new accessor property to the map. 26.113 - * 26.114 - * @param key {@link Property} key. 26.115 - * @param propertyFlags {@link Property} flags. 26.116 - * @param slot {@link Property} slot. 26.117 - * @param getter {@link Property} get accessor method. 26.118 - * @param setter {@link Property} set accessor method. 26.119 - * 26.120 - * @return New {@link PropertyMap} with {@link AccessorProperty} added. 26.121 - */ 26.122 - public PropertyMap newProperty(final String key, final int propertyFlags, final int slot, final MethodHandle getter, final MethodHandle setter) { 26.123 - return newProperty(new AccessorProperty(key, propertyFlags, slot, getter, setter)); 26.124 + PropertyMap addPropertyBind(final AccessorProperty property, final ScriptObject bindTo) { 26.125 + return addProperty(new AccessorProperty(property, bindTo)); 26.126 } 26.127 26.128 /** 26.129 @@ -479,6 +463,28 @@ 26.130 } 26.131 26.132 /** 26.133 + * Make this property map 'shared' one. Shared property map instances are 26.134 + * process wide singleton objects. A shaped map should never be added as a listener 26.135 + * to a proto object. Nor it should have history or proto history. A shared map 26.136 + * is just a template that is meant to be duplicated before use. All nasgen initialized 26.137 + * property maps are shared. 26.138 + * 26.139 + * @return this map after making it as shared 26.140 + */ 26.141 + public PropertyMap setIsShared() { 26.142 + assert !isListenerAdded() : "making PropertyMap shared after listener added"; 26.143 + assert protoHistory == null : "making PropertyMap shared after associating a proto with it"; 26.144 + if (Context.DEBUG) { 26.145 + sharedCount++; 26.146 + } 26.147 + 26.148 + flags |= IS_SHARED; 26.149 + // clear any history on this PropertyMap, won't be used. 26.150 + history = null; 26.151 + return this; 26.152 + } 26.153 + 26.154 + /** 26.155 * Check for any configurable properties. 26.156 * 26.157 * @return {@code true} if any configurable. 26.158 @@ -544,6 +550,8 @@ 26.159 * @param newMap {@link PropertyMap} associated with prototype. 26.160 */ 26.161 private void addToProtoHistory(final ScriptObject newProto, final PropertyMap newMap) { 26.162 + assert !isShared() : "proto history modified on a shared PropertyMap"; 26.163 + 26.164 if (protoHistory == null) { 26.165 protoHistory = new WeakHashMap<>(); 26.166 } 26.167 @@ -558,6 +566,8 @@ 26.168 * @param newMap Modified {@link PropertyMap}. 26.169 */ 26.170 private void addToHistory(final Property property, final PropertyMap newMap) { 26.171 + assert !isShared() : "history modified on a shared PropertyMap"; 26.172 + 26.173 if (!properties.isEmpty()) { 26.174 if (history == null) { 26.175 history = new LinkedHashMap<>(); 26.176 @@ -683,6 +693,15 @@ 26.177 } 26.178 26.179 /** 26.180 + * Check if this map shared or not. 26.181 + * 26.182 + * @return true if this map is shared. 26.183 + */ 26.184 + public boolean isShared() { 26.185 + return (flags & IS_SHARED) != 0; 26.186 + } 26.187 + 26.188 + /** 26.189 * Test to see if {@link PropertyMap} is extensible. 26.190 * 26.191 * @return {@code true} if {@link PropertyMap} can be added to. 26.192 @@ -745,6 +764,8 @@ 26.193 * @return New {@link PropertyMap} with prototype changed. 26.194 */ 26.195 PropertyMap changeProto(final ScriptObject oldProto, final ScriptObject newProto) { 26.196 + assert !isShared() : "proto associated with a shared PropertyMap"; 26.197 + 26.198 if (oldProto == newProto) { 26.199 return this; 26.200 } 26.201 @@ -860,6 +881,8 @@ 26.202 // counters updated only in debug mode 26.203 private static int count; 26.204 private static int clonedCount; 26.205 + private static int sharedCount; 26.206 + private static int duplicatedCount; 26.207 private static int historyHit; 26.208 private static int protoInvalidations; 26.209 private static int protoHistoryHit; 26.210 @@ -880,6 +903,20 @@ 26.211 } 26.212 26.213 /** 26.214 + * @return The number of maps that are shared. 26.215 + */ 26.216 + public static int getSharedCount() { 26.217 + return sharedCount; 26.218 + } 26.219 + 26.220 + /** 26.221 + * @return The number of maps that are duplicated. 26.222 + */ 26.223 + public static int getDuplicatedCount() { 26.224 + return duplicatedCount; 26.225 + } 26.226 + 26.227 + /** 26.228 * @return The number of times history was successfully used. 26.229 */ 26.230 public static int getHistoryHit() {
27.1 --- a/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java Fri Jul 05 19:35:39 2013 +0200 27.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptEnvironment.java Mon Jul 08 16:33:50 2013 +0530 27.3 @@ -119,9 +119,15 @@ 27.4 /** Create a new class loaded for each compilation */ 27.5 public final boolean _loader_per_compile; 27.6 27.7 + /** Do not support Java support extensions. */ 27.8 + public final boolean _no_java; 27.9 + 27.10 /** Do not support non-standard syntax extensions. */ 27.11 public final boolean _no_syntax_extensions; 27.12 27.13 + /** Do not support typed arrays. */ 27.14 + public final boolean _no_typed_arrays; 27.15 + 27.16 /** Package to which generated class files are added */ 27.17 public final String _package; 27.18 27.19 @@ -207,7 +213,9 @@ 27.20 _fx = options.getBoolean("fx"); 27.21 _lazy_compilation = options.getBoolean("lazy.compilation"); 27.22 _loader_per_compile = options.getBoolean("loader.per.compile"); 27.23 + _no_java = options.getBoolean("no.java"); 27.24 _no_syntax_extensions = options.getBoolean("no.syntax.extensions"); 27.25 + _no_typed_arrays = options.getBoolean("no.typed.arrays"); 27.26 _package = options.getString("package"); 27.27 _parse_only = options.getBoolean("parse.only"); 27.28 _print_ast = options.getBoolean("print.ast");
28.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Fri Jul 05 19:35:39 2013 +0200 28.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Jul 08 16:33:50 2013 +0530 28.3 @@ -213,7 +213,7 @@ 28.4 final UserAccessorProperty prop = this.newUserAccessors(key, property.getFlags(), property.getGetterFunction(source), property.getSetterFunction(source)); 28.5 newMap = newMap.addProperty(prop); 28.6 } else { 28.7 - newMap = newMap.newPropertyBind((AccessorProperty)property, source); 28.8 + newMap = newMap.addPropertyBind((AccessorProperty)property, source); 28.9 } 28.10 } 28.11 }
29.1 --- a/src/jdk/nashorn/internal/runtime/resources/Options.properties Fri Jul 05 19:35:39 2013 +0200 29.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Options.properties Mon Jul 08 16:33:50 2013 +0530 29.3 @@ -192,6 +192,14 @@ 29.4 default=true \ 29.5 } 29.6 29.7 +nashorn.option.no.java = { \ 29.8 + name="--no-java", \ 29.9 + short_name="-nj", \ 29.10 + is_undocumented=true, \ 29.11 + desc="No Java support", \ 29.12 + default=false \ 29.13 +} 29.14 + 29.15 nashorn.option.no.syntax.extensions = { \ 29.16 name="--no-syntax-extensions", \ 29.17 short_name="-nse", \ 29.18 @@ -200,6 +208,14 @@ 29.19 default=false \ 29.20 } 29.21 29.22 +nashorn.option.no.typed.arrays = { \ 29.23 + name="--no-typed-arrays", \ 29.24 + short_name="-nta", \ 29.25 + is_undocumented=true, \ 29.26 + desc="No Typed arrays support", \ 29.27 + default=false \ 29.28 +} 29.29 + 29.30 nashorn.option.package = { \ 29.31 name="--package", \ 29.32 is_undocumented=true, \
30.1 --- a/src/jdk/nashorn/internal/scripts/JO.java Fri Jul 05 19:35:39 2013 +0200 30.2 +++ b/src/jdk/nashorn/internal/scripts/JO.java Mon Jul 08 16:33:50 2013 +0530 30.3 @@ -33,7 +33,7 @@ 30.4 */ 30.5 public class JO extends ScriptObject { 30.6 30.7 - private static final PropertyMap map$ = PropertyMap.newMap(); 30.8 + private static final PropertyMap map$ = PropertyMap.newMap().setIsShared(); 30.9 30.10 /** 30.11 * Returns the initial property map to be used.
31.1 --- a/src/jdk/nashorn/tools/Shell.java Fri Jul 05 19:35:39 2013 +0200 31.2 +++ b/src/jdk/nashorn/tools/Shell.java Mon Jul 08 16:33:50 2013 +0530 31.3 @@ -435,6 +435,10 @@ 31.4 break; 31.5 } 31.6 31.7 + if (source.isEmpty()) { 31.8 + continue; 31.9 + } 31.10 + 31.11 Object res; 31.12 try { 31.13 res = context.eval(global, source, global, "<shell>", env._strict);