Search in sources :

Example 66 with DynamicObject

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

the class LocationTest method testUnrelatedPrimitivesGoToObject.

@Test
public void testUnrelatedPrimitivesGoToObject() {
    DynamicObject object = rootShape.newInstance();
    object.define("foo", 42L);
    Location location1 = object.getShape().getProperty("foo").getLocation();
    Assert.assertEquals(long.class, getLocationType(location1));
    DOTestAsserts.assertLocationFields(location1, 1, 0);
    DOTestAsserts.assertShapeFields(object, 1, 0);
    object.set("foo", 3.14);
    Location location2 = object.getShape().getProperty("foo").getLocation();
    Assert.assertEquals(Object.class, getLocationType(location2));
    DOTestAsserts.assertLocationFields(location2, 0, 1);
    DOTestAsserts.assertShapeFields(object, 1, 1);
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) Location(com.oracle.truffle.api.object.Location) ObjectLocation(com.oracle.truffle.api.object.ObjectLocation) Test(org.junit.Test)

Example 67 with DynamicObject

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

the class LocationTest method testChangeFlagsReuseLocation.

@Test
public void testChangeFlagsReuseLocation() {
    DynamicObject object = rootShape.newInstance();
    object.define("foo", 42);
    Location location = object.getShape().getProperty("foo").getLocation();
    object.define("foo", 43, 111);
    Assert.assertEquals(43, object.get("foo"));
    Property newProperty = object.getShape().getProperty("foo");
    Assert.assertEquals(111, newProperty.getFlags());
    Location newLocation = newProperty.getLocation();
    Assert.assertSame(location, newLocation);
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) Property(com.oracle.truffle.api.object.Property) Location(com.oracle.truffle.api.object.Location) ObjectLocation(com.oracle.truffle.api.object.ObjectLocation) Test(org.junit.Test)

Example 68 with DynamicObject

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

the class LocationTest method testOnlyObjectLocationForObject.

@Test
public void testOnlyObjectLocationForObject() {
    DynamicObject object = rootShape.newInstance();
    object.define("obj", new Object());
    Location location = object.getShape().getProperty("obj").getLocation();
    Assert.assertTrue(location instanceof ObjectLocation);
    DOTestAsserts.assertLocationFields(location, 0, 1);
    DOTestAsserts.assertShapeFields(object, 0, 1);
}
Also used : ObjectLocation(com.oracle.truffle.api.object.ObjectLocation) DynamicObject(com.oracle.truffle.api.object.DynamicObject) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Location(com.oracle.truffle.api.object.Location) ObjectLocation(com.oracle.truffle.api.object.ObjectLocation) Test(org.junit.Test)

Example 69 with DynamicObject

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

the class LocationTest method testDeleteDeclaredProperty.

@Test
public void testDeleteDeclaredProperty() {
    DynamicObject object = rootShape.newInstance();
    object.define("a", new Object(), 0, new LocationFactory() {

        public Location createLocation(Shape shape, Object value) {
            return shape.allocator().declaredLocation(value);
        }
    });
    Assert.assertTrue(object.containsKey("a"));
    object.define("a", 42);
    Assert.assertEquals(1, object.getShape().getPropertyCount());
    object.delete("a");
    Assert.assertFalse(object.containsKey("a"));
}
Also used : Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) DynamicObject(com.oracle.truffle.api.object.DynamicObject) LocationFactory(com.oracle.truffle.api.object.LocationFactory) Location(com.oracle.truffle.api.object.Location) ObjectLocation(com.oracle.truffle.api.object.ObjectLocation) Test(org.junit.Test)

Example 70 with DynamicObject

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

the class SharedShapeTest method testReuseReplaceProperty.

@Test
public void testReuseReplaceProperty() {
    DynamicObject object = sharedShape.newInstance();
    object.define("a", 1);
    Location location1 = object.getShape().getProperty("a").getLocation();
    object.define("a", 2, 42);
    Location location2 = object.getShape().getProperty("a").getLocation();
    DOTestAsserts.assertSameLocation(location1, location2);
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) Location(com.oracle.truffle.api.object.Location) Test(org.junit.Test)

Aggregations

DynamicObject (com.oracle.truffle.api.object.DynamicObject)100 Test (org.junit.Test)91 Location (com.oracle.truffle.api.object.Location)17 Shape (com.oracle.truffle.api.object.Shape)16 DynamicObjectFactory (com.oracle.truffle.api.object.DynamicObjectFactory)8 ObjectLocation (com.oracle.truffle.api.object.ObjectLocation)7 Property (com.oracle.truffle.api.object.Property)7 ObjectType (com.oracle.truffle.api.object.ObjectType)6 IncompatibleLocationException (com.oracle.truffle.api.object.IncompatibleLocationException)4 Layout (com.oracle.truffle.api.object.Layout)4 FinalLocationException (com.oracle.truffle.api.object.FinalLocationException)2 PropertyBuilder (com.oracle.truffle.object.dsl.processor.model.PropertyBuilder)2 VariableElement (javax.lang.model.element.VariableElement)2 LocationFactory (com.oracle.truffle.api.object.LocationFactory)1 ShapeImpl (com.oracle.truffle.object.ShapeImpl)1 DefaultLayoutFactory (com.oracle.truffle.object.basic.DefaultLayoutFactory)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1