Skip to content

Commit a1dbb59

Browse files
committed
[GR-71715] Adopt addition of ConstantReflectionProvider.makeIdentityHashCode
PullRequest: graal/22786
2 parents 65df3ec + 9a693c2 commit a1dbb59

File tree

23 files changed

+239
-222
lines changed

23 files changed

+239
-222
lines changed

common.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
"graalvm-ee-25-ea": {"name": "graalvm-jdk", "version": "25.0.0", "ea": "36", "platformspecific": true },
5050

5151
"oraclejdk-latest": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-25.0.1+8", "platformspecific": true, "extrabundles": ["static-libs"]},
52-
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b11", "platformspecific": true },
53-
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b11-debug", "platformspecific": true },
54-
"labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b11-sulong", "platformspecific": true },
55-
"labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b11", "platformspecific": true },
56-
"labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b11-debug", "platformspecific": true },
57-
"labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b11-sulong", "platformspecific": true }
52+
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b12", "platformspecific": true },
53+
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b12-debug", "platformspecific": true },
54+
"labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-25.0.1+8-jvmci-25.1-b12-sulong", "platformspecific": true },
55+
"labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b12", "platformspecific": true },
56+
"labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b12-debug", "platformspecific": true },
57+
"labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-25.0.1+8-jvmci-25.1-b12-sulong", "platformspecific": true }
5858
},
5959

6060
"eclipse": {

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/JVMCIVersionCheck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public final class JVMCIVersionCheck {
5858
// Checkstyle: stop stable iteration order check
5959
private static final Map<String, Map<String, Version>> JVMCI_MIN_VERSIONS = Map.of(
6060
"25", Map.of(
61-
"Oracle Corporation", createLabsJDKVersion("25.0.1+8", "25.1", 11),
62-
DEFAULT_VENDOR_ENTRY, createLabsJDKVersion("25.0.1+8", "25.1", 11)));
61+
"Oracle Corporation", createLabsJDKVersion("25.0.1+8", "25.1", 12),
62+
DEFAULT_VENDOR_ENTRY, createLabsJDKVersion("25.0.1+8", "25.1", 12)));
6363
// Checkstyle: resume stable iteration order check
6464

6565
private static final int NA = 0;

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/SymbolicSnippetEncoder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,14 @@ public Constant asObjectHub(ResolvedJavaType type) {
649649
}
650650

651651
@Override
652-
public Integer identityHashCode(JavaConstant constant) {
652+
public int identityHashCode(JavaConstant constant) {
653653
return constantReflection.identityHashCode(constant);
654654
}
655+
656+
@Override
657+
public int makeIdentityHashCode(JavaConstant constant, int requestedValue) {
658+
return constantReflection.makeIdentityHashCode(constant, requestedValue);
659+
}
655660
}
656661

657662
class SnippetObjectFilter {

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/proxy/HotSpotObjectConstantProxy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public int getIdentityHashCode() {
5656
return (int) handle(getIdentityHashCodeMethod, getIdentityHashCodeInvokable);
5757
}
5858

59+
private static final SymbolicMethod makeIdentityHashCodeMethod = method("makeIdentityHashCode", int.class);
60+
private static final InvokableMethod makeIdentityHashCodeInvokable = (receiver, args) -> ((HotSpotObjectConstant) receiver).makeIdentityHashCode((int) args[0]);
61+
62+
@Override
63+
public int makeIdentityHashCode(int requestedValue) {
64+
return (int) handle(makeIdentityHashCodeMethod, makeIdentityHashCodeInvokable, requestedValue);
65+
}
66+
5967
private static final SymbolicMethod getCallSiteTargetMethod = method("getCallSiteTarget");
6068
private static final InvokableMethod getCallSiteTargetInvokable = (receiver, args) -> ((HotSpotObjectConstant) receiver).getCallSiteTarget();
6169

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/proxy/HotSpotResolvedObjectTypeProxy.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ public int superCheckOffset() {
103103
return (int) handle(superCheckOffsetMethod, superCheckOffsetInvokable);
104104
}
105105

106-
private static final SymbolicMethod prototypeMarkWordMethod = method("prototypeMarkWord");
107-
private static final InvokableMethod prototypeMarkWordInvokable = (receiver, args) -> ((HotSpotResolvedObjectType) receiver).prototypeMarkWord();
108-
109-
@Override
110-
public long prototypeMarkWord() {
111-
return (long) handle(prototypeMarkWordMethod, prototypeMarkWordInvokable);
112-
}
113-
114106
private static final SymbolicMethod layoutHelperMethod = method("layoutHelper");
115107
private static final InvokableMethod layoutHelperInvokable = (receiver, args) -> ((HotSpotResolvedObjectType) receiver).layoutHelper();
116108

espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalConstantReflectionProvider.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public JavaConstant readArrayElement(JavaConstant array, int index) {
6363
throw JVMCIError.unimplemented();
6464
}
6565

66-
private static Class<?> safeGetClass(Object o) {
66+
static Class<?> safeGetClass(Object o) {
6767
if (o == null) {
6868
return null;
6969
}
@@ -80,7 +80,7 @@ public JavaConstant readFieldValue(ResolvedJavaField field, JavaConstant receive
8080
throw new IllegalArgumentException("expected an espresso field, got a " + safeGetClass(field));
8181
}
8282
Value receiverValue;
83-
if (field.isStatic()) {
83+
if (espressoField.isStatic()) {
8484
EspressoExternalResolvedInstanceType declaringClass = (EspressoExternalResolvedInstanceType) espressoField.getDeclaringClass();
8585
if (!declaringClass.isInitialized()) {
8686
return null;
@@ -92,13 +92,7 @@ public JavaConstant readFieldValue(ResolvedJavaField field, JavaConstant receive
9292
}
9393
receiverValue = espressoReceiver.getValue();
9494
}
95-
Value value;
96-
if (field.isPublic()) {
97-
// use a full descriptor with the type?
98-
value = receiverValue.getMember(espressoField.getName());
99-
} else {
100-
throw JVMCIError.unimplemented();
101-
}
95+
Value value = espressoField.readValue(receiverValue);
10296
return asJavaConstant(value, espressoField.getJavaKind(), access);
10397
}
10498

@@ -216,7 +210,7 @@ public Constant asObjectHub(ResolvedJavaType type) {
216210
}
217211

218212
@Override
219-
public Integer identityHashCode(JavaConstant constant) {
213+
public int identityHashCode(JavaConstant constant) {
220214
JavaKind kind = Objects.requireNonNull(constant).getJavaKind();
221215
if (kind != JavaKind.Object) {
222216
throw new IllegalArgumentException("Constant has unexpected kind " + kind + ": " + constant);
@@ -231,6 +225,24 @@ public Integer identityHashCode(JavaConstant constant) {
231225
return objectConstant.guestHashCode();
232226
}
233227

228+
@Override
229+
public int makeIdentityHashCode(JavaConstant constant, int requestedValue) {
230+
JavaKind kind = Objects.requireNonNull(constant).getJavaKind();
231+
if (kind != JavaKind.Object) {
232+
throw new IllegalArgumentException("Constant has unexpected kind " + kind + ": " + constant);
233+
}
234+
if (constant.isNull()) {
235+
throw new NullPointerException();
236+
}
237+
if (!(constant instanceof EspressoExternalObjectConstant objectConstant)) {
238+
throw new IllegalArgumentException("Constant has unexpected type " + constant.getClass() + ": " + constant);
239+
}
240+
if (requestedValue <= 0) {
241+
throw new IllegalArgumentException("hashcode must be > 0");
242+
}
243+
return access.invokeJVMCIHelper("makeIdentityHashCode", objectConstant.getValue(), requestedValue).asInt();
244+
}
245+
234246
@Override
235247
public AbstractEspressoResolvedInstanceType getTypeForStaticBase(JavaConstant staticBase) {
236248
if (!(staticBase instanceof EspressoExternalObjectConstant)) {

espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalResolvedJavaField.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,7 @@ public int hashCode() {
8888
return fieldMirror.hashCode();
8989
}
9090

91+
public Value readValue(Value receiver) {
92+
return fieldMirror.invokeMember("read", receiver);
93+
}
9194
}

espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalVMAccess.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package com.oracle.truffle.espresso.vmaccess;
2424

25+
import static com.oracle.truffle.espresso.vmaccess.EspressoExternalConstantReflectionProvider.safeGetClass;
26+
2527
import java.util.Objects;
2628

2729
import org.graalvm.polyglot.Context;
@@ -194,7 +196,7 @@ public Providers getProviders() {
194196
@Override
195197
public JavaConstant invoke(ResolvedJavaMethod method, JavaConstant receiver, JavaConstant... arguments) {
196198
if (!(method instanceof EspressoExternalResolvedJavaMethod espressoMethod)) {
197-
throw new IllegalArgumentException("Expected an EspressoExternalResolvedJavaMethod");
199+
throw new IllegalArgumentException("Expected an EspressoExternalResolvedJavaMethod, got " + safeGetClass(method));
198200
}
199201
return espressoMethod.invoke(receiver, arguments);
200202
}

espresso/src/com.oracle.truffle.espresso.jvmci/src/com/oracle/truffle/espresso/jvmci/meta/EspressoConstantReflectionProvider.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public Constant asObjectHub(ResolvedJavaType type) {
284284
}
285285

286286
@Override
287-
public Integer identityHashCode(JavaConstant constant) {
287+
public int identityHashCode(JavaConstant constant) {
288288
JavaKind kind = Objects.requireNonNull(constant).getJavaKind();
289289
if (kind != JavaKind.Object) {
290290
throw new IllegalArgumentException("Constant has unexpected kind " + kind + ": " + constant);
@@ -300,6 +300,24 @@ public Integer identityHashCode(JavaConstant constant) {
300300
return System.identityHashCode(unwrapped);
301301
}
302302

303+
@Override
304+
public int makeIdentityHashCode(JavaConstant constant, int requestedValue) {
305+
JavaKind kind = Objects.requireNonNull(constant).getJavaKind();
306+
if (kind != JavaKind.Object) {
307+
throw new IllegalArgumentException("Constant has unexpected kind " + kind + ": " + constant);
308+
}
309+
if (constant.isNull()) {
310+
throw new NullPointerException();
311+
}
312+
if (!(constant instanceof EspressoObjectConstant objectConstant)) {
313+
throw new IllegalArgumentException("Constant has unexpected type " + constant.getClass() + ": " + constant);
314+
}
315+
Object unwrapped = unwrap(objectConstant);
316+
return makeIdentityHashCode0(unwrapped, requestedValue);
317+
}
318+
319+
private native int makeIdentityHashCode0(Object unwrapped, int requestedValue);
320+
303321
public JavaConstant forObject(Object object) {
304322
return wrap(object);
305323
}

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoLanguage.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ public StaticProperty getArrayProperty() {
551551
}
552552

553553
public StaticProperty getArrayHashCodeProperty() {
554-
if (!continuum) {
554+
if (!canSetCustomIdentityHashCode()) {
555555
CompilerDirectives.transferToInterpreterAndInvalidate();
556-
throw EspressoError.shouldNotReachHere("Accessing array hash code property without continuum set up.");
556+
throw EspressoError.shouldNotReachHere("Accessing array hash code property without continuum or JVMCI set up.");
557557
}
558558
return arrayHashCodeProperty;
559559
}
@@ -567,12 +567,16 @@ public StaticShape<StaticObjectFactory> getArrayShape() {
567567
private StaticShape<StaticObjectFactory> createArrayShape() {
568568
assert arrayShape == null;
569569
StaticShape.Builder builder = StaticShape.newBuilder(this).property(arrayProperty, Object.class, true);
570-
if (continuum) {
570+
if (canSetCustomIdentityHashCode()) {
571571
builder.property(arrayHashCodeProperty, int.class, false);
572572
}
573573
return builder.build(StaticObject.class, StaticObjectFactory.class);
574574
}
575575

576+
public boolean canSetCustomIdentityHashCode() {
577+
return isContinuumEnabled() || isJVMCIEnabled();
578+
}
579+
576580
public StaticProperty getForeignProperty() {
577581
return foreignProperty;
578582
}

0 commit comments

Comments
 (0)