Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 623cc73

Browse files
committed
8271055: Crash during deoptimization with "assert(bb->is_reachable()) failed: getting result from unreachable basicblock" with -XX:+VerifyStack
Backport-of: e44dc638b8936b1b76ca9ddf9ece0c5c4705a19c
1 parent 8956913 commit 623cc73

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed

src/hotspot/share/runtime/deoptimization.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,21 @@ void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_arr
707707
assert(f->is_interpreted_frame(), "must be interpreted");
708708
}
709709

710+
#ifndef PRODUCT
711+
static bool falls_through(Bytecodes::Code bc) {
712+
switch (bc) {
713+
// List may be incomplete. Here we really only care about bytecodes where compiled code
714+
// can deoptimize.
715+
case Bytecodes::_goto:
716+
case Bytecodes::_goto_w:
717+
case Bytecodes::_athrow:
718+
return false;
719+
default:
720+
return true;
721+
}
722+
}
723+
#endif
724+
710725
// Return BasicType of value being returned
711726
JRT_LEAF(BasicType, Deoptimization::unpack_frames(JavaThread* thread, int exec_mode))
712727

@@ -814,7 +829,7 @@ JRT_LEAF(BasicType, Deoptimization::unpack_frames(JavaThread* thread, int exec_m
814829
// calls. It seems to be hard to tell whether the compiler
815830
// has emitted debug information matching the "state before"
816831
// a given bytecode or the state after, so we try both
817-
if (!Bytecodes::is_invoke(cur_code) && cur_code != Bytecodes::_athrow) {
832+
if (!Bytecodes::is_invoke(cur_code) && falls_through(cur_code)) {
818833
// Get expression stack size for the next bytecode
819834
InterpreterOopMap next_mask;
820835
OopMapCache::compute_one_oop_map(mh, str.bci(), &next_mask);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
package compiler/interpreter;
25+
26+
/* JASM simplified from the following Java pattern:
27+
*
28+
* public class Custom {
29+
*
30+
* static void test(int v) {
31+
* int i8 = 1;
32+
* try {
33+
* v += 1;
34+
* } catch (ArithmeticException exc1) {
35+
* } finally {
36+
* for (; i8 < 100; i8++) {
37+
* }
38+
* }
39+
* }
40+
*
41+
*/
42+
43+
super public class Custom {
44+
45+
public static Method test:"(I)V" stack 2 locals 3 {
46+
iconst_1;
47+
istore_1;
48+
try t0;
49+
iinc 0, 1;
50+
endtry t0;
51+
Loop:
52+
iload_1;
53+
bipush 100;
54+
if_icmpge Lexit;
55+
iinc 1, 1;
56+
goto Loop; // deoptimize here on backwards branch
57+
catch t0 java/lang/ArithmeticException; // unreachable block
58+
astore_2;
59+
Lexit:
60+
return
61+
}
62+
63+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2021, Alibaba Group Holding Limited. All Rights Reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
26+
/*
27+
* @test VerifyStackWithUnreachableBlock
28+
* @bug 8271055
29+
* @compile Custom.jasm VerifyStackWithUnreachableBlock.java
30+
* @summary Using VerifyStack for method that contains unreachable basic blocks
31+
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack compiler.interpreter.VerifyStackWithUnreachableBlock
32+
*/
33+
34+
package compiler.interpreter;
35+
36+
public class VerifyStackWithUnreachableBlock {
37+
public static void main(String[] strArr) {
38+
for (int i = 0; i < 10000; i++) {
39+
Custom.test(i);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)