-
Notifications
You must be signed in to change notification settings - Fork 6.3k
8380060: C2: Wrong execution with COH and arraycopy #30873
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
Closed
Closed
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
66060f4
8380060: C2: Wrong execution with COH and arraycopy
rkennke 493c098
Better fix: clone should update all memory slices, not just raw
rkennke 276b968
Fix wiring of memory
rkennke 15144c4
Adjust ArrayCopyNode::finish_transform() to accept the new possible s…
rkennke c213dea
Simplify boolean expression
rkennke f1943ff
Clarify and simplify ACN::finish_transform()
rkennke 3d6e038
Fix comment
rkennke 9c1b3e5
Remove redundant set_all_memory_call
rkennke 550912b
more
rwestrel 0d10a13
more
rwestrel 1acae56
Merge branch 'master' into JDK-8380060
rwestrel 6d9b13e
Merge branch 'master' into JDK-8380060
rwestrel 86db712
review
rwestrel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
test/hotspot/jtreg/compiler/arraycopy/TestBlockArrayCopyMisaligned.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| /* | ||
| * @test | ||
| * @bug 8380060 | ||
| * @summary C2 block arraycopy initial-word pick-off folds load to zero | ||
| * | ||
| * @run main/othervm -Xbatch -XX:+UseCompactObjectHeaders | ||
| * -XX:CompileCommand=compileonly,compiler.arraycopy.TestBlockArrayCopyMisaligned::test* | ||
| * compiler.arraycopy.TestBlockArrayCopyMisaligned | ||
| * @run main/othervm -Xbatch -XX:-UseCompactObjectHeaders | ||
| * -XX:CompileCommand=compileonly,compiler.arraycopy.TestBlockArrayCopyMisaligned::test* | ||
| * compiler.arraycopy.TestBlockArrayCopyMisaligned | ||
| */ | ||
|
|
||
| package compiler.arraycopy; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public class TestBlockArrayCopyMisaligned { | ||
|
|
||
| // Byte array with enough data to exercise the block arraycopy path. | ||
| // The clone + substring pattern triggers a tightly-coupled allocation | ||
| // where the source is initialized via a raw arraycopy (clone) and the | ||
| // destination is a nozero allocation filled by a block arraycopy. | ||
| static final byte[] BYTES = new byte[] { | ||
| 108, 77, 120, 120, 100, 77, 105, 113, | ||
| 83, 97, 71, 108, 116, 107, 90, 71, | ||
| 72, 107, 73, 85, 54, 65, 61, 61 | ||
| }; | ||
|
|
||
| // Test via String(byte[],hibyte,off,count) + substring. | ||
| // The deprecated String constructor clones the byte array via | ||
| // Arrays.copyOfRange; substring then does another copyOfRange | ||
| // on the clone, triggering the block arraycopy optimization. | ||
| static String testStringSubstring() { | ||
| String s = new String(BYTES, 0, 0, 24); | ||
| return s.substring(0, 23); | ||
| } | ||
|
|
||
| // Test via explicit clone + Arrays.copyOfRange. | ||
| static byte[] testCloneCopyOfRange() { | ||
| byte[] clone = BYTES.clone(); | ||
| return Arrays.copyOfRange(clone, 0, 23); | ||
| } | ||
|
|
||
| // Test via explicit clone + Arrays.copyOf. | ||
| static byte[] testCloneCopyOf() { | ||
| byte[] clone = BYTES.clone(); | ||
| return Arrays.copyOf(clone, 20); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| String golden = new String(BYTES, 0, 0, 23); | ||
|
|
||
| for (int i = 0; i < 10_000; i++) { | ||
| // Test 1: String path | ||
| String result1 = testStringSubstring(); | ||
| if (!result1.equals(golden)) { | ||
| throw new RuntimeException("testStringSubstring: expected " | ||
| + golden + ", got " + result1); | ||
| } | ||
|
|
||
| // Test 2: clone + copyOfRange | ||
| byte[] result2 = testCloneCopyOfRange(); | ||
| for (int j = 0; j < 23; j++) { | ||
| if (result2[j] != BYTES[j]) { | ||
| throw new RuntimeException("testCloneCopyOfRange: mismatch at index " + j | ||
| + ", expected " + BYTES[j] + ", got " + result2[j]); | ||
| } | ||
| } | ||
|
|
||
| // Test 3: clone + copyOf | ||
| byte[] result3 = testCloneCopyOf(); | ||
| for (int j = 0; j < 20; j++) { | ||
| if (result3[j] != BYTES[j]) { | ||
| throw new RuntimeException("testCloneCopyOf: mismatch at index " + j | ||
| + ", expected " + BYTES[j] + ", got " + result3[j]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
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.
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.
It makes sense to place alias index probing into
NarrowMemProjNodector. Or, at least, put an assert there to ensure the index is present.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.
Added in new commit. Does that look ok to you?