On Mon, 31 May 2021 12:37:55 GMT, David Holmes <david.hol...@oracle.com> wrote:

> > 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

Why? If an annotation has a CLASS retention when some source that uses it is 
compiled, such annotation usage is compiled into the 
`RuntimeInvisibleAnnotations` attribute of the class that corresponds to the 
source that uses the annotation. So when later the annotation is migrated to 
have RUNTIME retention, the AnnotationParser would return such annotation if 
only its encoded bytestream has been given to it. But since it is present in 
the `RuntimeInvisibleAnnotations` attribute of the class that uses such 
annotation, by default it is not (only `RuntimeVisibleAnnotations` attribute 
annotations are passed to AnnotationParser). Unless you give JVM the 
`-XX:+PreserveAllAnnotations` option to also preserve (in its internal 
structures) all annotations (from `RuntimeVisibleAnnotations` and  
`RuntimeInvisibleAnnotations` attributes). So in that case, the 
AnnotationParser has a chance to parse such "migrated" annotation for which the 
usages have not been recompiled yet. When such usages get re
 compiled, such annotation uses will get compiled into 
`RuntimeVisibleAnnotations` attribute(s) of classes that use the annotation and 
the option will not be needed any more...

This is how I understand the JVM option. I might be wrong.

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

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

Reply via email to