Skip to content

Commit 1353601

Browse files
Matias Saavedra Silvadean-long
Matias Saavedra Silva
andcommitted
8338924: C1: assert(0 <= i && i < _len) failed: illegal index 5 for length 5
Co-authored-by: Dean Long <dlong@openjdk.org> Reviewed-by: kvn, thartmann
1 parent 433f6d8 commit 1353601

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

src/hotspot/share/c1/c1_GraphBuilder.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,11 @@ void GraphBuilder::jsr(int dest) {
13891389
// If the bytecodes are strange (jumping out of a jsr block) then we
13901390
// might end up trying to re-parse a block containing a jsr which
13911391
// has already been activated. Watch for this case and bail out.
1392+
if (next_bci() >= method()->code_size()) {
1393+
// This can happen if the subroutine does not terminate with a ret,
1394+
// effectively turning the jsr into a goto.
1395+
BAILOUT("too-complicated jsr/ret structure");
1396+
}
13921397
for (ScopeData* cur_scope_data = scope_data();
13931398
cur_scope_data != nullptr && cur_scope_data->parsing_jsr() && cur_scope_data->scope() == scope();
13941399
cur_scope_data = cur_scope_data->parent()) {
@@ -3736,6 +3741,9 @@ bool GraphBuilder::try_inline_intrinsics(ciMethod* callee, bool ignore_return) {
37363741
bool GraphBuilder::try_inline_jsr(int jsr_dest_bci) {
37373742
// Introduce a new callee continuation point - all Ret instructions
37383743
// will be replaced with Gotos to this point.
3744+
if (next_bci() >= method()->code_size()) {
3745+
return false;
3746+
}
37393747
BlockBegin* cont = block_at(next_bci());
37403748
assert(cont != nullptr, "continuation must exist (BlockListBuilder starts a new block after a jsr");
37413749

src/hotspot/share/compiler/methodLiveness.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -222,6 +222,9 @@ void MethodLiveness::init_basic_blocks() {
222222
dest = _block_map->at(bytes.get_dest());
223223
assert(dest != nullptr, "branch destination must start a block.");
224224
dest->add_normal_predecessor(current_block);
225+
if (bci + Bytecodes::length_for(code) >= method_len) {
226+
break;
227+
}
225228
BasicBlock *jsrExit = _block_map->at(current_block->limit_bci());
226229
assert(jsrExit != nullptr, "jsr return bci must start a block.");
227230
jsr_exit_list->append(jsrExit);
@@ -232,6 +235,9 @@ void MethodLiveness::init_basic_blocks() {
232235
dest = _block_map->at(bytes.get_far_dest());
233236
assert(dest != nullptr, "branch destination must start a block.");
234237
dest->add_normal_predecessor(current_block);
238+
if (bci + Bytecodes::length_for(code) >= method_len) {
239+
break;
240+
}
235241
BasicBlock *jsrExit = _block_map->at(current_block->limit_bci());
236242
assert(jsrExit != nullptr, "jsr return bci must start a block.");
237243
jsr_exit_list->append(jsrExit);

test/hotspot/jtreg/ProblemList-Xcomp.txt

-2
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,3 @@ vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/TestDescription.java 829
5151
vmTestbase/nsk/stress/thread/thread006.java 8321476 linux-all
5252

5353
gc/arguments/TestNewSizeFlags.java 8299116 macosx-aarch64
54-
55-
runtime/interpreter/LastJsrTest.java 8338924 generic-all

test/hotspot/jtreg/runtime/interpreter/LastJsrTest.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@
2323

2424
/*
2525
* @test
26-
* @bug 8335664
26+
* @bug 8335664 8338924
2727
* @summary Ensure a program that ends with a JSR does not crash
2828
* @library /test/lib
2929
* @compile LastJsr.jasm
3030
* @compile LastJsrReachable.jasm
31-
* @run main/othervm LastJsrTest
31+
* @run main/othervm -Xbatch LastJsrTest
3232
*/
3333

3434
public class LastJsrTest {
3535
public static void main(String[] args) {
36-
LastJsr.test();
37-
LastJsrReachable.test();
36+
for (int i = 0; i < 1000; ++i) {
37+
LastJsr.test();
38+
LastJsrReachable.test();
39+
}
3840
System.out.println("PASSED");
3941
}
4042
}

0 commit comments

Comments
 (0)