Skip to content

[GR-73642][Native Image] Class.forName not dispatchable from runtime-loaded bytecode (RuntimeClassLoading/Crema) #13031

@borkdude

Description

@borkdude

Describe the Issue

Class.forName(String) crashes when called from bytecode loaded at runtime via Crema (RuntimeClassLoading). The method is internally substituted by native-image and the substitution is inlined at each call site, so the original method is never compiled as a standalone entry point. When the interpreter encounters invokestatic java.lang.Class.forName(String) in runtime-loaded bytecode, there is no compiled code to dispatch to.

  Error:

  Fatal error: Trying to dispatch to compiled code for AOT method
  InterpreterResolvedJavaMethod<holder=Ljava/lang/Class; name=forName
  descriptor=(Ljava/lang/String;)Ljava/lang/Class;> but it was not compiled
  because it was not seen as reachable by analysis

Repro: https://github.com/borkdude/graal-repros/tree/crema-class-for-name-repro

Main.java (AOT, compiled into native image) loads CallsForName.class at runtime via URLClassLoader. CallsForName.run() calls Class.forName("java.util.ArrayList") and crashes.

What doesn't help:

  • java.lang is preserved via -H:Preserve=package=java.lang
  • reflect-config.json registers Class.forName for reflection

Neither makes the original method available as a dispatch target for the interpreter.

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

GraalVM version: 25e1 EA (25.0.1-ea)

Operating System and Version

mac aarch64 / linux amd64

Troubleshooting Confirmation

Run Command

See https://github.com/borkdude/graal-repros/blob/crema-class-for-name-repro/README.md

Expected Behavior

CallsForName.run() prints Class: java.util.ArrayList. The Class.forName(String) method should be dispatchable from Crema's interpreter, since java.lang is preserved via -H:Preserve=package=java.lang.

Actual Behavior

See https://github.com/borkdude/graal-repros/blob/crema-class-for-name-repro/output.txt

Steps to Reproduce

See https://github.com/borkdude/graal-repros/blob/crema-class-for-name-repro/README.md

Additional Context

No response

Run-Time Log Output and Error Messages

https://github.com/borkdude/graal-repros/blob/crema-class-for-name-repro/output.txt

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions