Skip to content

Conversation

@bulasevich
Copy link
Contributor

@bulasevich bulasevich commented Sep 10, 2025

This PR backports:

Conflicts:

First commit.

Simple conflicts (here and below I do not mention trivial Java import section conflicts).
The surrounding code was changed, so emitCallerEpilogue() had to be inserted manually.

<<<<<<< HEAD
        returnValue = adaptReturnValue(method, providers, nativeLibraries, kit, returnValue);
=======
        returnValue = adaptReturnValue(method, nativeLibraries, kit, returnValue);

        emitCallerEpilogue(kit);

>>>>>>> c11d974c85b (Support cross-isolate exception dispatch for isolated compilation.)

<<<<<<< HEAD
    protected abstract ValueNode createTargetAddressNode(HostedGraphKit kit, HostedProviders providers, List<ValueNode> arguments);
=======
    protected void emitCallerEpilogue(@SuppressWarnings("unused") HostedGraphKit kit) {
    }

    protected abstract ValueNode createTargetAddressNode(HostedGraphKit kit, List<ValueNode> arguments);
>>>>>>> c11d974c85b (Support cross-isolate exception dispatch for isolated compilation.)

<<<<<<< HEAD
    protected ValueNode createTargetAddressNode(HostedGraphKit kit, HostedProviders providers, List<ValueNode> arguments) {

=======
    protected void emitCallerEpilogue(HostedGraphKit kit) {
        CEntryPointOptions options = getOriginal().getAnnotation(CEntryPointOptions.class);
        if (options != null && options.callerEpilogue() != null && options.callerEpilogue() != CEntryPointOptions.NoCallerEpilogue.class) {
            AnalysisType epilogue = kit.getMetaAccess().lookupJavaType(options.callerEpilogue());
            AnalysisMethod[] epilogueMethods = epilogue.getDeclaredMethods(false);
            UserError.guarantee(epilogueMethods.length == 1 && epilogueMethods[0].isStatic() && epilogueMethods[0].getSignature().getParameterCount(false) == 0,
                            "Caller epilogue class must declare exactly one static method without parameters: %s -> %s", getOriginal(), epilogue);
            kit.createInvokeWithExceptionAndUnwind(epilogueMethods[0], CallTargetNode.InvokeKind.Static, kit.getFrameState(), kit.bci());
        }
    }

    @Override
    protected ValueNode createTargetAddressNode(HostedGraphKit kit, List<ValueNode> arguments) {
>>>>>>> c11d974c85b (Support cross-isolate exception dispatch for isolated compilation.)

Fixing some compilation issues (adaptation for the graalvm-community-jdk21u code base):

diff --git a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCompileClient.java b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCompileClient.java
index 2fdce2eba5a..11638882c90 100644
--- a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCompileClient.java
+++ b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCompileClient.java
@@ -27 +26,0 @@ package com.oracle.svm.graal.isolated;
-import org.graalvm.compiler.word.Word;
@@ -33,0 +33 @@ import org.graalvm.word.WordBase;
+import org.graalvm.word.WordFactory;
@@ -80 +80 @@ public final class IsolatedCompileClient extends IsolatedCompilationExceptionDis
-            return Word.signed(v);
+            return WordFactory.signed(v);
diff --git a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCompileContext.java b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCompileContext.java
index aeee3cdddc7..cdbeaf3faec 100644
--- a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCompileContext.java
+++ b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/isolated/IsolatedCompileContext.java
@@ -27 +26,0 @@ package com.oracle.svm.graal.isolated;
-import org.graalvm.compiler.word.Word;
@@ -34,0 +34 @@ import org.graalvm.word.WordBase;
+import org.graalvm.word.WordFactory;
@@ -70 +70 @@ public final class IsolatedCompileContext extends IsolatedCompilationExceptionDi
-            return Word.signed(get().handleException(t));
+            return WordFactory.signed(get().handleException(t));
@@ -78 +78 @@ public final class IsolatedCompileContext extends IsolatedCompilationExceptionDi
-            return Word.signed(v);
+            return WordFactory.signed(v);
diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointJavaCallStubMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointJavaCallStubMethod.java
index 553d81b4458..ffe4eb527d7 100644
--- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointJavaCallStubMethod.java
+++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointJavaCallStubMethod.java
@@ -82,8 +82,8 @@ public class CEntryPointJavaCallStubMethod extends CCallStubMethod {
     protected void emitCallerEpilogue(HostedGraphKit kit) {
         CEntryPointOptions options = getOriginal().getAnnotation(CEntryPointOptions.class);
         if (options != null && options.callerEpilogue() != null && options.callerEpilogue() != CEntryPointOptions.NoCallerEpilogue.class) {
-            AnalysisType epilogue = kit.getMetaAccess().lookupJavaType(options.callerEpilogue());
-            AnalysisMethod[] epilogueMethods = epilogue.getDeclaredMethods(false);
+            ResolvedJavaType epilogue = kit.getMetaAccess().lookupJavaType(options.callerEpilogue());
+            ResolvedJavaMethod[] epilogueMethods = epilogue.getDeclaredMethods(false);
             UserError.guarantee(epilogueMethods.length == 1 && epilogueMethods[0].isStatic() && epilogueMethods[0].getSignature().getParameterCount(false) == 0,
                             "Caller epilogue class must declare exactly one static method without parameters: %s -> %s", getOriginal(), epilogue);
             kit.createInvokeWithExceptionAndUnwind(epilogueMethods[0], CallTargetNode.InvokeKind.Static, kit.getFrameState(), kit.bci());

Second commit.

  • code after the new comment was updated in another change
  • resolution: insert a comment into the old code
<<<<<<< HEAD
        try (DebugContext debug = new Builder(RuntimeOptionValues.singleton(), new GraalDebugHandlersFactory(GraalSupport.getRuntimeConfig().getSnippetReflection())).build()) {
            SubstrateGraalUtils.doCompile(debug, GraalSupport.getRuntimeConfig(), GraalSupport.getLIRSuites(), ImageHeapObjects.deref(methodRef));
=======
        // The context is cleared in the CEntryPointOptions.epilogue (also in case of an exception)

        RuntimeConfiguration runtimeConfiguration = TruffleRuntimeCompilationSupport.getRuntimeConfig();
        try (DebugContext debug = new Builder(RuntimeOptionValues.singleton(), new GraalDebugHandlersFactory(runtimeConfiguration.getProviders().getSnippetReflection())).build()) {
            SubstrateGraalUtils.doCompile(debug, TruffleRuntimeCompilationSupport.getRuntimeConfig(), TruffleRuntimeCompilationSupport.getLIRSuites(), ImageHeapObjects.deref(methodRef));
>>>>>>> 5d213ef006d (Add isolated compilation exception dispatch.)
  • upstream changed CompilationIdentifier -> TruffleCompilationIdentifier in another change
  • resolution: kept the old CompilationIdentifier type but removed the thrownException assignment.
<<<<<<< HEAD
                ClientHandle<CompilationIdentifier> compilationIdentifier = client.hand(delegate.createCompilationIdentifier(task, compilable));
                ClientHandle<String> thrownException = doCompile0(context,
=======
                ClientHandle<TruffleCompilationIdentifier> compilationIdentifier = client.hand(delegate.createCompilationIdentifier(task, compilable));
                doCompile0(context,
>>>>>>> 5d213ef006d (Add isolated compilation exception dispatch.)
  • API changed
  • keep the old code, just correct annotations manually
<<<<<<< HEAD
    @CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
    private static void prepareForCompilation0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<SubstrateCompilableTruffleAST> handle) {
=======
    @CEntryPoint(exceptionHandler = IsolatedCompileClient.BooleanExceptionHandler.class, include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
    @CEntryPointOptions(callerEpilogue = IsolatedCompileClient.ExceptionRethrowCallerEpilogue.class)
    private static boolean prepareForCompilation0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<SubstrateCompilableTruffleAST> handle,
                    boolean rootCompilation, int compilationTier, boolean lastTier) {
>>>>>>> 5d213ef006d (Add isolated compilation exception dispatch.)

<<<<<<< HEAD
    @CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
    private static CompilerHandle<String> toString0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<CompilationIdentifier> idHandle, int verbosityOrdinal) {
        CompilationIdentifier id = IsolatedCompileClient.get().unhand(idHandle);
=======
    @CEntryPoint(exceptionHandler = IsolatedCompileClient.WordExceptionHandler.class, include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
    @CEntryPointOptions(callerEpilogue = IsolatedCompileClient.ExceptionRethrowCallerEpilogue.class)
    private static CompilerHandle<String> toString0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<TruffleCompilationIdentifier> idHandle, int verbosityOrdinal) {
        TruffleCompilationIdentifier id = IsolatedCompileClient.get().unhand(idHandle);
>>>>>>> 5d213ef006d (Add isolated compilation exception dispatch.)

Note. Handler should be aligned method return type: prepareForCompilation0 is void on graalvm-community-jdk21u, so use VoidExceptionHandler.

diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java
index 1be00be8861..af52112df12 100644
--- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java
+++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/isolated/IsolatedCompilableTruffleAST.java
@@ -242,7 +242,7 @@ final class IsolatedCompilableTruffleAST extends IsolatedObjectProxy<SubstrateCo
         return compilable.getKnownCallSiteCount();
     }

-    @CEntryPoint(exceptionHandler = IsolatedCompileClient.BooleanExceptionHandler.class, include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
+    @CEntryPoint(exceptionHandler = IsolatedCompileClient.VoidExceptionHandler.class, include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
     @CEntryPointOptions(callerEpilogue = IsolatedCompileClient.ExceptionRethrowCallerEpilogue.class)
     private static void prepareForCompilation0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<SubstrateCompilableTruffleAST> handle) {
         TruffleCompilable ast = IsolatedCompileClient.get().unhand(handle);

Closes: #193

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 10, 2025
(cherry picked from commit c11d974c85bbc02075f67a78d59a1327f21507ea)
(cherry picked from commit 5d213ef006d56e55c7e8ba41013fedfc1bc54670)
Copy link
Contributor

@zakkak zakkak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @bulasevich

@zakkak zakkak merged commit dbcb885 into graalvm:master Oct 3, 2025
12 checks passed
@zakkak zakkak added this to the 23.1.9 milestone Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backport] [Oracle GraalVM] [GR-68722] Backport to 23.1: Cross-isolate exception dispatch for isolated compilation.

3 participants