[Native Image] Crema + compilation isolates: Truffle compilation aborts (guarantee in ImageHeapObjects.ref) on a constant whose class was loaded at run time
Describe the Issue
With runtime class loading (-H:+RuntimeClassLoading) and the default compilation in isolates, a Truffle compilation aborts the whole process (Fatal error: guarantee failed) as soon as partial evaluation needs the class of a constant object whose class was defined at run time.
IsolatedObjectConstant.getObjectClass0 returns the class to the compiler isolate as ImageHeapObjects.ref(target.getClass()), which guarantees that the Class/DynamicHub is in the image heap. A class Crema defined at run time has a hub allocated at run time, so the guarantee fails. The same program compiles fine with -XX:-CompileInIsolates, and with the constant's class taken from the image.
Using the latest version of GraalVM can resolve many issues.
- I tried with the latest version of GraalVM.
GraalVM Version
Reproduced with both:
openjdk version "25.0.4.1.1" 2026-08-18
OpenJDK Runtime Environment GraalVM CE 25.4.4.1.1+1.1 (build 25.0.4.1.1+1-jvmci-25.4-b23)
OpenJDK 64-Bit Server VM GraalVM CE 25.4.4.1.1+1.1 (build 25.0.4.1.1+1-jvmci-25.4-b23, mixed mode, sharing)java version "25.0.4.1.1" 2026-08-18 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 25.4.4.1.1-dev+1.1 (build 25.0.4.1.1+1-LTS-jvmci-25.4-b23)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 25.4.4.1.1-dev+1.1 (build 25.0.4.1.1+1-LTS-jvmci-25.4-b23, mixed mode, sharing)(Also reproduced on Oracle GraalVM 25.3.4.1.)
Operating System and Version
Linux x86_64Troubleshooting Confirmation
- I tried the suggestions in the troubleshooting guide.
Run Command
native-image -H:+UnlockExperimentalVMOptions -H:+RuntimeClassLoading --initialize-at-build-time=repro -cp classes:$TRUFFLE_CP repro.Main -o repro
./repro dynamicExpected Behavior
The root compiles (the compiler isolate resolves runtime-defined classes, or the constant is treated as an unknown-type object), as it does with -XX:-CompileInIsolates.
Actual Behavior
The process aborts during the first compilation of the root (./repro image, the same root with an image class, compiles and runs).
Steps to Reproduce
repro/ReproLanguage.java(compile withtruffle-dsl-processoron the processor path):package repro; import com.oracle.truffle.api.CallTarget; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.TruffleLanguage; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.RootNode; import java.lang.classfile.ClassFile; import java.lang.constant.ClassDesc; import java.lang.constant.ConstantDescs; import java.lang.constant.MethodTypeDesc; /** * Every parse returns a root whose compiled code type-checks a constant object. Source "dynamic" makes that object an * instance of a class defined at run time (Crema); any other source uses a class from the image. */ @TruffleLanguage.Registration(id = ReproLanguage.ID, name = "Repro") public final class ReproLanguage extends TruffleLanguage<Object> { public static final String ID = "repro"; @Override protected Object createContext(Env env) { return new Object(); } @Override protected CallTarget parse(ParsingRequest request) throws Exception { boolean dynamic = request.getSource().getCharacters().toString().equals("dynamic"); Object value = dynamic ? defineRunnable().getConstructor().newInstance() : (Runnable) () -> { }; return new ConstantRoot(this, value).getCallTarget(); } static final class ConstantRoot extends RootNode { @CompilationFinal private final Object value; ConstantRoot(TruffleLanguage<?> language, Object value) { super(language); this.value = value; } // Folding the type check needs the constant's class. @Override public Object execute(VirtualFrame frame) { if (value instanceof Runnable action) { run(action); return 1; } return 0; } @TruffleBoundary static void run(Runnable action) { action.run(); } } private static Class<?> defineRunnable() { var bytes = ClassFile.of().build(ClassDesc.of("repro.Dynamic"), c -> c.withFlags(ClassFile.ACC_PUBLIC).withSuperclass(ConstantDescs.CD_Object) .withInterfaceSymbols(ClassDesc.of("java.lang.Runnable")) .withMethodBody("<init>", MethodTypeDesc.of(ConstantDescs.CD_void), ClassFile.ACC_PUBLIC, b -> b.aload(0).invokespecial(ConstantDescs.CD_Object, "<init>", MethodTypeDesc.of(ConstantDescs.CD_void)).return_()) .withMethodBody("run", MethodTypeDesc.of(ConstantDescs.CD_void), ClassFile.ACC_PUBLIC, b -> b.return_())); return new ClassLoader(ReproLanguage.class.getClassLoader()) { Class<?> define() { return defineClass("repro.Dynamic", bytes, 0, bytes.length); } }.define(); } }repro/Main.java:package repro; import org.graalvm.polyglot.Context; public final class Main { public static void main(String[] args) { String source = args.length > 0 ? args[0] : "dynamic"; try (var context = Context.newBuilder(ReproLanguage.ID).allowExperimentalOptions(true).option("engine.BackgroundCompilation", "false") .option("engine.TraceCompilation", "true").build()) { // Each eval of the cached source calls the same root's call target. var code = org.graalvm.polyglot.Source.create(ReproLanguage.ID, source); long sum = 0; for (int i = 0; i < 200_000; i++) sum += context.eval(code).asInt(); System.out.println("done " + source + " " + sum); } } }$TRUFFLE_CPis the 25.4.4.1.1 Maven artifactstruffle-api,truffle-runtime,truffle-compiler,polyglot,collections,word,nativeimage,jniutils. Build with the command above../repro image: compiles (tier 1 and 2) and printsdone image 200000../repro dynamic:Fatal error: guarantee failedinImageHeapObjects.ref../repro dynamic -XX:-CompileInIsolates: compiles and printsdone dynamic 200000.
Additional Context
No response
Run-Time Log Output and Error Messages
CE 25.4.4.1.1:
Fatal error: guarantee failed
i SP 0x00007ff4ce1127c0 IP 0x000055ca3b42c707 size=32 [image code] com.oracle.svm.core.jdk.VMErrorSubstitutions.shutdown(VMErrorSubstitutions.java:156)
i SP 0x00007ff4ce1127c0 IP 0x000055ca3b42c707 size=32 [image code] com.oracle.svm.core.jdk.VMErrorSubstitutions.shouldNotReachHere(VMErrorSubstitutions.java:149)
A SP 0x00007ff4ce1127c0 IP 0x000055ca3b42c707 size=32 [image code] com.oracle.svm.shared.util.VMError.shouldNotReachHere(VMError.java:92)
i SP 0x00007ff4ce1127e0 IP 0x000055ca3b341b07 size=32 [image code] com.oracle.svm.shared.util.VMError.guarantee(VMError.java:158)
A SP 0x00007ff4ce1127e0 IP 0x000055ca3b341b07 size=32 [image code] com.oracle.svm.graal.isolated.ImageHeapObjects.ref(ImageHeapObjects.java:54)
A SP 0x00007ff4ce112800 IP 0x000055ca3b3473d1 size=48 [image code] com.oracle.svm.graal.isolated.IsolatedObjectConstant.getObjectClass0(IsolatedObjectConstant.java:74)
A SP 0x00007ff4ce112830 IP 0x000055ca3b1234d5 size=112 [image code] com.oracle.svm.core.code.IsolateEnterStub.IsolatedObjectConstant_getObjectClass0_NUY7jxmHfq1AZJWVftcPd0(IsolateEnterStub.java:0)
C SP 0x00007ff4ce1128a0 IP 0x000055ca3b4380d0 size=4400 unknown
i SP 0x00007ff4ce1139d0 IP 0x000055ca3b4380d0 size=208 [image code] com.oracle.svm.core.code.IsolateLeaveStub.doCompile0(IsolateLeaveStub.java:191)
A SP 0x00007ff4ce1139d0 IP 0x000055ca3b4380d0 size=208 [image code] com.oracle.svm.truffle.isolated.IsolateAwareTruffleCompiler.doCompile(IsolateAwareTruffleCompiler.java:112)
A SP 0x00007ff4ce113aa0 IP 0x000055ca3ba2c178 size=80 [image code] com.oracle.truffle.runtime.OptimizedTruffleRuntime.compileImpl(OptimizedTruffleRuntime.java:785)
A SP 0x00007ff4ce113af0 IP 0x000055ca3ba2c668 size=176 [image code] com.oracle.truffle.runtime.OptimizedTruffleRuntime.doCompile(OptimizedTruffleRuntime.java:767)
A SP 0x00007ff4ce113ba0 IP 0x000055ca3b9ff957 size=64 [image code] com.oracle.truffle.runtime.CompilationTask$1.accept(CompilationTask.java:67)Source: oracle/graal