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

[wasm] Allow printing of WasmCode without an Isolate.

R=titzer@chromium.org

Change-Id: I760a2568194edce486383d2bf32d598bdb9d44b1
Reviewed-on: https://chromium-review.googlesource.com/1109938Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54001}
parent 3b86e176
......@@ -585,10 +585,13 @@ void RelocInfo::Print(Isolate* isolate, std::ostream& os) { // NOLINT
} else if (rmode_ == EMBEDDED_OBJECT) {
os << " (" << Brief(target_object()) << ")";
} else if (rmode_ == EXTERNAL_REFERENCE) {
ExternalReferenceEncoder ref_encoder(isolate);
os << " ("
<< ref_encoder.NameOfAddress(isolate, target_external_reference())
<< ") (" << reinterpret_cast<const void*>(target_external_reference())
if (isolate) {
ExternalReferenceEncoder ref_encoder(isolate);
os << " ("
<< ref_encoder.NameOfAddress(isolate, target_external_reference())
<< ") ";
}
os << " (" << reinterpret_cast<const void*>(target_external_reference())
<< ")";
} else if (IsCodeTarget(rmode_)) {
const Address code_target = target_address();
......@@ -600,8 +603,7 @@ void RelocInfo::Print(Isolate* isolate, std::ostream& os) { // NOLINT
} else if (code->kind() == Code::STUB) {
os << " " << CodeStub::MajorName(CodeStub::GetMajorKey(code));
}
os << ") ";
os << " (" << reinterpret_cast<const void*>(target_address()) << ")";
os << ") (" << reinterpret_cast<const void*>(target_address()) << ")";
} else if (IsRuntimeEntry(rmode_) && isolate->deoptimizer_data() != nullptr) {
// Deoptimization bailouts are stored as runtime entries.
DeoptimizeKind type;
......
......@@ -2391,7 +2391,7 @@ extern void _v8_internal_Print_Code(void* object) {
isolate->wasm_engine()->code_manager()->LookupCode(address);
if (wasm_code) {
i::StdoutStream os;
wasm_code->Disassemble(nullptr, isolate, os, address);
wasm_code->Disassemble(nullptr, os, address);
return;
}
......
......@@ -205,14 +205,14 @@ void WasmCode::Validate() const {
#endif
}
void WasmCode::Print(Isolate* isolate) const {
void WasmCode::Print(const char* name) const {
StdoutStream os;
os << "--- WebAssembly code ---\n";
Disassemble(nullptr, isolate, os);
Disassemble(name, os);
os << "--- End code ---\n";
}
void WasmCode::Disassemble(const char* name, Isolate* isolate, std::ostream& os,
void WasmCode::Disassemble(const char* name, std::ostream& os,
Address current_pc) const {
if (name) os << "name: " << name << "\n";
if (index_.IsJust()) os << "index: " << index_.FromJust() << "\n";
......@@ -231,9 +231,7 @@ void WasmCode::Disassemble(const char* name, Isolate* isolate, std::ostream& os,
}
DCHECK_LT(0, instruction_size);
os << "Instructions (size = " << instruction_size << ")\n";
// TODO(mtrofin): rework the dependency on isolate and code in
// Disassembler::Decode.
Disassembler::Decode(isolate, &os, instructions().start(),
Disassembler::Decode(nullptr, &os, instructions().start(),
instructions().start() + instruction_size,
CodeReference(this), current_pc);
os << "\n";
......@@ -252,7 +250,7 @@ void WasmCode::Disassemble(const char* name, Isolate* isolate, std::ostream& os,
os << "RelocInfo (size = " << reloc_size_ << ")\n";
for (RelocIterator it(instructions(), reloc_info(), constant_pool());
!it.done(); it.next()) {
it.rinfo()->Print(isolate, os);
it.rinfo()->Print(nullptr, os);
}
os << "\n";
#endif // ENABLE_DISASSEMBLER
......@@ -514,10 +512,7 @@ WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code,
// made while iterating over the RelocInfo above.
Assembler::FlushICache(ret->instructions().start(),
ret->instructions().size());
if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(mstarzinger): don't need the isolate here.
ret->Print(code->GetIsolate());
}
if (FLAG_print_code || FLAG_print_wasm_code) ret->Print();
ret->Validate();
return ret;
}
......@@ -572,10 +567,7 @@ WasmCode* NativeModule::AddCode(
// made while iterating over the RelocInfo above.
Assembler::FlushICache(ret->instructions().start(),
ret->instructions().size());
if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(mstarzinger): don't need the isolate here.
ret->Print(module_object()->GetIsolate());
}
if (FLAG_print_code || FLAG_print_wasm_code) ret->Print();
ret->Validate();
return ret;
}
......
......@@ -152,8 +152,8 @@ class V8_EXPORT_PRIVATE WasmCode final {
}
void Validate() const;
void Print(Isolate* isolate) const;
void Disassemble(const char* name, Isolate* isolate, std::ostream& os,
void Print(const char* name = nullptr) const;
void Disassemble(const char* name, std::ostream& os,
Address current_pc = kNullAddress) const;
static bool ShouldBeLogged(Isolate* isolate);
......
......@@ -511,10 +511,8 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
// made while iterating over the RelocInfo above.
Assembler::FlushICache(ret->instructions().start(),
ret->instructions().size());
if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(mstarzinger): don't need the isolate here.
ret->Print(isolate_);
}
if (FLAG_print_code || FLAG_print_wasm_code) ret->Print();
ret->Validate();
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