< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FieldObjectCreator.java

Print this page




 150         return propertyMap;
 151     }
 152 
 153     /**
 154      * Store a value in a field of the generated class object.
 155      *
 156      * @param method      Script method.
 157      * @param key         Property key.
 158      * @param fieldIndex  Field number.
 159      * @param tuple       Tuple to store.
 160      */
 161     private void putField(final MethodEmitter method, final String key, final int fieldIndex, final MapTuple<T> tuple) {
 162         final Type    fieldType   = codegen.useDualFields() && tuple.isPrimitive() ? PRIMITIVE_FIELD_TYPE : Type.OBJECT;
 163         final String  fieldClass  = getClassName();
 164         final String  fieldName   = getFieldName(fieldIndex, fieldType);
 165         final String  fieldDesc   = typeDescriptor(fieldType.getTypeClass());
 166 
 167         assert fieldName.equals(getFieldName(fieldIndex, PRIMITIVE_FIELD_TYPE)) || fieldType.isObject() :    key + " object keys must store to L*-fields";
 168         assert fieldName.equals(getFieldName(fieldIndex, Type.OBJECT))          || fieldType.isPrimitive() : key + " primitive keys must store to J*-fields";
 169 
 170         loadTuple(method, tuple);
 171 
 172         method.putField(fieldClass, fieldName, fieldDesc);
 173     }
 174 
 175     /**
 176      * Store a value in an indexed slot of a generated class object.
 177      *
 178      * @param method Script method.
 179      * @param index  Slot index.
 180      * @param tuple  Tuple to store.
 181      */
 182     private void putSlot(final MethodEmitter method, final long index, final MapTuple<T> tuple) {
 183         if (JSType.isRepresentableAsInt(index)) {
 184             method.load((int)index);
 185         } else {
 186             method.load(index);
 187         }
 188         loadTuple(method, tuple, false); //we don't pack array like objects
 189         method.dynamicSetIndex(callSiteFlags);
 190     }
 191 
 192     /**
 193      * Locate (or indirectly create) the object container class.
 194      */
 195     private void findClass() {
 196         fieldObjectClassName = isScope() ?
 197                 ObjectClassGenerator.getClassName(fieldCount, paramCount, codegen.useDualFields()) :
 198                 ObjectClassGenerator.getClassName(paddedFieldCount, codegen.useDualFields());
 199 
 200         try {
 201             this.fieldObjectClass = Context.forStructureClass(Compiler.binaryName(fieldObjectClassName));
 202         } catch (final ClassNotFoundException e) {
 203             throw new AssertionError("Nashorn has encountered an internal error.  Structure can not be created.");
 204         }
 205     }
 206 
 207     @Override




 150         return propertyMap;
 151     }
 152 
 153     /**
 154      * Store a value in a field of the generated class object.
 155      *
 156      * @param method      Script method.
 157      * @param key         Property key.
 158      * @param fieldIndex  Field number.
 159      * @param tuple       Tuple to store.
 160      */
 161     private void putField(final MethodEmitter method, final String key, final int fieldIndex, final MapTuple<T> tuple) {
 162         final Type    fieldType   = codegen.useDualFields() && tuple.isPrimitive() ? PRIMITIVE_FIELD_TYPE : Type.OBJECT;
 163         final String  fieldClass  = getClassName();
 164         final String  fieldName   = getFieldName(fieldIndex, fieldType);
 165         final String  fieldDesc   = typeDescriptor(fieldType.getTypeClass());
 166 
 167         assert fieldName.equals(getFieldName(fieldIndex, PRIMITIVE_FIELD_TYPE)) || fieldType.isObject() :    key + " object keys must store to L*-fields";
 168         assert fieldName.equals(getFieldName(fieldIndex, Type.OBJECT))          || fieldType.isPrimitive() : key + " primitive keys must store to J*-fields";
 169 
 170         loadTuple(method, tuple, true);

 171         method.putField(fieldClass, fieldName, fieldDesc);
 172     }
 173 
 174     /**
 175      * Store a value in an indexed slot of a generated class object.
 176      *
 177      * @param method Script method.
 178      * @param index  Slot index.
 179      * @param tuple  Tuple to store.
 180      */
 181     private void putSlot(final MethodEmitter method, final long index, final MapTuple<T> tuple) {
 182         loadIndex(method, index);




 183         loadTuple(method, tuple, false); //we don't pack array like objects
 184         method.dynamicSetIndex(callSiteFlags);
 185     }
 186 
 187     /**
 188      * Locate (or indirectly create) the object container class.
 189      */
 190     private void findClass() {
 191         fieldObjectClassName = isScope() ?
 192                 ObjectClassGenerator.getClassName(fieldCount, paramCount, codegen.useDualFields()) :
 193                 ObjectClassGenerator.getClassName(paddedFieldCount, codegen.useDualFields());
 194 
 195         try {
 196             this.fieldObjectClass = Context.forStructureClass(Compiler.binaryName(fieldObjectClassName));
 197         } catch (final ClassNotFoundException e) {
 198             throw new AssertionError("Nashorn has encountered an internal error.  Structure can not be created.");
 199         }
 200     }
 201 
 202     @Override


< prev index next >