Skip to content

Commit 9ed0a9d

Browse files
committed
Resolved review comments.
1 parent 1aa82a0 commit 9ed0a9d

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/guestgraal/truffle/BuildTime.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public static void configureGraalForLibGraal() {
6262
/**
6363
* Obtains a {@link Lookup} instance for resolving method handles to invoke Graal and JVMCI
6464
* methods.
65+
* <p>
66+
* This method is invoked reflectively by {@code GuestGraalFeature.initializeTruffle()} in the
67+
* native-image classloader to facilitate the exchange of lookup instances between the
68+
* native-image classloader and the guest Graal classloader.
69+
* </p>
6570
*
6671
* @param lookup a {@link Lookup} instance used to resolve handles for calling into the
6772
* native-image host.
@@ -72,7 +77,10 @@ public static void configureGraalForLibGraal() {
7277
* methods. The {@link Lookup} instance can be used to resolve the compiler entry
7378
* methods within the provided class.
7479
*/
75-
public static Entry<Lookup, Class<?>> getLookup(Lookup lookup, Class<?> fromLibGraal, Class<?> nativeImageSupport) {
80+
public static Entry<Lookup, Class<?>> initializeLookup(Lookup lookup, Class<?> fromLibGraal, Class<?> nativeImageSupport) {
81+
if (hostLookup != null) {
82+
throw new IllegalStateException("Host lookup has already been initialized. BuildTime.initializeLookup should only be called once during the native image build process.");
83+
}
7684
hostLookup = Objects.requireNonNull(lookup, "lookup must be non null");
7785
truffleFromLibGraalStartPoint = Objects.requireNonNull(fromLibGraal, "fromLibGraal must be non null");
7886
nativeImageHostEntryPoint = Objects.requireNonNull(nativeImageSupport, "nativeImageSupport must be non null");
@@ -107,7 +115,7 @@ static MethodHandle getHostMethodHandleOrFail(String name) {
107115
* The getHostMethodHandleOrFail should never be called in the native-image execution
108116
* time.
109117
*/
110-
throw new IllegalStateException("Should not be reachable in the libgraal execution time");
118+
throw new IllegalStateException("Should not be reachable at libgraal runtime");
111119
} else {
112120
/*
113121
* HS proxy classes and BuildTime are not used in Jargraal, but the CheckGraalInvariants

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/guestgraal/truffle/HSTruffleCompilerRuntime.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,16 @@ public TruffleCompilable asCompilableTruffleAST(JavaConstant constant) {
115115
if (constant.isNull()) {
116116
return null;
117117
}
118-
long jniLocalRef = HotSpotJVMCIRuntime.runtime().getJObjectValue((HotSpotObjectConstant) constant);
118+
long jniLocalRef;
119+
try {
120+
jniLocalRef = HotSpotJVMCIRuntime.runtime().getJObjectValue((HotSpotObjectConstant) constant);
121+
} catch (IllegalStateException ise) {
122+
/*
123+
* TODO: GR-57161: IllegalStateException: Cannot call getJObjectValue without Java frame
124+
* anchor
125+
*/
126+
return null;
127+
}
119128
Object compilableHsHandle = NativeImageHostCalls.createLocalHandleForLocalReference(jniLocalRef);
120129
return compilableHsHandle == null ? null : new HSTruffleCompilable(compilableHsHandle);
121130
}

substratevm/src/com.oracle.svm.graal.hotspot.guestgraal/src/com/oracle/svm/graal/hotspot/guestgraal/GuestGraal.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,13 @@ final class GuestGraalTruffleToLibGraalEntryPoints {
377377

378378
private static volatile int lastJavaPCOffset = -1;
379379

380-
// The null MethodHandle values are overwritten reflectively in the constructor
380+
/*
381+
* Each of the following MethodHandle fields corresponds to a TruffleToLibGraal.Id value. The
382+
* naming convention requires that each field name match the method name returned by
383+
* TruffleToLibGraal.Id.getMethodName(). Additionally, the GraalEntryPoints method that the
384+
* MethodHandle references must also follow this naming convention. The null MethodHandle values
385+
* are overwritten reflectively in the constructor
386+
*/
381387
private final MethodHandle initializeIsolate = null;
382388
private final MethodHandle registerRuntime = null;
383389
private final MethodHandle initializeRuntime = null;
@@ -404,6 +410,7 @@ final class GuestGraalTruffleToLibGraalEntryPoints {
404410
private final MethodHandle getDataPatchesCount = null;
405411
private final MethodHandle purgePartialEvaluationCaches = null;
406412
private final MethodHandle getCompilerVersion = null;
413+
407414
private final MethodHandle getCurrentJavaThread;
408415
private final MethodHandle getLastJavaPCOffset;
409416

@@ -511,7 +518,7 @@ public static boolean registerRuntime(JNIEnv env, JClass hsClazz, @IsolateThread
511518
public static long initializeRuntime(JNIEnv env, JClass hsClazz, @IsolateThreadContext long isolateThreadId,
512519
JObject truffleRuntime, JClass hsClassLoaderDelegate) {
513520
try (JNIMethodScope s = openScope(Id.InitializeRuntime, env)) {
514-
HSObject hsHandle = new HSObject(env, truffleRuntime);
521+
HSObject hsHandle = new HSObject(env, truffleRuntime, true, false);
515522
Object hsTruffleRuntime = singleton().initializeRuntime.invoke(hsHandle, hsClassLoaderDelegate.rawValue());
516523
return LibGraalObjectHandles.create(hsTruffleRuntime);
517524
} catch (Throwable t) {

substratevm/src/com.oracle.svm.graal.hotspot.guestgraal/src/com/oracle/svm/graal/hotspot/guestgraal/GuestGraalFeature.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ private static void initGraalRuntimeHandles(MethodHandle getRuntimeHandles) thro
434434
@SuppressWarnings("unchecked")
435435
private void initializeTruffle() throws Throwable {
436436
Class<?> truffleBuildTimeClass = loader.loadClassOrFail("jdk.graal.compiler.hotspot.guestgraal.truffle.BuildTime");
437-
MethodHandle getLookup = mhl.findStatic(truffleBuildTimeClass, "getLookup", methodType(Map.Entry.class, Lookup.class, Class.class, Class.class));
437+
MethodHandle getLookup = mhl.findStatic(truffleBuildTimeClass, "initializeLookup", methodType(Map.Entry.class, Lookup.class, Class.class, Class.class));
438438
Map.Entry<Lookup, Class<?>> truffleGuestGraal = (Map.Entry<Lookup, Class<?>>) getLookup.invoke(mhl, TruffleFromLibGraalStartPoints.class, NativeImageHostEntryPoints.class);
439439
ImageSingletons.add(GuestGraalTruffleToLibGraalEntryPoints.class, new GuestGraalTruffleToLibGraalEntryPoints(truffleGuestGraal.getKey(), truffleGuestGraal.getValue()));
440440
MethodHandle truffleConfigureGraalForLibGraal = mhl.findStatic(truffleBuildTimeClass, "configureGraalForLibGraal", methodType(void.class));

0 commit comments

Comments
 (0)