Questions about type annotation on type casts.

John Rose john.r.rose at oracle.com
Fri Dec 11 20:47:37 UTC 2015


On Dec 10, 2015, at 4:25 PM, Alex Buckley <alex.buckley at oracle.com> wrote:
> 
> 
> For the "(@T int)10" expression above, it would be the ldc that pushes 10. For "(float)1", it would be the fconst_1. For an auto-unbox like "int x = (int)new Integer(1);", it would be the invokevirtual on Integer.intValue().
> 
> In effect, I'm recommending the offset of the last instruction of the chunk of code generated to evaluate the expression being cast. However, if javac prefers to record the offset of first instruction, I would not complain.

There is something especially useful about pointing at the bytecode (or one of the bytecodes) that creates the finished expression value (or at least moves it somewhere:  astore, areturn, etc).

By contrast, some earlier instruction which begins to execute the whole expression is not securely related to the value whose type has been annotated.  Loose language about "chunk of code" makes me nervous that we might get dangling annotations.

For example, if I annotate the first instruction of the whole expression `(@T int)a[i++]`, the annotation reader will see a logically unrelated operation on `i`.  Surely pointing `@T` at `i++` is worse than merely a QOI problem.  The meaning of `@T` might be "I know this is an even number", and there's no way to get from the `i` bytecode to see the `a[i++]`, and a reader might erroneously conclude that the programmer is saying `i` is an even number.

— John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20151211/a85f10a2/attachment.html>


More information about the compiler-dev mailing list