Search in sources :

Example 11 with Property

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

the class ConstantLocationTest method testConstantLocation.

@Test
public void testConstantLocation() {
    DynamicObject object = shapeWithConstant.newInstance();
    Assert.assertSame(value, object.get("constant"));
    object.set("constant", value);
    Assert.assertSame(shapeWithConstant, object.getShape());
    Property property = object.getShape().getProperty("constant");
    Assert.assertEquals(true, property.getLocation().canStore(value));
    Assert.assertEquals(true, property.getLocation().canSet(value));
    try {
        property.set(object, value, shapeWithConstant);
    } catch (IncompatibleLocationException | FinalLocationException e) {
        Assert.fail(e.getMessage());
    }
    Object newValue = new Object();
    Assert.assertEquals(false, property.getLocation().canStore(newValue));
    Assert.assertEquals(false, property.getLocation().canSet(newValue));
    try {
        property.set(object, newValue, shapeWithConstant);
        Assert.fail();
    } catch (FinalLocationException | IncompatibleLocationException e) {
        Assert.assertTrue(e instanceof FinalLocationException);
    }
    Assert.assertSame(value, object.get("constant"));
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) IncompatibleLocationException(com.oracle.truffle.api.object.IncompatibleLocationException) DynamicObject(com.oracle.truffle.api.object.DynamicObject) FinalLocationException(com.oracle.truffle.api.object.FinalLocationException) Property(com.oracle.truffle.api.object.Property) Test(org.junit.Test)

Example 12 with Property

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

the class DeclaredLocationTest method testAddDeclaredLocation.

@Test
public void testAddDeclaredLocation() {
    Property property = shapeWithDeclared.getProperty("declared");
    DynamicObject object = rootShape.newInstance();
    property.setSafe(object, value, rootShape, shapeWithDeclared);
    Assert.assertSame(shapeWithDeclared, object.getShape());
    Assert.assertSame(value, object.get("declared"));
    DynamicObject object2 = rootShape.newInstance();
    Object newValue = new Object();
    Assert.assertEquals(false, property.getLocation().canStore(newValue));
    Assert.assertEquals(false, property.getLocation().canSet(newValue));
    try {
        property.set(object2, newValue, rootShape, shapeWithDeclared);
        Assert.fail();
    } catch (IncompatibleLocationException e) {
    // Expected
    }
    Assert.assertSame(rootShape, object2.getShape());
    Assert.assertEquals(false, object2.containsKey("declared"));
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) IncompatibleLocationException(com.oracle.truffle.api.object.IncompatibleLocationException) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Property(com.oracle.truffle.api.object.Property) Test(org.junit.Test)

Example 13 with Property

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

the class ConsListPropertyMap method getEquals.

private Property getEquals(Object key) {
    for (ConsListPropertyMap current = this; !current.isEmpty(); current = current.getParentMap()) {
        Property p = current.getLastProperty();
        Object pKey = p.getKey();
        if (pKey == key || pKey.equals(key)) {
            return p;
        }
    }
    return null;
}
Also used : Property(com.oracle.truffle.api.object.Property)

Example 14 with Property

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

the class DynamicObjectImpl method delete.

/**
 * @since 0.17 or earlier
 */
@Override
@TruffleBoundary
public boolean delete(Object key) {
    ShapeImpl oldShape = getShape();
    Property existing = oldShape.getProperty(key);
    if (existing != null) {
        oldShape.getLayout().getStrategy().objectRemoveProperty(this, existing, oldShape);
        return true;
    } else {
        return false;
    }
}
Also used : Property(com.oracle.truffle.api.object.Property) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 15 with Property

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

the class SLWritePropertyCacheNode method lookupLocation.

/**
 * Try to find the given property in the shape.
 */
protected static Location lookupLocation(Shape shape, Object name) {
    CompilerAsserts.neverPartOfCompilation();
    Property property = shape.getProperty(name);
    if (property == null) {
        /* Property does not exist yet, so a shape change is necessary. */
        return null;
    }
    return property.getLocation();
}
Also used : Property(com.oracle.truffle.api.object.Property)

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