On Sun, 30 May 2021 20:06:49 GMT, Jaroslav Tulach 
<github.com+26887752+jaroslavtul...@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.

-------------

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

Reply via email to