Search in sources :

Example 16 with Location

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

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

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

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

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

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