changeset 53121:1884ecc20c38

8210392: assert(Compile::current()->live_nodes() < Compile::current()->max_node_limit()) failed: Live Node limit exceeded limit Summary: Avoid excessive split-if. Reviewed-by: thartmann, neliasso
author phedlin
date Tue, 18 Dec 2018 10:12:28 +0100
parents b5281bf751ea
children 314c5b5d9369
files src/hotspot/share/opto/loopnode.hpp src/hotspot/share/opto/loopopts.cpp test/hotspot/jtreg/compiler/loopopts/Test8210392.java
diffstat 3 files changed, 89 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/opto/loopnode.hpp	Tue Jan 15 09:44:18 2019 +0100
+++ b/src/hotspot/share/opto/loopnode.hpp	Tue Dec 18 10:12:28 2018 +0100
@@ -1306,6 +1306,14 @@
   bool identical_backtoback_ifs(Node *n);
   bool can_split_if(Node *n_ctrl);
 
+  // Determine if a method is too big for a/another round of split-if, based on
+  // a magic (approximate) ratio derived from the equally magic constant 35000,
+  // previously used for this purpose (but without relating to the node limit).
+  bool must_throttle_split_if() {
+    uint threshold = C->max_node_limit() * 2 / 5;
+    return C->live_nodes() > threshold;
+  }
+
   bool _created_loop_node;
 public:
   void set_created_loop_node() { _created_loop_node = true; }
--- a/src/hotspot/share/opto/loopopts.cpp	Tue Jan 15 09:44:18 2019 +0100
+++ b/src/hotspot/share/opto/loopopts.cpp	Tue Dec 18 10:12:28 2018 +0100
@@ -1024,8 +1024,7 @@
     }
   }
 
-  // Use same limit as split_if_with_blocks_post
-  if( C->live_nodes() > 35000 ) return n; // Method too big
+  if (must_throttle_split_if()) return n;
 
   // Split 'n' through the merge point if it is profitable
   Node *phi = split_thru_phi( n, n_blk, policy );
@@ -1143,9 +1142,10 @@
   return true;
 }
 
-bool PhaseIdealLoop::can_split_if(Node *n_ctrl) {
-  if (C->live_nodes() > 35000) {
-    return false; // Method too big
+
+bool PhaseIdealLoop::can_split_if(Node* n_ctrl) {
+  if (must_throttle_split_if()) {
+    return false;
   }
 
   // Do not do 'split-if' if irreducible loops are present.
@@ -1462,12 +1462,13 @@
 // Check for aggressive application of 'split-if' optimization,
 // using basic block level info.
 void PhaseIdealLoop::split_if_with_blocks(VectorSet &visited, Node_Stack &nstack, bool last_round) {
-  Node *n = C->root();
-  visited.set(n->_idx); // first, mark node as visited
+  Node* root = C->root();
+  visited.set(root->_idx); // first, mark root as visited
   // Do pre-visit work for root
-  n = split_if_with_blocks_pre( n );
-  uint cnt = n->outcnt();
-  uint i   = 0;
+  Node* n   = split_if_with_blocks_pre(root);
+  uint  cnt = n->outcnt();
+  uint  i   = 0;
+
   while (true) {
     // Visit all children
     if (i < cnt) {
@@ -1475,7 +1476,7 @@
       ++i;
       if (use->outcnt() != 0 && !visited.test_set(use->_idx)) {
         // Now do pre-visit work for this use
-        use = split_if_with_blocks_pre( use );
+        use = split_if_with_blocks_pre(use);
         nstack.push(n, i); // Save parent and next use's index.
         n   = use;         // Process all children of current use.
         cnt = use->outcnt();
@@ -1486,7 +1487,10 @@
       // All of n's children have been processed, complete post-processing.
       if (cnt != 0 && !n->is_Con()) {
         assert(has_node(n), "no dead nodes");
-        split_if_with_blocks_post( n, last_round );
+        split_if_with_blocks_post(n, last_round);
+      }
+      if (must_throttle_split_if()) {
+        nstack.clear();
       }
       if (nstack.is_empty()) {
         // Finished all nodes on stack.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/loopopts/Test8210392.java	Tue Dec 18 10:12:28 2018 +0100
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2019, 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 8210392
+ * @summary C2 Assert failure: Live node limit exceeded
+ *
+ * @run main/othervm compiler.loopopts.Test8210392
+ */
+
+package compiler.loopopts;
+
+public class Test8210392 {
+    public static int ival = 17;
+
+    public static int intFn() {
+        int v = 0, k = 0;
+        for (int i = 17; i < 311; i += 3) {
+            v = Test8210392.ival;
+            int j = 1;
+            do {
+                v *= i;
+                v += j * v;
+                while (++k < 1)
+                    ;
+            } while (++j < 13);
+        }
+        return v;
+    }
+
+    public void mainTest() {
+        for (int i = 0; i < 30000; i++) {
+            Test8210392.ival = intFn();
+        }
+    }
+
+    public static void main(String[] _args) {
+        Test8210392 tc = new Test8210392();
+        for (int i = 0; i < 10; i++) {
+            tc.mainTest();
+        }
+    }
+}
+