Search in sources :

Example 51 with DynamicObject

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

the class LocationTest method testOnlyPrimLocationForPrimitive.

@Test
public void testOnlyPrimLocationForPrimitive() {
    DynamicObject object = rootShape.newInstance();
    object.define("prim", 42);
    Location location = object.getShape().getProperty("prim").getLocation();
    Assert.assertEquals(int.class, getLocationType(location));
    DOTestAsserts.assertLocationFields(location, 1, 0);
    DOTestAsserts.assertShapeFields(object, 1, 0);
}
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 52 with DynamicObject

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

the class LocationTest method testPrim2Object.

@Test
public void testPrim2Object() {
    DynamicObject object = rootShape.newInstance();
    object.define("foo", 42);
    Location location1 = object.getShape().getProperty("foo").getLocation();
    Assert.assertEquals(int.class, getLocationType(location1));
    DOTestAsserts.assertLocationFields(location1, 1, 0);
    DOTestAsserts.assertShapeFields(object, 1, 0);
    object.set("foo", new Object());
    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) 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 53 with DynamicObject

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

the class LocationTest method testDelete.

@Test
public void testDelete() {
    DynamicObject object = rootShape.newInstance();
    object.define("a", 1);
    object.define("b", 2);
    object.delete("a");
    Assert.assertFalse(object.containsKey("a"));
    Assert.assertTrue(object.containsKey("b"));
    Assert.assertEquals(2, object.get("b"));
    object.define("a", 3);
    object.delete("b");
    Assert.assertEquals(3, object.get("a"));
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) Test(org.junit.Test)

Example 54 with DynamicObject

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

the class SharedShapeTest method testShapeIsSharedAndIdentity.

@Test
public void testShapeIsSharedAndIdentity() {
    DynamicObject object = rootShape.newInstance();
    Assert.assertEquals(false, rootShape.isShared());
    Assert.assertSame(sharedShape, rootShape.makeSharedShape());
    Assert.assertEquals(true, sharedShape.isShared());
    object.setShapeAndGrow(rootShape, sharedShape);
    object.define("a", 1);
    final Shape sharedShapeWithA = object.getShape();
    Assert.assertEquals(true, sharedShapeWithA.isShared());
    DynamicObject object2 = rootShape.newInstance();
    object2.setShapeAndGrow(rootShape, sharedShape);
    object2.define("a", 1);
    Assert.assertSame(sharedShapeWithA, object2.getShape());
    // Currently, sharing is a transition and transitions do not commute magically
    DynamicObject object3 = rootShape.newInstance();
    object3.define("a", 1);
    object3.setShapeAndGrow(object3.getShape(), object3.getShape().makeSharedShape());
    Assert.assertNotSame(sharedShapeWithA, object3.getShape());
}
Also used : Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Test(org.junit.Test)

Example 55 with DynamicObject

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

the class SharedShapeTest method testNoReuseOfPreviousLocation.

@Test
public void testNoReuseOfPreviousLocation() {
    DynamicObject object = sharedShape.newInstance();
    object.define("a", 1);
    Location location1 = object.getShape().getProperty("a").getLocation();
    object.define("a", 2L);
    Location location2 = object.getShape().getProperty("a").getLocation();
    DOTestAsserts.assertNotSameLocation(location1, location2);
    Assert.assertEquals(Object.class, getLocationType(location2));
    object.define("b", 3);
    Location locationB = object.getShape().getProperty("b").getLocation();
    DOTestAsserts.assertShape("{" + "\"b\":int@1,\n" + "\"a\":Object@0" + "\n}", object.getShape());
    DOTestAsserts.assertShapeFields(object, 2, 1);
    // The old location can still be read
    Assert.assertEquals(1, location1.get(object));
    Assert.assertEquals(2L, location2.get(object));
    Assert.assertEquals(3, locationB.get(object));
}
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