Skip to content

Commit 334c870

Browse files
committed
Migrate usages to new Shape.Builder.layout(Class,Lookup).
1 parent 6624eb0 commit 334c870

File tree

9 files changed

+87
-31
lines changed

9 files changed

+87
-31
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/truffle/test/DynamicObjectPartialEvaluationTest.java

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,18 +24,8 @@
2424
*/
2525
package jdk.graal.compiler.truffle.test;
2626

27-
import jdk.graal.compiler.truffle.test.nodes.AbstractTestNode;
28-
import jdk.graal.compiler.truffle.test.nodes.RootTestNode;
29-
import jdk.graal.compiler.graph.Node;
30-
import jdk.graal.compiler.nodes.NamedLocationIdentity;
31-
import jdk.graal.compiler.nodes.StructuredGraph;
32-
import jdk.graal.compiler.nodes.extended.GuardedUnsafeLoadNode;
33-
import jdk.graal.compiler.nodes.extended.RawLoadNode;
34-
import jdk.graal.compiler.nodes.extended.RawStoreNode;
35-
import jdk.graal.compiler.nodes.extended.UnsafeAccessNode;
36-
import jdk.graal.compiler.nodes.java.LoadFieldNode;
37-
import jdk.graal.compiler.nodes.java.StoreFieldNode;
38-
import jdk.graal.compiler.truffle.nodes.ObjectLocationIdentity;
27+
import java.lang.invoke.MethodHandles;
28+
3929
import org.junit.Assert;
4030
import org.junit.Before;
4131
import org.junit.Test;
@@ -50,6 +40,18 @@
5040
import com.oracle.truffle.api.object.Shape;
5141
import com.oracle.truffle.runtime.OptimizedCallTarget;
5242

43+
import jdk.graal.compiler.graph.Node;
44+
import jdk.graal.compiler.nodes.NamedLocationIdentity;
45+
import jdk.graal.compiler.nodes.StructuredGraph;
46+
import jdk.graal.compiler.nodes.extended.GuardedUnsafeLoadNode;
47+
import jdk.graal.compiler.nodes.extended.RawLoadNode;
48+
import jdk.graal.compiler.nodes.extended.RawStoreNode;
49+
import jdk.graal.compiler.nodes.extended.UnsafeAccessNode;
50+
import jdk.graal.compiler.nodes.java.LoadFieldNode;
51+
import jdk.graal.compiler.nodes.java.StoreFieldNode;
52+
import jdk.graal.compiler.truffle.nodes.ObjectLocationIdentity;
53+
import jdk.graal.compiler.truffle.test.nodes.AbstractTestNode;
54+
import jdk.graal.compiler.truffle.test.nodes.RootTestNode;
5355
import jdk.vm.ci.meta.JavaKind;
5456

5557
public class DynamicObjectPartialEvaluationTest extends PartialEvaluationTest {
@@ -59,8 +61,9 @@ public class DynamicObjectPartialEvaluationTest extends PartialEvaluationTest {
5961

6062
@Before
6163
public void before() {
62-
rootShapeWithoutFields = Shape.newBuilder().layout(TestDynamicObject.class).build();
63-
rootShapeWithFields = Shape.newBuilder().layout(TestDynamicObjectWithFields.class).build();
64+
var lookup = MethodHandles.lookup();
65+
rootShapeWithoutFields = Shape.newBuilder().layout(TestDynamicObject.class, lookup).build();
66+
rootShapeWithFields = Shape.newBuilder().layout(TestDynamicObjectWithFields.class, lookup).build();
6467
newInstanceWithFields();
6568
newInstanceWithoutFields();
6669
}

truffle/src/com.oracle.truffle.object.basic.test/src/com/oracle/truffle/object/basic/test/DynamicObjectConstructorTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -43,6 +43,8 @@
4343
import static org.hamcrest.CoreMatchers.containsString;
4444
import static org.hamcrest.MatcherAssert.assertThat;
4545

46+
import java.lang.invoke.MethodHandles;
47+
4648
import org.junit.Test;
4749

4850
import com.oracle.truffle.api.object.DynamicObjectLibrary;
@@ -53,15 +55,15 @@ public class DynamicObjectConstructorTest extends AbstractLibraryTest {
5355

5456
@Test
5557
public void testIncompatibleShape() {
56-
Shape shape = Shape.newBuilder().layout(TestDynamicObjectDefault.class).build();
58+
Shape shape = Shape.newBuilder().layout(TestDynamicObjectDefault.class, MethodHandles.lookup()).build();
5759

5860
assertFails(() -> new TestDynamicObjectMinimal(shape), IllegalArgumentException.class,
5961
ex -> assertThat(ex.getMessage(), containsString("Incompatible shape")));
6062
}
6163

6264
@Test
6365
public void testNonEmptyShape() {
64-
Shape emptyShape = Shape.newBuilder().layout(TestDynamicObjectDefault.class).build();
66+
Shape emptyShape = Shape.newBuilder().layout(TestDynamicObjectDefault.class, MethodHandles.lookup()).build();
6567
TestDynamicObjectDefault obj = new TestDynamicObjectDefault(emptyShape);
6668
DynamicObjectLibrary.getUncached().put(obj, "key", "value");
6769
Shape nonEmptyShape = obj.getShape();

truffle/src/com.oracle.truffle.object.basic.test/src/com/oracle/truffle/object/basic/test/DynamicObjectLibraryTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import static org.junit.Assert.fail;
4949
import static org.junit.Assume.assumeTrue;
5050

51+
import java.lang.invoke.MethodHandles;
5152
import java.util.ArrayList;
5253
import java.util.Arrays;
5354
import java.util.Collection;
@@ -85,10 +86,14 @@ public static Collection<Object[]> parameters() {
8586
Supplier<? extends DynamicObject> minimalSupplier = () -> new TestDynamicObjectMinimal(shapeMin);
8687
addParams(params, minimalSupplier);
8788

88-
Shape shapeDef = Shape.newBuilder().layout(TestDynamicObjectDefault.class).build();
89+
Shape shapeDef = Shape.newBuilder().layout(TestDynamicObjectDefault.class, MethodHandles.lookup()).build();
8990
Supplier<? extends DynamicObject> defaultSupplier = () -> new TestDynamicObjectDefault(shapeDef);
9091
addParams(params, defaultSupplier);
9192

93+
Shape shapeDefLegacy = Shape.newBuilder().layout(TestDynamicObjectDefault.class).build();
94+
Supplier<? extends DynamicObject> defaultSupplierLegacy = () -> new TestDynamicObjectDefault(shapeDefLegacy);
95+
addParams(params, defaultSupplierLegacy);
96+
9297
return params;
9398
}
9499

truffle/src/com.oracle.truffle.object.basic.test/src/com/oracle/truffle/object/basic/test/LeakCheckTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -43,6 +43,7 @@
4343
import static org.junit.Assert.assertNull;
4444
import static org.junit.Assert.assertSame;
4545

46+
import java.lang.invoke.MethodHandles;
4647
import java.lang.ref.Reference;
4748
import java.lang.ref.WeakReference;
4849
import java.util.ArrayList;
@@ -59,7 +60,7 @@ public class LeakCheckTest {
5960
private static final DynamicObjectLibrary LIBRARY = DynamicObjectLibrary.getUncached();
6061

6162
private static Shape newEmptyShape() {
62-
return Shape.newBuilder().layout(TestDynamicObjectDefault.class).build();
63+
return Shape.newBuilder().layout(TestDynamicObjectDefault.class, MethodHandles.lookup()).build();
6364
}
6465

6566
private static DynamicObject newInstance(Shape emptyShape) {

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

+22-4
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@
4242

4343
import static com.oracle.truffle.object.basic.test.DOTestAsserts.getLocationType;
4444

45+
import java.lang.invoke.MethodHandles;
4546
import java.util.Arrays;
4647
import java.util.List;
4748

4849
import org.junit.Assert;
50+
import org.junit.Before;
4951
import org.junit.Test;
5052
import org.junit.runner.RunWith;
5153
import org.junit.runners.Parameterized;
54+
import org.junit.runners.Parameterized.Parameter;
5255
import org.junit.runners.Parameterized.Parameters;
5356

5457
import com.oracle.truffle.api.object.DynamicObject;
@@ -63,12 +66,27 @@
6366
@RunWith(Parameterized.class)
6467
public class LocationTest extends AbstractParametrizedLibraryTest {
6568

66-
@Parameters(name = "{0}")
67-
public static List<TestRun> data() {
68-
return Arrays.asList(TestRun.values());
69+
@Parameter(1) public boolean useLookup;
70+
71+
@Parameters(name = "{0},{1}")
72+
public static List<Object[]> data() {
73+
return Arrays.stream(TestRun.values()).flatMap(run -> List.of(Boolean.FALSE, Boolean.TRUE).stream().map(lookup -> new Object[]{run, lookup})).toList();
6974
}
7075

71-
final Shape rootShape = Shape.newBuilder().layout(TestDynamicObjectDefault.class).build();
76+
Shape rootShape;
77+
78+
@Before
79+
public void setup() {
80+
rootShape = makeRootShape();
81+
}
82+
83+
private Shape makeRootShape() {
84+
if (useLookup) {
85+
return Shape.newBuilder().layout(TestDynamicObjectDefault.class, MethodHandles.lookup()).build();
86+
} else {
87+
return Shape.newBuilder().layout(TestDynamicObjectDefault.class).build();
88+
}
89+
}
7290

7391
private DynamicObject newInstance() {
7492
return new TestDynamicObjectDefault(rootShape);

truffle/src/com.oracle.truffle.object.basic.test/src/com/oracle/truffle/object/basic/test/RemoveKeyTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,6 +40,7 @@
4040
*/
4141
package com.oracle.truffle.object.basic.test;
4242

43+
import java.lang.invoke.MethodHandles;
4344
import java.util.Arrays;
4445
import java.util.List;
4546
import java.util.Map;
@@ -62,7 +63,7 @@ public static List<TestRun> data() {
6263
return Arrays.asList(TestRun.values());
6364
}
6465

65-
final Shape rootShape = Shape.newBuilder().allowImplicitCastIntToDouble(true).layout(TestDynamicObjectDefault.class).build();
66+
final Shape rootShape = Shape.newBuilder().allowImplicitCastIntToDouble(true).layout(TestDynamicObjectDefault.class, MethodHandles.lookup()).build();
6667

6768
@Test
6869
public void testRemoveAfterReplace() {

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

+25-1
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,42 @@
4040
*/
4141
package com.oracle.truffle.object.basic.test;
4242

43+
import java.lang.invoke.MethodHandles;
44+
import java.util.Arrays;
45+
import java.util.List;
46+
4347
import org.junit.Test;
48+
import org.junit.runner.RunWith;
49+
import org.junit.runners.Parameterized;
50+
import org.junit.runners.Parameterized.Parameter;
51+
import org.junit.runners.Parameterized.Parameters;
4452

4553
import com.oracle.truffle.api.object.Property;
4654
import com.oracle.truffle.api.object.Shape;
4755
import com.oracle.truffle.object.ShapeImpl;
4856

4957
@SuppressWarnings("deprecation")
58+
@RunWith(Parameterized.class)
5059
public class ShapeTest {
5160

61+
@Parameters(name = "{0}")
62+
public static List<Boolean> data() {
63+
return Arrays.asList(Boolean.FALSE, Boolean.TRUE);
64+
}
65+
66+
@Parameter public boolean useLookup;
67+
68+
private Shape makeRootShape() {
69+
if (useLookup) {
70+
return Shape.newBuilder().layout(TestDynamicObjectDefault.class, MethodHandles.lookup()).allowImplicitCastIntToLong(true).build();
71+
} else {
72+
return Shape.newBuilder().layout(TestDynamicObjectDefault.class).allowImplicitCastIntToLong(true).build();
73+
}
74+
}
75+
5276
@Test
5377
public void testToString() {
54-
ShapeImpl rootShape = (ShapeImpl) Shape.newBuilder().layout(TestDynamicObjectDefault.class).allowImplicitCastIntToLong(true).build();
78+
ShapeImpl rootShape = (ShapeImpl) makeRootShape();
5579
DOTestAsserts.assertShape(new String[]{}, rootShape);
5680

5781
ShapeImpl aInt = rootShape.defineProperty("a", 1, 0);

truffle/src/com.oracle.truffle.object.basic.test/src/com/oracle/truffle/object/basic/test/SharedShapeTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
4242

4343
import static com.oracle.truffle.object.basic.test.DOTestAsserts.getLocationType;
4444

45+
import java.lang.invoke.MethodHandles;
4546
import java.util.Arrays;
4647
import java.util.List;
4748

@@ -66,7 +67,7 @@ public static List<TestRun> data() {
6667
return Arrays.asList(TestRun.values());
6768
}
6869

69-
final Shape rootShape = Shape.newBuilder().layout(TestDynamicObjectDefault.class).allowImplicitCastIntToLong(true).build();
70+
final Shape rootShape = Shape.newBuilder().layout(TestDynamicObjectDefault.class, MethodHandles.lookup()).allowImplicitCastIntToLong(true).build();
7071
final Shape sharedShape = rootShape.makeSharedShape();
7172

7273
private DynamicObject newInstance() {

truffle/src/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLLanguage.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
package com.oracle.truffle.sl;
4242

4343
import java.io.PrintStream;
44+
import java.lang.invoke.MethodHandles;
4445
import java.util.ArrayList;
4546
import java.util.Collections;
4647
import java.util.List;
@@ -266,7 +267,7 @@ public final class SLLanguage extends TruffleLanguage<SLContext> {
266267

267268
public SLLanguage() {
268269
counter++;
269-
this.rootShape = Shape.newBuilder().layout(SLObject.class).build();
270+
this.rootShape = Shape.newBuilder().layout(SLObject.class, MethodHandles.lookup()).build();
270271
}
271272

272273
@Override

0 commit comments

Comments
 (0)