Search in sources :

Example 6 with Shape

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

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

the class SharedShapeTest method testShapeIsSharedAndIdentity.

@Test
public void testShapeIsSharedAndIdentity() {
    DynamicObject object = rootShape.newInstance();
    Assert.assertEquals(false, rootShape.isShared());
    Assert.assertSame(sharedShape, rootShape.makeSharedShape());
    Assert.assertEquals(true, sharedShape.isShared());
    object.setShapeAndGrow(rootShape, sharedShape);
    object.define("a", 1);
    final Shape sharedShapeWithA = object.getShape();
    Assert.assertEquals(true, sharedShapeWithA.isShared());
    DynamicObject object2 = rootShape.newInstance();
    object2.setShapeAndGrow(rootShape, sharedShape);
    object2.define("a", 1);
    Assert.assertSame(sharedShapeWithA, object2.getShape());
    // Currently, sharing is a transition and transitions do not commute magically
    DynamicObject object3 = rootShape.newInstance();
    object3.define("a", 1);
    object3.setShapeAndGrow(object3.getShape(), object3.getShape().makeSharedShape());
    Assert.assertNotSame(sharedShapeWithA, object3.getShape());
}
Also used : Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Test(org.junit.Test)

Example 8 with Shape

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

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

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

Aggregations

Shape (com.oracle.truffle.api.object.Shape)18 DynamicObject (com.oracle.truffle.api.object.DynamicObject)16 Test (org.junit.Test)15 Location (com.oracle.truffle.api.object.Location)7 ObjectType (com.oracle.truffle.api.object.ObjectType)7 Layout (com.oracle.truffle.api.object.Layout)5 DefaultLayoutFactory (com.oracle.truffle.object.basic.DefaultLayoutFactory)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 DynamicObjectFactory (com.oracle.truffle.api.object.DynamicObjectFactory)1 LocationFactory (com.oracle.truffle.api.object.LocationFactory)1 ObjectLocation (com.oracle.truffle.api.object.ObjectLocation)1 Property (com.oracle.truffle.api.object.Property)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1