Storing annotations on exception parameters

Werner Dietl wdietl at gmail.com
Tue Jan 22 20:30:21 PST 2013


Jon,

in a separate thread you mentioned method
com.sun.tools.javac.jvm.Gen.genCatch(JCCatch, Env<GenContext>, int,
int, List<Integer>)

and I had a look at using that today.

I now have three parts of the puzzle:

In com.sun.tools.javac.code.TypeAnnotations.TypeAnnotationPositions.separateAnnotationsKinds
and resolveFrame I have the AST, the type annotations, and
AnnotatedTypes for the exception types. However, I don't know anything
about the exception table yet and could only store a position within
the multicatch.

In jvm.Code.fillExceptionParameterPositions I have the local variable
for the exception, all type annotations attached to it, and the
exception table indices - but I don't know how the type annotations
correspond to exception indices.

In jvm.Gen.genCatch I have the individual multicatch types, however
I'm not sure whether there is a relation to the exception indices for
Code.fillExceptionParameterPositions.
More severely, when I look at subCatch.type (in genCatch) the type
annotations are no longer present - AnnotatedType gets "lost" very
easily as it delegates all operations to the underlying type.
Do you know what operations happen to the exception type between the end of
com.sun.tools.javac.comp.Attr.attribClassBody
(where I call TypeAnnotations.organizeTypeAnnotationsBodies and still
have AnnotatedTypes)
and Gen.genCatch where I only see unannotated types?

Thanks,
cu, WMD.


On Tue, Jan 22, 2013 at 7:00 PM, Jonathan Gibbons
<jonathan.gibbons at oracle.com> wrote:
> On 11/27/2012 06:26 PM, Jonathan Gibbons wrote:
>>
>> On 11/27/2012 05:49 PM, Werner Dietl wrote:
>>>
>>> As discussed on the type-annotations-spec-experts list (see
>>>
>>> http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/2012-November/000038.html)
>>> Section 3.3.8 of the JSR 308 specification will stay unchanged.
>>>
>>> For local variables, method:
>>>
>>> com.sun.tools.javac.jvm.Code.fillLocalVarPosition(LocalVar)
>>>
>>> determines the necessary information.
>>>
>>> Could somebody point me to a place where I could determine the
>>> exception table index for an exception parameter?
>>> I found method
>>>
>>> com.sun.tools.javac.jvm.Gen.genCatch(JCCatch, Env<GenContext>, int,
>>> int, List<Integer>)
>>>
>>> but I didn't see an exception table index there.
>>>
>>> Thanks,
>>> cu, WMD.
>>>
>>
>> Werner,
>>
>> I believe the data structure you should be looking at is this one in
>> Code.java
>>
>>     /** A buffer for expression catch data. Each enter is a vector
>>      *  of four unsigned shorts.
>>      */
>>     ListBuffer<char[]> catchInfo = new ListBuffer<char[]>();
>>
>> And this method:
>>
>>     /** Add a catch clause to code.
>>      */
>>     public void addCatch(
>>         char startPc, char endPc, char handlerPc, char catchType) {
>>             catchInfo.append(new char[]{startPc, endPc, handlerPc,
>> catchType});
>>         }
>>
>> So, on the face of it, the index in the catchInfo array is the value you
>> want. But life is never that simple, since there's this method too:
>>
>>     public void compressCatchTable() {
>>
>> which can eliminate some entries. You may need to search catchInfo for the
>> handler you need.
>>
>> -- Jon
>
>
>
> Werner,
>
> Did this earlier response help you in determining type annotation positions
> for multicatch catch clauses?
>
> -- Jon



-- 
http://www.google.com/profiles/wdietl


More information about the type-annotations-dev mailing list