[type-annos-observers] Comments on annotations on exception parameters
Alex Buckley
alex.buckley at oracle.com
Tue Nov 27 15:01:10 PST 2012
Werner Dietl suggested:
*****
In "3.3.8 Exception parameters" the JSR 308 design document from Nov.
7 2012 states that annotations on an exception parameter (e.g. ...
catch (@A Exception e) ...) are stored as an exception table index.
I'm wondering whether for uniformity this could be stored like a local
variable or resource variable, where we store the information for the
variables explicitly. Unifying this aspect would simplify both the
specification and its implementation. Thoughts?
*****
The declaration of an exception parameter is syntactically similar to
the declaration of a local variable or resource variable, but the JVM
representation is different.
When an exception object is thrown, the JVM places a reference to the
thrown object on top of the operand stack. The bytecode of an exception
handler (i.e. a catch block) may or may not store this reference in a
local variable. There is no compiler spec to govern the matter. For
simple catch blocks, a compiler might be able to dup the top stack entry
and avoid local variables entirely.
Even if a compiler stores the reference in a local variable, the live
range of that local variable would be tricky to compute because there is
no "end" to an exception handler. Multiple handlers for one try block
may be compiled in such a way that they jump between themselves to share
code.
For these reasons, and to avoid duplicating the information in
Code.exception_table, I think 3.3.8 should continue to index the
exception_table.
Alex
More information about the type-annotations-spec-observers
mailing list