changeset 57743:d19d1a02d1b2

8235762: JVM crash in SWPointer during C2 compilation Reviewed-by: thartmann, chagedorn, neliasso
author fyang
date Thu, 09 Jan 2020 19:12:16 +0800
parents 6825c74baa36
children 5bb84e036c14
files src/hotspot/share/opto/superword.cpp src/hotspot/share/opto/superword.hpp test/hotspot/jtreg/compiler/loopopts/superword/TestSearchAlignment.java
diffstat 3 files changed, 103 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/opto/superword.cpp	Wed Jan 15 13:17:46 2020 -0800
+++ b/src/hotspot/share/opto/superword.cpp	Thu Jan 09 19:12:16 2020 +0800
@@ -576,12 +576,13 @@
   }
 
   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);
@@ -699,34 +700,40 @@
         // 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
 
@@ -761,7 +768,7 @@
 // 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
@@ -848,6 +855,7 @@
   }
 #endif
 
+  idx = max_idx;
   if (max_ct > 0) {
 #ifdef ASSERT
     if (TraceSuperWord) {
--- a/src/hotspot/share/opto/superword.hpp	Wed Jan 15 13:17:46 2020 -0800
+++ b/src/hotspot/share/opto/superword.hpp	Thu Jan 09 19:12:16 2020 +0800
@@ -408,7 +408,7 @@
   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?
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/loopopts/superword/TestSearchAlignment.java	Thu Jan 09 19:12:16 2020 +0800
@@ -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.");
+    }
+
+}