On Fri, 13 Feb 2026 18:58:47 GMT, Frederic Parain <[email protected]> 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 two 
> additional commits since the last revision:
> 
>  - Fixes from Stefan's comments
>  - Fix more use sites and some TRAPS returns

Copyright year unchanged in some of the files.

src/hotspot/share/ci/ciArray.cpp line 66:

> 64:     {
> 65:       if (ary->is_refArray()) {
> 66:         refArrayOop refary = refArrayOopDesc::cast(ary);

oop_cast<refArrayOop>(ary);

src/hotspot/share/oops/oopCast.inline.hpp line 43:

> 41: template<>
> 42: inline bool is_oop_type<refArrayOop>(oop theOop) { return 
> theOop->is_refArray(); }
> 43: template<>

add:

template<>
inline bool is_oop_type<flatArrayOop>(oop theOop) { return 
theOop->is_flatArray(); }


So we can get rid of `flatArrayOopDesc::cast`

src/hotspot/share/prims/foreignGlobals.inline.hpp line 36:

> 34: template<typename T>
> 35: void ForeignGlobals::parse_register_array(objArrayOop jarray, StorageType 
> type_index, GrowableArray<T>& array, T (*converter)(int)) {
> 36:   refArrayOop refarray = refArrayOopDesc::cast(jarray);

why not use `oop_cast` as below? And probably remove `flatArrayOopDesc::cast` 
so we don't introduce new uses of `flatArrayOopDesc::cast`. Eventually get rid 
of `refArrayOopDesc::cast` (it is already used in so many places).

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

PR Review: 
https://git.openjdk.org/valhalla/pull/2033#pullrequestreview-3808558955
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2033#discussion_r2812405012
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2033#discussion_r2812411792
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2033#discussion_r2812364079

Reply via email to