< prev index next >

src/jdk/nashorn/internal/codegen/SpillObjectCreator.java

Print this page




  92                         if (dualFields && constantValue instanceof Number) {
  93                             jpresetValues[slot] = ObjectClassGenerator.pack((Number)constantValue);
  94                         } else {
  95                             opresetValues[slot] = constantValue;
  96                         }
  97                     } else {
  98                         // array index key
  99                         final long oldLength = arrayData.length();
 100                         final int  index     = ArrayIndex.getArrayIndex(key);
 101                         final long longIndex = ArrayIndex.toLongIndex(index);
 102 
 103                         assert ArrayIndex.isValidArrayIndex(index);
 104 
 105                         if (longIndex >= oldLength) {
 106                             arrayData = arrayData.ensure(longIndex);
 107                         }
 108 
 109                         //avoid blowing up the array if we can
 110                         if (constantValue instanceof Integer) {
 111                             arrayData = arrayData.set(index, ((Integer)constantValue).intValue(), false);
 112                         } else if (constantValue instanceof Long) {
 113                             arrayData = arrayData.set(index, ((Long)constantValue).longValue(), false);
 114                         } else if (constantValue instanceof Double) {
 115                             arrayData = arrayData.set(index, ((Double)constantValue).doubleValue(), false);
 116                         } else {
 117                             arrayData = arrayData.set(index, constantValue, false);
 118                         }
 119 
 120                         if (longIndex > oldLength) {
 121                             arrayData = arrayData.delete(oldLength, longIndex - 1);
 122                         }
 123                     }
 124                 }
 125             }
 126             pos++;
 127         }
 128 
 129         // create object and invoke constructor
 130         method._new(objectClass).dup();
 131         codegen.loadConstant(propertyMap);
 132 
 133         // load primitive value spill array


 152 
 153     @Override
 154     public void populateRange(final MethodEmitter method, final Type objectType, final int objectSlot, final int start, final int end) {
 155         final int  callSiteFlags = codegen.getCallSiteFlags();
 156         method.load(objectType, objectSlot);
 157 
 158         // set postfix values
 159         for (int i = start; i < end; i++) {
 160             final MapTuple<Expression> tuple = tuples.get(i);
 161 
 162             if (LiteralNode.isConstant(tuple.value)) {
 163                 continue;
 164             }
 165 
 166             final Property property = propertyMap.findProperty(tuple.key);
 167 
 168             if (property == null) {
 169                 final int index = ArrayIndex.getArrayIndex(tuple.key);
 170                 assert ArrayIndex.isValidArrayIndex(index);
 171                 method.dup();
 172                 method.load(ArrayIndex.toLongIndex(index));
 173                 loadTuple(method, tuple);
 174                 method.dynamicSetIndex(callSiteFlags);
 175             } else {
 176                 method.dup();
 177                 loadTuple(method, tuple);
 178                 method.dynamicSet(property.getKey(), codegen.getCallSiteFlags(), false);
 179             }
 180         }
 181     }
 182 
 183     @Override
 184     protected PropertyMap makeMap() {
 185         assert propertyMap == null : "property map already initialized";
 186         final Class<? extends ScriptObject> clazz = getAllocatorClass();
 187         propertyMap = new MapCreator<>(clazz, tuples).makeSpillMap(false, codegen.useDualFields());
 188         return propertyMap;
 189     }
 190 
 191     @Override
 192     protected void loadValue(final Expression expr, final Type type) {
 193         codegen.loadExpressionAsType(expr, type);
 194     }
 195 
 196     @Override
 197     protected Class<? extends ScriptObject> getAllocatorClass() {


  92                         if (dualFields && constantValue instanceof Number) {
  93                             jpresetValues[slot] = ObjectClassGenerator.pack((Number)constantValue);
  94                         } else {
  95                             opresetValues[slot] = constantValue;
  96                         }
  97                     } else {
  98                         // array index key
  99                         final long oldLength = arrayData.length();
 100                         final int  index     = ArrayIndex.getArrayIndex(key);
 101                         final long longIndex = ArrayIndex.toLongIndex(index);
 102 
 103                         assert ArrayIndex.isValidArrayIndex(index);
 104 
 105                         if (longIndex >= oldLength) {
 106                             arrayData = arrayData.ensure(longIndex);
 107                         }
 108 
 109                         //avoid blowing up the array if we can
 110                         if (constantValue instanceof Integer) {
 111                             arrayData = arrayData.set(index, ((Integer)constantValue).intValue(), false);


 112                         } else if (constantValue instanceof Double) {
 113                             arrayData = arrayData.set(index, ((Double)constantValue).doubleValue(), false);
 114                         } else {
 115                             arrayData = arrayData.set(index, constantValue, false);
 116                         }
 117 
 118                         if (longIndex > oldLength) {
 119                             arrayData = arrayData.delete(oldLength, longIndex - 1);
 120                         }
 121                     }
 122                 }
 123             }
 124             pos++;
 125         }
 126 
 127         // create object and invoke constructor
 128         method._new(objectClass).dup();
 129         codegen.loadConstant(propertyMap);
 130 
 131         // load primitive value spill array


 150 
 151     @Override
 152     public void populateRange(final MethodEmitter method, final Type objectType, final int objectSlot, final int start, final int end) {
 153         final int  callSiteFlags = codegen.getCallSiteFlags();
 154         method.load(objectType, objectSlot);
 155 
 156         // set postfix values
 157         for (int i = start; i < end; i++) {
 158             final MapTuple<Expression> tuple = tuples.get(i);
 159 
 160             if (LiteralNode.isConstant(tuple.value)) {
 161                 continue;
 162             }
 163 
 164             final Property property = propertyMap.findProperty(tuple.key);
 165 
 166             if (property == null) {
 167                 final int index = ArrayIndex.getArrayIndex(tuple.key);
 168                 assert ArrayIndex.isValidArrayIndex(index);
 169                 method.dup();
 170                 loadIndex(method, ArrayIndex.toLongIndex(index));
 171                 loadTuple(method, tuple, false);
 172                 method.dynamicSetIndex(callSiteFlags);
 173             } else {
 174                 method.dup();
 175                 loadTuple(method, tuple, false);
 176                 method.dynamicSet(property.getKey(), codegen.getCallSiteFlags(), false);
 177             }
 178         }
 179     }
 180 
 181     @Override
 182     protected PropertyMap makeMap() {
 183         assert propertyMap == null : "property map already initialized";
 184         final Class<? extends ScriptObject> clazz = getAllocatorClass();
 185         propertyMap = new MapCreator<>(clazz, tuples).makeSpillMap(false, codegen.useDualFields());
 186         return propertyMap;
 187     }
 188 
 189     @Override
 190     protected void loadValue(final Expression expr, final Type type) {
 191         codegen.loadExpressionAsType(expr, type);
 192     }
 193 
 194     @Override
 195     protected Class<? extends ScriptObject> getAllocatorClass() {
< prev index next >