# HG changeset patch # User phedlin # Date 1571827913 -7200 # Node ID 77148b8bb7a16c157d9a80eae644dee3400a0749 # Parent a4cdca87152b417e2f6acdf8e55c8742589de3c5 8231565: More node budget asserts in fuzzed tests. Reviewed-by: neliasso, thartmann diff -r a4cdca87152b -r 77148b8bb7a1 src/hotspot/share/opto/loopnode.hpp --- a/src/hotspot/share/opto/loopnode.hpp Mon Oct 28 11:27:27 2019 +0100 +++ b/src/hotspot/share/opto/loopnode.hpp Wed Oct 23 12:51:53 2019 +0200 @@ -1378,7 +1378,7 @@ bool exceeding_node_budget(uint required = 0) { assert(C->live_nodes() < C->max_node_limit(), "sanity"); uint available = C->max_node_limit() - C->live_nodes(); - return available < required + _nodes_required; + return available < required + _nodes_required + REQUIRE_MIN; } uint require_nodes(uint require, uint minreq = REQUIRE_MIN) { diff -r a4cdca87152b -r 77148b8bb7a1 src/hotspot/share/opto/loopopts.cpp --- a/src/hotspot/share/opto/loopopts.cpp Mon Oct 28 11:27:27 2019 +0100 +++ b/src/hotspot/share/opto/loopopts.cpp Wed Oct 23 12:51:53 2019 +0200 @@ -3159,7 +3159,8 @@ Node_List worklist(area); Node_List sink_list(area); - if (!may_require_nodes(loop->est_loop_clone_sz(2))) { + uint estimate = loop->est_loop_clone_sz(1); + if (exceeding_node_budget(estimate)) { return false; } @@ -3184,8 +3185,7 @@ // Set of non-cfg nodes to peel are those that are control // dependent on the cfg nodes. - uint i; - for(i = 0; i < loop->_body.size(); i++ ) { + for (uint i = 0; i < loop->_body.size(); i++) { Node *n = loop->_body.at(i); Node *n_c = has_ctrl(n) ? get_ctrl(n) : n; if (peel.test(n_c->_idx)) { @@ -3200,7 +3200,7 @@ // Get a post order schedule of nodes in the peel region // Result in right-most operand. - scheduled_nodelist(loop, peel, peel_list ); + scheduled_nodelist(loop, peel, peel_list); assert(is_valid_loop_partition(loop, peel, peel_list, not_peel), "bad partition"); @@ -3220,25 +3220,21 @@ // Evacuate nodes in peel region into the not_peeled region if possible uint new_phi_cnt = 0; uint cloned_for_outside_use = 0; - for (i = 0; i < peel_list.size();) { + for (uint i = 0; i < peel_list.size();) { Node* n = peel_list.at(i); #ifndef PRODUCT if (TracePartialPeeling) n->dump(); #endif bool incr = true; - if ( !n->is_CFG() ) { - - if ( has_use_in_set(n, not_peel) ) { - + if (!n->is_CFG()) { + if (has_use_in_set(n, not_peel)) { // If not used internal to the peeled region, // move "n" from peeled to not_peeled region. - - if ( !has_use_internal_to_set(n, peel, loop) ) { - + if (!has_use_internal_to_set(n, peel, loop)) { // if not pinned and not a load (which maybe anti-dependent on a store) // and not a CMove (Matcher expects only bool->cmove). if (n->in(0) == NULL && !n->is_Load() && !n->is_CMove()) { - cloned_for_outside_use += clone_for_use_outside_loop( loop, n, worklist ); + cloned_for_outside_use += clone_for_use_outside_loop(loop, n, worklist); sink_list.push(n); peel >>= n->_idx; // delete n from peel set. not_peel <<= n->_idx; // add n to not_peel set. @@ -3254,7 +3250,7 @@ } else { // Otherwise check for special def-use cases that span // the peel/not_peel boundary such as bool->if - clone_for_special_use_inside_loop( loop, n, not_peel, sink_list, worklist ); + clone_for_special_use_inside_loop(loop, n, not_peel, sink_list, worklist); new_phi_cnt++; } } @@ -3262,7 +3258,11 @@ if (incr) i++; } - if (new_phi_cnt > old_phi_cnt + PartialPeelNewPhiDelta) { + estimate += cloned_for_outside_use + new_phi_cnt; + bool exceed_node_budget = !may_require_nodes(estimate); + bool exceed_phi_limit = new_phi_cnt > old_phi_cnt + PartialPeelNewPhiDelta; + + if (exceed_node_budget || exceed_phi_limit) { #ifndef PRODUCT if (TracePartialPeeling) { tty->print_cr("\nToo many new phis: %d old %d new cmpi: %c", @@ -3310,7 +3310,7 @@ const uint clone_exit_idx = 1; const uint orig_exit_idx = 2; - assert(is_valid_clone_loop_form( loop, peel_list, orig_exit_idx, clone_exit_idx ), "bad clone loop"); + assert(is_valid_clone_loop_form(loop, peel_list, orig_exit_idx, clone_exit_idx), "bad clone loop"); Node* head_clone = old_new[head->_idx]; LoopNode* new_head_clone = old_new[new_head->_idx]->as_Loop(); @@ -3318,7 +3318,7 @@ // Add phi if "def" node is in peel set and "use" is not - for(i = 0; i < peel_list.size(); i++ ) { + for (uint i = 0; i < peel_list.size(); i++) { Node *def = peel_list.at(i); if (!def->is_CFG()) { for (DUIterator_Fast jmax, j = def->fast_outs(jmax); j < jmax; j++) { @@ -3374,7 +3374,7 @@ // cloned-not_peeled in(0) in(0) // orig-peeled - for(i = 0; i < loop->_body.size(); i++ ) { + for (uint i = 0; i < loop->_body.size(); i++) { Node *n = loop->_body.at(i); if (!n->is_CFG() && n->in(0) != NULL && not_peel.test(n->_idx) && peel.test(n->in(0)->_idx)) { diff -r a4cdca87152b -r 77148b8bb7a1 test/hotspot/jtreg/compiler/loopopts/LoopRotateBadNodeBudget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/hotspot/jtreg/compiler/loopopts/LoopRotateBadNodeBudget.java Wed Oct 23 12:51:53 2019 +0200 @@ -0,0 +1,81 @@ +/* + * 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 8231565 + * @summary Node estimate for loop rotate is not correct/sufficient: + * assert(delta <= 2 * required) failed: Bad node estimate ... + * + * @requires !vm.graal.enabled + * + * @run main/othervm -XX:PartialPeelNewPhiDelta=5 LoopRotateBadNodeBudget + * @run main/othervm -Xbatch -XX:PartialPeelNewPhiDelta=5 LoopRotateBadNodeBudget + * + * @run main/othervm LoopRotateBadNodeBudget + * @run main/othervm -Xbatch LoopRotateBadNodeBudget + * + * NOTE: Test-case seldom manifesting the problem on fast machines. + */ + +public class LoopRotateBadNodeBudget { + + int h; + float j(int a, int b) { + double d = 0.19881; + int c, e[] = new int[9]; + c = 1; + while (++c < 12) + switch ((c % 7 * 5) + 122) { + case 156: + case 46128: + case 135: + case 148: + case 127: + break; + default: + } + while ((d += 2) < 62) + ; + long k = l(e); + return k; + } + long l(int[] a) { + long m = 0; + for (int i = 0; i < a.length; i++) + m = a[i]; + return m; + } + void f(String[] g) { + int i = 2; + for (; i < 20000; ++i) + j(3, h); + } + public static void main(String[] o) { + try { + LoopRotateBadNodeBudget n = new LoopRotateBadNodeBudget(); + n.f(o); + } catch (Exception ex) { + } + } +}