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