Skip to content

Commit 70bbadf

Browse files
committed
backport fdb4350fcecef1915cdbc27ece24153a1b6c884d
1 parent d23be78 commit 70bbadf

4 files changed

Lines changed: 63 additions & 9 deletions

File tree

src/hotspot/share/opto/escape.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,7 +2762,7 @@ PhiNode *ConnectionGraph::create_split_phi(PhiNode *orig_phi, int alias_idx, Gro
27622762
// Return a new version of Memory Phi "orig_phi" with the inputs having the
27632763
// specified alias index.
27642764
//
2765-
PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist) {
2765+
PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, uint rec_depth) {
27662766
assert(alias_idx != Compile::AliasIdxBot, "can't split out bottom memory");
27672767
Compile *C = _compile;
27682768
PhaseGVN* igvn = _igvn;
@@ -2778,7 +2778,7 @@ PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, Gro
27782778
bool finished = false;
27792779
while(!finished) {
27802780
while (idx < phi->req()) {
2781-
Node *mem = find_inst_mem(phi->in(idx), alias_idx, orig_phi_worklist);
2781+
Node *mem = find_inst_mem(phi->in(idx), alias_idx, orig_phi_worklist, rec_depth + 1);
27822782
if (mem != nullptr && mem->is_Phi()) {
27832783
PhiNode *newphi = create_split_phi(mem->as_Phi(), alias_idx, orig_phi_worklist, new_phi_created);
27842784
if (new_phi_created) {
@@ -2920,7 +2920,12 @@ void ConnectionGraph::move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phi
29202920
// Search memory chain of "mem" to find a MemNode whose address
29212921
// is the specified alias index.
29222922
//
2923-
Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArray<PhiNode *> &orig_phis) {
2923+
#define FIND_INST_MEM_RECURSION_DEPTH_LIMIT 1000
2924+
Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArray<PhiNode *> &orig_phis, uint rec_depth) {
2925+
if (rec_depth > FIND_INST_MEM_RECURSION_DEPTH_LIMIT) {
2926+
_compile->record_failure(_invocation > 0 ? C2Compiler::retry_no_iterative_escape_analysis() : C2Compiler::retry_no_escape_analysis());
2927+
return nullptr;
2928+
}
29242929
if (orig_mem == nullptr) {
29252930
return orig_mem;
29262931
}
@@ -2994,7 +2999,7 @@ Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArra
29942999
if (result == mmem->base_memory()) {
29953000
// Didn't find instance memory, search through general slice recursively.
29963001
result = mmem->memory_at(C->get_general_index(alias_idx));
2997-
result = find_inst_mem(result, alias_idx, orig_phis);
3002+
result = find_inst_mem(result, alias_idx, orig_phis, rec_depth + 1);
29983003
if (C->failing()) {
29993004
return nullptr;
30003005
}
@@ -3062,7 +3067,7 @@ Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArra
30623067
orig_phis.append_if_missing(mphi);
30633068
} else if (C->get_alias_index(t) != alias_idx) {
30643069
// Create a new Phi with the specified alias index type.
3065-
result = split_memory_phi(mphi, alias_idx, orig_phis);
3070+
result = split_memory_phi(mphi, alias_idx, orig_phis, rec_depth + 1);
30663071
}
30673072
}
30683073
// the result is either MemNode, PhiNode, InitializeNode.

src/hotspot/share/opto/escape.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -530,10 +530,10 @@ class ConnectionGraph: public ResourceObj {
530530
bool split_AddP(Node *addp, Node *base);
531531

532532
PhiNode *create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, bool &new_created);
533-
PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist);
533+
PhiNode *split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, uint rec_depth);
534534

535535
void move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phis);
536-
Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist);
536+
Node* find_inst_mem(Node* mem, int alias_idx,GrowableArray<PhiNode *> &orig_phi_worklist, uint rec_depth = 0);
537537
Node* step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop);
538538

539539

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8324345
27+
* @summary Ensure that ConnectionGraph::find_inst_mem does not cause a stack
28+
* overflow.
29+
*
30+
* @run main/othervm -Xcomp -XX:CompileThreshold=10 -XX:-TieredCompilation
31+
* -XX:CompileCommand=CompileOnly,javax.swing.plaf.basic.BasicLookAndFeel::initComponentDefaults
32+
* -XX:CompileCommand=MemLimit,*.*,0
33+
* compiler.escapeAnalysis.TestFindInstMemRecursion
34+
*
35+
*/
36+
37+
package compiler.escapeAnalysis;
38+
39+
import javax.swing.*;
40+
import javax.swing.plaf.metal.*;
41+
42+
public class TestFindInstMemRecursion {
43+
public static void main(String[] args) throws Exception {
44+
LookAndFeel lookAndFeel = new MetalLookAndFeel();
45+
for (int i = 0; i < 20; ++i) {
46+
UIManager.setLookAndFeel(lookAndFeel);
47+
}
48+
}
49+
}

test/hotspot/jtreg/compiler/vectorapi/VectorReplicateLongSpecialImmTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* @library /test/lib
3737
* @requires os.arch == "aarch64"
3838
* @modules jdk.incubator.vector
39-
* @run testng/othervm -XX:UseSVE=0 -XX:-TieredCompilation -XX:CompileThreshold=100 compiler.vectorapi.VectorReplicateLongSpecialImmTest
39+
* @run testng/othervm -XX:UseSVE=0 -XX:-TieredCompilation -XX:CompileThreshold=100 -XX:+IgnoreUnrecognizedVMOptions -XX:CompileCommand=MemLimit,*.*,0 compiler.vectorapi.VectorReplicateLongSpecialImmTest
4040
*/
4141
public class VectorReplicateLongSpecialImmTest {
4242

0 commit comments

Comments
 (0)