Skip to content

Commit 97b0dd2

Browse files
mhaessigeme64dean-long
authored andcommitted
8336906: C2: assert(bb->is_reachable()) failed: getting result from unreachable basicblock
Co-authored-by: Emanuel Peter <epeter@openjdk.org> Co-authored-by: Dean Long <dlong@openjdk.org> Reviewed-by: epeter, dlong
1 parent a989245 commit 97b0dd2

File tree

3 files changed

+209
-2
lines changed

3 files changed

+209
-2
lines changed

src/hotspot/share/runtime/deoptimization.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,24 @@ void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_arr
842842
}
843843

844844
#ifndef PRODUCT
845+
// Return true if the execution after the provided bytecode continues at the
846+
// next bytecode in the code. This is not the case for gotos, returns, and
847+
// throws.
845848
static bool falls_through(Bytecodes::Code bc) {
846849
switch (bc) {
847-
// List may be incomplete. Here we really only care about bytecodes where compiled code
848-
// can deoptimize.
849850
case Bytecodes::_goto:
850851
case Bytecodes::_goto_w:
851852
case Bytecodes::_athrow:
853+
case Bytecodes::_areturn:
854+
case Bytecodes::_dreturn:
855+
case Bytecodes::_freturn:
856+
case Bytecodes::_ireturn:
857+
case Bytecodes::_lreturn:
858+
case Bytecodes::_jsr:
859+
case Bytecodes::_ret:
860+
case Bytecodes::_return:
861+
case Bytecodes::_lookupswitch:
862+
case Bytecodes::_tableswitch:
852863
return false;
853864
default:
854865
return true;
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2025, 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+
/*
26+
* @test id=return
27+
* @bug 8336906
28+
* @summary Ensure VerifyStack does not crash on bytecodes in unreachable basic blocks after return.
29+
* @compile TestVerifyStackWithUnreachableBytecodeImpl.jasm TestVerifyStackWithUnreachableBytecode.java
30+
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack -Xcomp
31+
* -XX:CompileCommand=compileonly,compiler/interpreter/TestVerifyStackWithUnreachableBytecodeImpl.test*
32+
* compiler.interpreter.TestVerifyStackWithUnreachableBytecode return
33+
*/
34+
35+
/*
36+
* @test id=areturn
37+
* @bug 8336906
38+
* @summary Ensure VerifyStack does not crash on bytecodes in unreachable basic blocks after areturn.
39+
* @compile TestVerifyStackWithUnreachableBytecodeImpl.jasm TestVerifyStackWithUnreachableBytecode.java
40+
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack -Xcomp
41+
* -XX:CompileCommand=compileonly,compiler/interpreter/TestVerifyStackWithUnreachableBytecodeImpl.test*
42+
* compiler.interpreter.TestVerifyStackWithUnreachableBytecode areturn
43+
*/
44+
45+
/*
46+
* @test id=goto
47+
* @bug 8336906 8271055
48+
* @summary Ensure VerifyStack does not crash on bytecodes in unreachable basic blocks after goto.
49+
* @compile TestVerifyStackWithUnreachableBytecodeImpl.jasm TestVerifyStackWithUnreachableBytecode.java
50+
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack -Xcomp
51+
* -XX:CompileCommand=compileonly,compiler/interpreter/TestVerifyStackWithUnreachableBytecodeImpl.test*
52+
* compiler.interpreter.TestVerifyStackWithUnreachableBytecode goto
53+
*/
54+
55+
/*
56+
* @test id=gotow
57+
* @bug 8336906 8271055
58+
* @summary Ensure VerifyStack does not crash on bytecodes in unreachable basic blocks after gotow.
59+
* @compile TestVerifyStackWithUnreachableBytecodeImpl.jasm TestVerifyStackWithUnreachableBytecode.java
60+
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack -Xcomp
61+
* -XX:CompileCommand=compileonly,compiler/interpreter/TestVerifyStackWithUnreachableBytecodeImpl.test*
62+
* compiler.interpreter.TestVerifyStackWithUnreachableBytecode gotow
63+
*/
64+
65+
package compiler.interpreter;
66+
67+
import compiler.interpreter.TestVerifyStackWithUnreachableBytecodeImpl;
68+
69+
public class TestVerifyStackWithUnreachableBytecode {
70+
public static void main(String[] args) {
71+
TestCase t = testCaseFromString(args[0]);
72+
73+
// The following is designed to cause a deopt with the reason `null_assert_or_unreached0`
74+
// when accessing A.val using getstatic due to the class B not being loaded and the consequent
75+
// assumption of A.val == null.
76+
TestVerifyStackWithUnreachableBytecodeA.val = null;
77+
dispatchTest(t);
78+
TestVerifyStackWithUnreachableBytecodeA.val = new TestVerifyStackWithUnreachableBytecodeB(42);
79+
dispatchTest(t);
80+
}
81+
82+
private enum TestCase {
83+
ARETURN,
84+
GOTO,
85+
GOTOW,
86+
RETURN;
87+
}
88+
89+
private static TestCase testCaseFromString(String s) {
90+
return switch (s) {
91+
case "areturn" -> TestCase.ARETURN;
92+
case "return" -> TestCase.RETURN;
93+
case "goto" -> TestCase.GOTO;
94+
case "gotow" -> TestCase.GOTOW;
95+
default -> throw new RuntimeException("Test argument not recognized: " + s);
96+
};
97+
}
98+
99+
private static void dispatchTest(TestCase testCase) {
100+
switch (testCase) {
101+
case ARETURN -> TestVerifyStackWithUnreachableBytecodeImpl.testAreturn();
102+
case RETURN -> TestVerifyStackWithUnreachableBytecodeImpl.testReturn();
103+
case GOTO -> TestVerifyStackWithUnreachableBytecodeImpl.testGoto();
104+
case GOTOW -> TestVerifyStackWithUnreachableBytecodeImpl.testGotow();
105+
}
106+
}
107+
}
108+
109+
class TestVerifyStackWithUnreachableBytecodeA {
110+
public static TestVerifyStackWithUnreachableBytecodeB val = null;
111+
}
112+
113+
class TestVerifyStackWithUnreachableBytecodeB {
114+
public int val = 0;
115+
116+
TestVerifyStackWithUnreachableBytecodeB(int v) { this.val = v; }
117+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2025, 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+
package compiler/interpreter;
26+
27+
// We need a class file format version < 50:0 so we do not need to specify a
28+
// stack map for the unreachable bytecodes, which are the reason this test
29+
// relies on a JASM implementation.
30+
super class TestVerifyStackWithUnreachableBytecodeImpl version 49:0
31+
{
32+
public Method "<init>":"()V"
33+
stack 1 locals 1
34+
{
35+
aload_0;
36+
invokespecial Method java/lang/Object."<init>":"()V";
37+
return;
38+
}
39+
public static Method testAreturn:"()Ljava/lang/Object;"
40+
stack 1 locals 0
41+
{
42+
// If A not loaded -> trap for TestVerifyStackWithUnreachableBytecodeA unloaded
43+
// If a loaded, but TestVerifyStackWithUnreachableBytecodeB not -> assume TestVerifyStackWithUnreachableBytecodeA.val null, else trap.
44+
// -> "null_assert_or_unreached0"
45+
getstatic Field compiler/interpreter/TestVerifyStackWithUnreachableBytecodeA.val:"Lcompiler/interpreter/TestVerifyStackWithUnreachableBytecodeB;";
46+
areturn;
47+
48+
// some unreachable instruction after return
49+
iconst_0;
50+
}
51+
public static Method testReturn:"()V"
52+
stack 1 locals 0
53+
{
54+
getstatic Field compiler/interpreter/TestVerifyStackWithUnreachableBytecodeA.val:"Lcompiler/interpreter/TestVerifyStackWithUnreachableBytecodeB;";
55+
return;
56+
// unreachable
57+
iconst_0;
58+
}
59+
public static Method testGoto:"()V"
60+
stack 1 locals 0
61+
{
62+
getstatic Field compiler/interpreter/TestVerifyStackWithUnreachableBytecodeA.val:"Lcompiler/interpreter/TestVerifyStackWithUnreachableBytecodeB;";
63+
goto There;
64+
// unreachable
65+
iconst_0;
66+
There:
67+
return;
68+
}
69+
public static Method testGotow:"()V"
70+
stack 1 locals 0
71+
{
72+
getstatic Field compiler/interpreter/TestVerifyStackWithUnreachableBytecodeA.val:"Lcompiler/interpreter/TestVerifyStackWithUnreachableBytecodeB;";
73+
goto_w There;
74+
// unreachable
75+
iconst_0;
76+
There:
77+
return;
78+
}
79+
}

0 commit comments

Comments
 (0)