Search in sources :

Example 26 with Property

use of com.oracle.truffle.api.object.Property in project graal by oracle.

the class ConsListPropertyMap method copyAndRemove.

public ImmutableMap<Object, Property> copyAndRemove(Object key) {
    Deque<Property> shelve = new ArrayDeque<>();
    ConsListPropertyMap current = this;
    while (!current.isEmpty()) {
        if (current.getLastProperty().getKey().equals(key)) {
            ConsListPropertyMap newMap = current.getParentMap();
            for (Property property : shelve) {
                newMap = newMap.putCopy(property);
            }
            return newMap;
        } else {
            shelve.push(current.getLastProperty());
            current = current.getParentMap();
        }
    }
    return this;
}
Also used : Property(com.oracle.truffle.api.object.Property) ArrayDeque(java.util.ArrayDeque)

Example 27 with Property

use of com.oracle.truffle.api.object.Property in project graal by oracle.

the class ConsListPropertyMap method replaceCopy.

@Override
public ConsListPropertyMap replaceCopy(Property oldValue, Property newValue) {
    Deque<Property> shelve = new ArrayDeque<>();
    ConsListPropertyMap current = this;
    while (!current.isEmpty()) {
        if (current.getLastProperty().equals(oldValue)) {
            ConsListPropertyMap newMap = current.getParentMap();
            newMap = newMap.putCopy(newValue);
            for (Property property : shelve) {
                newMap = newMap.putCopy(property);
            }
            return newMap;
        } else {
            shelve.push(current.getLastProperty());
            current = current.getParentMap();
        }
    }
    return this;
}
Also used : Property(com.oracle.truffle.api.object.Property) ArrayDeque(java.util.ArrayDeque)

Example 28 with Property

use of com.oracle.truffle.api.object.Property in project graal by oracle.

the class Debug method dumpObject.

static String dumpObject(DynamicObject object, int level, int levelStop) {
    List<Property> properties = object.getShape().getPropertyListInternal(true);
    StringBuilder sb = new StringBuilder(properties.size() * 10);
    sb.append("{\n");
    for (Property property : properties) {
        indent(sb, level + 1);
        sb.append(property.getKey());
        sb.append('[').append(property.getLocation()).append(']');
        Object value = property.get(object, false);
        if (value instanceof DynamicObject) {
            if (level < levelStop) {
                value = dumpObject((DynamicObject) value, level + 1, levelStop);
            } else {
                value = value.toString();
            }
        }
        sb.append(": ");
        sb.append(value);
        if (property != properties.get(properties.size() - 1)) {
            sb.append(",");
        }
        sb.append("\n");
    }
    indent(sb, level);
    sb.append("}");
    return sb.toString();
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Property(com.oracle.truffle.api.object.Property)

Example 29 with Property

use of com.oracle.truffle.api.object.Property in project graal by oracle.

the class DynamicObjectImpl method copyProperties.

private void copyProperties(DynamicObject fromObject) {
    ShapeImpl fromShape = (ShapeImpl) fromObject.getShape();
    ShapeImpl toShape = getShape();
    assert toShape.isRelated(fromShape);
    assert toShape.isValid();
    assert !fromShape.isShared();
    PropertyMap fromMap = fromShape.getPropertyMap();
    for (Iterator<Property> toMapIt = toShape.getPropertyMap().reverseOrderedValueIterator(); toMapIt.hasNext(); ) {
        Property toProperty = toMapIt.next();
        Property fromProperty = fromMap.get(toProperty.getKey());
        // copy only if property has a location and it's not the same as the source location
        if (!toProperty.getLocation().isValue() && !toProperty.getLocation().equals(fromProperty.getLocation())) {
            toProperty.setInternal(this, fromProperty.get(fromObject, false));
            assert toShape.isValid();
        }
    }
}
Also used : Property(com.oracle.truffle.api.object.Property)

Example 30 with Property

use of com.oracle.truffle.api.object.Property in project graal by oracle.

the class DynamicObjectImpl method changeFlags.

/**
 * @since 0.17 or earlier
 */
@TruffleBoundary
public boolean changeFlags(Object key, int newFlags) {
    Shape oldShape = getShape();
    Property existing = oldShape.getProperty(key);
    if (existing != null) {
        if (existing.getFlags() != newFlags) {
            Property newProperty = existing.copyWithFlags(newFlags);
            Shape newShape = oldShape.replaceProperty(existing, newProperty);
            this.setShape(newShape);
        }
        return true;
    } else {
        return false;
    }
}
Also used : Shape(com.oracle.truffle.api.object.Shape) Property(com.oracle.truffle.api.object.Property) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

Property (com.oracle.truffle.api.object.Property)31 DynamicObject (com.oracle.truffle.api.object.DynamicObject)8 Test (org.junit.Test)7 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)6 IncompatibleLocationException (com.oracle.truffle.api.object.IncompatibleLocationException)4 Location (com.oracle.truffle.api.object.Location)4 ArrayDeque (java.util.ArrayDeque)3 FinalLocationException (com.oracle.truffle.api.object.FinalLocationException)2 ObjectLocation (com.oracle.truffle.api.object.ObjectLocation)2 DeclaredLocation (com.oracle.truffle.object.Locations.DeclaredLocation)2 Layout (com.oracle.truffle.api.object.Layout)1 Shape (com.oracle.truffle.api.object.Shape)1 ValueLocation (com.oracle.truffle.object.Locations.ValueLocation)1 PropertyMap (com.oracle.truffle.object.PropertyMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Random (java.util.Random)1