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);
}
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);
}
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"));
}
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());
}
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));
}
Aggregations