RFR: 8329750: Change Universe functions to return more specific Klass* types [v2]

Stefan Karlsson stefank at openjdk.org
Mon Apr 8 07:36:09 UTC 2024


On Fri, 5 Apr 2024 22:10:46 GMT, Dean Long <dlong at openjdk.org> wrote:

>> Stefan Karlsson has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Update src/hotspot/share/classfile/systemDictionary.cpp
>>   
>>   Dean's suggestion
>>   
>>   Co-authored-by: Dean Long <17332032+dean-long at users.noreply.github.com>
>
> src/hotspot/share/classfile/systemDictionary.cpp line 371:
> 
>> 369:   } else {
>> 370:     k = Universe::typeArrayKlass(t);
>> 371:     k = k->array_klass(ndims, CHECK_NULL);
> 
> I assume the cast was an attempt to de-virtualize the array_klass() call, so it is better not to use Klass* here.

My experience is that these type of casts doesn't make the compiler devirtualize the calls. I tried it now and verified that both with and without the cast we still get the virtual call. You typically need to tell the compiler what function it should be using. (I played around a lot with this when writing the devirtualization layer for the oop_iterate/OopIterateClosure code.)

I tested writing the code above as `TypeArrayKlass::cast(k)->TypeArrayKlass::array_klass(ndims, CHECK_NULL)` and that gets rid of the virtual call. However, the compiler still can't inline the code ArrayKlass::array_klass code because it is inside a .cpp file and not an .inline.hpp, so this results in a direct call instead of inlined code.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18652#discussion_r1555350440


More information about the graal-dev mailing list