Request for reviews (M): 7170463: C2 should recognize "obj.getClass() == A.class" code pattern

Vladimir Kozlov vladimir.kozlov at
Thu May 24 10:32:59 PDT 2012

John Rose wrote:
> On May 23, 2012, at 4:47 PM, Vladimir Kozlov wrote:
>> I updated webrev:
>> I found additional issue with original changes. They accidentally 
>> removed optimization which replaces LoadKlass node with ConP (klass 
>> type) in map. Next code will not be executed:
>>   cast = con;  // Replace non-constant val by con.
>> New code should do separate map update of object which klass is compared.
> That's fine; I like it.
> New question:  Can the following call return Top?
>   obj_type->join(con_type)

Yes, it could but the cast is pinned to True path which is dead (not executed) 
in such case (we don't change control flow in this code).

But current code will assert in TOP case during call to is_oopptr() which is not 


I am changing this code so it will skip TOP case:

   const TypeOopPtr* tboth = obj_type->join(con_type)->isa_oopptr();
   if (tboth != NULL && tboth != obj_type) {


> E.g.,
>   Number x = 5;
>   if (x.getClass() == String.class)
>     System.out.println("fail!");
> Perhaps the compare will short-circuit before that happens.  If it 
> doesn't, we'll get assertion failures or worse.
> — John

More information about the hotspot-compiler-dev mailing list