Search in sources :

Example 6 with Location

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

Example 7 with Location

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

the class SharedShapeTest method testDifferentLocationsImplicitCast.

@Test
public void testDifferentLocationsImplicitCast() {
    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));
    // The old location can still be read
    Assert.assertEquals(1, location1.get(object));
    Assert.assertEquals(2L, location2.get(object));
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) Location(com.oracle.truffle.api.object.Location) Test(org.junit.Test)

Example 8 with Location

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

the class SharedShapeTest method testCanReuseLocationsUntilShared.

@Test
public void testCanReuseLocationsUntilShared() {
    DynamicObject object = rootShape.newInstance();
    object.define("a", 1);
    Location locationA1 = object.getShape().getProperty("a").getLocation();
    object.define("a", 2L);
    Location locationA2 = object.getShape().getProperty("a").getLocation();
    DOTestAsserts.assertSameLocation(locationA1, locationA2);
    Assert.assertEquals(long.class, getLocationType(locationA2));
    DOTestAsserts.assertShape("{\"a\":long@0\n}", object.getShape());
    DOTestAsserts.assertShapeFields(object, 1, 0);
    // Share object
    object.setShapeAndGrow(object.getShape(), object.getShape().makeSharedShape());
    object.define("b", 3);
    Location locationB1 = object.getShape().getProperty("b").getLocation();
    object.define("b", 4L);
    Location locationB2 = object.getShape().getProperty("b").getLocation();
    object.define("c", 5);
    DOTestAsserts.assertNotSameLocation(locationB1, locationB2);
    Assert.assertEquals(Object.class, getLocationType(locationB2));
    DOTestAsserts.assertShape("{" + "\"c\":int@2,\n" + "\"b\":Object@0,\n" + "\"a\":long@0\n" + "}", object.getShape());
    DOTestAsserts.assertShapeFields(object, 3, 1);
    Assert.assertEquals(2L, locationA2.get(object));
    // The old location can still be read
    Assert.assertEquals(3, locationB1.get(object));
    Assert.assertEquals(4L, locationB2.get(object));
    Assert.assertEquals(5, object.get("c"));
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject) Location(com.oracle.truffle.api.object.Location) Test(org.junit.Test)

Example 9 with Location

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

the class LayoutStrategy method generalizeProperty.

/**
 * @since 0.17 or earlier
 */
protected ShapeImpl generalizeProperty(Property oldProperty, Object value, ShapeImpl currentShape, ShapeImpl nextShape) {
    Location oldLocation = oldProperty.getLocation();
    Location newLocation = currentShape.allocator().locationForValueUpcast(value, oldLocation);
    Property newProperty = oldProperty.relocate(newLocation);
    ShapeImpl newShape = nextShape.replaceProperty(oldProperty, newProperty);
    return newShape;
}
Also used : Property(com.oracle.truffle.api.object.Property) Location(com.oracle.truffle.api.object.Location) DeclaredLocation(com.oracle.truffle.object.Locations.DeclaredLocation)

Example 10 with Location

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

the class LayoutStrategy method definePropertyChangeFlags.

/**
 * @since 0.17 or earlier
 */
protected ShapeImpl definePropertyChangeFlags(ShapeImpl oldShape, Property oldProperty, Object value, int flags) {
    Location oldLocation = oldProperty.getLocation();
    Location newLocation;
    if (oldLocation.canSet(value)) {
        newLocation = oldLocation;
    } else {
        newLocation = oldShape.allocator().locationForValueUpcast(value, oldLocation);
    }
    Property newProperty = Property.create(oldProperty.getKey(), newLocation, flags);
    ShapeImpl newShape = oldShape.replaceProperty(oldProperty, newProperty);
    return newShape;
}
Also used : Property(com.oracle.truffle.api.object.Property) Location(com.oracle.truffle.api.object.Location) DeclaredLocation(com.oracle.truffle.object.Locations.DeclaredLocation)

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