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

Dean Long dlong at openjdk.org
Wed Apr 10 01:59:11 UTC 2024


On Mon, 8 Apr 2024 07:32:58 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:

>> 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.

OK, I guess the compiler needs to be conservative in case TypeArrayKlass has a subclass.

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

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


More information about the graal-dev mailing list