8324345: Stack overflow during C2 compilation when splitting memory phi

Reviewed-by: thartmann, kvn
This commit is contained in:
Daniel Lundén 2024-07-31 16:05:42 +00:00
parent f2ba2ebbca
commit fdb4350fce
4 changed files with 63 additions and 9 deletions

View File

@ -3879,7 +3879,7 @@ PhiNode *ConnectionGraph::create_split_phi(PhiNode *orig_phi, int alias_idx, Gro
// Return a new version of Memory Phi "orig_phi" with the inputs having the
// specified alias index.
//
PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist) {
PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, uint rec_depth) {
assert(alias_idx != Compile::AliasIdxBot, "can't split out bottom memory");
Compile *C = _compile;
PhaseGVN* igvn = _igvn;
@ -3895,7 +3895,7 @@ PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, Gro
bool finished = false;
while(!finished) {
while (idx < phi->req()) {
Node *mem = find_inst_mem(phi->in(idx), alias_idx, orig_phi_worklist);
Node *mem = find_inst_mem(phi->in(idx), alias_idx, orig_phi_worklist, rec_depth + 1);
if (mem != nullptr && mem->is_Phi()) {
PhiNode *newphi = create_split_phi(mem->as_Phi(), alias_idx, orig_phi_worklist, new_phi_created);
if (new_phi_created) {
@ -4037,7 +4037,12 @@ void ConnectionGraph::move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phi
// Search memory chain of "mem" to find a MemNode whose address
// is the specified alias index.
//
Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArray<PhiNode *> &orig_phis) {
#define FIND_INST_MEM_RECURSION_DEPTH_LIMIT 1000
Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArray<PhiNode *> &orig_phis, uint rec_depth) {
if (rec_depth > FIND_INST_MEM_RECURSION_DEPTH_LIMIT) {
_compile->record_failure(_invocation > 0 ? C2Compiler::retry_no_iterative_escape_analysis() : C2Compiler::retry_no_escape_analysis());
return nullptr;
}
if (orig_mem == nullptr) {
return orig_mem;
}
@ -4111,7 +4116,7 @@ Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArra
if (result == mmem->base_memory()) {
// Didn't find instance memory, search through general slice recursively.
result = mmem->memory_at(C->get_general_index(alias_idx));
result = find_inst_mem(result, alias_idx, orig_phis);
result = find_inst_mem(result, alias_idx, orig_phis, rec_depth + 1);
if (C->failing()) {
return nullptr;
}
@ -4179,7 +4184,7 @@ Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArra
orig_phis.append_if_missing(mphi);
} else if (C->get_alias_index(t) != alias_idx) {
// Create a new Phi with the specified alias index type.
result = split_memory_phi(mphi, alias_idx, orig_phis);
result = split_memory_phi(mphi, alias_idx, orig_phis, rec_depth + 1);
}
}
// the result is either MemNode, PhiNode, InitializeNode.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, 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
@ -549,10 +549,10 @@ private:
bool split_AddP(Node *addp, Node *base);
PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, bool &new_created);
PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist);
PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, uint rec_depth);
void move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phis);
Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist);
Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist, uint rec_depth = 0);
Node* step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop);
Node_Array _node_map; // used for bookkeeping during type splitting

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2024, 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 8324345
* @summary Ensure that ConnectionGraph::find_inst_mem does not cause a stack
* overflow.
*
* @run main/othervm -Xcomp -XX:CompileThreshold=10 -XX:-TieredCompilation
* -XX:CompileCommand=CompileOnly,javax.swing.plaf.basic.BasicLookAndFeel::initComponentDefaults
* -XX:CompileCommand=MemLimit,*.*,0
* compiler.escapeAnalysis.TestFindInstMemRecursion
*
*/
package compiler.escapeAnalysis;
import javax.swing.*;
import javax.swing.plaf.metal.*;
public class TestFindInstMemRecursion {
public static void main(String[] args) throws Exception {
LookAndFeel lookAndFeel = new MetalLookAndFeel();
for (int i = 0; i < 20; ++i) {
UIManager.setLookAndFeel(lookAndFeel);
}
}
}

View File

@ -36,7 +36,7 @@ import org.testng.annotations.Test;
* @library /test/lib
* @requires os.arch == "aarch64"
* @modules jdk.incubator.vector
* @run testng/othervm -XX:UseSVE=0 -XX:-TieredCompilation -XX:CompileThreshold=100 compiler.vectorapi.VectorReplicateLongSpecialImmTest
* @run testng/othervm -XX:UseSVE=0 -XX:-TieredCompilation -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:CompileCommand=MemLimit,*.*,0 compiler.vectorapi.VectorReplicateLongSpecialImmTest
*/
public class VectorReplicateLongSpecialImmTest {