RFR: 8366024: Remove unnecessary InstanceKlass::cast()
Ioi Lam
iklam at openjdk.org
Wed Aug 27 18:22:43 UTC 2025
On Wed, 27 Aug 2025 09:17:31 GMT, Andrew Dinn <adinn at openjdk.org> wrote:
> I found two more occurrences of casting super() to InstanceKlass:
>
> ```
> src/hotspot/share/jfr/leakprofiler/chains/edgeUtils.cpp:79
>
> ik = (const InstanceKlass*)ik->super();
> ```
I fixed this one with `java_super()`. Similar to the case in deoptimization.cpp, the cost is dominated by the JavaFieldStream so a virtual call should be fine here.
> ```src/hotspot/share/prims/jni.cpp:209
>
> intptr_t jfieldIDWorkaround::encode_klass_hash(Klass* k, int offset) {
> if (offset <= small_offset_mask) {
> Klass* field_klass = k;
> Klass* super_klass = field_klass->super();
> // With compressed oops the most super class with nonstatic fields would
> // be the owner of fields embedded in the header.
> while (InstanceKlass::cast(super_klass)->has_nonstatic_fields() &&
> InstanceKlass::cast(super_klass)->contains_field_offset(offset)) {
> field_klass = super_klass; // super contains the field also
> super_klass = field_klass->super();
> }
> ```
Here we have the same logic as in the (removed) `superklass()` function, without any explanation why the cast is safe. The code seems to assume that the incoming `k` parameter cannot be a type such as `[Ljava/lang/String;`. I am not familiar with this code, so I will leave it as is.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/26908#issuecomment-3229259517
More information about the hotspot-dev
mailing list