[wasm] Fix code printing for off-the-heap code
We were trying to disassemble the whole body of a function, including safepoints and the constant pool. This lead to DCHECK errors on mips. This CL fixes that, and adds printing of source positions. It also fixes the output of instructions size to only contain the instructions for both on-the-heap and off-the-heap code. R=titzer@chromium.org Bug: chromium:800233 Change-Id: Idb15a779680af7997eb78aea2a329189b684d53e Reviewed-on: https://chromium-review.googlesource.com/856458 Reviewed-by: Ben Titzer <titzer@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#50444}
This commit is contained in:
parent
54cb64ac94
commit
453d60b1e9
@ -5147,15 +5147,6 @@ WasmCodeWrapper WasmCompilationUnit::FinishTurbofanCompilation(
|
||||
codegen_ms);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DISASSEMBLER
|
||||
if (FLAG_print_code || FLAG_print_wasm_code) {
|
||||
// TODO(wasm): Use proper log files, here and elsewhere.
|
||||
PrintF("--- Native Wasm code ---\n");
|
||||
code->Print(isolate_);
|
||||
PrintF("--- End code ---\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
Handle<ByteArray> source_positions =
|
||||
tf_.job_->compilation_info()->wasm_code_desc()->source_positions_table;
|
||||
MaybeHandle<HandlerTable> handler_table =
|
||||
@ -5167,6 +5158,18 @@ WasmCodeWrapper WasmCompilationUnit::FinishTurbofanCompilation(
|
||||
native_module_->compiled_module()->handler_table()->set(
|
||||
func_index_, *handler_table.ToHandleChecked());
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DISASSEMBLER
|
||||
// Note: only do this after setting source positions, as this will be
|
||||
// accessed and printed here.
|
||||
if (FLAG_print_code || FLAG_print_wasm_code) {
|
||||
// TODO(wasm): Use proper log files, here and elsewhere.
|
||||
PrintF("--- Native Wasm code ---\n");
|
||||
code->Print(isolate_);
|
||||
PrintF("--- End code ---\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO(mtrofin): this should probably move up in the common caller,
|
||||
// once liftoff has source positions. Until then, we'd need to handle
|
||||
// undefined values, which is complicating the code.
|
||||
|
@ -14522,8 +14522,7 @@ void HandlerTable::HandlerTableReturnPrint(std::ostream& os) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Code::Disassemble(const char* name, std::ostream& os) { // NOLINT
|
||||
void Code::Disassemble(const char* name, std::ostream& os) {
|
||||
os << "kind = " << Kind2String(kind()) << "\n";
|
||||
if (is_stub()) {
|
||||
const char* n = CodeStub::MajorName(CodeStub::GetMajorKey(this));
|
||||
@ -14551,7 +14550,7 @@ void Code::Disassemble(const char* name, std::ostream& os) { // NOLINT
|
||||
os << "compiler = " << (is_turbofanned() ? "turbofan" : "unknown") << "\n";
|
||||
os << "address = " << static_cast<const void*>(this) << "\n";
|
||||
|
||||
os << "Instructions (size = " << instruction_size() << ")\n";
|
||||
os << "Body (size = " << instruction_size() << ")\n";
|
||||
{
|
||||
Isolate* isolate = GetIsolate();
|
||||
int size = instruction_size();
|
||||
@ -14563,6 +14562,7 @@ void Code::Disassemble(const char* name, std::ostream& os) { // NOLINT
|
||||
|
||||
// Stop before reaching any embedded tables
|
||||
int code_size = Min(safepoint_offset, constant_pool_offset);
|
||||
os << "Instructions (size = " << code_size << ")\n";
|
||||
byte* begin = instruction_start();
|
||||
byte* end = begin + code_size;
|
||||
Disassembler::Decode(isolate, &os, begin, end, this);
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "src/wasm/wasm-code-manager.h"
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
#include "src/assembler-inl.h"
|
||||
#include "src/base/atomic-utils.h"
|
||||
#include "src/base/macros.h"
|
||||
@ -176,22 +178,38 @@ bool WasmCode::HasTrapHandlerIndex() const { return trap_handler_index_ >= 0; }
|
||||
|
||||
void WasmCode::ResetTrapHandlerIndex() { trap_handler_index_ = -1; }
|
||||
|
||||
// TODO(mtrofin): rework the dependency on isolate and code in
|
||||
// Disassembler::Decode.
|
||||
void WasmCode::Disassemble(Isolate* isolate, const char* name,
|
||||
std::ostream& os) const {
|
||||
if (name) os << name << std::endl;
|
||||
Disassembler::Decode(isolate, &os, instructions().start(),
|
||||
instructions().end(), nullptr);
|
||||
}
|
||||
|
||||
void WasmCode::Print(Isolate* isolate) const {
|
||||
OFStream os(stdout);
|
||||
if (index_.IsJust()) {
|
||||
os << "index: " << index_.FromJust() << "\n";
|
||||
}
|
||||
os << "kind: " << GetWasmCodeKindAsString(kind_) << "\n";
|
||||
Disassemble(isolate, nullptr, os);
|
||||
os << "compiler: " << (is_liftoff() ? "Liftoff" : "TurboFan") << "\n";
|
||||
size_t body_size = instructions().size();
|
||||
os << "Body (size = " << body_size << ")\n";
|
||||
|
||||
size_t instruction_size =
|
||||
std::min(constant_pool_offset_, safepoint_table_offset_);
|
||||
os << "Instructions (size = " << instruction_size << ")\n";
|
||||
// TODO(mtrofin): rework the dependency on isolate and code in
|
||||
// Disassembler::Decode.
|
||||
Disassembler::Decode(isolate, &os, instructions().start(),
|
||||
instructions().start() + instruction_size, nullptr);
|
||||
os << "\n";
|
||||
|
||||
Object* source_positions_or_undef =
|
||||
owner_->compiled_module()->source_positions()->get(index());
|
||||
if (!source_positions_or_undef->IsUndefined(isolate)) {
|
||||
os << "Source positions:\n pc offset position\n";
|
||||
for (SourcePositionTableIterator it(
|
||||
ByteArray::cast(source_positions_or_undef));
|
||||
!it.done(); it.Advance()) {
|
||||
os << std::setw(10) << std::hex << it.code_offset() << std::dec
|
||||
<< std::setw(10) << it.source_position().ScriptOffset()
|
||||
<< (it.is_statement() ? " statement" : "") << "\n";
|
||||
}
|
||||
os << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
const char* GetWasmCodeKindAsString(WasmCode::Kind kind) {
|
||||
|
@ -123,7 +123,6 @@ class V8_EXPORT_PRIVATE WasmCode final {
|
||||
return *protected_instructions_.get();
|
||||
}
|
||||
|
||||
void Disassemble(Isolate* isolate, const char* name, std::ostream& os) const;
|
||||
void Print(Isolate* isolate) const;
|
||||
|
||||
~WasmCode();
|
||||
|
Loading…
Reference in New Issue
Block a user