classfile format for type annotations on instructions
Eric Bruneton
ebruneton at free.fr
Wed Sep 12 22:17:58 PDT 2012
Hi,
For type annotations on class, fields and methods, it is clear how the
annotations can be recovered from a class file, using both the
target_type and target_info fields, and the Signature attribute of the
corresponding class, field or method.
However, I don't see how this is possible for type annotations on
instructions. The only generic type information that is available for
instructions is about the local variables, in the LocalVariableTypeTable
attribute
(http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.14).
Even with some kind of type inference mechanism, I don't see how this is
sufficient to know the generic types for any erased type on the stack or
in the locals, at any point in the code (since an annotation can target
any instruction). Can you explain how this works?
I also have a question about annotations for constructor calls (sections
3.3.9 and 3.3.10). Why do they target the 'new' instruction instead of
the 'invokespecial' that corresponds to the actual constructor call? At
the 'new' instruction we don't even know which constructor will be
called, how many arguments it takes and of which types, etc. On the
contrary, this information is available at the 'invokespecial'
instruction. Thus it seems more logical to target this instruction, to
know the types targeted by 'target_info', to do consistency checks, etc.
Eric
More information about the type-annotations-spec-comments
mailing list