Hi Joel,

I see, there is a dilema how to cache type annotations. To satisfy
single-annotation-returning methods and repeating annotation logic, a
HashMap would be a logical choice, but it has much bigger footprint than
simple arrays of annotations...

I experimented with an idea of using a special purpose immutable Map
implementation:

https://github.com/plevart/jdk8-tl/blob/anno-map/jdk/src/share/classes/sun/reflect/annotation/UniqueIndex.java

and:

https://github.com/plevart/jdk8-tl/blob/anno-map/jdk/src/share/classes/sun/reflect/annotation/AnnotationMap.java

This is just a preview. I still have to create some tests to see how it
compares to HashMap. Being an immutable wrapper for a single array of
annotations it has a nice feature that a reference to it can be passed to
other threads via a data race with no danger of data inconsistency, which
simplifies caching mechanisms and helps scalability.
Might even be a space-saving replacement for existing HashMaps of
annotations. Depending on performance, of course.
What do you think? Is it worth pursuing this further?

Regards, Peter
 On Jan 17, 2013 5:24 PM, "Joel Borggrén-Franck" <joel.fra...@oracle.com>
wrote:

> Hi,
>
> Here is a webrev for core reflection support for type annotations:
>
> http://cr.openjdk.java.net/~jfranck/8004698/webrev.00/
>
> This code is based on the tl/jdk repository, but in order to run the tests
> you need a javac with type annotations support and also a recent copy of
> the VM that includes this change set:
> http://hg.openjdk.java.net/hsx/hotspot-main/hotspot/rev/35431a769282(This 
> also means this code can't be pushed until all supporting pieces are
> in place.)
>
> Type annotations are still a bit of a moving target so there will be
> follow up work on this. There is no caching of annotations in this version
> and I am not sure how we want to do the space/time trade of for type
> annotations.
>
> cheers
> /Joel

Reply via email to