Skip to content

Commit

Permalink
8235762: JVM crash in SWPointer during C2 compilation
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann, chagedorn, neliasso
  • Loading branch information
RealFYang committed Jan 9, 2020
1 parent b95d346 commit e3eb6db
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 25 deletions.
56 changes: 32 additions & 24 deletions src/hotspot/share/opto/superword.cpp
Expand Up @@ -576,12 +576,13 @@ void SuperWord::find_adjacent_refs() {
}

Node_List align_to_refs;
int max_idx;
int best_iv_adjustment = 0;
MemNode* best_align_to_mem_ref = NULL;

while (memops.size() != 0) {
// Find a memory reference to align to.
MemNode* mem_ref = find_align_to_ref(memops);
MemNode* mem_ref = find_align_to_ref(memops, max_idx);
if (mem_ref == NULL) break;
align_to_refs.push(mem_ref);
int iv_adjustment = get_iv_adjustment(mem_ref);
Expand Down Expand Up @@ -699,34 +700,40 @@ void SuperWord::find_adjacent_refs() {
// Put memory ops from remaining packs back on memops list for
// the best alignment search.
uint orig_msize = memops.size();
if (_packset.length() == 1 && orig_msize == 0) {
// If there are no remaining memory ops and only 1 pack we have only one choice
// for the alignment
Node_List* p = _packset.at(0);
assert(p->size() > 0, "sanity");
for (int i = 0; i < _packset.length(); i++) {
Node_List* p = _packset.at(i);
MemNode* s = p->at(0)->as_Mem();
assert(!same_velt_type(s, mem_ref), "sanity");
best_align_to_mem_ref = s;
} else {
for (int i = 0; i < _packset.length(); i++) {
Node_List* p = _packset.at(i);
MemNode* s = p->at(0)->as_Mem();
assert(!same_velt_type(s, mem_ref), "sanity");
memops.push(s);
memops.push(s);
}
best_align_to_mem_ref = find_align_to_ref(memops, max_idx);
if (best_align_to_mem_ref == NULL) {
if (TraceSuperWord) {
tty->print_cr("SuperWord::find_adjacent_refs(): best_align_to_mem_ref == NULL");
}
best_align_to_mem_ref = find_align_to_ref(memops);
if (best_align_to_mem_ref == NULL) {
if (TraceSuperWord) {
tty->print_cr("SuperWord::find_adjacent_refs(): best_align_to_mem_ref == NULL");
// best_align_to_mem_ref will be used for adjusting the pre-loop limit in
// SuperWord::align_initial_loop_index. Find one with the biggest vector size,
// smallest data size and smallest iv offset from memory ops from remaining packs.
if (_packset.length() > 0) {
if (orig_msize == 0) {
best_align_to_mem_ref = memops.at(max_idx)->as_Mem();
} else {
for (uint i = 0; i < orig_msize; i++) {
memops.remove(0);
}
best_align_to_mem_ref = find_align_to_ref(memops, max_idx);
assert(best_align_to_mem_ref == NULL, "sanity");
best_align_to_mem_ref = memops.at(max_idx)->as_Mem();
}
break;
assert(best_align_to_mem_ref != NULL, "sanity");
}
best_iv_adjustment = get_iv_adjustment(best_align_to_mem_ref);
NOT_PRODUCT(find_adjacent_refs_trace_1(best_align_to_mem_ref, best_iv_adjustment);)
// Restore list.
while (memops.size() > orig_msize)
(void)memops.pop();
break;
}
best_iv_adjustment = get_iv_adjustment(best_align_to_mem_ref);
NOT_PRODUCT(find_adjacent_refs_trace_1(best_align_to_mem_ref, best_iv_adjustment);)
// Restore list.
while (memops.size() > orig_msize)
(void)memops.pop();
}
} // unaligned memory accesses

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

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

idx = max_idx;
if (max_ct > 0) {
#ifdef ASSERT
if (TraceSuperWord) {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/superword.hpp
Expand Up @@ -408,7 +408,7 @@ class SuperWord : public ResourceObj {
void print_loop(bool whole);
#endif
// Find a memory reference to align the loop induction variable to.
MemNode* find_align_to_ref(Node_List &memops);
MemNode* find_align_to_ref(Node_List &memops, int &idx);
// Calculate loop's iv adjustment for this memory ops.
int get_iv_adjustment(MemNode* mem);
// Can the preloop align the reference to position zero in the vector?
Expand Down
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2020, Huawei Technologies Co. Ltd. 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 8235762
* @summary JVM crash in SWPointer during C2 compilation
*
* @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
-XX:CompileCommand=compileonly,compiler.loopopts.superword.TestSearchAlignment::vMeth
* compiler.loopopts.superword.TestSearchAlignment
*/

package compiler.loopopts.superword;

public class TestSearchAlignment {

public static final int N = 400;
public static byte bArr[] = new byte[N];
public static int iArr[] = new int[N];
public static long lArr[] = new long[N];

public static void vMeth(byte bArg, int iArg, long lArg) {
int i = N - 1;
do {
iArr[i - 1] += iArg;
iArr[i] += iArg;
lArr[i - 1] = lArg;
bArr[i - 1] = bArg;
} while (--i > 0);
}

public void mainTest() {
byte b = 0;
int i = 0;
long l = 0;
for (int j = 0; j < N; ++j) {
vMeth(b, i, l);
}
}

public static void main(String[] args) {
TestSearchAlignment _instance = new TestSearchAlignment();
for (int i = 0; i < 10; i++) {
_instance.mainTest();
}
System.out.println("Test passed.");
}

}

0 comments on commit e3eb6db

Please sign in to comment.