-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
8320308: C2 compilation crashes in LibraryCallKit::inline_unsafe_access #20033
Conversation
👋 Welcome back tholenstein! A progress list of the required criteria for merging this PR into |
@tobiasholenstein This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 104 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@tobiasholenstein The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
remove UnlockDiagnosticVMOptions
|
/label remove graal |
@tobiasholenstein |
Webrevs
|
To understand what happens here. Did null check |
Even though the proposed check in I'd prefer to see both places fixed. Seeing Moreover, there are many places in the code susceptible to the same problem where a type is compared with |
Yes, exactly
While casting the base to not null ( |
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.
Looks good :)
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.
Looks good to me too.
So it would make sense to go over the uses of Type*::BOTTOM/Type*::NOTNULL and check they are not tested with pointer equality
What about this concern? Did anyone check yet or should be file a follow-up task?
test/hotspot/jtreg/compiler/parsing/TestUnsafeArrayAccessWithNullBase.java
Outdated
Show resolved
Hide resolved
…ullBase.java Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
test/hotspot/jtreg/compiler/parsing/TestUnsafeArrayAccessWithNullBase.java
Outdated
Show resolved
Hide resolved
@@ -2362,6 +2362,7 @@ bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, c | |||
SafePointNode* old_map = clone_map(); | |||
|
|||
Node* adr = make_unsafe_address(base, offset, type, kind == Relaxed); | |||
assert(!stopped(), "Inlining of unsafe access failed: address construction stopped unexpectedly"); | |||
|
|||
if (_gvn.type(base)->isa_ptr() == TypePtr::NULL_PTR) { |
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.
Why not uncast
here?
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.
makes sense to add here as well. Done
I filed a follow up task: https://bugs.openjdk.org/browse/JDK-8341023 |
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.
Good.
@tobiasholenstein Integration of this pull request has been delegated and may be completed by any project committer using the /integrate pull request command. |
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.
Looks good.
/integrate |
Going to push as commit 8d6d37f.
Your commit was automatically rebased without conflicts. |
We failed in
LibraryCallKit::inline_unsafe_access()
while trying to inlineUnsafe::getShortUnaligned
.jdk/test/hotspot/jtreg/compiler/parsing/TestUnsafeArrayAccessWithNullBase.java
Line 86 in 34c6e0d
The reason is that base (the array) is
ConP #null
hidden behind twoCheckCastPP
withspeculative=byte[int:>=0]
We call
Node* adr = make_unsafe_address(base, offset, type, kind == Relaxed);
jdk/src/hotspot/share/opto/library_call.cpp
Line 2361 in 34c6e0d
147 CheckCastPP
118 ConP === 0 [[[ 106 101 71 ] #null
Depending on the offset we go two different paths in
LibraryCallKit::make_unsafe_address
which both lead to the same error in the end.For
UNSAFE.getShortUnaligned(array, 1_049_000)
we get kind =Type::AnyPtr
becauseoffset >= os::vm_page_size()
. Since we assume base can't be null we insert an assert:jdk/src/hotspot/share/opto/library_call.cpp
Line 2111 in 34c6e0d
whereas for
UNSAFE.getShortUnaligned(array, 1)
we get kind =Type:: OopPtr
jdk/src/hotspot/share/opto/library_call.cpp
Line 2078 in c17fa91
and insert a null check
jdk/src/hotspot/share/opto/library_call.cpp
Line 2090 in 34c6e0d
In both cases we return call
basic_plus_adr(..)
on a base beingtop()
which returns adr =1 Con === 0 [[ ]] #top
jdk/src/hotspot/share/opto/library_call.cpp
Line 2386 in 3d5d51e
_gvn.type(adr)
is topjdk/src/hotspot/share/opto/library_call.cpp
Line 2394 in 3d5d51e
adr_type
is nullptrjdk/src/hotspot/share/opto/library_call.cpp
Lines 2405 to 2406 in 3d5d51e
BasicType bt
is T_ILLEGALjdk/src/hotspot/share/opto/library_call.cpp
Line 2424 in 3d5d51e
SIGSEGV: null pointer dereference
becausealias_type->adr_type()
is nullptrFix (updated on 18th Sep 2024)
The fix modifies the
LibraryCallKit::classify_unsafe_addr()
method to handle cases where thebase
might be hidden behind speculative type information.In the original situation,
null_check_oop()
detects that the base value isNULL
and transforms the check into an unconditional uncommon trap. The problem arises becauseLibraryCallKit::classify_unsafe_addr()
sometimes fails to recognize this due to speculative typing, particularly when the base is hidden behindCheckCastPP
nodes.To resolve this, we add
base->uncast()
inclassify_unsafe_addr()
. Theuncast()
method strips away the speculative information from the base node, allowing the comparison againstTypePtr::NULL_PTR
to succeed. This ensures that when the base isNULL
, the method can properly classify the address and avoid generating dead or incorrect code.jdk/src/hotspot/share/opto/library_call.cpp
Line 2044 in 2ab02f8
In summary, the
uncast()
fix helps the method recognize when the base isNULL
, aligningLibraryCallKit::classify_unsafe_addr()
with the behavior ofnull_check_oop()
, preventing errors when inlining unsafe accesses.Testing: tier1-4 pass
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20033/head:pull/20033
$ git checkout pull/20033
Update a local copy of the PR:
$ git checkout pull/20033
$ git pull https://git.openjdk.org/jdk.git pull/20033/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20033
View PR using the GUI difftool:
$ git pr show -t 20033
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20033.diff
Webrev
Link to Webrev Comment