Accessing Annotations

Sebastian Sickelmann sebastian.sickelmann at gmx.de
Sun Nov 13 20:18:33 PST 2011


Hi, i unfortunatly send my previous mail to hs-comp-dev but i think it 
should be hs-runtime-dev.
So crossposting hs-comp-dev here to end the thread and move to 
hs-runtime-dev.

I found the a part of the answer by myself. The bytes of the typeArray 
are exactly the bytes
after the attribute_length field in RuntimeVisibleAnnotations_attribute 
from Classfile-Spec.

RuntimeVisibleAnnotations_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 num_annotations;
annotation annotations[num_annotations];
}

I checked the indices it with the constant-pool and it matches exactly 
with my expectations.

The second-part of my question is still unanswered and i hope to get 
some hint.
I want to implement a class that helps me processing the 
annotation(type-array), my idea
is to create a annotationKlass class so that i can code something like this:
annotationKlass::cast(typeArrayOop annotationTypeArray) and some 
accessory methods
to easiliy work with annotations inside the vm.
Or is there any implementation that does the annotation access-part that 
i haven't found yet?

-- Sebastian


Am 10.11.2011 15:14, schrieb Sebastian Sickelmann:
> Hi,
>
> i actually explore how i could implement
> "Removing public fields without breaking binary 
> compatibility"[0][1][2] inside of the vm.
>
> In [0] i made an early prototype with annotations and 
> class-weaving(changing) at load-time.
> Now i want to shift this prototype to an inside-the-vm implementation.
>
> The first place i ran into is the verifier. Here i need to return true 
> if there is are methods
> annotated with the new AccessorMethod-Annotation (which i made part of 
> java/lang in my
> private openjdk clone). Just for completeness: the methods parameters 
> and return value must
> fit to the expected field (said in other words "one get and one set 
> method").
>
> I tried to hack on Reflection::verify_field_access and added something 
> like this[3] to access the
> methods and their annotations. I tried it in various ways (and after 
> some errors on my side) i
> get an typeArrayOop/typeArrayKlass which i think i can access the 
> annotations. Asking the
> typeArrayKlass for its name/external-name/dimensions answers [B/[B/1 
> which seems to be an
> one-dimensional byte-array. Is this the structure of the 
> RuntimeVisibleAnnotation described in
> class-file-spec[4]?
>
>
> Must i access its byte content and parse it, or have i missed an 
> "annotationKlass" impl?
>
> If i first must implement such a annotationKlass-implementation. Is 
> there a good starting for this?
>
>
> Some hints to get me working on this again would be fine.
>
> Kind regards
> Sebastian
>
> [0] 
> http://mail.openjdk.java.net/pipermail/jdk8-dev/2011-October/000199.html
> [1] 
> http://mail.openjdk.java.net/pipermail/core-libs-dev/2011-September/007676.html 
>
> [2] 
> http://codingwizard.wordpress.com/2011/09/13/remove-flaws-in-java-apis/
> [3] 
> http://dl.dropbox.com/u/43692695/oss-patches/openjdk8/compatiblefieldaccess/question1-2011-11-10/index.html
> [4] 
> http://java.sun.com/docs/books/jvms/second_edition/ClassFileFormat-Java5.pdf



More information about the hotspot-compiler-dev mailing list