8339526: C2: store incorrectly removed for clone() transformed to series of loads/stores #27604
+99
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the
test1()
method of the test case:inlined2()
callsclone()
for an object loaded from fieldfield
that has inexact type
A
at parse time. The intrinsic forclone()
inserts an
Allocate
and anArrayCopy
nodes. When igvn runs, theload of
field
is optimized out because it reads back a newlyallocated
B
written tofield
in the same method.ArrayCopy
cannow be optimized because the type of its
src
input is known. Thetype of its
dest
input is theCheckCastPP
from the allocation ofthe cloned object created at parse time. That one has type
A
. Aseries of
Load
s/Store
s are created to copy the fields of classB
from
src
(of typeB
) todest
of (typeA
).Writting to
dest
with offsets for fields that don't exist inA
,causes this code in
Compile::flatten_alias_type()
:to assign it some slice that doesn't match the one that's used at the
same offset in
B
.That causes an assert in
ArrayCopyNode::try_clone_instance()
tofire. With a release build, execution proceeds.
test1()
also has anon escaping allocation. That one causes EA to run and
ConnectionGraph::split_unique_types()
to move the store to the nonescaping allocation to a new slice. In the process, when it iterates
over
MergeMem
nodes, it notices the stores added byArrayCopyNode::try_clone_instance()
, finds that some are not on theright slice, tries to move them to the correct slice (expecting they
are from a non escaping EA). That causes some of the
Store
s to bedisconnected. When the resulting code runs, execution fails as some
fields are not copied.
The fix I propose is to skip
ArrayCopyNode::try_clone_instance()
when
src
anddest
classes don't match as this seems like a rareenough corner case.
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27604/head:pull/27604
$ git checkout pull/27604
Update a local copy of the PR:
$ git checkout pull/27604
$ git pull https://git.openjdk.org/jdk.git pull/27604/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 27604
View PR using the GUI difftool:
$ git pr show -t 27604
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27604.diff
Using Webrev
Link to Webrev Comment