Skip to content

Commit 6c3e621

Browse files
committed
8308749: C2 failed: regular loops only (counted loop inside infinite loop)
Reviewed-by: kvn, chagedorn
1 parent f5cbe53 commit 6c3e621

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

src/hotspot/share/opto/loopnode.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,21 @@ bool PhaseIdealLoop::is_counted_loop(Node* x, IdealLoopTree*&loop, BasicType iv_
17451745
// =================================================
17461746
// ---- SUCCESS! Found A Trip-Counted Loop! -----
17471747
//
1748+
1749+
if (x->Opcode() == Op_Region) {
1750+
// x has not yet been transformed to Loop or LongCountedLoop.
1751+
// This should only happen if we are inside an infinite loop.
1752+
// It happens like this:
1753+
// build_loop_tree -> do not attach infinite loop and nested loops
1754+
// beautify_loops -> does not transform the infinite and nested loops to LoopNode, because not attached yet
1755+
// build_loop_tree -> find and attach infinite and nested loops
1756+
// counted_loop -> nested Regions are not yet transformed to LoopNodes, we land here
1757+
assert(x->as_Region()->is_in_infinite_subgraph(),
1758+
"x can only be a Region and not Loop if inside infinite loop");
1759+
// Come back later when Region is transformed to LoopNode
1760+
return false;
1761+
}
1762+
17481763
assert(x->Opcode() == Op_Loop || x->Opcode() == Op_LongCountedLoop, "regular loops only");
17491764
C->print_method(PHASE_BEFORE_CLOOPS, 3);
17501765

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2023, 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 TestCountedLoopInsideInfiniteLoop
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:"(IIII)V"
34+
stack 200 locals 4
35+
{
36+
iload 0; // arg0 == 0
37+
ifeq LEND;
38+
39+
LOOP1: // counted loop to kick off beautify_loops
40+
iload 1;
41+
ifeq LOOP1;
42+
iload 2;
43+
ifle LOOP1;
44+
45+
LOOP2: // infinite loop (still Region)
46+
goto LOOP2b;
47+
48+
LOOP2b: // counted loop (still Region)
49+
iinc 3, -1;
50+
iload 3;
51+
ifgt LOOP2b;
52+
53+
iconst_0;
54+
ifeq LOOP2; // always true
55+
goto LOOP2b;
56+
57+
LEND:
58+
return;
59+
}
60+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2023, 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 8308749
27+
* @compile TestCountedLoopInsideInfiniteLoop.jasm
28+
* @summary Counted Loops inside infinite loops are only detected later,
29+
* and may still be a Region and not a LoopNode as expected.
30+
* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:PerMethodTrapLimit=0
31+
* -XX:CompileCommand=compileonly,TestCountedLoopInsideInfiniteLoop::test
32+
* TestCountedLoopInsideInfiniteLoopMain
33+
*/
34+
35+
public class TestCountedLoopInsideInfiniteLoopMain {
36+
public static void main (String[] args) {
37+
TestCountedLoopInsideInfiniteLoop.test(0, 0, 0, 0);
38+
}
39+
}

0 commit comments

Comments
 (0)