On Tue, 13 Jan 2026 20:01:31 GMT, Volkan Yazici <[email protected]> wrote:

>> ## Issue
>> 
>> This is a redo of [JDK-8361842](https://bugs.openjdk.org/browse/JDK-8361842) 
>> which was backed out by 
>> [JDK-8374210](https://bugs.openjdk.org/browse/JDK-8374210) due to C2-related 
>> regressions. The original change moved input validation checks for 
>> java.lang.StringCoding from the intrinsic to Java code (leaving the 
>> intrinsic check only with the `VerifyIntrinsicChecks` flag). Refer to the 
>> [original PR](https://github.com/openjdk/jdk/pull/25998) for details.
>> 
>> This additional issue happens because, in some cases, for instance when the 
>> Java checking code is not inlined and we give an out-of-range constant as 
>> input, we fold the data path but not the control path and we crash in the 
>> backend.
>> 
>> ## Causes
>> 
>> The cause of this is that the out-of-range constant (e.g. -1) floats into 
>> the intrinsic and there (assuming the input is valid) we add a constraint to 
>> its type to positive integers (e.g. to compute the array address) which 
>> makes it top.
>> 
>> ## Fix
>> 
>> A possible fix is to introduce an opaque node (OpaqueGuardNode) similar to 
>> what we do in `must_be_not_null` for values that we know cannot be null:
>> https://github.com/openjdk/jdk/blob/ce721665cd61d9a319c667d50d9917c359d6c104/src/hotspot/share/opto/graphKit.cpp#L1484
>> This will temporarily add the range check to ensure that C2 figures that 
>> out-of-range values cannot reach the intrinsic. Then, during macro 
>> expansion, we replace the opaque node with the corresponding constant 
>> (true/false) in product builds such that the actually unneeded guards are 
>> folded and do not end up in the emitted code.
>> 
>> # Testing
>> 
>> * Tier 1-3+
>> * 2 JTReg tests added
>>   * `TestRangeCheck.java` as regression test for the reported issue
>>   * `TestOpaqueGuardNodes.java` to check that opaque guard nodes are added 
>> when parsing and removed at macro expansion
>
> src/hotspot/share/opto/library_call.hpp line 170:
> 
>> 168:                                     Node* length, bool char_count,
>> 169:                                     bool halt_on_oob = false,
>> 170:                                     bool is_opaque = false);
> 
> Do we really need to introduce two new toggles: `halt_on_oob` and 
> `is_opaque`? At all call-sites either one of the following is used:
> 
> 1. `halt_on_oob=true, is_opaque=!VerifyIntrinsicChecks`
> 2. defaults (i.e., `halt_on_oob=is_opaque=false`)
> 
> Can we instead only settle one, e.g., `halt_on_oob=VerifyIntrinsicChecks`?

Giving this a second thought, do we need these two flags anyway? That is,

1. We can remove `if (is_opaque)` add the `OpaqueGuard` anyway, since it is 
ineffective for `!ASSERT`. (This is what `must_be_not_null` does too.)
2. We can replace `if (halt_on_oob) { ... } else { ... }` with `#ifdef ASSERT 
...`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29164#discussion_r2689690430

Reply via email to