Skip to content

Commit 24a1a36

Browse files
committed
[GR-66233] Remove "basic" dynamic object model.
PullRequest: graal/21813
2 parents 5a8629d + f4cbf63 commit 24a1a36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1974
-4874
lines changed

truffle/mx.truffle/mx_truffle.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ def _truffle_gate_runner(args, tasks):
490490
with Task('Truffle UnitTests', tasks, tags=TruffleGateTags.truffle_test) as t:
491491
if t:
492492
unittest(['--suite', 'truffle', '--enable-timing', '--verbose', '--max-class-failures=25'])
493-
unittest(['--suite', 'truffle', '--enable-timing', '-Dtruffle.object.LayoutFactory=com.oracle.truffle.api.object.CoreLayoutFactory', 'com.oracle.truffle.object'])
494493
if jdk.javaCompliance >= '22':
495494
with Task('Truffle NFI tests with Panama Backend', tasks, tags=TruffleGateTags.panama_test) as t:
496495
if t:

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/basic/test/DOTestAsserts.java

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
*/
4141
package com.oracle.truffle.object.basic.test;
4242

43-
import static org.hamcrest.CoreMatchers.either;
44-
import static org.hamcrest.CoreMatchers.endsWith;
45-
import static org.hamcrest.MatcherAssert.assertThat;
4643
import static org.junit.Assert.assertEquals;
4744
import static org.junit.Assert.assertTrue;
4845

@@ -52,12 +49,13 @@
5249
import java.util.HashMap;
5350
import java.util.Iterator;
5451
import java.util.Map;
52+
import java.util.NoSuchElementException;
5553
import java.util.regex.Matcher;
5654
import java.util.regex.Pattern;
5755
import java.util.stream.Collectors;
56+
import java.util.stream.Stream;
5857

5958
import org.junit.Assert;
60-
import org.junit.Assume;
6159

6260
import com.oracle.truffle.api.Assumption;
6361
import com.oracle.truffle.api.object.DynamicObject;
@@ -75,7 +73,9 @@ public static <T> T invokeGetter(String methodName, Object receiver) {
7573
@SuppressWarnings("unchecked")
7674
public static <T> T invokeMethod(String methodName, Object receiver, Object... args) {
7775
try {
78-
Method method = Arrays.stream(receiver.getClass().getMethods()).filter(m -> m.getName().equals(methodName)).findFirst().get();
76+
Method method = Stream.concat(Arrays.stream(receiver.getClass().getMethods()), Arrays.stream(receiver.getClass().getDeclaredMethods())).filter(
77+
m -> m.getName().equals(methodName)).findFirst().orElseThrow(
78+
() -> new NoSuchElementException("Method " + methodName + " not found in " + receiver.getClass()));
7979
method.setAccessible(true);
8080
return (T) method.invoke(receiver, args);
8181
} catch (IllegalAccessException | InvocationTargetException e) {
@@ -144,33 +144,12 @@ public static Class<?> getLocationType(Location location) {
144144
}
145145
}
146146

147-
public static void assumeExtLayout() {
148-
Shape shape = Shape.newBuilder().build();
149-
assertThat("Unexpected Shape class name (the assertion may need to be updated if the code is refactored)",
150-
shape.getClass().getName(), either(endsWith("ShapeExt")).or(endsWith("ShapeBasic")));
151-
Assume.assumeTrue("Test is specific to the Extended Dynamic Object Layout",
152-
shape.getClass().getName().endsWith("ShapeExt"));
153-
}
154-
155-
public static Location assumeCoreLocation(Location location) {
156-
Assume.assumeTrue(isCoreLocation(location));
157-
return location;
158-
}
159-
160-
public static boolean isCoreLocation(Location location) {
161-
try {
162-
Class<?> locationBaseClass = Class.forName("com.oracle.truffle.api.object.CoreLocation");
163-
return locationBaseClass.isInstance(location);
164-
} catch (ClassNotFoundException | IllegalArgumentException e) {
165-
throw new AssertionError(e);
166-
}
167-
}
168-
169147
public static void assertShape(String[] fields, Shape shape) {
170148
String shapeString = shapeLocationsToString(shape);
171149
// ignore trailing extra info in location strings.
172-
String regex = Arrays.asList(fields).stream().map(Pattern::quote).collect(Collectors.joining("[^\"]*?", "\\{", "[^\"]*?\\}"));
173-
assertTrue("expected " + Arrays.stream(fields).collect(Collectors.joining(", ", "{", "}")) + ", actual: " + shapeString, Pattern.matches(regex, shapeString));
150+
String regex = Arrays.stream(fields).map(Pattern::quote).collect(Collectors.joining("[^\"]*?", "\\{", "[^\"]*?\\}"));
151+
assertTrue("expected " + Arrays.stream(fields).collect(Collectors.joining(", ", "{", "}")) + ", actual: " + shapeString + ", regex: " + regex,
152+
Pattern.matches(regex, shapeString));
174153
}
175154

176155
private static String shapeLocationsToString(Shape shape) {
@@ -182,7 +161,6 @@ private static String shapeLocationsToString(Shape shape) {
182161
sb.append("{");
183162
for (Iterator<Property> iterator = shape.getPropertyListInternal(false).iterator(); iterator.hasNext();) {
184163
Property p = iterator.next();
185-
assumeCoreLocation(p.getLocation());
186164
sb.append("\"").append(p.getKey()).append("\":").append(p.getLocation());
187165
if (iterator.hasNext()) {
188166
sb.append(",");

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/basic/test/LocationTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import static com.oracle.truffle.object.basic.test.DOTestAsserts.getLocationType;
4747
import static com.oracle.truffle.object.basic.test.DOTestAsserts.invokeGetter;
4848
import static com.oracle.truffle.object.basic.test.DOTestAsserts.invokeMethod;
49-
import static com.oracle.truffle.object.basic.test.DOTestAsserts.isCoreLocation;
5049
import static org.junit.Assert.assertEquals;
5150
import static org.junit.Assert.assertFalse;
5251
import static org.junit.Assert.assertTrue;
@@ -142,7 +141,7 @@ public void testPrim2Object() {
142141
Location location2 = object.getShape().getProperty("foo").getLocation();
143142
assertEquals(Object.class, getLocationType(location2));
144143
assertLocationFields(location2, 0, 1);
145-
assertShapeFields(object, isCoreLocation(location2) ? 1 : 0, 1);
144+
assertShapeFields(object, 0, 1);
146145
}
147146

148147
@Test
@@ -161,7 +160,7 @@ public void testUnrelatedPrimitivesGoToObject() {
161160
Location location2 = object.getShape().getProperty("foo").getLocation();
162161
assertEquals(Object.class, getLocationType(location2));
163162
assertLocationFields(location2, 0, 1);
164-
assertShapeFields(object, isCoreLocation(location2) ? 1 : 0, 1);
163+
assertShapeFields(object, 0, 1);
165164
}
166165

167166
@Test

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/basic/test/ShapeTest.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,47 @@ public void testToString() {
8989

9090
Shape aObjBInt = aObj.defineProperty("b", 2, 0);
9191
DOTestAsserts.assertShape(new String[]{
92-
"\"b\":int@1",
92+
"\"b\":int@0",
9393
"\"a\":Object@0"}, aObjBInt);
9494

9595
Shape aIntBObj = aInt.defineProperty("b", new Object(), 0);
9696
DOTestAsserts.assertShape(new String[]{
97-
"\"b\":Object@0",
98-
"\"a\":int@0"}, aIntBObj);
97+
"\"b\":Object@1",
98+
"\"a\":Object@0"}, aIntBObj);
9999

100100
Location boolLocation = locationForType(rootShape, boolean.class);
101101
Shape bool = invokeMethod("addProperty", rootShape, Property.create("bool", boolLocation, 0));
102-
DOTestAsserts.assertShape(new String[]{"\"bool\":boolean@0"}, bool);
102+
DOTestAsserts.assertShape(new String[]{"\"bool\":Object@0"}, bool);
103103

104104
Location strLocation = locationForType(rootShape, String.class);
105105
Shape str = invokeMethod("addProperty", rootShape, Property.create("str", strLocation, 0));
106106
DOTestAsserts.assertShape(new String[]{"\"str\":Object@0"}, str);
107107

108-
Shape shapeWithExtArray = aIntBObj.defineProperty("c", true, 0).defineProperty("d", 3.14, 0).defineProperty("e", 1L << 44, 0);
108+
Shape shapeWithManyFields = aIntBObj.//
109+
defineProperty("c", true, 0).//
110+
defineProperty("d", 3.14, 0).//
111+
defineProperty("e", 1L << 44, 0).//
112+
defineProperty("f", 9001, 0);
113+
DOTestAsserts.assertShape(new String[]{
114+
"\"f\":int@2",
115+
"\"e\":long@1",
116+
"\"d\":double@0",
117+
"\"c\":Object@2",
118+
"\"b\":Object@1",
119+
"\"a\":Object@0"}, shapeWithManyFields);
120+
121+
Shape shapeWithExtArray = makeRootShape().//
122+
defineProperty("a", 1, 0).//
123+
defineProperty("b", new Object(), 0).//
124+
defineProperty("c", true, 0).//
125+
defineProperty("d", 3.14, 0).//
126+
defineProperty("e", 1L << 33, 0).//
127+
defineProperty("f", 1L << 44, 0);
109128
DOTestAsserts.assertShape(new String[]{
110-
"\"e\":long[0]",
111-
"\"d\":double@2",
112-
"\"c\":boolean@1",
129+
"\"f\":long[0]",
130+
"\"e\":long@2",
131+
"\"d\":double@1",
132+
"\"c\":Object@1",
113133
"\"b\":Object@0",
114134
"\"a\":int@0"}, shapeWithExtArray);
115135
}

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/ext/test/GR42603.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
*/
4141
package com.oracle.truffle.object.ext.test;
4242

43-
import static com.oracle.truffle.object.basic.test.DOTestAsserts.assumeExtLayout;
44-
4543
import java.util.ArrayList;
4644
import java.util.List;
4745
import java.util.concurrent.ExecutionException;
@@ -64,7 +62,6 @@ public class GR42603 {
6462

6563
@Test
6664
public void testReplacePropertyRace() throws Throwable {
67-
assumeExtLayout();
6865
for (int i = 0; i < 100; i++) {
6966
testConcurrentReplaceProperty();
7067
}

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/ext/test/GR52036.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
*/
4141
package com.oracle.truffle.object.ext.test;
4242

43-
import static com.oracle.truffle.object.basic.test.DOTestAsserts.assumeExtLayout;
4443
import static com.oracle.truffle.object.basic.test.DOTestAsserts.getTypeAssumption;
4544
import static com.oracle.truffle.object.basic.test.DOTestAsserts.getTypeAssumptionRecord;
4645
import static org.junit.Assert.assertFalse;
@@ -70,7 +69,6 @@ public class GR52036 {
7069
@SuppressWarnings("try")
7170
@Test
7271
public void testGR52036Reproducer() throws Throwable {
73-
assumeExtLayout();
7472

7573
class ObjType1 extends DynamicObject {
7674
protected ObjType1(Shape shape) {

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/ext/test/ObjectModelRegressionTest.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242

4343
import static com.oracle.truffle.object.basic.test.DOTestAsserts.assertObjectLocation;
4444
import static com.oracle.truffle.object.basic.test.DOTestAsserts.assertPrimitiveLocation;
45-
import static com.oracle.truffle.object.basic.test.DOTestAsserts.assumeExtLayout;
46-
import static com.oracle.truffle.object.basic.test.DOTestAsserts.invokeGetter;
45+
import static com.oracle.truffle.object.basic.test.DOTestAsserts.invokeMethod;
4746
import static org.junit.Assert.assertEquals;
4847
import static org.junit.Assert.assertFalse;
4948
import static org.junit.Assert.assertNotNull;
@@ -55,7 +54,7 @@
5554
import java.util.Arrays;
5655
import java.util.Collection;
5756
import java.util.List;
58-
import java.util.Map;
57+
import java.util.function.BiConsumer;
5958

6059
import org.hamcrest.CoreMatchers;
6160
import org.hamcrest.MatcherAssert;
@@ -221,12 +220,17 @@ public void testDeclaredPropertyShapeTransitionCount() {
221220
}
222221

223222
private static int countTransitions(Shape shape) {
224-
Map<?, ? extends Shape> transitionMap = invokeGetter("getTransitionMapForRead", shape);
225-
int count = transitionMap.size();
226-
for (Shape childShape : transitionMap.values()) {
227-
count += countTransitions(childShape);
228-
}
229-
return count;
223+
var consumer = new BiConsumer<Object, Shape>() {
224+
int count = 0;
225+
226+
@Override
227+
public void accept(Object t, Shape childShape) {
228+
count += 1;
229+
count += countTransitions(childShape);
230+
}
231+
};
232+
invokeMethod("forEachTransition", shape, consumer);
233+
return consumer.count;
230234
}
231235

232236
@Test
@@ -388,8 +392,6 @@ public void testChangeFlagsConstantToNonConstant() {
388392

389393
@Test
390394
public void testTryMergeShapes() {
391-
assumeExtLayout();
392-
393395
// Assume (MaxMergeDepth >= 5)
394396
Shape emptyShape = Shape.newBuilder().allowImplicitCastIntToDouble(true).build();
395397

@@ -439,8 +441,6 @@ public void testTryMergeShapes() {
439441

440442
@Test
441443
public void testTryMergeShapes2() {
442-
assumeExtLayout();
443-
444444
// Assume (MaxMergeDepth >= 5 && MaxMergeDiff >= 2)
445445

446446
Shape emptyShape = Shape.newBuilder().allowImplicitCastIntToDouble(true).build();
@@ -477,8 +477,6 @@ public void testTryMergeShapes2() {
477477

478478
@Test
479479
public void testBooleanLocationTypeAssumption() {
480-
assumeExtLayout();
481-
482480
Shape emptyShape = Shape.newBuilder().build();
483481

484482
DynamicObject obj = new TestDynamicObject(emptyShape);
@@ -566,8 +564,6 @@ public void testPropertyAssumptionInvalidAfterRemove() {
566564
*/
567565
@Test
568566
public void testPropertyAssumptionInvalidAfterReplace1() {
569-
assumeExtLayout();
570-
571567
Shape emptyShape = Shape.newBuilder().propertyAssumptions(true).build();
572568

573569
int flag = 2;
@@ -602,8 +598,6 @@ public void testPropertyAssumptionInvalidAfterReplace1() {
602598
*/
603599
@Test
604600
public void testPropertyAssumptionInvalidAfterReplace2() {
605-
assumeExtLayout();
606-
607601
Shape emptyShape = Shape.newBuilder().propertyAssumptions(true).build();
608602

609603
int flag = 2;

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/object/ext/test/PolymorphicPrimitivesTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
import static com.oracle.truffle.object.basic.test.DOTestAsserts.assertObjectLocation;
4444
import static com.oracle.truffle.object.basic.test.DOTestAsserts.assertPrimitiveLocation;
45-
import static com.oracle.truffle.object.basic.test.DOTestAsserts.assumeExtLayout;
4645
import static org.junit.Assert.assertEquals;
4746
import static org.junit.Assert.assertSame;
4847
import static org.junit.Assert.assertTrue;
@@ -51,7 +50,6 @@
5150
import java.util.Arrays;
5251
import java.util.List;
5352

54-
import org.junit.Before;
5553
import org.junit.Test;
5654
import org.junit.runner.RunWith;
5755
import org.junit.runners.Parameterized;
@@ -84,11 +82,6 @@ private static DynamicObject newInstance(Shape emptyShape) {
8482
return new TestDynamicObject(emptyShape);
8583
}
8684

87-
@Before
88-
public void before() {
89-
assumeExtLayout();
90-
}
91-
9285
@Test
9386
public void testIntLongBoxed() {
9487
Shape emptyShape = newEmptyShape();

0 commit comments

Comments
 (0)