Skip to content

Commit 4a05d40

Browse files
committed
Move printing code to nmethod.cpp.
1 parent 003680d commit 4a05d40

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

src/hotspot/share/code/codeBlob.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -910,28 +910,7 @@ void CodeBlob::dump_for_addr(address addr, outputStream* st, bool verbose) const
910910
nm->print_nmethod(true);
911911
} else {
912912
nm->print_on(st);
913-
if (nm->entry_point() <= addr && addr < nm->code_end()) {
914-
// Pointing into an nmethod. Try to disassemble some instructions around addr.
915-
address start = (addr < nm->verified_entry_point()) ? nm->entry_point() : nm->verified_entry_point();
916-
address end = nm->code_end();
917-
// Try using relocations to find known instruction start and end points.
918-
// (Some platforms have variable length instructions and can only
919-
// disassemble correctly at instruction start addresses.)
920-
RelocIterator iter(nm, start);
921-
while (iter.next() && iter.addr() < addr) { // find relocation before addr
922-
start = iter.addr();
923-
}
924-
if (iter.has_current()) {
925-
if (iter.addr() == addr) iter.next(); // find relocation after addr
926-
if (iter.has_current()) end = iter.addr();
927-
}
928-
929-
// Always print hex. Disassembler may still have problems if start is not a correct instruction start.
930-
os::print_hex_dump(st, start, end, 1, /* print_ascii=*/false);
931-
if (!Disassembler::is_abstract()) {
932-
Disassembler::decode(start, end, st);
933-
}
934-
}
913+
nm->print_code_snippet(st, addr);
935914
}
936915
return;
937916
}

src/hotspot/share/code/nmethod.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,6 +3995,31 @@ void nmethod::print_value_on_impl(outputStream* st) const {
39953995
#endif
39963996
}
39973997

3998+
void nmethod::print_code_snippet(outputStream* st, address addr) const {
3999+
if (entry_point() <= addr && addr < code_end()) {
4000+
// Pointing into the nmethod's code. Try to disassemble some instructions around addr.
4001+
address start = (addr < verified_entry_point()) ? entry_point() : verified_entry_point();
4002+
address end = code_end();
4003+
// Try using relocations to find known instruction start and end points.
4004+
// (Some platforms have variable length instructions and can only
4005+
// disassemble correctly at instruction start addresses.)
4006+
RelocIterator iter((nmethod*)this, start);
4007+
while (iter.next() && iter.addr() < addr) { // find relocation before addr
4008+
start = iter.addr();
4009+
}
4010+
if (iter.has_current()) {
4011+
if (iter.addr() == addr) iter.next(); // find relocation after addr
4012+
if (iter.has_current()) end = iter.addr();
4013+
}
4014+
4015+
// Always print hex. Disassembler may still have problems when hitting an incorrect instruction start.
4016+
os::print_hex_dump(st, start, end, 1, /* print_ascii=*/false);
4017+
if (!Disassembler::is_abstract()) {
4018+
Disassembler::decode(start, end, st);
4019+
}
4020+
}
4021+
}
4022+
39984023
#ifndef PRODUCT
39994024

40004025
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
@@ -996,6 +996,7 @@ class nmethod : public CodeBlob {
996996
void print_on_impl(outputStream* st) const;
997997
void print_code();
998998
void print_value_on_impl(outputStream* st) const;
999+
void print_code_snippet(outputStream* st, address addr) const;
9991000

10001001
#if defined(SUPPORT_DATA_STRUCTS)
10011002
// print output in opt build for disassembler library

0 commit comments

Comments
 (0)