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 {
namespace {
WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) {
Context* GetNativeContextFromWasmInstanceOnStackTop(Isolate* isolate) {
StackFrameIterator it(isolate, isolate->thread_local_top());
// On top: C entry stub.
DCHECK_EQ(StackFrame::EXIT, it.frame()->type());
it.Advance();
// Next: the wasm (compiled or interpreted) frame.
WasmInstanceObject* result = nullptr;
WasmInstanceObject* instance = nullptr;
if (it.frame()->is_wasm_compiled()) {
result = WasmCompiledFrame::cast(it.frame())->wasm_instance();
instance = WasmCompiledFrame::cast(it.frame())->wasm_instance();
} else {
DCHECK(it.frame()->is_wasm_interpreter_entry());
result = WasmInterpreterEntryFrame::cast(it.frame())->wasm_instance();
instance = WasmInterpreterEntryFrame::cast(it.frame())->wasm_instance();
}
return result;
}
Context* GetNativeContextFromWasmInstanceOnStackTop(Isolate* isolate) {
return GetWasmInstanceOnStackTop(isolate)->native_context();
return instance->native_context();
}
class ClearThreadInWasmScope {
......@@ -234,8 +230,6 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
HandleScope scope(isolate);
CONVERT_NUMBER_CHECKED(int32_t, func_index, Int32, args[0]);
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
// Smi (lowest bit not set, as checked by IsSmi), but is no valid Smi. We just
......@@ -246,11 +240,8 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
ClearThreadInWasmScope wasm_flag(true);
// Set the current isolate's context.
DCHECK_NULL(isolate->context());
isolate->set_context(instance->native_context());
// Find the frame pointer of the interpreter entry.
// Find the frame pointer and instance of the interpreter frame on the stack.
Handle<WasmInstanceObject> instance;
Address frame_pointer = 0;
{
StackFrameIterator it(isolate, isolate->thread_local_top());
......@@ -259,9 +250,15 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
it.Advance();
// Next: the wasm interpreter entry.
DCHECK_EQ(StackFrame::WASM_INTERPRETER_ENTRY, it.frame()->type());
instance = handle(
WasmInterpreterEntryFrame::cast(it.frame())->wasm_instance(), isolate);
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}
// nor the {InterpreterHandle} have to exist, because interpretation might
// 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