@@ -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 {
0 commit comments