On Thu, 12 Feb 2026 21:21:54 GMT, Frederic Parain <[email protected]> wrote:
>> Different array layouts result in distinct array klass metadata which are
>> stored in a linked list with the base ObjArrayKlass acting as the head.
>> Multiple layouts are currently uncommon, so this assert was sufficient:
>>
>> `assert(objarray_k == k || objarray_k->next_refined_array_klass() == k)
>> failed: must be`
>>
>> This assert is not correct since `k` could refer to another refined array
>> klass further down the linked list. This patch corrects this assert by
>> adding a find method to iterate through the linked list in case there are
>> multiple layouts for the same type. A new test was added to catch this
>> failure. Verified with tier 1-5 tests.
>
> src/hotspot/share/classfile/javaClasses.cpp line 1273:
>
>> 1271: }
>> 1272: } else {
>> 1273: ObjArrayKlass* objarray_k = (ObjArrayKlass*)as_Klass(m);
>
> This is the else clause of the `if (!k->is_array_klass())` , which means that
> k is either and objArrayKlass (or sub-type) or a typeArrayKlass. How is it
> safe to unconditionally cast to objArrayKlass?
You're right, this seems to work by accident. In this case, `k` could be a
TypeArrayKlass and casting it to ObjArrayKlass doesn't seem to break anything
so it passes the assert. I'll update this case to an `else if`
-------------
PR Review Comment:
https://git.openjdk.org/valhalla/pull/2095#discussion_r2801172960