On Sat, 20 Jun 2026 08:35:18 GMT, Christian Hagedorn <[email protected]> 
wrote:

>> The provided test cases fail when inlining the `Array.copyOf/copyOfRange()` 
>> intrinsics where the source array is flat and from an abstract value class.
>> 
>> The current code checks whether the source array or the destination array 
>> klass contain oops by assuming that a flat value class array is always 
>> concrete and thus an `InlineKlass` (i.e. can call `inline_klass()`). 
>> However, we could also have abstract value class arrays that are known to be 
>> flat (see test cases). This leads to a cast assertion failure because 
>> abstract value classes are represented by an `InstanceKlass` and not an 
>> `InlineKlass`.
>> 
>> To fix this, I added a simple bailout when detecting an abstract flat value 
>> class array. This is a conservative correctness fix and should be revisited 
>> again post-Valhalla-integration. We have 
>> [JDK-8251971](https://bugs.openjdk.org/browse/JDK-8251971) in place for that 
>> which should also tackle other issues around the arraycopy intrinsics and 
>> also address performance problems.
>> 
>> Thanks,
>> Christian
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Christian Hagedorn has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   improve checks and further refactor exclude_flat to make it easier to read

src/hotspot/share/opto/library_call.cpp line 5199:

> 5197:     const TypeAryPtr* orig_t = _gvn.type(original)->isa_aryptr();
> 5198:     const TypeAryKlassPtr* dest_klass_t = 
> _gvn.type(klass_node)->is_klassptr()->isa_aryklassptr();
> 5199:     const bool can_src_be_abstract_flat_value_class_array = orig_t != 
> nullptr && !orig_t->elem()->is_inlinetypeptr() && !orig_t->is_not_flat();

This name is a little misleading, I think you want to catch the case `orig_t == 
nullptr` below, but if the static type is `j.l.O`, the runtime type can still 
be an abstract flat array.

src/hotspot/share/opto/library_call.cpp line 5200:

> 5198:     const TypeAryKlassPtr* dest_klass_t = 
> _gvn.type(klass_node)->is_klassptr()->isa_aryklassptr();
> 5199:     const bool can_src_be_abstract_flat_value_class_array = orig_t != 
> nullptr && !orig_t->elem()->is_inlinetypeptr() && !orig_t->is_not_flat();
> 5200:     const bool can_dest_be_value_class_array = dest_klass_t != nullptr 
> && dest_klass_t->can_be_inline_array();

What if `dest` is not an `aryklassptr`? I think in that case this should also 
be true, right?

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2569#discussion_r3460929438
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2569#discussion_r3460916901

Reply via email to