[wasm] Reduce usage of frame->wasm_instance()

As part of the effort to despecialize WASM code, convert many uses of
WasmInstanceObject which were simply indirecting through to either
the compiled module or the shared module data with helpers on
the respective Frame objects.

R=mstarzinger@chromium.org

Bug: 
Change-Id: I05bd1a18b1d81cceef8a80d9f6988e4f5d537e66
Reviewed-on: https://chromium-review.googlesource.com/876125
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50798}
This commit is contained in:
Ben L. Titzer 2018-01-23 12:46:51 +01:00 committed by Commit Bot
parent ecb3afcaed
commit 66ce6153df
10 changed files with 66 additions and 47 deletions

View File

@ -43,8 +43,9 @@ FrameInspector::FrameInspector(StandardFrame* frame, int inlined_frame_index,
js_frame, inlined_frame_index, isolate)); js_frame, inlined_frame_index, isolate));
} else if (frame_->is_wasm_interpreter_entry()) { } else if (frame_->is_wasm_interpreter_entry()) {
wasm_interpreted_frame_ = wasm_interpreted_frame_ =
summary.AsWasm().wasm_instance()->debug_info()->GetInterpretedFrame( WasmInterpreterEntryFrame::cast(frame_)
frame_->fp(), inlined_frame_index); ->debug_info()
->GetInterpretedFrame(frame_->fp(), inlined_frame_index);
DCHECK(wasm_interpreted_frame_); DCHECK(wasm_interpreted_frame_);
} }
} }

View File

@ -176,8 +176,7 @@ v8::debug::ScopeIterator::ScopeType DebugWasmScopeIterator::GetType() {
v8::Local<v8::Object> DebugWasmScopeIterator::GetObject() { v8::Local<v8::Object> DebugWasmScopeIterator::GetObject() {
DCHECK(!Done()); DCHECK(!Done());
Handle<WasmDebugInfo> debug_info( Handle<WasmDebugInfo> debug_info(
WasmInterpreterEntryFrame::cast(frame_)->wasm_instance()->debug_info(), WasmInterpreterEntryFrame::cast(frame_)->debug_info(), isolate_);
isolate_);
switch (type_) { switch (type_) {
case debug::ScopeIterator::ScopeTypeGlobal: case debug::ScopeIterator::ScopeTypeGlobal:
return Utils::ToLocal(WasmDebugInfo::GetGlobalScopeObject( return Utils::ToLocal(WasmDebugInfo::GetGlobalScopeObject(

View File

@ -929,7 +929,7 @@ void Debug::PrepareStep(StepAction step_action) {
if (frame->is_wasm_compiled()) return; if (frame->is_wasm_compiled()) return;
WasmInterpreterEntryFrame* wasm_frame = WasmInterpreterEntryFrame* wasm_frame =
WasmInterpreterEntryFrame::cast(frame); WasmInterpreterEntryFrame::cast(frame);
wasm_frame->wasm_instance()->debug_info()->PrepareStep(step_action); wasm_frame->debug_info()->PrepareStep(step_action);
return; return;
} }

View File

@ -189,6 +189,20 @@ DISABLE_ASAN Address ReadMemoryAt(Address address) {
return Memory::Address_at(address); return Memory::Address_at(address);
} }
WasmInstanceObject* LookupWasmInstanceObjectFromStandardFrame(
const StandardFrame* frame) {
// TODO(titzer): WASM instances cannot be found from the code in the future.
WasmInstanceObject* ret =
FLAG_wasm_jit_to_native
? WasmInstanceObject::GetOwningInstance(
frame->isolate()->wasm_engine()->code_manager()->LookupCode(
frame->pc()))
: WasmInstanceObject::GetOwningInstanceGC(frame->LookupCode());
// This is a live stack frame, there must be a live wasm instance available.
DCHECK_NOT_NULL(ret);
return ret;
}
} // namespace } // namespace
SafeStackFrameIterator::SafeStackFrameIterator( SafeStackFrameIterator::SafeStackFrameIterator(
@ -1711,9 +1725,8 @@ void WasmCompiledFrame::Print(StringStream* accumulator, PrintMode mode,
.start() .start()
: LookupCode()->instruction_start(); : LookupCode()->instruction_start();
int pc = static_cast<int>(this->pc() - instruction_start); int pc = static_cast<int>(this->pc() - instruction_start);
WasmSharedModuleData* shared = wasm_instance()->compiled_module()->shared();
Vector<const uint8_t> raw_func_name = Vector<const uint8_t> raw_func_name =
shared->GetRawFunctionName(this->function_index()); shared()->GetRawFunctionName(this->function_index());
const int kMaxPrintedFunctionName = 64; const int kMaxPrintedFunctionName = 64;
char func_name[kMaxPrintedFunctionName + 1]; char func_name[kMaxPrintedFunctionName + 1];
int func_name_len = std::min(kMaxPrintedFunctionName, raw_func_name.length()); int func_name_len = std::min(kMaxPrintedFunctionName, raw_func_name.length());
@ -1744,23 +1757,24 @@ WasmCodeWrapper WasmCompiledFrame::wasm_code() const {
} }
WasmInstanceObject* WasmCompiledFrame::wasm_instance() const { WasmInstanceObject* WasmCompiledFrame::wasm_instance() const {
WasmInstanceObject* obj = return LookupWasmInstanceObjectFromStandardFrame(this);
FLAG_wasm_jit_to_native }
? WasmInstanceObject::GetOwningInstance(
isolate()->wasm_engine()->code_manager()->LookupCode(pc())) WasmSharedModuleData* WasmCompiledFrame::shared() const {
: WasmInstanceObject::GetOwningInstanceGC(LookupCode()); return LookupWasmInstanceObjectFromStandardFrame(this)
// This is a live stack frame; it must have a live instance. ->compiled_module()
DCHECK_NOT_NULL(obj); ->shared();
return obj; }
WasmCompiledModule* WasmCompiledFrame::compiled_module() const {
return LookupWasmInstanceObjectFromStandardFrame(this)->compiled_module();
} }
uint32_t WasmCompiledFrame::function_index() const { uint32_t WasmCompiledFrame::function_index() const {
return FrameSummary::GetSingle(this).AsWasmCompiled().function_index(); return FrameSummary::GetSingle(this).AsWasmCompiled().function_index();
} }
Script* WasmCompiledFrame::script() const { Script* WasmCompiledFrame::script() const { return shared()->script(); }
return wasm_instance()->compiled_module()->shared()->script();
}
int WasmCompiledFrame::position() const { int WasmCompiledFrame::position() const {
return FrameSummary::GetSingle(this).SourcePosition(); return FrameSummary::GetSingle(this).SourcePosition();
@ -1770,7 +1784,8 @@ void WasmCompiledFrame::Summarize(std::vector<FrameSummary>* functions) const {
DCHECK(functions->empty()); DCHECK(functions->empty());
WasmCodeWrapper code = wasm_code(); WasmCodeWrapper code = wasm_code();
int offset = static_cast<int>(pc() - code.instructions().start()); int offset = static_cast<int>(pc() - code.instructions().start());
Handle<WasmInstanceObject> instance = code.wasm_instance(); Handle<WasmInstanceObject> instance(
LookupWasmInstanceObjectFromStandardFrame(this), isolate());
FrameSummary::WasmCompiledFrameSummary summary( FrameSummary::WasmCompiledFrameSummary summary(
isolate(), instance, code, offset, at_to_number_conversion()); isolate(), instance, code, offset, at_to_number_conversion());
functions->push_back(summary); functions->push_back(summary);
@ -1841,7 +1856,8 @@ void WasmInterpreterEntryFrame::Print(StringStream* accumulator, PrintMode mode,
void WasmInterpreterEntryFrame::Summarize( void WasmInterpreterEntryFrame::Summarize(
std::vector<FrameSummary>* functions) const { std::vector<FrameSummary>* functions) const {
Handle<WasmInstanceObject> instance(wasm_instance(), isolate()); Handle<WasmInstanceObject> instance(
LookupWasmInstanceObjectFromStandardFrame(this), isolate());
std::vector<std::pair<uint32_t, int>> interpreted_stack = std::vector<std::pair<uint32_t, int>> interpreted_stack =
instance->debug_info()->GetInterpretedStack(fp()); instance->debug_info()->GetInterpretedStack(fp());
@ -1860,27 +1876,33 @@ Code* WasmInterpreterEntryFrame::unchecked_code() const {
} }
} }
// TODO(titzer): deprecate this method.
WasmInstanceObject* WasmInterpreterEntryFrame::wasm_instance() const { WasmInstanceObject* WasmInterpreterEntryFrame::wasm_instance() const {
WasmInstanceObject* ret = return LookupWasmInstanceObjectFromStandardFrame(this);
FLAG_wasm_jit_to_native
? WasmInstanceObject::GetOwningInstance(
isolate()->wasm_engine()->code_manager()->LookupCode(pc()))
: WasmInstanceObject::GetOwningInstanceGC(LookupCode());
// This is a live stack frame, there must be a live wasm instance available.
DCHECK_NOT_NULL(ret);
return ret;
} }
Script* WasmInterpreterEntryFrame::script() const { WasmDebugInfo* WasmInterpreterEntryFrame::debug_info() const {
return wasm_instance()->compiled_module()->shared()->script(); return LookupWasmInstanceObjectFromStandardFrame(this)->debug_info();
} }
WasmSharedModuleData* WasmInterpreterEntryFrame::shared() const {
return LookupWasmInstanceObjectFromStandardFrame(this)
->compiled_module()
->shared();
}
WasmCompiledModule* WasmInterpreterEntryFrame::compiled_module() const {
return LookupWasmInstanceObjectFromStandardFrame(this)->compiled_module();
}
Script* WasmInterpreterEntryFrame::script() const { return shared()->script(); }
int WasmInterpreterEntryFrame::position() const { int WasmInterpreterEntryFrame::position() const {
return FrameSummary::GetBottom(this).AsWasmInterpreted().SourcePosition(); return FrameSummary::GetBottom(this).AsWasmInterpreted().SourcePosition();
} }
Object* WasmInterpreterEntryFrame::context() const { Object* WasmInterpreterEntryFrame::context() const {
return wasm_instance()->compiled_module()->native_context(); return compiled_module()->native_context();
} }
Address WasmInterpreterEntryFrame::GetCallerStackPointer() const { Address WasmInterpreterEntryFrame::GetCallerStackPointer() const {

View File

@ -30,6 +30,9 @@ class RootVisitor;
class StackFrameIteratorBase; class StackFrameIteratorBase;
class ThreadLocalTop; class ThreadLocalTop;
class WasmInstanceObject; class WasmInstanceObject;
class WasmSharedModuleData;
class WasmDebugInfo;
class WasmCompiledModule;
class InnerPointerToCodeCache { class InnerPointerToCodeCache {
public: public:
@ -973,7 +976,7 @@ class WasmCompiledFrame final : public StandardFrame {
Code* unchecked_code() const override; Code* unchecked_code() const override;
// Accessors. // Accessors.
WasmInstanceObject* wasm_instance() const; WasmInstanceObject* wasm_instance() const; // TODO(titzer): deprecate.
WasmCodeWrapper wasm_code() const; WasmCodeWrapper wasm_code() const;
uint32_t function_index() const; uint32_t function_index() const;
Script* script() const override; Script* script() const override;
@ -994,6 +997,8 @@ class WasmCompiledFrame final : public StandardFrame {
private: private:
friend class StackFrameIteratorBase; friend class StackFrameIteratorBase;
WasmCompiledModule* compiled_module() const;
WasmSharedModuleData* shared() const;
}; };
class WasmInterpreterEntryFrame final : public StandardFrame { class WasmInterpreterEntryFrame final : public StandardFrame {
@ -1013,7 +1018,9 @@ class WasmInterpreterEntryFrame final : public StandardFrame {
Code* unchecked_code() const override; Code* unchecked_code() const override;
// Accessors. // Accessors.
WasmInstanceObject* wasm_instance() const; WasmDebugInfo* debug_info() const;
WasmInstanceObject* wasm_instance() const; // TODO(titzer): deprecate.
Script* script() const override; Script* script() const override;
int position() const override; int position() const override;
Object* context() const override; Object* context() const override;
@ -1030,6 +1037,8 @@ class WasmInterpreterEntryFrame final : public StandardFrame {
private: private:
friend class StackFrameIteratorBase; friend class StackFrameIteratorBase;
WasmCompiledModule* compiled_module() const;
WasmSharedModuleData* shared() const;
}; };
class WasmToJsFrame : public StubFrame { class WasmToJsFrame : public StubFrame {

View File

@ -1425,7 +1425,7 @@ Object* Isolate::UnwindAndFindHandler() {
WasmInterpreterEntryFrame* interpreter_frame = WasmInterpreterEntryFrame* interpreter_frame =
WasmInterpreterEntryFrame::cast(frame); WasmInterpreterEntryFrame::cast(frame);
// TODO(wasm): Implement try-catch in the interpreter. // TODO(wasm): Implement try-catch in the interpreter.
interpreter_frame->wasm_instance()->debug_info()->Unwind(frame->fp()); interpreter_frame->debug_info()->Unwind(frame->fp());
} break; } break;
default: default:

View File

@ -856,8 +856,7 @@ RUNTIME_FUNCTION(Runtime_GetAllScopesDetails) {
// local). // local).
if (frame->is_wasm_interpreter_entry()) { if (frame->is_wasm_interpreter_entry()) {
Handle<WasmDebugInfo> debug_info( Handle<WasmDebugInfo> debug_info(
WasmInterpreterEntryFrame::cast(frame)->wasm_instance()->debug_info(), WasmInterpreterEntryFrame::cast(frame)->debug_info(), isolate);
isolate);
return *WasmDebugInfo::GetScopeDetails(debug_info, frame->fp(), return *WasmDebugInfo::GetScopeDetails(debug_info, frame->fp(),
inlined_frame_index); inlined_frame_index);
} }

View File

@ -59,11 +59,5 @@ Vector<uint8_t> WasmCodeWrapper::instructions() const {
static_cast<size_t>(code->instruction_size())}; static_cast<size_t>(code->instruction_size())};
} }
Handle<WasmInstanceObject> WasmCodeWrapper::wasm_instance() const {
return IsCodeObject()
? handle(WasmInstanceObject::GetOwningInstanceGC(*GetCode()))
: handle(WasmInstanceObject::GetOwningInstance(GetWasmCode()));
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8

View File

@ -30,8 +30,6 @@ class WasmCodeWrapper {
Vector<uint8_t> instructions() const; Vector<uint8_t> instructions() const;
Handle<WasmInstanceObject> wasm_instance() const;
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
void Disassemble(const char* name, Isolate* isolate, std::ostream& os) const; void Disassemble(const char* name, Isolate* isolate, std::ostream& os) const;
#endif #endif

View File

@ -438,7 +438,6 @@ class InterpreterHandle {
Handle<JSObject> GetLocalScopeObject(wasm::InterpretedFrame* frame, Handle<JSObject> GetLocalScopeObject(wasm::InterpretedFrame* frame,
Handle<WasmDebugInfo> debug_info) { Handle<WasmDebugInfo> debug_info) {
Isolate* isolate = debug_info->GetIsolate(); Isolate* isolate = debug_info->GetIsolate();
Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate);
Handle<JSObject> local_scope_object = Handle<JSObject> local_scope_object =
isolate_->factory()->NewJSObjectWithNullProto(); isolate_->factory()->NewJSObjectWithNullProto();
@ -497,8 +496,6 @@ class InterpreterHandle {
Handle<JSArray> GetScopeDetails(Address frame_pointer, int frame_index, Handle<JSArray> GetScopeDetails(Address frame_pointer, int frame_index,
Handle<WasmDebugInfo> debug_info) { Handle<WasmDebugInfo> debug_info) {
auto frame = GetInterpretedFrame(frame_pointer, frame_index); auto frame = GetInterpretedFrame(frame_pointer, frame_index);
Isolate* isolate = debug_info->GetIsolate();
Handle<WasmInstanceObject> instance(debug_info->wasm_instance(), isolate);
Handle<FixedArray> global_scope = Handle<FixedArray> global_scope =
isolate_->factory()->NewFixedArray(ScopeIterator::kScopeDetailsSize); isolate_->factory()->NewFixedArray(ScopeIterator::kScopeDetailsSize);