RFR and comments: 8031744: Annotations on many Language Model elements are not returned

Joel Borggrén-Franck joel.franck at oracle.com
Mon Feb 23 20:24:00 UTC 2015


Hi,

For a while now I have been working on refactoring the annotations handling code in javac, with the intent of cleaning up issues introduced with the merging of repeating annotations and improving support for type annotations in javax.lang.model.

The work has been going on over in the anno-pipeline/dev forest at http://hg.openjdk.java.net/anno-pipeline/dev/langtools/ and I think the patch set has been stable enough for a while now to propose a merge.

This quite large webrev addresses two issues that were hard to separate out to two distinct patches:

1) Simplify and remove the use of 2 queues for repeating annotations.

This refactoring removes the need and use of queues for declaration annotations. It does this by attaching a new piece of metadata (Annotate.AnnotationTypeMetadata) to the ClassSymbols that represent the declaration of an annotation type. This metadata can then be queried when attributing/entering instances of annotations of that annotation type. This eliminates the need for the queues and I have refactored the pipeline for normal declaration annotations (including repeating annotations) to only use one queue. 

The observation here is that in order to determine if 

@Foo @Foo

is valid, you need to look at the declaration of Foo, to see if it is annotated with @Repeatable and in that case you need to look at the annotation type the @Repeatable instance designates. Before this was handled with a second queue, now this is handled by a separate visitor that just annotates @Target and @Repeatable "just in time" without using the queues. Most of the refactoring in Annotate.java is to support this.

2) Improving support for type annotations in javax.lang.model.

The second part is a number of changes to Type and Types in order to support type annotations on Type instances. Also, type annotation instances are actually being added to Type instances that are used in type checking. This is potentially quite intrusive as in some cases methods in Types depended on Type instances being == while now they will no longer be so. To see why, consider the annotated cast (@TA Object).

Currently the fixes for javax.lang.model only work for types coming from source files, we are working on improving the support from classes read from the class path as well.

I know this patch introduces a performance regression, even for code not using type annotations. The plan is to reduce this regression in future work. I don’t think we can eliminate it entirely, but we should be able to reduce the regression significantly at least for code not using type annotations.

The patch has been through internal reviews and and I have been fortunate to have Werner Dietl of the checkers framework beta test and report many issues. But with a patch of this size there are certainly more bugs lurking, so more testing would be most welcome. 

Webrev here: http://cr.openjdk.java.net/~jfranck/8031744/webrev.00/

cheers
/Joel


More information about the compiler-dev mailing list