Search in sources :

Example 1 with Location

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

the class ImplicitCastTest method testOtherInt.

@Test
public void testOtherInt() {
    Shape rootShape = layout.createShape(new ObjectType());
    DynamicObject object = rootShape.newInstance();
    object.define("a", otherVal);
    Location location1 = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(otherPrimClass, getLocationType(location1));
    object.define("a", intVal);
    Location location2 = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(otherPrimClass, getLocationType(location2));
    Assert.assertEquals(otherVal.getClass(), object.get("a").getClass());
    DOTestAsserts.assertSameLocation(location1, location2);
}
Also used : ObjectType(com.oracle.truffle.api.object.ObjectType) Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Location(com.oracle.truffle.api.object.Location) Test(org.junit.Test)

Example 2 with Location

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

the class ImplicitCastTest method testLocationDecoratorEquals.

@Test
public void testLocationDecoratorEquals() {
    Layout defaultLayout = new DefaultLayoutFactory().createLayout(Layout.newLayout());
    Shape defaultRootShape = defaultLayout.createShape(new ObjectType());
    Shape implicitCastRootShape = layout.createShape(new ObjectType());
    DynamicObject object1 = implicitCastRootShape.newInstance();
    object1.define("a", otherVal);
    Location location1 = object1.getShape().getProperty("a").getLocation();
    // Location of "a" should not change if an Integer is set
    object1.set("a", intVal);
    Assert.assertEquals(location1, object1.getShape().getProperty("a").getLocation());
    DynamicObject object2 = defaultRootShape.newInstance();
    object2.define("a", otherVal);
    Location location2 = object2.getShape().getProperty("a").getLocation();
    // This test relies on the assumption that both locations are of the same class
    Assert.assertEquals(location1.getClass(), location2.getClass());
    Assert.assertNotEquals(location1, location2);
}
Also used : ObjectType(com.oracle.truffle.api.object.ObjectType) Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Layout(com.oracle.truffle.api.object.Layout) DefaultLayoutFactory(com.oracle.truffle.object.basic.DefaultLayoutFactory) Location(com.oracle.truffle.api.object.Location) Test(org.junit.Test)

Example 3 with Location

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

the class ImplicitCastTest method testIntObject.

@Test
public void testIntObject() {
    Shape rootShape = layout.createShape(new ObjectType());
    DynamicObject object = rootShape.newInstance();
    object.define("a", intVal);
    object.define("a", "");
    Location location = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(Object.class, getLocationType(location));
    Assert.assertEquals(String.class, object.get("a").getClass());
}
Also used : ObjectType(com.oracle.truffle.api.object.ObjectType) Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Location(com.oracle.truffle.api.object.Location) Test(org.junit.Test)

Example 4 with Location

use of com.oracle.truffle.api.object.Location 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 5 with Location

use of com.oracle.truffle.api.object.Location 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)

Aggregations

Location (com.oracle.truffle.api.object.Location)20 Test (org.junit.Test)18 DynamicObject (com.oracle.truffle.api.object.DynamicObject)17 ObjectLocation (com.oracle.truffle.api.object.ObjectLocation)8 Shape (com.oracle.truffle.api.object.Shape)7 ObjectType (com.oracle.truffle.api.object.ObjectType)6 Property (com.oracle.truffle.api.object.Property)4 DeclaredLocation (com.oracle.truffle.object.Locations.DeclaredLocation)2 Layout (com.oracle.truffle.api.object.Layout)1 LocationFactory (com.oracle.truffle.api.object.LocationFactory)1 Allocator (com.oracle.truffle.api.object.Shape.Allocator)1 DefaultLayoutFactory (com.oracle.truffle.object.basic.DefaultLayoutFactory)1