Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8244724: CTW: C2 compilation fails with "Live Node limit exceeded limit"
Fix live limit assert in node construction to be ignored during code generation in Compile::Code_Gen().

Reviewed-by: kvn, neliasso
  • Loading branch information
chhagedorn committed Jul 1, 2020
1 parent 2a37607 commit 13b7c2e131b684c4206c4f31a96a8c6b2012c662
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 6 deletions.
@@ -1004,6 +1004,7 @@ void Compile::Init(int aliaslevel) {
register_library_intrinsics();
#ifdef ASSERT
_type_verify_symmetry = true;
_phase_optimize_finished = false;
#endif
}

@@ -2240,6 +2241,7 @@ void Compile::Optimize() {
}

print_method(PHASE_OPTIMIZE_FINISHED, 2);
DEBUG_ONLY(set_phase_optimize_finished();)
}

//---------------------------- Bitwise operation packing optimization ---------------------------
@@ -327,7 +327,8 @@ class Compile : public Phase {
VectorSet _dead_node_list; // Set of dead nodes
uint _dead_node_count; // Number of dead nodes; VectorSet::Size() is O(N).
// So use this to keep count and make the call O(1).
DEBUG_ONLY( Unique_Node_List* _modified_nodes; ) // List of nodes which inputs were modified
DEBUG_ONLY(Unique_Node_List* _modified_nodes;) // List of nodes which inputs were modified
DEBUG_ONLY(bool _phase_optimize_finished;) // Used for live node verification while creating new nodes

debug_only(static int _debug_idx;) // Monotonic counter (not reset), use -XX:BreakAtNode=<idx>
Arena _node_arena; // Arena for new-space Nodes
@@ -784,6 +785,8 @@ class Compile : public Phase {
return (uint) val;
}
#ifdef ASSERT
void set_phase_optimize_finished() { _phase_optimize_finished = true; }
bool phase_optimize_finished() const { return _phase_optimize_finished; }
uint count_live_nodes_by_graph_walk();
void print_missing_nodes();
#endif
@@ -67,21 +67,27 @@ extern int nodes_created;
void Node::verify_construction() {
_debug_orig = NULL;
int old_debug_idx = Compile::debug_idx();
int new_debug_idx = old_debug_idx+1;
int new_debug_idx = old_debug_idx + 1;
if (new_debug_idx > 0) {
// Arrange that the lowest five decimal digits of _debug_idx
// will repeat those of _idx. In case this is somehow pathological,
// we continue to assign negative numbers (!) consecutively.
const int mod = 100000;
int bump = (int)(_idx - new_debug_idx) % mod;
if (bump < 0) bump += mod;
if (bump < 0) {
bump += mod;
}
assert(bump >= 0 && bump < mod, "");
new_debug_idx += bump;
}
Compile::set_debug_idx(new_debug_idx);
set_debug_idx( new_debug_idx );
assert(Compile::current()->unique() < (INT_MAX - 1), "Node limit exceeded INT_MAX");
assert(Compile::current()->live_nodes() < Compile::current()->max_node_limit(), "Live Node limit exceeded limit");
set_debug_idx(new_debug_idx);
Compile* C = Compile::current();
assert(C->unique() < (INT_MAX - 1), "Node limit exceeded INT_MAX");
if (!C->phase_optimize_finished()) {
// Only check assert during parsing and optimization phase. Skip it while generating code.
assert(C->live_nodes() <= C->max_node_limit(), "Live Node limit exceeded limit");
}
if (BreakAtNode != 0 && (_debug_idx == BreakAtNode || (int)_idx == BreakAtNode)) {
tty->print_cr("BreakAtNode: _idx=%d _debug_idx=%d", _idx, _debug_idx);
BREAKPOINT;
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2020, 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 8244724
* @summary Test which exceeds the live node limit in Compile::Code_Gen(). The previouslz failing assert is now only checked during parsing and during Compile::Optimize().
*
* @compile -XDstringConcat=inline TestLiveNodeLimit.java
* @run main/othervm -Xcomp -XX:CompileCommand=compileonly,compiler.c2.TestLiveNodeLimit::test* compiler.c2.TestLiveNodeLimit
*/
package compiler.c2;

import java.util.ArrayList;

public class TestLiveNodeLimit {

public static ArrayList<String> arrList = new ArrayList<String>();

public static void main(String[] args) {
for (int i = 0; i < 10000; i++) {
testNodeLimitInBuildCfg();
testNodeLimitInGlobalCodeMotion();
}
}

// Hits live node limit in PhaseCFG::build_cfg(). There are around 70000 nodes right before build_cfg()
// which creates another 15000 nodes which exceeds the default max node limit of 80000.
public static int testNodeLimitInBuildCfg() {
// Just some string operations that create a lot of nodes when compiled with javac with -XDstringConcat=inline
// which generate a lot of StringBuilder objects and calls
String someString = "as@df#as@df" + "fdsa";
String[] split = someString.split("#");
String[] tmp1 = split[0].split("@");
String[] tmp2 = split[0].split("@");
String concat1 = tmp1[0] + tmp2[0] + split[0];
String concat2 = tmp1[0] + tmp2[0] + split[0];
String concat3 = tmp1[0] + tmp2[0];
String concat4 = tmp1[0] + tmp2[0];
String string1 = "string1";
String[] stringArr1 = arrList.toArray(new String[4]);
String[] stringArr2 = new String[3];
String[] stringArr3 = new String[3];
if (stringArr1.length > 1) {
stringArr2 = new String[3 * stringArr1.length];
stringArr3 = new String[3 * stringArr1.length];
for (int i = 0; i < stringArr1.length; i++) {
stringArr2[3 * i ] = string1 + concat1 + concat3 + stringArr1[i];
stringArr2[3 * i + 1] = string1 + concat1 + concat3 + stringArr1[i];
stringArr2[3 * i + 2] = string1 + concat1 + concat3 + stringArr1[i];
stringArr3[3 * i ] = string1 + concat2 + concat3 + concat4 + stringArr1[i];
stringArr3[3 * i + 1] = string1 + concat2 + concat3 + concat4 + stringArr1[i];
stringArr3[3 * i + 2] = string1 + concat2 + concat3 + concat4 + stringArr1[i];
}
}
return stringArr1.length + stringArr2.length + stringArr3.length;
}

// Hits live node limit in PhaseCFG::global_code_motion(). There are around 79000 nodes right before global_code_motion()
// which creates another 2000 nodes which exceeds the default max node limit of 80000.
public static int testNodeLimitInGlobalCodeMotion() {
// Just some string operations that create a lot of nodes when compiled with javac with -XDstringConcat=inline
// which generate a lot of StringBuilder objects and calls
String someString = "as@df#as@df" + "fdsa";
String[] split = someString.split("#");
String[] tmp1 = split[0].split("@");
String[] tmp2 = split[0].split("@");
String concat1 = tmp1[0] + tmp2[0] + split[0];
String concat2 = tmp1[0] + tmp2[0] + split[0];
String concat3 = tmp1[0] + tmp2[0] + split[0];
String concat4 = tmp1[0] + tmp2[0] + split[0];
String string1 = "string1";
String[] stringArr1 = arrList.toArray(new String[4]);
String[] stringArr2 = new String[3];
String[] stringArr3 = new String[3];
if (stringArr1.length > 1) {
stringArr2 = new String[3 * stringArr1.length];
stringArr3 = new String[3 * stringArr1.length];
for (int i = 0; i < stringArr1.length; i++) {
stringArr2[3 * i ] = string1 + concat1 + concat3 + stringArr1[i];
stringArr2[3 * i + 1] = string1 + concat1 + concat3 + stringArr1[i];
stringArr2[3 * i + 2] = string1 + concat1 + concat3 + stringArr1[i];
stringArr3[3 * i ] = string1 + concat2 + concat4 + stringArr1[i];
stringArr3[3 * i + 1] = string1 + concat2 + concat4 + stringArr1[i];
stringArr3[3 * i + 2] = string1 + concat2 + stringArr1[i];
}
}
return stringArr1.length + stringArr2.length + stringArr3.length;
}
}

0 comments on commit 13b7c2e

Please sign in to comment.