Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk20u Public archive

Commit a85a059

Browse files
committed
8296412: Special case infinite loops with unmerged backedges in IdealLoopTree::check_safepts
Backport-of: da38d43fcc640ea9852db6c7c23817dcef7080d5
1 parent d296d6f commit a85a059

File tree

3 files changed

+252
-0
lines changed

3 files changed

+252
-0
lines changed

src/hotspot/share/opto/loopnode.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,17 @@ void IdealLoopTree::check_safepts(VectorSet &visited, Node_List &stack) {
36323632
// Skip to head of inner loop
36333633
assert(_phase->is_dominator(_head, nlpt->_head), "inner head dominated by outer head");
36343634
n = nlpt->_head;
3635+
if (_head == n) {
3636+
// this and nlpt (inner loop) have the same loop head. This should not happen because
3637+
// during beautify_loops we call merge_many_backedges. However, infinite loops may not
3638+
// have been attached to the loop-tree during build_loop_tree before beautify_loops,
3639+
// but then attached in the build_loop_tree afterwards, and so still have unmerged
3640+
// backedges. Check if we are indeed in an infinite subgraph, and terminate the scan,
3641+
// since we have reached the loop head of this.
3642+
assert(_head->as_Region()->is_in_infinite_subgraph(),
3643+
"only expect unmerged backedges in infinite loops");
3644+
break;
3645+
}
36353646
}
36363647
}
36373648
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/*
2+
* Copyright (c) 2022, 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+
super public class TestInfiniteLoopWithUnmergedBackedges
25+
{
26+
public Method "<init>":"()V"
27+
stack 2 locals 1
28+
{
29+
aload_0;
30+
invokespecial Method java/lang/Object."<init>":"()V";
31+
return;
32+
}
33+
static Method test_001:"(IIIII)V"
34+
stack 5 locals 10
35+
{
36+
iload_0;
37+
ifgt LOOP;
38+
// below is dominated by the one above
39+
iload_0;
40+
ifle BACK;
41+
goto HEAD;
42+
HEAD:
43+
iload_3;
44+
ifeq BACK;
45+
BACK:
46+
goto HEAD;
47+
LOOP:
48+
iload_1;
49+
iflt LOOP;
50+
iload_2;
51+
iflt LOOP;
52+
return;
53+
}
54+
static Method test_002:"(IIIII)V"
55+
stack 5 locals 30
56+
{
57+
iload_0;
58+
ifgt LOOP;
59+
60+
iconst_0;
61+
istore 9;
62+
63+
goto HEAD;
64+
TAIL:
65+
iload_3;
66+
iload 9;
67+
if_icmpeq HEAD;
68+
iinc 9, 1;
69+
HEAD:
70+
goto TAIL;
71+
LOOP:
72+
iload_1;
73+
iflt LOOP;
74+
iload_2;
75+
iflt LOOP;
76+
return;
77+
}
78+
static Method test_003:"(IIIII)I"
79+
stack 5 locals 30
80+
{
81+
iload_0;
82+
ifgt SKIP;
83+
84+
iconst_0;
85+
istore 9;
86+
87+
goto HEAD;
88+
TAIL:
89+
iload_3;
90+
iload 9;
91+
if_icmpeq HEAD;
92+
iinc 9, 1;
93+
// Two paths lead to HEAD, so we have an inner and outer loop
94+
// But no SafePoint is placed here, because we go forward in bci
95+
HEAD:
96+
// SafePoint is placed here, because we go from here back in bci
97+
goto TAIL;
98+
99+
SKIP:
100+
iconst_0;
101+
istore 8;
102+
iconst_0;
103+
istore 9;
104+
// loop with two backedges, which calls
105+
// merge_many_backedges and then recomputes
106+
// build_loop_tree
107+
LOOP:
108+
iinc 9, 1;
109+
iinc 8, -1;
110+
iload 9;
111+
ldc 7;
112+
irem;
113+
ifeq LOOP;
114+
iload 9;
115+
ldc 10001;
116+
if_icmple LOOP;
117+
iload 8;
118+
ireturn;
119+
}
120+
static Method test_004:"(IIIII)I"
121+
stack 5 locals 30
122+
{
123+
iload_0;
124+
ifgt SKIP;
125+
126+
iconst_0;
127+
istore 9;
128+
129+
goto HEAD;
130+
TAIL:
131+
iload_3;
132+
iload 9;
133+
if_icmpeq HEAD;
134+
iinc 9, 1;
135+
iload 9;
136+
ldc 10001;
137+
if_icmpeq HEAD; // a second one
138+
iinc 9, 1;
139+
HEAD:
140+
goto TAIL;
141+
142+
SKIP:
143+
iconst_0;
144+
istore 8;
145+
iconst_0;
146+
istore 9;
147+
LOOP:
148+
iinc 9, 1;
149+
iinc 8, -1;
150+
iload 9;
151+
ldc 7;
152+
irem;
153+
ifeq LOOP;
154+
iload 9;
155+
ldc 10001;
156+
if_icmple LOOP;
157+
iload 8;
158+
ireturn;
159+
}
160+
static Method test_005:"(IIIII)I"
161+
stack 5 locals 30
162+
{
163+
iload_0;
164+
ifgt SKIP;
165+
166+
iconst_0;
167+
istore 9;
168+
169+
goto HEAD;
170+
TAIL:
171+
iload_3;
172+
iload 9;
173+
if_icmpeq HEAD;
174+
iinc 9, 1;
175+
iload 9;
176+
ldc 10001;
177+
if_icmpeq HEAD; // a second one
178+
iinc 9, 1;
179+
HEAD:
180+
goto TAIL;
181+
182+
SKIP:
183+
iconst_0;
184+
istore 8;
185+
iconst_0;
186+
istore 9;
187+
LOOP:
188+
iinc 9, 1;
189+
iinc 8, -1;
190+
iload 9;
191+
ldc 7;
192+
irem;
193+
ifeq LOOP;
194+
iload 9;
195+
ldc 10001;
196+
if_icmple LOOP;
197+
iload 8;
198+
ireturn;
199+
}
200+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2022, 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 8296412
27+
* @compile TestInfiniteLoopWithUnmergedBackedges.jasm
28+
* @summary Infinite loops may not have the backedges merged, before we call IdealLoopTree::check_safepts
29+
* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:-LoopUnswitching
30+
* -XX:CompileCommand=compileonly,TestInfiniteLoopWithUnmergedBackedges::test*
31+
* TestInfiniteLoopWithUnmergedBackedgesMain
32+
*/
33+
34+
public class TestInfiniteLoopWithUnmergedBackedgesMain {
35+
public static void main (String[] args) {
36+
TestInfiniteLoopWithUnmergedBackedges.test_001(1, 0, 0, 0, 0);
37+
TestInfiniteLoopWithUnmergedBackedges.test_002(1, 0, 0, 0, 0);
38+
TestInfiniteLoopWithUnmergedBackedges.test_003(1, 0, 0, 0, 0);
39+
TestInfiniteLoopWithUnmergedBackedges.test_004(1, 0, 0, 0, 0);
40+
}
41+
}

0 commit comments

Comments
 (0)