RFR: JDK-8267936: PreserveAllAnnotations option doesn't expose the annotation to Java code [v2]

David Holmes david.holmes at oracle.com
Mon May 31 12:35:54 UTC 2021


On 31/05/2021 8:29 pm, Peter Levart wrote:
> On Sun, 30 May 2021 20:06:49 GMT, Jaroslav Tulach <github.com+26887752+JaroslavTulach at openjdk.org> wrote:
> 
>> My use-case relates to [@JavaScriptBody](https://bits.netbeans.org/html+java/1.7.1/net/java/html/js/package-summary.html) annotation used for Java/JavaScript interop. Originally all existing usages (Post Processing Classes, Instrumentation Agent, Special classloading, etc.) of the annotation performed the manipulation on `.class` files. However recently a new use-case relying on JVMCI appeared. JVMCI is working on "live" classes and doesn't provide access to the `.class` files (as far as I know, CCing @dougxc). Using `-XX:+PreserveAllAnnotation` solved the first part of problem - the HotSpot code loaded the `RuntimeInvisibleAnnotations`"in". The second part was solved by on the fly patching of `@JavaScriptBody` class to claim to have`RetentionPolicy.RUNTIME`. That part is a bit tricky, so I created this pull request for your consideration.
>>
>> Obvious suggestion is to change the `@JavaScriptBody` retention to `RUNTIME` - however there are plenty of libraries already compiled with the existing annotation and they would have to be all recompiled to new version. I'd rather avoid that and that's another reason why I decided to bring the `-XX:+PreserveAllAnnotation` to your attention and propose to improve it.
> 
> Hi Jaroslav,
> 
> If you change  `@JavaScriptBody` retention to `RUNTIME`, you don't need to re-compile any code that uses this annotation. You just have to use `-XX:+PreserveAllAnnotations` to expose all anotations to JVM and consequently to AnnotationParser. The parser will then return just the `RUNTIME` retention-marked annotations. This means you just have to run the app with the version of the JavaScriptBody.class that is retention-marked as `RUNTIME`...
> 
> I think that `-XX:+PreserveAllAnnotations` was meant as a migration aid for exactly the case when some annotations migrate from `CLASS` to `RUNTIME` retention and libraries using such annotations are not re-compiled yet.

That reads backwards to me. +PreserveAllAnnotations means that CLASS 
retention annotations are retained by the VM not just RUNTIME ones. So 
in that sense it might be a migration aid if moving from RUNTIME to 
CLASS, not CLASS to RUNTIME.

David
-----

> -------------
> 
> PR: https://git.openjdk.java.net/jdk/pull/4245
> 


More information about the core-libs-dev mailing list