Commit fd047dde authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Simplify --print-wasm-code to print earlier.

This makes sure {WasmCode} object are printed right after they have been
added to a {NativeModule} instead of waiting until the module is done.
This way debug output can be inspected as early as possible and works
even when there are issues later before the module is finished.

R=herhut@chromium.org
BUG=chromium:849713

Change-Id: Icced39cfaad7c033de569fbec21c26506f5796a6
Reviewed-on: https://chromium-review.googlesource.com/1088614Reviewed-by: 's avatarStephan Herhut <herhut@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53549}
parent 57f0e26f
...@@ -575,8 +575,7 @@ void PrintCode(Handle<Code> code, OptimizedCompilationInfo* info) { ...@@ -575,8 +575,7 @@ void PrintCode(Handle<Code> code, OptimizedCompilationInfo* info) {
? FLAG_print_builtin_code ? FLAG_print_builtin_code
: (FLAG_print_code || (info->IsStub() && FLAG_print_code_stubs) || : (FLAG_print_code || (info->IsStub() && FLAG_print_code_stubs) ||
(info->IsOptimizing() && FLAG_print_opt_code && (info->IsOptimizing() && FLAG_print_opt_code &&
info->shared_info()->PassesFilter(FLAG_print_opt_code_filter)) || info->shared_info()->PassesFilter(FLAG_print_opt_code_filter)));
(info->IsWasm() && FLAG_print_wasm_code));
if (print_code) { if (print_code) {
std::unique_ptr<char[]> debug_name = info->GetDebugName(); std::unique_ptr<char[]> debug_name = info->GetDebugName();
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer()); CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
......
...@@ -218,7 +218,7 @@ void WasmCode::ResetTrapHandlerIndex() { trap_handler_index_ = -1; } ...@@ -218,7 +218,7 @@ void WasmCode::ResetTrapHandlerIndex() { trap_handler_index_ = -1; }
bool WasmCode::ShouldBeLogged(Isolate* isolate) { bool WasmCode::ShouldBeLogged(Isolate* isolate) {
return isolate->logger()->is_listening_to_code_events() || return isolate->logger()->is_listening_to_code_events() ||
isolate->is_profiling() || FLAG_print_wasm_code || FLAG_print_code; isolate->is_profiling();
} }
void WasmCode::LogCode(Isolate* isolate) const { void WasmCode::LogCode(Isolate* isolate) const {
...@@ -236,18 +236,6 @@ void WasmCode::LogCode(Isolate* isolate) const { ...@@ -236,18 +236,6 @@ void WasmCode::LogCode(Isolate* isolate) const {
PROFILE(isolate, PROFILE(isolate,
CodeCreateEvent(CodeEventListener::FUNCTION_TAG, this, CodeCreateEvent(CodeEventListener::FUNCTION_TAG, this,
{cname.get(), static_cast<size_t>(name_length)})); {cname.get(), static_cast<size_t>(name_length)}));
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(wasm): Use proper log files, here and elsewhere.
OFStream os(stdout);
os << "--- Wasm " << (is_liftoff() ? "liftoff" : "turbofan")
<< " code ---\n";
this->Disassemble(cname.get(), isolate, os);
os << "--- End code ---\n";
}
#endif
if (!source_positions().is_empty()) { if (!source_positions().is_empty()) {
LOG_CODE_EVENT(isolate, CodeLinePosInfoRecordEvent(instruction_start(), LOG_CODE_EVENT(isolate, CodeLinePosInfoRecordEvent(instruction_start(),
source_positions())); source_positions()));
...@@ -287,7 +275,9 @@ void WasmCode::Validate() const { ...@@ -287,7 +275,9 @@ void WasmCode::Validate() const {
void WasmCode::Print(Isolate* isolate) const { void WasmCode::Print(Isolate* isolate) const {
OFStream os(stdout); OFStream os(stdout);
os << "--- WebAssembly code ---\n";
Disassemble(nullptr, isolate, os); Disassemble(nullptr, isolate, os);
os << "--- End code ---\n";
} }
void WasmCode::Disassemble(const char* name, Isolate* isolate, std::ostream& os, void WasmCode::Disassemble(const char* name, Isolate* isolate, std::ostream& os,
...@@ -557,7 +547,7 @@ WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code, ...@@ -557,7 +547,7 @@ WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code,
// made while iterating over the RelocInfo above. // made while iterating over the RelocInfo above.
Assembler::FlushICache(ret->instructions().start(), Assembler::FlushICache(ret->instructions().start(),
ret->instructions().size()); ret->instructions().size());
if (FLAG_print_wasm_code) { if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(mstarzinger): don't need the isolate here. // TODO(mstarzinger): don't need the isolate here.
ret->Print(code->GetIsolate()); ret->Print(code->GetIsolate());
} }
...@@ -624,6 +614,10 @@ WasmCode* NativeModule::AddCode( ...@@ -624,6 +614,10 @@ WasmCode* NativeModule::AddCode(
// made while iterating over the RelocInfo above. // made while iterating over the RelocInfo above.
Assembler::FlushICache(ret->instructions().start(), Assembler::FlushICache(ret->instructions().start(),
ret->instructions().size()); ret->instructions().size());
if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(mstarzinger): don't need the isolate here.
ret->Print(source_pos_table->GetIsolate());
}
return ret; return ret;
} }
......
...@@ -550,11 +550,15 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) { ...@@ -550,11 +550,15 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
UNREACHABLE(); UNREACHABLE();
} }
} }
// Flush the i-cache here instead of in AddOwnedCode, to include the changes // Flush the i-cache here instead of in AddOwnedCode, to include the changes
// made while iterating over the RelocInfo above. // made while iterating over the RelocInfo above.
Assembler::FlushICache(ret->instructions().start(), Assembler::FlushICache(ret->instructions().start(),
ret->instructions().size()); ret->instructions().size());
if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(mstarzinger): don't need the isolate here.
ret->Print(isolate_);
}
return true; return true;
} }
......
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