Repository navigation
[svm] Check for hiding reflection members only after the registration is published - #14913
Draft
MarkusBernhardt wants to merge 1 commit into
Draft
MarkusBernhardt wants to merge 1 commit into
MarkusBernhardt wants to merge 1 commit into
Conversation
Without exact reachability metadata, ReflectionDataBuilder records
subtype members that hide a registered method or field, so that a
lookup on the subtype does not return the supertype member. The check
was started from inside the ConcurrentHashMap.compute call that
registers the supertype member, i.e. before the new mapping is visible
to other threads.
checkHidingMethods and checkHidingFields either register a subtype
reachability handler, which is notified synchronously for subtypes that
are already reachable, or post a task for each reachable subtype. Both
paths run checkSubtypeForOverriding{Method,Field} as an analysis task
that can start on another thread right away. That task first checks
methods.containsKey or fields.containsKey for the supertype member and
skips it if absent. If it ran before compute returned, it saw no
registration and the hiding member was never recorded. Nothing re-runs
the check for an already reachable subtype, so the image then returns
the supertype member for a lookup on the subtype, and the reflection
metadata depends on thread timing.
Decide inside compute whether the check is needed, so that it still
runs exactly once per member, but start it only after compute has
returned.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application. When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated. If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public. |
|
Thank you for signing the OCA. |
This was referenced Nov 5, 2026
Draft
This branch has not been deployed
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.
Problem
Without exact reachability metadata,
ReflectionDataBuilderrecords subtype members that override or hide a registered method or field, the "hiding" members. This way,Sub.class.getMethod("m")does not return the registeredSuper.m()whenSubdeclares its own, unregisteredm().registerMethodandregisterFieldstart this check (checkHidingMethods/checkHidingFields) from inside theConcurrentHashMap.computecall that creates the registration. At that point, the new mapping is not yet visible to other threads. The check runscheckSubtypeForOverridingMethod/checkSubtypeForOverridingFieldas an analysis task:registerSubtypeReachabilityHandler, which notifies already reachable subtypes synchronously, and the callback posts the task.That task first checks
methods.containsKey(supertypeMethod)(orfields.containsKey(...)) and returns if the member is absent. If a worker thread picks it up before the registering thread leavescompute(forACCESSEDmethods, the registering thread is still runningregisterMethodAccessor), the check sees no registration and does nothing. The subtype has already been notified, so nothing re-runs the check. The image then lacks the hiding entry,Sub.class.getMethod("m")returnsSuper.m(), and the reflection metadata depends on thread timing.We found this while making native-image builds bit-for-bit reproducible. To confirm it on current master, we used a fixture that wraps the builder's
methods/fieldsmaps and only delays the end of thecomputecall; the production code insidecomputeis unchanged. The fixture registers a method and a field of a supertype after their overriding subtypes are reachable. Results:3810b9fb0f4, the posted check ran while the registration was unpublished in 4 of 4 builds. In 3 of the 4, the hiding entries were never recorded, and the image returnedMethodBase.raceMarker()/FieldBase.raceFieldforMethodChild.class.getMethod(...)/FieldChild.class.getField(...). In the remaining build, another path still recorded them.We are happy to share the fixture.
Fix
Decide inside
computewhether the hiding check is needed, so that it still runs exactly once per member, on the registration that first makes itQUERIED. CallcheckHidingMethods/checkHidingFieldsonly aftercomputehas returned. Posting the check then happens-after the mapping is published.Test
New
com.oracle.svm.test.reflect.HidingMemberRegistrationTest, run with its own feature via@NativeImageBuildArgs. The feature makesMethodChildandFieldChildreachable inbeforeAnalysisand registersMethodBase.member()andFieldBase.memberonly in the firstduringAnalysis, the order in which the race exists. The tests check that the registered members work and thatgetMethod/getFieldon the subtypes do not return the supertype members.This is a regression test for the scenario, not a reproducer. Without the fix, it passed in 3 of 3 runs on our machine, because the race window is narrow without the fixture's delay. A deterministic reproducer has to interpose on the builder's private maps, which did not seem appropriate for the test suite.
On darwin-aarch64 (labsjdk 25.0.5.1, JVMCI 25.6-b27), the test passes with the fix (2 of 2 runs), and
mx checkstyle --primarypasses.mx eclipseformatwas not run.Notes
!throwMissingRegistrationErrors()call sites to!exactReachabilityMetadataSupported(). If [GR-73222] Make exact reflection a future default and refine exact reachability metadata at run time #14158 lands first, the flag assignment becomesneedsHidingCheck[0] = !exactReachabilityMetadataSupported();.ifblocks and putneedsHidingCheck[0] = !throwMissingRegistrationErrors();into the second one, the one gated on!previous.includes(QUERIED). On the combined state, both new tests pass and the fixture records both hiding entries.🤖 Generated with Claude Code