Commit 8cf7223f authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[Liftoff] Also disassemble code on the native heap

With --jit-to-native, we current don't disassemble any Liftoff code.
This CL adds that, and also adds printing of relocation info of native
wasm code.

R=mstarzinger@chromium.org
CC=titzer@chromium.org

Bug: v8:6600
Change-Id: Icb1249868224180171107b82e2dd7dc69e23db16
Reviewed-on: https://chromium-review.googlesource.com/863762
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50553}
parent 08cdc023
...@@ -5218,6 +5218,24 @@ WasmCodeWrapper WasmCompilationUnit::FinishLiftoffCompilation( ...@@ -5218,6 +5218,24 @@ WasmCodeWrapper WasmCompilationUnit::FinishLiftoffCompilation(
false, // is_turbofanned false, // is_turbofanned
liftoff_.asm_.GetTotalFrameSlotCount(), // stack_slots liftoff_.asm_.GetTotalFrameSlotCount(), // stack_slots
liftoff_.safepoint_table_offset_); liftoff_.safepoint_table_offset_);
if (isolate_->logger()->is_logging_code_events() ||
isolate_->is_profiling()) {
RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate_, code,
"wasm#%d-liftoff", func_index_);
}
PackProtectedInstructions(code);
ret = WasmCodeWrapper(code);
} else {
// TODO(mtrofin): figure a way to raise events.
// Consider lifting it to FinishCompilation.
native_module_->compiled_module()->source_positions()->set(
func_index_, *source_positions);
ret = WasmCodeWrapper(
native_module_->AddCode(desc, liftoff_.asm_.GetTotalFrameSlotCount(),
func_index_, liftoff_.safepoint_table_offset_,
std::move(protected_instructions_), true));
}
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
if (FLAG_print_code || FLAG_print_wasm_code) { if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(wasm): Use proper log files, here and elsewhere. // TODO(wasm): Use proper log files, here and elsewhere.
...@@ -5230,28 +5248,11 @@ WasmCodeWrapper WasmCompilationUnit::FinishLiftoffCompilation( ...@@ -5230,28 +5248,11 @@ WasmCodeWrapper WasmCompilationUnit::FinishLiftoffCompilation(
} else { } else {
SNPrintF(func_name, "wasm#%d", func_index()); SNPrintF(func_name, "wasm#%d", func_index());
} }
code->Disassemble(func_name.start(), os); ret.Disassemble(func_name.start(), isolate_, os);
os << "--- End code ---\n"; os << "--- End code ---\n";
} }
#endif #endif
if (isolate_->logger()->is_logging_code_events() || return ret;
isolate_->is_profiling()) {
RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate_, code,
"wasm#%d-liftoff", func_index_);
}
PackProtectedInstructions(code);
return WasmCodeWrapper(code);
} else {
// TODO(mtrofin): figure a way to raise events; also, disassembly.
// Consider lifting them both to FinishCompilation.
native_module_->compiled_module()->source_positions()->set(
func_index_, *source_positions);
return WasmCodeWrapper(
native_module_->AddCode(desc, liftoff_.asm_.GetTotalFrameSlotCount(),
func_index_, liftoff_.safepoint_table_offset_,
std::move(protected_instructions_), true));
}
} }
// static // static
......
...@@ -180,14 +180,20 @@ void WasmCode::ResetTrapHandlerIndex() { trap_handler_index_ = -1; } ...@@ -180,14 +180,20 @@ void WasmCode::ResetTrapHandlerIndex() { trap_handler_index_ = -1; }
void WasmCode::Print(Isolate* isolate) const { void WasmCode::Print(Isolate* isolate) const {
OFStream os(stdout); OFStream os(stdout);
if (index_.IsJust()) { Disassemble(nullptr, isolate, os);
os << "index: " << index_.FromJust() << "\n"; }
}
void WasmCode::Disassemble(const char* name, Isolate* isolate,
std::ostream& os) const {
if (name) os << "name: " << name << "\n";
if (index_.IsJust()) os << "index: " << index_.FromJust() << "\n";
os << "kind: " << GetWasmCodeKindAsString(kind_) << "\n"; os << "kind: " << GetWasmCodeKindAsString(kind_) << "\n";
os << "compiler: " << (is_liftoff() ? "Liftoff" : "TurboFan") << "\n"; os << "compiler: " << (is_liftoff() ? "Liftoff" : "TurboFan") << "\n";
size_t body_size = instructions().size(); size_t body_size = instructions().size();
os << "Body (size = " << body_size << ")\n"; os << "Body (size = " << body_size << ")\n";
#ifdef ENABLE_DISASSEMBLER
size_t instruction_size = size_t instruction_size =
std::min(constant_pool_offset_, safepoint_table_offset_); std::min(constant_pool_offset_, safepoint_table_offset_);
os << "Instructions (size = " << instruction_size << ")\n"; os << "Instructions (size = " << instruction_size << ")\n";
...@@ -210,6 +216,14 @@ void WasmCode::Print(Isolate* isolate) const { ...@@ -210,6 +216,14 @@ void WasmCode::Print(Isolate* isolate) const {
} }
os << "\n"; os << "\n";
} }
os << "RelocInfo (size = " << reloc_size_ << ")\n";
for (RelocIterator it(instructions(), reloc_info(), constant_pool());
!it.done(); it.next()) {
it.rinfo()->Print(isolate, os);
}
os << "\n";
#endif // ENABLE_DISASSEMBLER
} }
const char* GetWasmCodeKindAsString(WasmCode::Kind kind) { const char* GetWasmCodeKindAsString(WasmCode::Kind kind) {
......
...@@ -124,6 +124,7 @@ class V8_EXPORT_PRIVATE WasmCode final { ...@@ -124,6 +124,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
} }
void Print(Isolate* isolate) const; void Print(Isolate* isolate) const;
void Disassemble(const char* name, Isolate* isolate, std::ostream& os) const;
~WasmCode(); ~WasmCode();
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "src/objects.h" #include "src/objects.h"
#include "src/objects/code.h" #include "src/objects/code.h"
#include "src/wasm/wasm-code-manager.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -34,5 +35,16 @@ const wasm::WasmCode* WasmCodeWrapper::GetWasmCode() const { ...@@ -34,5 +35,16 @@ const wasm::WasmCode* WasmCodeWrapper::GetWasmCode() const {
bool WasmCodeWrapper::IsCodeObject() const { return !FLAG_wasm_jit_to_native; } bool WasmCodeWrapper::IsCodeObject() const { return !FLAG_wasm_jit_to_native; }
#ifdef ENABLE_DISASSEMBLER
void WasmCodeWrapper::Disassemble(const char* name, Isolate* isolate,
std::ostream& os) const {
if (IsCodeObject()) {
GetCode()->Disassemble(name, os);
} else {
GetWasmCode()->Disassemble(name, isolate, os);
}
}
#endif
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -26,6 +26,10 @@ class WasmCodeWrapper { ...@@ -26,6 +26,10 @@ class WasmCodeWrapper {
bool is_null() const { return code_ptr_.wasm_code_ == nullptr; } bool is_null() const { return code_ptr_.wasm_code_ == nullptr; }
bool IsCodeObject() const; bool IsCodeObject() const;
#ifdef ENABLE_DISASSEMBLER
void Disassemble(const char* name, Isolate* isolate, std::ostream& os) const;
#endif
private: private:
union { union {
const wasm::WasmCode* wasm_code_; const wasm::WasmCode* wasm_code_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment