Skip to content

Commit 3cc471d

Browse files
committed
Skip TranslatedException whose cause is a NoClassDefFoundError when registering UnsafeAccess plugins. (adopt JDK-8335553)
1 parent e4bb122 commit 3cc471d

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

substratevm/src/com.oracle.svm.graal.hotspot.libgraal/src/com/oracle/svm/graal/hotspot/libgraal/truffle/HSTruffleCompilerRuntime.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@
9292
@FromLibGraalEntryPointsResolver(value = TruffleFromLibGraal.Id.class, entryPointsClassName = "com.oracle.truffle.runtime.hotspot.libgraal.TruffleFromLibGraalEntryPoints")
9393
final class HSTruffleCompilerRuntime extends HSObject implements TruffleCompilerRuntime {
9494

95+
private static final Class<?> TRANSLATED_EXCEPTION;
96+
static {
97+
Class<?> clz;
98+
try {
99+
clz = Class.forName("jdk.internal.vm.TranslatedException");
100+
} catch (ClassNotFoundException cnf) {
101+
clz = null;
102+
}
103+
TRANSLATED_EXCEPTION = clz;
104+
}
105+
95106
private final ResolvedJavaType classLoaderDelegate;
96107
final TruffleFromLibGraalCalls calls;
97108

@@ -209,7 +220,27 @@ public ConstantFieldInfo getConstantFieldInfo(ResolvedJavaField field) {
209220
@Override
210221
public ResolvedJavaType resolveType(MetaAccessProvider metaAccess, String className, boolean required) {
211222
String internalName = getInternalName(className);
212-
JavaType jt = runtime().lookupType(internalName, (HotSpotResolvedObjectType) classLoaderDelegate, required);
223+
JavaType jt;
224+
try {
225+
jt = runtime().lookupType(internalName, (HotSpotResolvedObjectType) classLoaderDelegate, required);
226+
} catch (Exception e) {
227+
if (TRANSLATED_EXCEPTION != null && TRANSLATED_EXCEPTION.isInstance(e)) {
228+
/*
229+
* As of JDK 24 (JDK-8335553), a translated exception is boxed in a
230+
* TranslatedException. Unbox a translated unchecked exception as they are the only
231+
* ones that can be expected by callers since this method is not declared in checked
232+
* exceptions.
233+
*/
234+
Throwable cause = e.getCause();
235+
if (cause instanceof Error) {
236+
throw (Error) cause;
237+
}
238+
if (cause instanceof RuntimeException) {
239+
throw (RuntimeException) cause;
240+
}
241+
}
242+
throw e;
243+
}
213244
if (jt instanceof UnresolvedJavaType) {
214245
if (required) {
215246
throw new NoClassDefFoundError(internalName);

0 commit comments

Comments
 (0)