Search in sources :

Example 61 with DynamicObject

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

the class SLContext method createObject.

/**
 * Allocate an empty object. All new objects initially have no properties. Properties are added
 * when they are first stored, i.e., the store triggers a shape change of the object.
 */
public DynamicObject createObject() {
    DynamicObject object = null;
    allocationReporter.onEnter(null, 0, AllocationReporter.SIZE_UNKNOWN);
    object = emptyShape.newInstance();
    allocationReporter.onReturnValue(object, 0, AllocationReporter.SIZE_UNKNOWN);
    return object;
}
Also used : DynamicObject(com.oracle.truffle.api.object.DynamicObject)

Example 62 with DynamicObject

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

the class ImplicitCastTest method testIntOtherDoesNotGoBack.

@Test
public void testIntOtherDoesNotGoBack() {
    Shape rootShape = layout.createShape(new ObjectType());
    DynamicObject object = rootShape.newInstance();
    object.define("a", intVal);
    Location location1 = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(int.class, getLocationType(location1));
    object.define("a", otherVal);
    Location location2 = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(otherPrimClass, getLocationType(location2));
    Assert.assertEquals(otherVal.getClass(), object.get("a").getClass());
    DOTestAsserts.assertSameLocation(location1, location2);
    object.define("a", intVal);
    Location location3 = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(otherPrimClass, getLocationType(location3));
    Assert.assertEquals(otherVal.getClass(), object.get("a").getClass());
    DOTestAsserts.assertSameLocation(location2, location3);
}
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 63 with DynamicObject

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

the class ImplicitCastTest method testIntOther.

@Test
public void testIntOther() {
    Shape rootShape = layout.createShape(new ObjectType());
    DynamicObject object = rootShape.newInstance();
    object.define("a", intVal);
    Location location1 = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(int.class, getLocationType(location1));
    object.define("a", otherVal);
    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 64 with DynamicObject

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

the class ImplicitCastTest method testIntOtherObject.

@Test
public void testIntOtherObject() {
    Shape rootShape = layout.createShape(new ObjectType());
    DynamicObject object = rootShape.newInstance();
    object.define("a", intVal);
    object.define("a", otherVal);
    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 65 with DynamicObject

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

the class LocationTest method testChangeFlagsChangeLocation.

@Test
public void testChangeFlagsChangeLocation() {
    DynamicObject object = rootShape.newInstance();
    object.define("foo", 42);
    Location location = object.getShape().getProperty("foo").getLocation();
    object.define("foo", "str", 111);
    Assert.assertEquals("str", object.get("foo"));
    Property newProperty = object.getShape().getProperty("foo");
    Assert.assertEquals(111, newProperty.getFlags());
    Location newLocation = newProperty.getLocation();
    Assert.assertNotSame(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)

Aggregations

DynamicObject (com.oracle.truffle.api.object.DynamicObject)100 Test (org.junit.Test)91 Location (com.oracle.truffle.api.object.Location)17 Shape (com.oracle.truffle.api.object.Shape)16 DynamicObjectFactory (com.oracle.truffle.api.object.DynamicObjectFactory)8 ObjectLocation (com.oracle.truffle.api.object.ObjectLocation)7 Property (com.oracle.truffle.api.object.Property)7 ObjectType (com.oracle.truffle.api.object.ObjectType)6 IncompatibleLocationException (com.oracle.truffle.api.object.IncompatibleLocationException)4 Layout (com.oracle.truffle.api.object.Layout)4 FinalLocationException (com.oracle.truffle.api.object.FinalLocationException)2 PropertyBuilder (com.oracle.truffle.object.dsl.processor.model.PropertyBuilder)2 VariableElement (javax.lang.model.element.VariableElement)2 LocationFactory (com.oracle.truffle.api.object.LocationFactory)1 ShapeImpl (com.oracle.truffle.object.ShapeImpl)1 DefaultLayoutFactory (com.oracle.truffle.object.basic.DefaultLayoutFactory)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1