Questions about type annotation on type casts.

Alex Buckley alex.buckley at
Wed Jan 20 00:10:30 UTC 2016

I agree that the delayed offset computation is good.

A consideration is the JVMS 4.7.20 target_info item which "denotes precisely which type in a declaration or expression is annotated":

- For an annotated type in a cast expression, we're in good shape. The offset is deliberately not specified in terms of a concrete 'checkcast' but rather in looser terms: "the bytecode instruction corresponding to the cast expression". (

- For an annotation type in an instanceof expression, we're in less good shape. We never imagined that 'instanceof' or 'new' expressions in the language would be optimized, so the offset is specified to assume those bytecodes exist. ( It would be proper to file a specification/vm bug to loosen "the instanceof bytecode instruction corresponding to the instanceof expression" by dropping the first 'instanceof'.


----- Original Message ----- 
From: john.r.rose at 
To: srikanth.adayapalam at 
Cc: compiler-dev at 
Sent: Monday, January 18, 2016 12:31:13 AM GMT -08:00 US/Canada Pacific 
Subject: Re: Questions about type annotation on type casts. 

On Jan 17, 2016, at 10:52 PM, Srikanth < srikanth.adayapalam at > wrote: 

By computing the offset just after translation of the expression, the offset would point to the checkcast instruction 
when present and when absent would point to the offset where the checkcast expression would have been had it not been optimized 
away - i.e pointing to the earliest offset where the fully finished expression value is at the top of stack. 

This appears to me to a better arrangement than what we have at present. 

Also note that we have the same eager offset computation issue with instanceof - I don't see the compilers optimizing away 
instanceof instructions as of now though. 

That sounds good. One could think of the optimized checkcast as a zero-length opcode that leaves TOS unchanged. 

If instanceof is optimized, it will turn into an iconst_[01]. That would be the instruction to point at, I suppose. 

— John

More information about the compiler-dev mailing list