コード例 #1
0
ファイル: PropertyImpl.java プロジェクト: smarr/truffle
  private void setWithShapeSlowCase(
      DynamicObject store, Object value, Shape currentShape, Shape nextShape) {
    Shape oldShape = currentShape;
    if (store.updateShape()) {
      oldShape = store.getShape();
    }
    LayoutStrategy strategy = ((LayoutImpl) currentShape.getLayout()).getStrategy();
    LayoutStrategy.ShapeAndProperty newShapeAndProperty =
        strategy.generalizeProperty(this, value, (ShapeImpl) oldShape, (ShapeImpl) nextShape);
    if (store.updateShape()) {
      oldShape = store.getShape();
    }

    Shape newNextShape = newShapeAndProperty.getShape();
    Property newProperty = newShapeAndProperty.getProperty();

    assert newNextShape.isValid() && oldShape.isValid();
    newProperty.setSafe(store, value, oldShape, newNextShape);
  }
コード例 #2
0
 protected Shape transitionWithNewField(Shape oldShape, Object value) {
   // This duplicates quite a bit of DynamicObject.define(), but should be fixed in Truffle soon.
   final Property oldProperty = oldShape.getProperty(name);
   if (oldProperty != null) {
     if (oldProperty.getFlags() == 0 && oldProperty.getLocation().canSet(null, value)) {
       return oldShape; // already the right shape
     } else {
       DynamicObject copy = oldShape.getLayout().newInstance(oldShape);
       copy.define(name, value, 0);
       return copy.getShape();
     }
   } else {
     final Location location =
         oldShape
             .allocator()
             .locationForValue(
                 value, EnumSet.of(LocationModifier.Final, LocationModifier.NonNull));
     final Property newProperty = Property.create(name, location, 0);
     return oldShape.addProperty(newProperty);
   }
 }