Skip to content

Commit a86e196

Browse files
committed
8235762: JVM crash in SWPointer during C2 compilation
Reviewed-by: thartmann, chagedorn, neliasso
1 parent e80a188 commit a86e196

File tree

3 files changed

+103
-25
lines changed

3 files changed

+103
-25
lines changed

src/hotspot/share/opto/superword.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,13 @@ void SuperWord::find_adjacent_refs() {
576576
}
577577

578578
Node_List align_to_refs;
579+
int max_idx;
579580
int best_iv_adjustment = 0;
580581
MemNode* best_align_to_mem_ref = NULL;
581582

582583
while (memops.size() != 0) {
583584
// Find a memory reference to align to.
584-
MemNode* mem_ref = find_align_to_ref(memops);
585+
MemNode* mem_ref = find_align_to_ref(memops, max_idx);
585586
if (mem_ref == NULL) break;
586587
align_to_refs.push(mem_ref);
587588
int iv_adjustment = get_iv_adjustment(mem_ref);
@@ -699,34 +700,40 @@ void SuperWord::find_adjacent_refs() {
699700
// Put memory ops from remaining packs back on memops list for
700701
// the best alignment search.
701702
uint orig_msize = memops.size();
702-
if (_packset.length() == 1 && orig_msize == 0) {
703-
// If there are no remaining memory ops and only 1 pack we have only one choice
704-
// for the alignment
705-
Node_List* p = _packset.at(0);
706-
assert(p->size() > 0, "sanity");
703+
for (int i = 0; i < _packset.length(); i++) {
704+
Node_List* p = _packset.at(i);
707705
MemNode* s = p->at(0)->as_Mem();
708706
assert(!same_velt_type(s, mem_ref), "sanity");
709-
best_align_to_mem_ref = s;
710-
} else {
711-
for (int i = 0; i < _packset.length(); i++) {
712-
Node_List* p = _packset.at(i);
713-
MemNode* s = p->at(0)->as_Mem();
714-
assert(!same_velt_type(s, mem_ref), "sanity");
715-
memops.push(s);
707+
memops.push(s);
708+
}
709+
best_align_to_mem_ref = find_align_to_ref(memops, max_idx);
710+
if (best_align_to_mem_ref == NULL) {
711+
if (TraceSuperWord) {
712+
tty->print_cr("SuperWord::find_adjacent_refs(): best_align_to_mem_ref == NULL");
716713
}
717-
best_align_to_mem_ref = find_align_to_ref(memops);
718-
if (best_align_to_mem_ref == NULL) {
719-
if (TraceSuperWord) {
720-
tty->print_cr("SuperWord::find_adjacent_refs(): best_align_to_mem_ref == NULL");
714+
// best_align_to_mem_ref will be used for adjusting the pre-loop limit in
715+
// SuperWord::align_initial_loop_index. Find one with the biggest vector size,
716+
// smallest data size and smallest iv offset from memory ops from remaining packs.
717+
if (_packset.length() > 0) {
718+
if (orig_msize == 0) {
719+
best_align_to_mem_ref = memops.at(max_idx)->as_Mem();
720+
} else {
721+
for (uint i = 0; i < orig_msize; i++) {
722+
memops.remove(0);
723+
}
724+
best_align_to_mem_ref = find_align_to_ref(memops, max_idx);
725+
assert(best_align_to_mem_ref == NULL, "sanity");
726+
best_align_to_mem_ref = memops.at(max_idx)->as_Mem();
721727
}
722-
break;
728+
assert(best_align_to_mem_ref != NULL, "sanity");
723729
}
724-
best_iv_adjustment = get_iv_adjustment(best_align_to_mem_ref);
725-
NOT_PRODUCT(find_adjacent_refs_trace_1(best_align_to_mem_ref, best_iv_adjustment);)
726-
// Restore list.
727-
while (memops.size() > orig_msize)
728-
(void)memops.pop();
730+
break;
729731
}
732+
best_iv_adjustment = get_iv_adjustment(best_align_to_mem_ref);
733+
NOT_PRODUCT(find_adjacent_refs_trace_1(best_align_to_mem_ref, best_iv_adjustment);)
734+
// Restore list.
735+
while (memops.size() > orig_msize)
736+
(void)memops.pop();
730737
}
731738
} // unaligned memory accesses
732739

@@ -761,7 +768,7 @@ void SuperWord::find_adjacent_refs_trace_1(Node* best_align_to_mem_ref, int best
761768
// Find a memory reference to align the loop induction variable to.
762769
// Looks first at stores then at loads, looking for a memory reference
763770
// with the largest number of references similar to it.
764-
MemNode* SuperWord::find_align_to_ref(Node_List &memops) {
771+
MemNode* SuperWord::find_align_to_ref(Node_List &memops, int &idx) {
765772
GrowableArray<int> cmp_ct(arena(), memops.size(), memops.size(), 0);
766773

767774
// Count number of comparable memory ops
@@ -848,6 +855,7 @@ MemNode* SuperWord::find_align_to_ref(Node_List &memops) {
848855
}
849856
#endif
850857

858+
idx = max_idx;
851859
if (max_ct > 0) {
852860
#ifdef ASSERT
853861
if (TraceSuperWord) {

src/hotspot/share/opto/superword.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class SuperWord : public ResourceObj {
408408
void print_loop(bool whole);
409409
#endif
410410
// Find a memory reference to align the loop induction variable to.
411-
MemNode* find_align_to_ref(Node_List &memops);
411+
MemNode* find_align_to_ref(Node_List &memops, int &idx);
412412
// Calculate loop's iv adjustment for this memory ops.
413413
int get_iv_adjustment(MemNode* mem);
414414
// Can the preloop align the reference to position zero in the vector?
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2020, Huawei Technologies Co. Ltd. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8235762
27+
* @summary JVM crash in SWPointer during C2 compilation
28+
*
29+
* @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
30+
-XX:CompileCommand=compileonly,compiler.loopopts.superword.TestSearchAlignment::vMeth
31+
* compiler.loopopts.superword.TestSearchAlignment
32+
*/
33+
34+
package compiler.loopopts.superword;
35+
36+
public class TestSearchAlignment {
37+
38+
public static final int N = 400;
39+
public static byte bArr[] = new byte[N];
40+
public static int iArr[] = new int[N];
41+
public static long lArr[] = new long[N];
42+
43+
public static void vMeth(byte bArg, int iArg, long lArg) {
44+
int i = N - 1;
45+
do {
46+
iArr[i - 1] += iArg;
47+
iArr[i] += iArg;
48+
lArr[i - 1] = lArg;
49+
bArr[i - 1] = bArg;
50+
} while (--i > 0);
51+
}
52+
53+
public void mainTest() {
54+
byte b = 0;
55+
int i = 0;
56+
long l = 0;
57+
for (int j = 0; j < N; ++j) {
58+
vMeth(b, i, l);
59+
}
60+
}
61+
62+
public static void main(String[] args) {
63+
TestSearchAlignment _instance = new TestSearchAlignment();
64+
for (int i = 0; i < 10; i++) {
65+
_instance.mainTest();
66+
}
67+
System.out.println("Test passed.");
68+
}
69+
70+
}

0 commit comments

Comments
 (0)