Skip to content

Commit fe520f6

Browse files
committed
Backport b31bbfcf2f13fa5b16762f5384d95c2b5d9c5705
1 parent df87be8 commit fe520f6

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/hotspot/share/code/codeBlob.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ void CodeBlob::dump_for_addr(address addr, outputStream* st, bool verbose) const
672672
nm->print_nmethod(true);
673673
} else {
674674
nm->print(st);
675+
nm->print_code_snippet(st, addr);
675676
}
676677
return;
677678
}

src/hotspot/share/code/nmethod.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,6 +3385,46 @@ void nmethod::print_value_on(outputStream* st) const {
33853385
}
33863386
#endif
33873387

3388+
void nmethod::print_code_snippet(outputStream* st, address addr) const {
3389+
if (entry_point() <= addr && addr < code_end()) {
3390+
// Pointing into the nmethod's code. Try to disassemble some instructions around addr.
3391+
// Determine conservative start and end points.
3392+
address start;
3393+
if (frame_complete_offset() != CodeOffsets::frame_never_safe &&
3394+
addr >= code_begin() + frame_complete_offset()) {
3395+
start = code_begin() + frame_complete_offset();
3396+
} else {
3397+
start = (addr < verified_entry_point()) ? entry_point() : verified_entry_point();
3398+
}
3399+
address start_for_hex_dump = start; // We can choose a different starting point for hex dump, below.
3400+
address end = code_end();
3401+
3402+
// Try using relocations to find closer instruction start and end points.
3403+
// (Some platforms have variable length instructions and can only
3404+
// disassemble correctly at instruction start addresses.)
3405+
RelocIterator iter((nmethod*)this, start);
3406+
while (iter.next() && iter.addr() < addr) { // find relocation before addr
3407+
// Note: There's a relocation which doesn't point to an instruction start:
3408+
// ZBarrierRelocationFormatStoreGoodAfterMov with ZGC on x86_64
3409+
// We could detect and skip it, but hex dump is still usable when
3410+
// disassembler produces garbage in such a very rare case.
3411+
start = iter.addr();
3412+
// We want at least 64 Bytes ahead in hex dump.
3413+
if (iter.addr() <= (addr - 64)) start_for_hex_dump = iter.addr();
3414+
}
3415+
if (iter.has_current()) {
3416+
if (iter.addr() == addr) iter.next(); // find relocation after addr
3417+
if (iter.has_current()) end = iter.addr();
3418+
}
3419+
3420+
// Always print hex. Disassembler may still have problems when hitting an incorrect instruction start.
3421+
os::print_hex_dump(st, start_for_hex_dump, end, 1, /* print_ascii=*/false);
3422+
if (!Disassembler::is_abstract()) {
3423+
Disassembler::decode(start, end, st);
3424+
}
3425+
}
3426+
}
3427+
33883428
#ifndef PRODUCT
33893429

33903430
void nmethod::print_calls(outputStream* st) {

src/hotspot/share/code/nmethod.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ class nmethod : public CompiledMethod {
623623
void print() const;
624624
void print(outputStream* st) const;
625625
void print_code();
626+
void print_code_snippet(outputStream* st, address addr) const;
626627

627628
#if defined(SUPPORT_DATA_STRUCTS)
628629
// print output in opt build for disassembler library

0 commit comments

Comments
 (0)