Repository navigation
[svm] Forward QUERIED-to-ACCESSED upgrades of annotation methods to annotation proxy methods - #14912
Draft
MarkusBernhardt wants to merge 1 commit into
Draft
MarkusBernhardt wants to merge 1 commit into
MarkusBernhardt wants to merge 1 commit into
Conversation
ReflectionDataBuilder.registerMethod mirrors every registration of an annotation method onto the corresponding method of the annotation proxy class. The mirroring was gated on the annotation method becoming QUERIED for the first time, so a later upgrade of the annotation method from QUERIED to ACCESSED was never forwarded: the proxy method kept QUERIED and stayed non-invocable. With the opposite order, ACCESSED first and QUERIED second, the proxy method ends up ACCESSED. The order is not fixed in practice. Registering an annotation type for reflection queues a QUERIED registration of all its methods. Registering an element that carries the annotation, which also happens for every class whose hub is in the image heap, creates the annotation proxy class, and DynamicProxySupport.createProxyClass registers the annotation methods as ACCESSED. AnnotationFeature does both for annotation objects in the image heap. All of these run as separate analysis tasks, so the reflection metadata of the proxy class depended on task scheduling. Forward the registration whenever it raises the accessibility of the annotation method. The hiding-method check keeps its original gate. 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
ReflectionDataBuilder.registerMethodmirrors each registration of an annotation method onto the matching method of the annotation's proxy class (processAnnotationMethod). The mirroring is gated onprevious == null || !previous.includes(QUERIED), so it only runs the first time the annotation method becomes at leastQUERIED.As a result, the final accessibility of the proxy method depends on the order in which the annotation method's registrations are processed:
A.value()$ProxyN.value()ends upACCESSED, thenQUERIEDACCESSEDQUERIED, thenACCESSEDQUERIED(the upgrade is dropped)Both orders happen in practice, depending on analysis task scheduling:
registerClass(ACCESSED, …)→registerTypesForTypeQuery) queues aQUERIEDregistration of all its methods.registerHeapDynamicHub→registerTypesForAnnotations→registerType), creates the annotation proxy class throughRuntimeProxyCreation, andDynamicProxySupport.createProxyClassregisters the annotation interface's methods asACCESSED.AnnotationFeature.registerDeclaredMethodsissues both kinds of registration for annotation objects in the image heap.Each of these runs as its own task posted through
runConditionalTask, which has two consequences:annotation.getClass().getDeclaredMethod("value").invoke(annotation)throwsMissingReflectionRegistrationError, even thoughA.value()is registered for invocation.Fix
Forward the registration whenever it raises the annotation method's accessibility:
previous == null || !previous.includes(accessibility). The hiding-method check keeps its existing gate (!previous.includes(QUERIED)), so it still runs once per method.processAnnotationFielduses the same gate, but proxy classes do not declare the constant fields of the annotation interface (getUniqueDeclaredField(true, proxyType, name)finds no such field on the proxy). The field path therefore has no observable effect and is left unchanged.Test
New
com.oracle.svm.test.reflect.AnnotationProxyMethodRegistrationTest(plusAnnotationProxyMethodRegistrationTarget), run with its own feature via@NativeImageBuildArgs. It forces the losing order deterministically:QUERIED.ACCESSED.The annotated class must not be reachable in the first iteration, otherwise its annotations would already create the proxy there. So it is a top-level class, because the test harness registers the test class and with it all its nest members. The test also looks it up with
Class.forNameand a non-constant name, because a class literal would put its hub into the image heap. The test then invokes the proxy method reflectively.On darwin-aarch64 (labsjdk 25.0.5.1, JVMCI 25.6-b27):
3810b9fb0f4without the fix, the test fails in 4 of 4 runs withMissingReflectionRegistrationError: Cannot reflectively invoke method 'public final java.lang.String jdk.proxy4.$Proxy/….value()'.mx checkstyle --primarypasses.mx eclipseformatwas not run.Notes
🤖 Generated with Claude Code