Skip to content

Commit 8d70429

Browse files
committed
8313626: C2 crash due to unexpected exception control flow
Backport-of: f8203cb272e6136b784e5c43a500f6a0bfb19c8b
1 parent 7f3f76f commit 8d70429

File tree

3 files changed

+180
-0
lines changed

3 files changed

+180
-0
lines changed

src/hotspot/share/opto/doCall.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,8 @@ void Parse::catch_inline_exceptions(SafePointNode* ex_map) {
979979
if (PrintOpto && WizardMode) {
980980
tty->print_cr(" Catching every inline exception bci:%d -> handler_bci:%d", bci(), handler_bci);
981981
}
982+
// If this is a backwards branch in the bytecodes, add safepoint
983+
maybe_add_safepoint(handler_bci);
982984
merge_exception(handler_bci); // jump to handler
983985
return; // No more handling to be done here!
984986
}
@@ -1010,6 +1012,8 @@ void Parse::catch_inline_exceptions(SafePointNode* ex_map) {
10101012
klass->print_name();
10111013
tty->cr();
10121014
}
1015+
// If this is a backwards branch in the bytecodes, add safepoint
1016+
maybe_add_safepoint(handler_bci);
10131017
merge_exception(handler_bci);
10141018
}
10151019
set_control(not_subtype_ctrl);
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
public class MissingSafepointOnTryCatch version 52:0 {
25+
26+
static Method m:"()V" {
27+
return;
28+
}
29+
30+
static Method test1:"()V" stack 1 {
31+
try t;
32+
invokestatic m:"()V";
33+
return;
34+
35+
catch t java/lang/Throwable;
36+
stack_map class java/lang/Throwable;
37+
athrow;
38+
endtry t;
39+
}
40+
41+
static Method test2:"()V" stack 1 {
42+
try t0;
43+
try t1;
44+
invokestatic m:"()V";
45+
endtry t1;
46+
return;
47+
48+
catch t1 java/lang/Exception;
49+
stack_map class java/lang/Exception;
50+
return;
51+
52+
catch t0 java/lang/Throwable;
53+
stack_map class java/lang/Throwable;
54+
athrow;
55+
endtry t0;
56+
}
57+
58+
public static Method th:"()V"
59+
throws java/lang/Exception
60+
stack 2 locals 0
61+
{
62+
new class java/lang/Exception;
63+
dup;
64+
invokespecial Method java/lang/Exception."<init>":"()V";
65+
athrow;
66+
}
67+
68+
static Method test3:"()V" stack 1 locals 2 {
69+
try t;
70+
invokestatic m:"()V";
71+
iconst_1;
72+
istore_0;
73+
iconst_0;
74+
istore_1;
75+
return;
76+
catch t java/lang/Throwable;
77+
stack_map class java/lang/Throwable;
78+
invokestatic th:"()V";
79+
return;
80+
endtry t;
81+
}
82+
83+
static Method test4:"()V" stack 2 locals 2 {
84+
try t;
85+
invokestatic m:"()V";
86+
iconst_1;
87+
istore_0;
88+
iconst_0;
89+
istore_1;
90+
return;
91+
catch t java/lang/Throwable;
92+
stack_map class java/lang/Throwable;
93+
iconst_1;
94+
istore_0;
95+
invokestatic th:"()V";
96+
return;
97+
endtry t;
98+
}
99+
100+
static Method testInfinite:"()V" stack 1 {
101+
try t;
102+
invokestatic th:"()V";
103+
return;
104+
105+
catch t java/lang/Throwable;
106+
stack_map class java/lang/Throwable;
107+
athrow;
108+
endtry t;
109+
}
110+
111+
} // end Class MissingSafepointOnTryCatch
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 8313626
27+
* @summary assert(false) failed: malformed control flow to missing safepoint on backedge of a try-catch
28+
* @library /test/lib
29+
* @compile MissingSafepointOnTryCatch.jasm
30+
* @run main/othervm -XX:CompileCommand=quiet
31+
* -XX:CompileCommand=compileonly,MissingSafepointOnTryCatch::test*
32+
* -XX:CompileCommand=dontinline,MissingSafepointOnTryCatch::m
33+
* -XX:CompileCommand=inline,MissingSafepointOnTryCatch::th
34+
* -XX:-TieredCompilation -Xcomp TestMissingSafepointOnTryCatch
35+
*/
36+
37+
import jdk.test.lib.Utils;
38+
39+
public class TestMissingSafepointOnTryCatch {
40+
41+
public static void infiniteLoop() {
42+
try {
43+
Thread thread = new Thread() {
44+
public void run() {
45+
MissingSafepointOnTryCatch.testInfinite();
46+
}
47+
};
48+
thread.setDaemon(true);
49+
thread.start();
50+
Thread.sleep(Utils.adjustTimeout(500));
51+
} catch (Exception e) {}
52+
}
53+
54+
public static void main(String[] args) {
55+
try {
56+
// to make sure java/lang/Exception class is resolved
57+
MissingSafepointOnTryCatch.th();
58+
} catch (Exception e) {}
59+
MissingSafepointOnTryCatch.test1();
60+
MissingSafepointOnTryCatch.test2();
61+
MissingSafepointOnTryCatch.test3();
62+
MissingSafepointOnTryCatch.test4();
63+
infiniteLoop();
64+
}
65+
}

0 commit comments

Comments
 (0)