Questions about type annotation on type casts.

Alex Buckley alex.buckley at oracle.com
Fri Dec 11 20:21:03 UTC 2015


On 12/10/2015 7:50 PM, Srikanth wrote:
> On Friday 11 December 2015 05:55 AM, Alex Buckley wrote:
>> On 12/9/2015 8:19 PM, Srikanth wrote:
>>> While working on https://bugs.openjdk.java.net/browse/JDK-8144168,
>>> a few questions have surfaced regarding code generation for a type
>>> annotated cast.
>>> So what exactly intended to be the value of the offset item for a cast ?
>>> ATM, javac seems to interpret this as the offset of the first
>>> instruction of chunk
>>> of code generated to evaluate the the expression being typecast, while
>>> ECJ makes the offset point to the checkcast instruction itself.
>>
>> If javac implements a cast operator via checkcast (for a reference
>> target type) or {i,l,f,d}2{b,s,i,l,f,d} (for a primitive target type),
>> then that's the answer.
>>
>> If javac does not implement a cast operator at all (usually because
>> the target type is identical to the type of the expression being cast,
>
> Thanks, I think I have the answers to my questions.
>
> "... If javac does not implement a cast operator at all (usually because
> the target type is identical to the type of the expression being cast ..."
>
> At first glance, this strategy appears to lead to loss of information,
> but I presume what is not expressly available can in fact be
> recovered by analysis of bytecodes.

Yes, any analyzer of type annotations in method bodies has to be capable 
of understanding vendor-specific compiler output.

Alex


More information about the compiler-dev mailing list