nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FieldObjectCreator.java
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FieldObjectCreator.java Wed Jul 05 20:50:41 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FieldObjectCreator.java Sat Sep 19 16:04:28 2015 +0200
@@ -34,7 +34,6 @@
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndex;
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
-import java.util.Iterator;
import java.util.List;
import jdk.nashorn.internal.codegen.types.Type;
import jdk.nashorn.internal.ir.Symbol;
@@ -91,27 +90,20 @@
findClass();
}
- /**
- * Construct an object.
- *
- * @param method the method emitter
- */
@Override
- protected void makeObject(final MethodEmitter method) {
+ public void createObject(final MethodEmitter method) {
makeMap();
final String className = getClassName();
- try {
- // NOTE: we must load the actual structure class here, because the API operates with Nashorn Type objects,
- // and Type objects need a loaded class, for better or worse. We also have to be specific and use the type
- // of the actual structure class, we can't generalize it to e.g. Type.typeFor(ScriptObject.class) as the
- // exact type information is needed for generating continuations in rest-of methods. If we didn't do this,
- // object initializers like { x: arr[i] } would fail during deoptimizing compilation on arr[i], as the
- // values restored from the RewriteException would be cast to "ScriptObject" instead of to e.g. "JO4", and
- // subsequently the "PUTFIELD J04.L0" instruction in the continuation code would fail bytecode verification.
- method._new(Context.forStructureClass(className.replace('/', '.'))).dup();
- } catch (final ClassNotFoundException e) {
- throw new AssertionError(e);
- }
+ // NOTE: we must load the actual structure class here, because the API operates with Nashorn Type objects,
+ // and Type objects need a loaded class, for better or worse. We also have to be specific and use the type
+ // of the actual structure class, we can't generalize it to e.g. Type.typeFor(ScriptObject.class) as the
+ // exact type information is needed for generating continuations in rest-of methods. If we didn't do this,
+ // object initializers like { x: arr[i] } would fail during deoptimizing compilation on arr[i], as the
+ // values restored from the RewriteException would be cast to "ScriptObject" instead of to e.g. "JO4", and
+ // subsequently the "PUTFIELD J04.L0" instruction in the continuation code would fail bytecode verification.
+ assert fieldObjectClass != null;
+ method._new(fieldObjectClass).dup();
+
loadMap(method); //load the map
if (isScope()) {
@@ -126,14 +118,14 @@
} else {
method.invoke(constructorNoLookup(className, PropertyMap.class));
}
+ }
- helpOptimisticRecognizeDuplicateIdentity(method);
-
+ @Override
+ public void populateRange(final MethodEmitter method, final Type objectType, final int objectSlot, final int start, final int end) {
+ method.load(objectType, objectSlot);
// Set values.
- final Iterator<MapTuple<T>> iter = tuples.iterator();
-
- while (iter.hasNext()) {
- final MapTuple<T> tuple = iter.next();
+ for (int i = start; i < end; i++) {
+ final MapTuple<T> tuple = tuples.get(i);
//we only load when we have both symbols and values (which can be == the symbol)
//if we didn't load, we need an array property
if (tuple.symbol != null && tuple.value != null) {
@@ -212,6 +204,11 @@
}
}
+ @Override
+ protected Class<? extends ScriptObject> getAllocatorClass() {
+ return fieldObjectClass;
+ }
+
/**
* Get the class name for the object class,
* e.g. {@code com.nashorn.oracle.scripts.JO2P0}