-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8156534: Check if range checks can be moved into Java wrapper for intrinsics #25998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back vyazici! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
public static int countPositives(byte[] ba, int off, int len) { | ||
Objects.requireNonNull(ba, "ba"); | ||
Objects.checkFromIndexSize(off, len, ba.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall core libraries intentionally avoided this because of performance problems. Is it possible for us to say trust the len
argument to be non-negative? That allows us to simplify this to Objects.checkIndex(off, ba.length - len)
. See this usage in perf-sensitive FFM API:
jdk/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java
Line 401 in 1498824
void checkBounds(long offset, long length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the original code already checks for len >= 0
, right? See LibraryCallKit::inline_countPositives
-> generate_string_range_check
-> // Offset and count must not be negative
This PR is about moving the range checks from the intrinsics into the Java wrappers. Removing range checks is out of the scope and should be carefully evaluated on a case-by-case basis separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is this is a performance-sensitive API. We are using a known-slow check method checkFromIndexSize
which may introduce a performance regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use jdk.internal.util.Preconditions
directly instead?
Objects.checkFromIndexSize(off, len, ba.length); | |
Preconditions.checkFromIndexSize(off, len, ba.length, null); |
Warning
This is a draft PR to collect feedback on implementing JDK-8156534 only for
java.lang.StringCodec::countPositives
.Moves
String
-related intrinsic checks from C++ to Java – see the ticket for details on motivation.Implementation notes
The goal of this work is to, for
java.lang.String*
classes,@IntrinsicCandidate
-annotatedpublic
methods1 (in Java code) toprivate
ones, and wrap them with apublic
"front door" method@IntrinsicCandidate
annotation to a new method, intrinsic mappings – i.e., associateddo_intrinsic()
calls invmIntrinsics.hpp
– need to be updated tooVerifyIntrinsicChecks
flagFollowing preliminary work needs to be carried out as well:
VerifyIntrinsicChecks
VM flaggenerate_string_range_check
to produce aHaltNode
1
@IntrinsicCandidate
-annotated constructors are not subject to this change, since they are a special case.Verification
I've tested the implementation as follows:
Received
IOOBE
as expected.StringCodec.java
, and re-compiled the JDKcountPositives(...)
arguments in the program to(null, 1, 1)
, run it, and observed the VM crash withunexpected null in intrinsic
.countPositives(...)
arguments in the program to(new byte[]{1,2,3}, 2, 5)
, run it, and observed the VM crash withunexpected guard failure in intrinsic
.Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25998/head:pull/25998
$ git checkout pull/25998
Update a local copy of the PR:
$ git checkout pull/25998
$ git pull https://git.openjdk.org/jdk.git pull/25998/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25998
View PR using the GUI difftool:
$ git pr show -t 25998
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25998.diff