Improve Code Printing
Bug: v8:6666 Change-Id: I18258069703c225f2480bc5f81950b5b8f96fd4b Reviewed-on: https://chromium-review.googlesource.com/1179757 Commit-Queue: Sigurd Schneider <sigurds@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#55303}
This commit is contained in:
parent
7dc828b256
commit
240ab3b99c
@ -14,6 +14,7 @@
|
||||
#include "src/deoptimizer.h"
|
||||
#include "src/disasm.h"
|
||||
#include "src/ic/ic.h"
|
||||
#include "src/instruction-stream.h"
|
||||
#include "src/macro-assembler.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/snapshot/serializer-common.h"
|
||||
@ -216,8 +217,9 @@ static void PrintRelocInfo(StringBuilder* out, Isolate* isolate,
|
||||
}
|
||||
|
||||
static int DecodeIt(Isolate* isolate, ExternalReferenceEncoder* ref_encoder,
|
||||
std::ostream* os, const V8NameConverter& converter,
|
||||
byte* begin, byte* end, Address current_pc) {
|
||||
std::ostream* os, CodeReference code,
|
||||
const V8NameConverter& converter, byte* begin, byte* end,
|
||||
Address current_pc) {
|
||||
v8::internal::EmbeddedVector<char, 128> decode_buffer;
|
||||
v8::internal::EmbeddedVector<char, kOutBufferSize> out_buffer;
|
||||
StringBuilder out(out_buffer.start(), out_buffer.length());
|
||||
@ -225,8 +227,8 @@ static int DecodeIt(Isolate* isolate, ExternalReferenceEncoder* ref_encoder,
|
||||
disasm::Disassembler d(converter,
|
||||
disasm::Disassembler::kContinueOnUnimplementedOpcode);
|
||||
RelocIterator* it = nullptr;
|
||||
if (!converter.code().is_null()) {
|
||||
it = new RelocIterator(converter.code());
|
||||
if (!code.is_null()) {
|
||||
it = new RelocIterator(code);
|
||||
} else {
|
||||
// No relocation information when printing code stubs.
|
||||
}
|
||||
@ -305,7 +307,7 @@ static int DecodeIt(Isolate* isolate, ExternalReferenceEncoder* ref_encoder,
|
||||
// Print all the reloc info for this instruction which are not comments.
|
||||
for (size_t i = 0; i < pcs.size(); i++) {
|
||||
// Put together the reloc info
|
||||
const CodeReference& host = converter.code();
|
||||
const CodeReference& host = code;
|
||||
Address constant_pool =
|
||||
host.is_null() ? kNullAddress : host.constant_pool();
|
||||
RelocInfo relocinfo(pcs[i], rmodes[i], datas[i], nullptr, constant_pool);
|
||||
@ -318,13 +320,13 @@ static int DecodeIt(Isolate* isolate, ExternalReferenceEncoder* ref_encoder,
|
||||
// If this is a constant pool load and we haven't found any RelocInfo
|
||||
// already, check if we can find some RelocInfo for the target address in
|
||||
// the constant pool.
|
||||
if (pcs.empty() && !converter.code().is_null()) {
|
||||
if (pcs.empty() && !code.is_null()) {
|
||||
RelocInfo dummy_rinfo(reinterpret_cast<Address>(prev_pc), RelocInfo::NONE,
|
||||
0, nullptr);
|
||||
if (dummy_rinfo.IsInConstantPool()) {
|
||||
Address constant_pool_entry_address =
|
||||
dummy_rinfo.constant_pool_entry_address();
|
||||
RelocIterator reloc_it(converter.code());
|
||||
RelocIterator reloc_it(code);
|
||||
while (!reloc_it.done()) {
|
||||
if (reloc_it.rinfo()->IsInConstantPool() &&
|
||||
(reloc_it.rinfo()->constant_pool_entry_address() ==
|
||||
@ -362,16 +364,19 @@ static int DecodeIt(Isolate* isolate, ExternalReferenceEncoder* ref_encoder,
|
||||
int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
|
||||
byte* end, CodeReference code, Address current_pc) {
|
||||
V8NameConverter v8NameConverter(isolate, code);
|
||||
bool decode_off_heap = isolate && InstructionStream::PcIsOffHeap(
|
||||
isolate, bit_cast<Address>(begin));
|
||||
CodeReference code_ref = decode_off_heap ? CodeReference() : code;
|
||||
if (isolate) {
|
||||
// We have an isolate, so support external reference names.
|
||||
SealHandleScope shs(isolate);
|
||||
DisallowHeapAllocation no_alloc;
|
||||
ExternalReferenceEncoder ref_encoder(isolate);
|
||||
return DecodeIt(isolate, &ref_encoder, os, v8NameConverter, begin, end,
|
||||
current_pc);
|
||||
return DecodeIt(isolate, &ref_encoder, os, code_ref, v8NameConverter, begin,
|
||||
end, current_pc);
|
||||
} else {
|
||||
// No isolate => isolate-independent code. No external reference names.
|
||||
return DecodeIt(nullptr, nullptr, os, v8NameConverter, begin, end,
|
||||
return DecodeIt(nullptr, nullptr, os, code_ref, v8NameConverter, begin, end,
|
||||
current_pc);
|
||||
}
|
||||
}
|
||||
|
@ -14888,6 +14888,24 @@ void Code::PrintBuiltinCode(Isolate* isolate, const char* name) {
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
inline void DisassembleCodeRange(Isolate* isolate, std::ostream& os, Code* code,
|
||||
Address begin, size_t size,
|
||||
Address current_pc) {
|
||||
Address end = begin + size;
|
||||
// TODO(mstarzinger): Refactor CodeReference to avoid the
|
||||
// unhandlified->handlified transition.
|
||||
AllowHandleAllocation allow_handles;
|
||||
DisallowHeapAllocation no_gc;
|
||||
HandleScope handle_scope(isolate);
|
||||
Disassembler::Decode(isolate, &os, reinterpret_cast<byte*>(begin),
|
||||
reinterpret_cast<byte*>(end),
|
||||
CodeReference(handle(code, isolate)), current_pc);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void Code::Disassemble(const char* name, std::ostream& os, Address current_pc) {
|
||||
Isolate* isolate = GetIsolate();
|
||||
os << "kind = " << Kind2String(kind()) << "\n";
|
||||
@ -14906,9 +14924,16 @@ void Code::Disassemble(const char* name, std::ostream& os, Address current_pc) {
|
||||
os << "stack_slots = " << stack_slots() << "\n";
|
||||
}
|
||||
os << "compiler = " << (is_turbofanned() ? "turbofan" : "unknown") << "\n";
|
||||
os << "address = " << static_cast<const void*>(this) << "\n";
|
||||
os << "address = " << static_cast<const void*>(this) << "\n\n";
|
||||
|
||||
if (is_off_heap_trampoline()) {
|
||||
int trampoline_size = raw_instruction_size();
|
||||
os << "Trampoline (size = " << trampoline_size << ")\n";
|
||||
DisassembleCodeRange(isolate, os, this, raw_instruction_start(),
|
||||
trampoline_size, current_pc);
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
os << "Body (size = " << InstructionSize() << ")\n";
|
||||
{
|
||||
int size = InstructionSize();
|
||||
int safepoint_offset =
|
||||
@ -14920,25 +14945,16 @@ void Code::Disassemble(const char* name, std::ostream& os, Address current_pc) {
|
||||
int code_size =
|
||||
Min(handler_offset, Min(safepoint_offset, constant_pool_offset));
|
||||
os << "Instructions (size = " << code_size << ")\n";
|
||||
Address begin = InstructionStart();
|
||||
Address end = begin + code_size;
|
||||
{
|
||||
// TODO(mstarzinger): Refactor CodeReference to avoid the
|
||||
// unhandlified->handlified transition.
|
||||
AllowHandleAllocation allow_handles;
|
||||
DisallowHeapAllocation no_gc;
|
||||
HandleScope handle_scope(isolate);
|
||||
Disassembler::Decode(isolate, &os, reinterpret_cast<byte*>(begin),
|
||||
reinterpret_cast<byte*>(end),
|
||||
CodeReference(handle(this, isolate)), current_pc);
|
||||
}
|
||||
DisassembleCodeRange(isolate, os, this, InstructionStart(), code_size,
|
||||
current_pc);
|
||||
|
||||
if (constant_pool_offset < size) {
|
||||
int constant_pool_size = safepoint_offset - constant_pool_offset;
|
||||
DCHECK_EQ(constant_pool_size & kPointerAlignmentMask, 0);
|
||||
os << "\nConstant Pool (size = " << constant_pool_size << ")\n";
|
||||
Vector<char> buf = Vector<char>::New(50);
|
||||
intptr_t* ptr = reinterpret_cast<intptr_t*>(begin + constant_pool_offset);
|
||||
intptr_t* ptr = reinterpret_cast<intptr_t*>(InstructionStart() +
|
||||
constant_pool_offset);
|
||||
for (int i = 0; i < constant_pool_size; i += kPointerSize, ptr++) {
|
||||
SNPrintF(buf, "%4d %08" V8PRIxPTR, i, *ptr);
|
||||
os << static_cast<const void*>(ptr) << " " << buf.start() << "\n";
|
||||
|
Loading…
Reference in New Issue
Block a user