RFR: 8361842: Move input validation checks to Java for String-related intrinsics [v3]
Tobias Hartmann
thartmann at openjdk.org
Wed Jul 16 05:32:45 UTC 2025
On Tue, 15 Jul 2025 20:24:04 GMT, Volkan Yazici <vyazici at openjdk.org> wrote:
>> Validate input in `java.lang.StringCoding` intrinsic Java wrappers, improve their documentation, enhance the checks in the associated IR or assembly code, and adapt them to cause VM crash on invalid input.
>>
>> ## Implementation notes
>>
>> The goal of the associated umbrella issue [JDK-8156534](https://bugs.openjdk.org/browse/JDK-8156534) is to, for `java.lang.String*` classes,
>>
>> 1. Move `@IntrinsicCandidate`-annotated `public` methods<sup>1</sup> (in Java code) to `private` ones, and wrap them with a `public` ["front door" method](https://github.com/openjdk/jdk/pull/24982#discussion_r2087493446)
>> 2. Since we moved the `@IntrinsicCandidate` annotation to a new method, intrinsic mappings – i.e., associated `do_intrinsic()` calls in `vmIntrinsics.hpp` – need to be updated too
>> 3. Add necessary input validation (range, null, etc.) checks to the newly created public front door method
>> 4. Place all input validation checks in the intrinsic code (add if missing!) behind a `VerifyIntrinsicChecks` VM flag
>>
>> Following preliminary work needs to be carried out as well:
>>
>> 1. Add a new `VerifyIntrinsicChecks` VM flag
>> 2. Update `generate_string_range_check` to produce a `HaltNode`. That is, crash the VM if `VerifyIntrinsicChecks` is set and a Java wrapper fails to spot an invalid input.
>>
>> <sup>1</sup> `@IntrinsicCandidate`-annotated constructors are not subject to this change, since they are a special case.
>>
>> ## Functional and performance tests
>>
>> - `tier1` (which includes `test/hotspot/jtreg/compiler/intrinsics/string`) passes on several platforms. Further tiers will be executed after integrating reviewer feedback.
>>
>> - Performance impact is still actively monitored using `test/micro/org/openjdk/bench/java/lang/String{En,De}code.java`, among other tests. If you have suggestions on benchmarks, please share in the comments.
>>
>> ## Verification of the VM crash
>>
>> I've tested the VM crash scenario as follows:
>>
>> 1. Created the following test program:
>>
>> public class StrIntri {
>> public static void main(String[] args) {
>> Exception lastException = null;
>> for (int i = 0; i < 1_000_000; i++) {
>> try {
>> jdk.internal.access.SharedSecrets.getJavaLangAccess().countPositives(new byte[]{1,2,3}, 2, 5);
>> } catch (Exception exception) {
>> lastException = exception;
>> }
>> }
>> if (lastException != null) {
>> lastException.printStackTrace...
>
> Volkan Yazici has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 12 additional commits since the last revision:
>
> - Merge remote-tracking branch 'upstream/master' into strIntrinCheck
> - Apply review feedback (styling changes)
> - Minimize the number of touched lines in `vmIntrinsics.hpp`
> - Remove Markdown-styling in comments
> - Improve wording of the `VerifyIntrinsicChecks` flag
> - Merge remote-tracking branch 'upstream/master' into strIntrinCheck
> - Fix `EUC_JP.java.template` broken due to `encodeASCII` rename
> - Remove `StringCodingCountPositives`, `String{En,De}code` already cover our cases
>
> This reverts commit 196fc5d406851b8e7070c97ac53ca59c4615aad9.
> - Improve intrinsics in `StringCoding`
> - Add `StringCodingCountPositives` benchmark
> - ... and 2 more: https://git.openjdk.org/jdk/compare/32d96877...85f19864
Thanks a lot for working on this, Volkan! The changes look good to me, I just added two comments.
src/hotspot/share/opto/c2_globals.hpp line 665:
> 663: "prints attempted and successful inlining of intrinsics") \
> 664: \
> 665: develop(bool, VerifyIntrinsicChecks, false, \
We should add testing that uses this new flag. Maybe we could add a run to the tests that check the affected intrinsics? We could also add it to our (Oracle internal) stress test jobs at higher tiers.
src/hotspot/share/opto/library_call.cpp line 971:
> 969: } else {
> 970: PreserveJVMState pjvms(this);
> 971: set_control(_gvn.transform(bailout));
Suggestion:
bailout = _gvn.transform(bailout);
if (halt) {
Node* frame = _gvn.transform(new ParmNode(C->start(), TypeFunc::FramePtr));
Node* halt = _gvn.transform(new HaltNode(bailout, frame, "unexpected guard failure in intrinsic"));
C->root()->add_req(halt);
} else {
PreserveJVMState pjvms(this);
set_control(bailout);
-------------
Marked as reviewed by thartmann (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/25998#pullrequestreview-3023137214
PR Review Comment: https://git.openjdk.org/jdk/pull/25998#discussion_r2209259866
PR Review Comment: https://git.openjdk.org/jdk/pull/25998#discussion_r2209245394
More information about the graal-dev
mailing list