On Tue, 20 Jan 2026 11:25:59 GMT, Quan Anh Mai <[email protected]> wrote:

>> Some code added by 
>> [JDK-8372700](https://bugs.openjdk.org/browse/JDK-8372700) can compute the 
>> constant value of a field of a (flatten) element in a flat array. We get a 
>> crash when the element of the array is known to be `null`, and so the field 
>> doesn't exist.
>> 
>> So, let's just check in `ciConstant ciFlatArray::field_value(int index, 
>> ciField* field)` whether we get a null constant before interpreting it as a 
>> `ciInstance` and trying to retrieve a field from there. This should be 
>> enough since a `ciObject` is (directly) derived by `ciNullObject`, 
>> `ciInstance` and `ciArray`. Since we are looking up a value of a flat array, 
>> an element cannot be a `ciArray` (arrays have identities and can't be 
>> contained in a flat array). After looking up whether the flat array element 
>> is null, the `obj->as_instance()` cast acts as an assert, should we ever add 
>> another derived class from `ciObject`.
>> 
>> In case of a null array element, `field_value` simply returns an invalid 
>> `ciConstant`.
>> 
>> Tested with 
>> tier1,tier2,tier3,hs-precheckin-comp,hs-comp-stress,valhalla-comp-stress. 
>> Looks good.
>> 
>> Thanks,
>> Marc
>
> src/hotspot/share/opto/type.cpp line 414:
> 
>> 412: 
>> 413:   if (con.is_valid() &&          // not a mismatched access
>> 414:       !con.is_null_or_zero()) {  // not a default value
> 
> This is incorrect, the value is not constant if the element of the array is 
> `null`, not if the field we retrieved is `null`.

I think you're correct. While being sound, we might miss opportunities where 
the value is actually constant but we discard it. `con.is_value()` already  is 
enough to make sure the array element is not null (and constant).

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/1923#discussion_r2708249153

Reply via email to