[lworld] RFR: 8375306: [lworld] Investigate alternatives to flatArrayOopDesc::obj_at implementation [v3]
Stefan Karlsson
stefank at openjdk.org
Fri Feb 13 15:50:46 UTC 2026
On Thu, 12 Feb 2026 20:20:33 GMT, Frederic Parain <fparain at openjdk.org> wrote:
>> First batch of changes to remove potentially dangerous calls to objArrayOopDesc::obj_at().
>> Changes are more extensive than intended. In most cases, code modifications consist in using a refArrayOop type instead of a objArrayOop type, because most of the arrays the JVM deals with for its own purpose are always reference arrays (because they are arrays of identity type elements). The patch also adds a new API allowing the VM to request the allocation of a reference array.
>> Code dealing with user provided arrays must be ready to handle exceptions when accessing objArrays.
>>
>> This is a short term fix, fixing a few bugs, and trying to make the code more robust using the meta-data types. For the long term, a better solution is needed. Accesses to both arrays and fields are becoming more and more complex because of the introduction of flattening, multiple layouts, additional properties. Forcing enforcement at each access would be expensive and wasteful, as the JVM usually operates on well-known objects or arrays. But because of the increasing complexity, having a way to quickly check the validity of an access would help making the VM code more robust.
>
> Frederic Parain has updated the pull request incrementally with one additional commit since the last revision:
>
> Fix search of specific array klass
src/hotspot/share/memory/oopFactory.cpp line 127:
> 125: // Cast below must pass because the array description required a RefArrayKlass
> 126: RefArrayKlass* rak = RefArrayKlass::cast(oak);
> 127: oop array = rak->allocate_instance(length, properties, CHECK_NULL);
While looking at why we have all three `[Obj|Ref|Flat]ArrayKlass::allocate_instance` functions I realize that this will most likely make a virtual call to `ObjArrayKlass::allocate_instance`. If you want to call directly into `RefArrayKlass` this could be changed to:
Suggestion:
oop array = rak->RefArrayKlass::allocate_instance(length, properties, CHECK_NULL);
This is probably not super important, but I wanted to mention it because this was not obvious to me upon first reading of this function.
-------------
PR Review Comment: https://git.openjdk.org/valhalla/pull/2033#discussion_r2804867604
More information about the valhalla-dev
mailing list