Skip to content

Commit 7e4ac14

Browse files
committed
8380686: GenerateOopMap logging crashes in rewriter
Reviewed-by: matsaave, phubner
1 parent 7ffc4a4 commit 7e4ac14

3 files changed

Lines changed: 99 additions & 14 deletions

File tree

src/hotspot/share/interpreter/bytecodeTracer.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ class BytecodePrinter {
5252
Bytecodes::Code _code;
5353
address _next_pc; // current decoding position
5454
int _flags;
55-
bool _is_linked;
55+
bool _use_cp_cache;
5656

57-
bool is_linked() const { return _is_linked; }
57+
bool use_cp_cache() const { return _use_cp_cache; }
5858
void align() { _next_pc = align_up(_next_pc, sizeof(jint)); }
5959
int get_byte() { return *(jbyte*) _next_pc++; } // signed
6060
int get_index_u1() { return *(address)_next_pc++; } // returns 0x00 - 0xff as an int
@@ -69,7 +69,7 @@ class BytecodePrinter {
6969
bool is_wide() const { return _is_wide; }
7070
Bytecodes::Code raw_code() const { return Bytecodes::Code(_code); }
7171
ConstantPool* constants() const { return method()->constants(); }
72-
ConstantPoolCache* cpcache() const { assert(is_linked(), "must be"); return constants()->cache(); }
72+
ConstantPoolCache* cpcache() const { assert(use_cp_cache(), "must be"); return constants()->cache(); }
7373

7474
void print_constant(int i, outputStream* st);
7575
void print_cpcache_entry(int cpc_index, outputStream* st);
@@ -94,8 +94,9 @@ class BytecodePrinter {
9494
ResourceMark rm;
9595
bool method_changed = _current_method != method();
9696
_current_method = method();
97-
_is_linked = method->method_holder()->is_linked();
98-
assert(_is_linked, "this function must be called on methods that are already executing");
97+
_use_cp_cache = method->constants()->cache() != nullptr;
98+
assert(method->method_holder()->is_linked(),
99+
"this function must be called on methods that are already executing");
99100

100101
if (method_changed) {
101102
// Note 1: This code will not work as expected with true MT/MP.
@@ -150,7 +151,8 @@ class BytecodePrinter {
150151
// BytecodeStream, which will skip wide bytecodes.
151152
void trace(const methodHandle& method, address bcp, outputStream* st) {
152153
_current_method = method();
153-
_is_linked = method->method_holder()->is_linked();
154+
// This may be called during linking after bytecodes are rewritten to point to the cpCache.
155+
_use_cp_cache = method->constants()->cache() != nullptr;
154156
ResourceMark rm;
155157
Bytecodes::Code code = Bytecodes::code_at(method(), bcp);
156158
// Set is_wide
@@ -301,7 +303,7 @@ void BytecodePrinter::print_invokedynamic(int indy_index, int cp_index, outputSt
301303
if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_DYNAMIC)) {
302304
print_bsm(cp_index, st);
303305

304-
if (is_linked()) {
306+
if (use_cp_cache()) {
305307
ResolvedIndyEntry* indy_entry = constants()->resolved_indy_entry_at(indy_index);
306308
st->print(" ResolvedIndyEntry: ");
307309
indy_entry->print_on(st);
@@ -365,7 +367,7 @@ void BytecodePrinter::print_attributes(int bci, outputStream* st) {
365367
{
366368
int cp_index;
367369
if (Bytecodes::uses_cp_cache(raw_code())) {
368-
assert(is_linked(), "fast ldc bytecode must be in linked classes");
370+
assert(use_cp_cache(), "fast ldc bytecode must be in linked classes");
369371
int obj_index = get_index_u1();
370372
cp_index = constants()->object_to_cp_index(obj_index);
371373
} else {
@@ -380,7 +382,7 @@ void BytecodePrinter::print_attributes(int bci, outputStream* st) {
380382
{
381383
int cp_index;
382384
if (Bytecodes::uses_cp_cache(raw_code())) {
383-
assert(is_linked(), "fast ldc bytecode must be in linked classes");
385+
assert(use_cp_cache(), "fast ldc bytecode must be in linked classes");
384386
int obj_index = get_native_index_u2();
385387
cp_index = constants()->object_to_cp_index(obj_index);
386388
} else {
@@ -510,7 +512,7 @@ void BytecodePrinter::print_attributes(int bci, outputStream* st) {
510512
case Bytecodes::_getfield:
511513
{
512514
int cp_index;
513-
if (is_linked()) {
515+
if (use_cp_cache()) {
514516
int field_index = get_native_index_u2();
515517
cp_index = cpcache()->resolved_field_entry_at(field_index)->constant_pool_index();
516518
} else {
@@ -525,15 +527,15 @@ void BytecodePrinter::print_attributes(int bci, outputStream* st) {
525527
case Bytecodes::_invokestatic:
526528
{
527529
int cp_index;
528-
if (is_linked()) {
530+
if (use_cp_cache()) {
529531
int method_index = get_native_index_u2();
530532
ResolvedMethodEntry* method_entry = cpcache()->resolved_method_entry_at(method_index);
531533
cp_index = method_entry->constant_pool_index();
532534
print_field_or_method(cp_index, st);
533535

534536
if (raw_code() == Bytecodes::_invokehandle &&
535537
ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_METHOD_HANDLE)) {
536-
assert(is_linked(), "invokehandle is only in rewritten methods");
538+
assert(use_cp_cache(), "invokehandle is only in rewritten methods");
537539
method_entry->print_on(st);
538540
if (method_entry->has_appendix()) {
539541
st->print(" appendix: ");
@@ -550,7 +552,7 @@ void BytecodePrinter::print_attributes(int bci, outputStream* st) {
550552
case Bytecodes::_invokeinterface:
551553
{
552554
int cp_index;
553-
if (is_linked()) {
555+
if (use_cp_cache()) {
554556
int method_index = get_native_index_u2();
555557
cp_index = cpcache()->resolved_method_entry_at(method_index)->constant_pool_index();
556558
} else {
@@ -566,7 +568,7 @@ void BytecodePrinter::print_attributes(int bci, outputStream* st) {
566568
{
567569
int indy_index;
568570
int cp_index;
569-
if (is_linked()) {
571+
if (use_cp_cache()) {
570572
indy_index = get_native_index_u4();
571573
cp_index = constants()->resolved_indy_entry_at(indy_index)->constant_pool_index();
572574
} else {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2026, 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+
public super class JsrLogging version 49:0
26+
{
27+
static Field i:I;
28+
29+
public static Method test:"()V"
30+
stack 3 locals 1
31+
{
32+
nop;
33+
jsr LABEL;
34+
bipush 66;
35+
LABEL:
36+
bipush 55;
37+
putstatic Field i:"I";
38+
getstatic Field java/lang/System.out:"Ljava/io/PrintStream;";
39+
ldc String "hello";
40+
invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V";
41+
return;
42+
}
43+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2026, 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 8380686
27+
* @summary Ensure logging works while processing jsr while linking.
28+
* @library /test/lib
29+
* @compile JsrLogging.jasm
30+
* @run main/othervm -Xlog:generateoopmap=debug JsrLoggingTest
31+
*/
32+
33+
public class JsrLoggingTest {
34+
public static void main(String[] args) {
35+
for (int i = 0; i < 10; ++i) {
36+
JsrLogging.test();
37+
}
38+
System.out.println("PASSED");
39+
}
40+
}

0 commit comments

Comments
 (0)