[GR-74965] Respect class loader resource lookup delegation.#13475
Open
graalvmbot wants to merge 19 commits intomasterfrom
Open
[GR-74965] Respect class loader resource lookup delegation.#13475graalvmbot wants to merge 19 commits intomasterfrom
graalvmbot wants to merge 19 commits intomasterfrom
Conversation
For images built with classloader-respecting resource lookup, system-module resources that were baked into the native image must be served through the JDK module-reader path instead of falling through to the JRT-backed lookup machinery. This adds a RespectsClassLoader-only substitution for SystemModuleFinders.SystemModuleReader.read that first checks the embedded resource store, then executes a local copy of the original JDK fallback logic so misses still preserve normal JRT behavior and closed-reader semantics. The hellomodule test is extended to exercise resource access through both platform- and boot-loaded modules, and its resource configuration is updated to the modern module-aware glob form so java.base and jdk.dynalink module-info.class are embedded and the built-in resource path is covered explicitly.
The hello module test moved resource registration to the glob-based configuration, but we only registered resource-file.txt without module information. That works for unnamed resources, but it does not match the named test modules, so the file was never embedded into the image and the module resource lookup failed at runtime. This change registers resource-file.txt for moduletests.hello.app and moduletests.hello.lib explicitly, which restores the intended module resource checks.
File-backed module references are redacted during image building so that host build paths do not leak into the image heap. After that redaction, module readers for jar and exploded modules can no longer rely on the original build-time location when resolving resources at image run time. Preserve the module name in redacted file URIs for application modules and use that name to recover the runtime Module object when a substituted module reader needs to look up resources embedded in the image. This extends the existing system-module resource fallback to the jar and exploded module-reader paths used when class-loader-sensitive lookup is enabled. JarModuleReader now tolerates redacted jar locations, preserves normal jar behavior when a real JarFile is available, and falls back to embedded resource data or resource: URIs for open/read/find. ExplodedModuleReader similarly tries the filesystem path first and falls back to embedded resources when the path is unavailable. The substitutions keep the original closed-state and normal-reader behavior where it matters while allowing built-in resources to remain visible after module locations have been sanitized.
SystemModuleReader.open and read could already resolve embedded resources because read checked the image resource store before falling back to the JRT image. The URL-based path was still incomplete: Class.getResource on a class from a system module asks the module reader to find a URI, and SystemModuleReader.find went directly to the JRT image. In images without JRT file system support this caused URL lookup for an otherwise embedded system-module resource to fail with the disabled-JRT error. Teach SystemModuleReader.find to use the same embedded resource lookup before consulting the JRT image, while preserving the JDK closed-reader check and normal jrt: URI behavior when no embedded resource is present. Extend the hello module test to cover Class.getResource(...).openStream() for java.base, jdk.dynalink, and the application module-path jars, so both system-module and JarModuleReader URL lookup paths are exercised under -H:+ClassForNameRespectsClassLoader.
When ClassForNameRespectsClassLoader is enabled, class resource lookups can first probe system-module readers before falling back to classpath resources. If the image was built without JRT filesystem support, those system-module probes must still be able to miss cleanly after checking embedded resources instead of reaching deleted jimage state or throwing the disabled-JRT error. This change guards the JRT-backed SystemModuleReader find/read paths behind AllowJRTFileSystem while preserving embedded resource lookup, and adds a narrow BuiltinClassLoader classpath-resource fallback so normal classpath lookup is tried first and embedded resources are used only when the runtime classpath has no match.
Extend the hellomodule gate task so CI exercises the module smoke test both in the default configuration and with ClassForNameRespectsClassLoader enabled. The class-loader-sensitive mode uses different resource lookup paths, so running this variant in the gate keeps the embedded module resource fallback covered by the standard hellomodule CI job.
7036cd5 to
cc3be28
Compare
d64915d to
47f9ba8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR extends resource lookup for Native Image when
-H:+ClassForNameRespectsClassLoaderis enabled, especially for module/class-loader-sensitive runtime access.Summary:
JarModuleReaderstate from a runtime-provided module path when needed.jdk.internal.loader.ClassLoadersat run time for-H:+ClassForNameRespectsClassLoader, so runtimejava.class.pathvalues can be reflected in class-loader resource lookup.hellomodulecoverage to define a runtime module layer withModuleLayer#defineModulesWithOneLoader(...)under-H:+RuntimeClassLoading.moduletests.hello.libthat static analysis does not otherwise reach, and that code usesjavax.xml.namespace.QNamefromjava.xmlloaded through the runtime JRT filesystem.Follow-up:
GR-75374tracks the temporary explicit--add-modules=java.xmltest build argument. Therequires java.xmlinsubstratevm/src/native-image-module-tests/hello.lib/src/main/java/module-info.javashould eventually be sufficient.Verification:
mx hellomodule -H:+ClassForNameRespectsClassLoader -H:+RuntimeClassLoadingmx checkstylemx eclipseformat