Skip to content

Commit dd7e8b1

Browse files
Trigger the reference handling after a Truffle compilation finishes in libgraal.
1 parent 7ed3399 commit dd7e8b1

File tree

3 files changed

+18
-5
lines changed
  • compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal
  • substratevm/src
    • com.oracle.svm.core/src/com/oracle/svm/core/heap
    • com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal

3 files changed

+18
-5
lines changed

compiler/src/org.graalvm.compiler.truffle.compiler.hotspot.libgraal/src/org/graalvm/compiler/truffle/compiler/hotspot/libgraal/TruffleToLibGraalEntryPoints.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,17 @@ public static void closeCompilation(JNIEnv env, JClass hsClazz, @CEntryPoint.Iso
274274
} finally {
275275
compilable.release(env);
276276
HSObject.cleanHandles(env);
277+
doReferenceHandling();
277278
}
278279
} catch (Throwable t) {
279280
JNIExceptionWrapper.throwInHotSpot(env, t);
280281
}
281282
}
282283

284+
private static void doReferenceHandling() {
285+
// Substituted in LibGraalFeature.
286+
}
287+
283288
@TruffleToLibGraal(Shutdown)
284289
@SuppressWarnings({"unused", "try"})
285290
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_shutdown")

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Heap.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.graalvm.word.Pointer;
3939
import org.graalvm.word.UnsignedWord;
4040

41-
import com.oracle.svm.core.SubstrateOptions;
4241
import com.oracle.svm.core.annotate.Uninterruptible;
4342
import com.oracle.svm.core.hub.DynamicHub;
4443
import com.oracle.svm.core.hub.PredefinedClassesSupport;
@@ -200,10 +199,10 @@ public List<Class<?>> getLoadedClasses() {
200199

201200
/**
202201
* If the automatic reference handling is disabled (see
203-
* {@link SubstrateOptions.ConcealedOptions#AutomaticReferenceHandling}), then this method can
204-
* be called to do the reference handling manually. On execution, the current thread will
205-
* enqueue pending {@link Reference}s into their corresponding {@link ReferenceQueue}s and it
206-
* will execute pending cleaners.
202+
* {@link com.oracle.svm.core.SubstrateOptions.ConcealedOptions#AutomaticReferenceHandling}),
203+
* then this method can be called to do the reference handling manually. On execution, the
204+
* current thread will enqueue pending {@link Reference}s into their corresponding
205+
* {@link ReferenceQueue}s and it will execute pending cleaners.
207206
*
208207
* This method must not be called from within a VM operation as this could result in deadlocks.
209208
* Furthermore, it is up to the caller to ensure that this method is only called in places where

substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/LibGraalFeature.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,3 +863,12 @@ private static void notifyCrash(String crashMessage) {
863863
@Delete("shouldn't appear in libgraal")
864864
final class Target_org_graalvm_compiler_hotspot_SymbolicSnippetEncoder {
865865
}
866+
867+
@TargetClass(className = "org.graalvm.compiler.truffle.compiler.hotspot.libgraal.TruffleToLibGraalEntryPoints", onlyWith = LibGraalFeature.IsEnabled.class)
868+
final class Target_org_graalvm_compiler_truffle_compiler_hotspot_libgraal_TruffleToLibGraalEntryPoints {
869+
@SuppressWarnings("unused")
870+
@Substitute
871+
private static void doReferenceHandling() {
872+
Heap.getHeap().doReferenceHandling();
873+
}
874+
}

0 commit comments

Comments
 (0)