#ModuleAnnotations - some thoughts and an alternative implementation

Peter Levart peter.levart at gmail.com
Mon Jul 18 12:10:22 UTC 2016


Hi Alan,


On 07/18/2016 08:42 AM, Alan Bateman wrote:
> On 17/07/2016 23:36, Peter Levart wrote:
>
>> :
>>
>> Here's an alternative implementation that does not need to define the 
>> class in the VM:
>>
>> http://cr.openjdk.java.net/~plevart/jdk9-jake/Module.annotations/webrev.02/ 
>>
>>
>> It instead modifies AnnotationParser to use a special 
>> AnnotationParser.ConstantPool interface which is implemented by two 
>> classes: a classical reflection ConstantPool backed by VM and a 
>> lightweight Java-only implementation which is used to parse 
>> module-info.class. So while parsing module-info.class, the 
>> RuntimeVisibleAnnotations attribute is extracted and memorized in 
>> ModuleDescriptor. Together with the lightweight ConstantPool 
>> implementation, they are used in Module to parse the annotations when 
>> 1st requiested.
>>
>> It is more involved than current implementation, but it is also 
>> lighter and might be extended to support - let's call them 
>> annotation-descriptors - on ModuleDescriptor.
>>
>> What do you think?
> One of the initial prototypes that we did was to have 
> jdk.internal.reflect.ConstantPool backed by the constant pool in the 
> module-info.class so that the raw annotations + constant pool could be 
> used with the existing parser. So not too dissimilar to what you have 
> in this patch.
>
> With the proposal to keep things simple (in particular, not impacting 
> ModuleDescriptor, Builder, ...) then it opened up the door for a much 
> simpler implementations, hence the current implementation.

It is simpler, yes, but feels like overkill to create new class loader 
and transform and load a class in order to just parse annotations from it...

>
> BTW: I see you've changed Module to implement GenericDeclaration 
> rather than AnnotatedElement. I'm curious about.

This was just to simplify changes in 
sun.reflect.generics.factory.CoreReflectionFactory (used by 
AnnotationParser) which takes a GenericDeclaration. But it is odd to 
have a useless method that always returns an empty array, so a variant 
is to implement just AnnotatedElement and have an explicit Module field 
in CoreReflectionFactory:

http://cr.openjdk.java.net/~plevart/jdk9-jake/Module.annotations/webrev.03/

Regards, Peter

>
> -Alan



More information about the jigsaw-dev mailing list