Skip to content

Commit e0774be

Browse files
committed
8306997: C2: "malformed control flow" assert due to missing safepoint on backedge with a switch
Reviewed-by: thartmann, kvn
1 parent 462b1df commit e0774be

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed

src/hotspot/share/opto/parse2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ void Parse::do_tableswitch() {
435435

436436
// generate decision tree, using trichotomy when possible
437437
int rnum = len+2;
438-
bool makes_backward_branch = false;
438+
bool makes_backward_branch = (default_dest <= bci());
439439
SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum);
440440
int rp = -1;
441441
if (lo_index != min_jint) {
@@ -526,7 +526,7 @@ void Parse::do_lookupswitch() {
526526
}
527527

528528
int rnum = len*2+1;
529-
bool makes_backward_branch = false;
529+
bool makes_backward_branch = (default_dest <= bci());
530530
SwitchRange* ranges = NEW_RESOURCE_ARRAY(SwitchRange, rnum);
531531
int rp = -1;
532532
for (int j = 0; j < len; j++) {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2023, Red Hat, Inc. 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 MissingSafepointOnSwitch
25+
version 52:0
26+
{
27+
public Method "<init>":"()V"
28+
stack 1 locals 1
29+
{
30+
aload_0;
31+
invokespecial Method java/lang/Object."<init>":"()V";
32+
return;
33+
}
34+
/* Same as:
35+
public static void test(boolean flag, int v) {
36+
if (flag) {
37+
loop:
38+
for (; ; ) {
39+
switch(v) {
40+
case 0:
41+
case 1:
42+
case 2:
43+
break loop;
44+
default:
45+
}
46+
}
47+
}
48+
}
49+
but with the default: set to the loop entry
50+
*/
51+
public static Method test:"(ZI)V"
52+
stack 1 locals 2
53+
{
54+
iload_0;
55+
ifeq L32;
56+
L4: stack_frame_type same;
57+
iload_1;
58+
tableswitch{ //0 to 2
59+
0: L32;
60+
1: L32;
61+
2: L32;
62+
default: L4 };
63+
L32: stack_frame_type same;
64+
return;
65+
}
66+
67+
} // end Class TestMissingSafepointOnSwitch
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2023, Red Hat, Inc. 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 8306997
27+
* @summary C2: "malformed control flow" assert due to missing safepoint on backedge with a switch
28+
* @compile MissingSafepointOnSwitch.jasm
29+
* @run main/othervm -Xcomp -XX:CompileOnly=MissingSafepointOnSwitch::test TestMissingSafepointOnSwitch
30+
*/
31+
32+
public class TestMissingSafepointOnSwitch {
33+
public static void main(String[] args) {
34+
MissingSafepointOnSwitch.test(false, 0);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)