Commit 4a5650bf authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Avoid redundant stack-walk in {WasmRunInterpreter}.

R=clemensh@chromium.org
BUG=v8:8015

Change-Id: Ib40817fffe64a7b8774b7f33adf7552284859064
Reviewed-on: https://chromium-review.googlesource.com/1224435Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55869}
parent 5ad91b27
...@@ -24,24 +24,20 @@ namespace internal { ...@@ -24,24 +24,20 @@ namespace internal {
namespace { namespace {
WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) { Context* GetNativeContextFromWasmInstanceOnStackTop(Isolate* isolate) {
StackFrameIterator it(isolate, isolate->thread_local_top()); StackFrameIterator it(isolate, isolate->thread_local_top());
// On top: C entry stub. // On top: C entry stub.
DCHECK_EQ(StackFrame::EXIT, it.frame()->type()); DCHECK_EQ(StackFrame::EXIT, it.frame()->type());
it.Advance(); it.Advance();
// Next: the wasm (compiled or interpreted) frame. // Next: the wasm (compiled or interpreted) frame.
WasmInstanceObject* result = nullptr; WasmInstanceObject* instance = nullptr;
if (it.frame()->is_wasm_compiled()) { if (it.frame()->is_wasm_compiled()) {
result = WasmCompiledFrame::cast(it.frame())->wasm_instance(); instance = WasmCompiledFrame::cast(it.frame())->wasm_instance();
} else { } else {
DCHECK(it.frame()->is_wasm_interpreter_entry()); DCHECK(it.frame()->is_wasm_interpreter_entry());
result = WasmInterpreterEntryFrame::cast(it.frame())->wasm_instance(); instance = WasmInterpreterEntryFrame::cast(it.frame())->wasm_instance();
} }
return result; return instance->native_context();
}
Context* GetNativeContextFromWasmInstanceOnStackTop(Isolate* isolate) {
return GetWasmInstanceOnStackTop(isolate)->native_context();
} }
class ClearThreadInWasmScope { class ClearThreadInWasmScope {
...@@ -234,8 +230,6 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) { ...@@ -234,8 +230,6 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
HandleScope scope(isolate); HandleScope scope(isolate);
CONVERT_NUMBER_CHECKED(int32_t, func_index, Int32, args[0]); CONVERT_NUMBER_CHECKED(int32_t, func_index, Int32, args[0]);
CONVERT_ARG_HANDLE_CHECKED(Object, arg_buffer_obj, 1); CONVERT_ARG_HANDLE_CHECKED(Object, arg_buffer_obj, 1);
Handle<WasmInstanceObject> instance(GetWasmInstanceOnStackTop(isolate),
isolate);
// The arg buffer is the raw pointer to the caller's stack. It looks like a // The arg buffer is the raw pointer to the caller's stack. It looks like a
// Smi (lowest bit not set, as checked by IsSmi), but is no valid Smi. We just // Smi (lowest bit not set, as checked by IsSmi), but is no valid Smi. We just
...@@ -246,11 +240,8 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) { ...@@ -246,11 +240,8 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
ClearThreadInWasmScope wasm_flag(true); ClearThreadInWasmScope wasm_flag(true);
// Set the current isolate's context. // Find the frame pointer and instance of the interpreter frame on the stack.
DCHECK_NULL(isolate->context()); Handle<WasmInstanceObject> instance;
isolate->set_context(instance->native_context());
// Find the frame pointer of the interpreter entry.
Address frame_pointer = 0; Address frame_pointer = 0;
{ {
StackFrameIterator it(isolate, isolate->thread_local_top()); StackFrameIterator it(isolate, isolate->thread_local_top());
...@@ -259,9 +250,15 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) { ...@@ -259,9 +250,15 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
it.Advance(); it.Advance();
// Next: the wasm interpreter entry. // Next: the wasm interpreter entry.
DCHECK_EQ(StackFrame::WASM_INTERPRETER_ENTRY, it.frame()->type()); DCHECK_EQ(StackFrame::WASM_INTERPRETER_ENTRY, it.frame()->type());
instance = handle(
WasmInterpreterEntryFrame::cast(it.frame())->wasm_instance(), isolate);
frame_pointer = it.frame()->fp(); frame_pointer = it.frame()->fp();
} }
// Set the current isolate's context.
DCHECK_NULL(isolate->context());
isolate->set_context(instance->native_context());
// Run the function in the interpreter. Note that neither the {WasmDebugInfo} // Run the function in the interpreter. Note that neither the {WasmDebugInfo}
// nor the {InterpreterHandle} have to exist, because interpretation might // nor the {InterpreterHandle} have to exist, because interpretation might
// have been triggered by another Isolate sharing the same WasmEngine. // have been triggered by another Isolate sharing the same WasmEngine.
......
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