RFR: 8138659: Speed up InstanceKlass subclass discrimination

Kim Barrett kim.barrett at oracle.com
Thu Oct 8 17:30:52 UTC 2015


On Oct 8, 2015, at 7:21 AM, Coleen Phillimore <coleen.phillimore at oracle.com> wrote:
> 
> 
> 
> On 10/7/15 8:43 PM, Kim Barrett wrote:
>> On Oct 7, 2015, at 7:35 PM, Coleen Phillimore <coleen.phillimore at oracle.com> wrote:
>>> Kim,
>>> 
>>> This looks *very* nice.   Thank you for doing this:
>>> 
>>> +    return static_cast<InstanceMirrorKlass*>(k);
>>> 
>>> 
>>> For bonus points can you change this to a static_cast<>  ???
>>> 
>>>  // Casting from Klass*
>>>  static InstanceKlass* cast(Klass* k) {
>>>    assert(k == NULL || k->is_klass(), "must be");
>>>    assert(k == NULL || k->oop_is_instance(), "cast to InstanceKlass");
>>>    return (InstanceKlass*) k;
>>>  }
>> Yikes!  I somehow forgot that InstanceKlass::cast accepted NULL.  But I wonder if that case really
>> arises?  Certainly a large percentage of uses of it will (nearly) instantly crash if k is NULL, because
>> we immediately call some member function on the result of the cast.
> 
> Oh, yeah, this looks bad!  File another bug and someone will look for why we allow null here.

https://bugs.openjdk.java.net/browse/JDK-8139163

A quick look found a place that requires that behavior, though it could easily be rewritten to not.
There are likely at least a few more, but I would still be inclined to make the change and fix the
problem cases.  See the bug report for more details, including some numbers.



More information about the hotspot-dev mailing list