Skip to content

Commit 8d88be2

Browse files
author
Harold Seigel
committed
8291459: JVM crash with GenerateOopMap::error_work(char const*, __va_list_tag*)
Reviewed-by: dholmes, coleenp
1 parent 8a804f6 commit 8d88be2

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

src/hotspot/share/oops/generateOopMap.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,13 @@ bool GenerateOopMap::jump_targets_do(BytecodeStream *bcs, jmpFct_t jmpFct, int *
547547
case Bytecodes::_ifnull:
548548
case Bytecodes::_ifnonnull:
549549
(*jmpFct)(this, bcs->dest(), data);
550-
(*jmpFct)(this, bci + 3, data);
550+
// Class files verified by the old verifier can have a conditional branch
551+
// as their last bytecode, provided the conditional branch is unreachable
552+
// during execution. Check if this instruction is the method's last bytecode
553+
// and, if so, don't call the jmpFct.
554+
if (bci + 3 < method()->code_size()) {
555+
(*jmpFct)(this, bci + 3, data);
556+
}
551557
break;
552558

553559
case Bytecodes::_goto:
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
/*
25+
* @test
26+
* @bug 8291459
27+
* @summary Test that GenerateOopMap does not crash if last bytecode is a conditional branch
28+
* @library /test/lib /
29+
* @requires vm.flagless
30+
* @compile if_icmpleIsLastOpcode.jasm
31+
* @run driver TestGenerateOopMapCrash
32+
*/
33+
34+
import jdk.test.lib.process.OutputAnalyzer;
35+
import jdk.test.lib.process.ProcessTools;
36+
37+
// This test was copied from compiler test TestLinkageErrorInGenerateOopMap.java.
38+
public class TestGenerateOopMapCrash {
39+
40+
public static void main(String args[]) throws Exception {
41+
if (args.length == 0) {
42+
// Spawn new VM instance to execute test
43+
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
44+
"-XX:-TieredCompilation",
45+
"-XX:CompileCommand=dontinline,if_icmpleIsLastOpcode.m*",
46+
"-Xmx64m",
47+
TestGenerateOopMapCrash.class.getName(),
48+
"run");
49+
OutputAnalyzer output = new OutputAnalyzer(pb.start());
50+
output.shouldHaveExitValue(0);
51+
} else {
52+
// Execute test
53+
if_icmpleIsLastOpcode.test();
54+
}
55+
}
56+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
25+
// Old class file with a method whose last bytecode is an unreachable
26+
// conditional branch.
27+
public class if_icmpleIsLastOpcode version 49:0 {
28+
public static Method m1:"()I" stack 1 locals 0 {
29+
iconst_0;
30+
ireturn;
31+
}
32+
33+
public static Method m2:"(I)V" stack 1 locals 1 {
34+
return;
35+
}
36+
37+
public static Method test:"()V" stack 2 locals 1 {
38+
iconst_0;
39+
istore_0;
40+
Loop: stack_frame_type append;
41+
locals_map int;
42+
iload_0;
43+
invokestatic Method if_icmpleIsLastOpcode."m1":"()I";
44+
invokestatic Method if_icmpleIsLastOpcode."m2":"(I)V";
45+
iinc 0, 1;
46+
ldc 100000;
47+
if_icmple Loop;
48+
return;
49+
ldc 100000;
50+
if_icmple Loop;
51+
}
52+
}

0 commit comments

Comments
 (0)