Commit 6e903d93 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Instantiate interpreter for testing directly

Avoid going through the {WasmDebugInfo}, which existed for debugging in
the interpreter in production. Instead, tests now instantiate the
interpreter directly.

This will unblock the removal of the whole {WasmDebugInfo}, and finally
moving the interpreter to the test directory.

R=ahaas@chromium.org

Bug: v8:10389
Change-Id: I8ae76a1d5bff716c129781b11a15369a80b13603
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2235543Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68258}
parent 206a88ba
...@@ -1024,21 +1024,6 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { ...@@ -1024,21 +1024,6 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
return debug_info; return debug_info;
} }
wasm::WasmInterpreter* WasmDebugInfo::SetupForTesting(
Handle<WasmInstanceObject> instance_obj) {
Handle<WasmDebugInfo> debug_info = WasmDebugInfo::New(instance_obj);
Isolate* isolate = instance_obj->GetIsolate();
// Use the maximum stack size to estimate the maximum size of the interpreter.
// The interpreter keeps its own stack internally, and the size of the stack
// should dominate the overall size of the interpreter. We multiply by '2' to
// account for the growing strategy for the backing store of the stack.
size_t interpreter_size = FLAG_stack_size * KB * 2;
auto interp_handle = Managed<wasm::InterpreterHandle>::Allocate(
isolate, interpreter_size, isolate, debug_info);
debug_info->set_interpreter_handle(*interp_handle);
return interp_handle->raw()->interpreter();
}
// static // static
Handle<Code> WasmDebugInfo::GetCWasmEntry(Handle<WasmDebugInfo> debug_info, Handle<Code> WasmDebugInfo::GetCWasmEntry(Handle<WasmDebugInfo> debug_info,
const wasm::FunctionSig* sig) { const wasm::FunctionSig* sig) {
......
...@@ -840,13 +840,6 @@ class WasmDebugInfo : public Struct { ...@@ -840,13 +840,6 @@ class WasmDebugInfo : public Struct {
static Handle<WasmDebugInfo> New(Handle<WasmInstanceObject>); static Handle<WasmDebugInfo> New(Handle<WasmInstanceObject>);
// Setup a WasmDebugInfo with an existing WasmInstance struct.
// Returns a pointer to the interpreter instantiated inside this
// WasmDebugInfo.
// Use for testing only.
V8_EXPORT_PRIVATE static wasm::WasmInterpreter* SetupForTesting(
Handle<WasmInstanceObject>);
V8_EXPORT_PRIVATE static Handle<Code> GetCWasmEntry(Handle<WasmDebugInfo>, V8_EXPORT_PRIVATE static Handle<Code> GetCWasmEntry(Handle<WasmDebugInfo>,
const wasm::FunctionSig*); const wasm::FunctionSig*);
......
...@@ -67,7 +67,9 @@ TestingModuleBuilder::TestingModuleBuilder( ...@@ -67,7 +67,9 @@ TestingModuleBuilder::TestingModuleBuilder(
} }
if (tier == ExecutionTier::kInterpreter) { if (tier == ExecutionTier::kInterpreter) {
interpreter_ = WasmDebugInfo::SetupForTesting(instance_object_); interpreter_ = std::make_unique<WasmInterpreter>(
isolate_, test_module_ptr_,
ModuleWireBytes{native_module_->wire_bytes()}, instance_object_);
} }
} }
......
...@@ -204,7 +204,7 @@ class TestingModuleBuilder { ...@@ -204,7 +204,7 @@ class TestingModuleBuilder {
return &test_module_->functions[index]; return &test_module_->functions[index];
} }
WasmInterpreter* interpreter() const { return interpreter_; } WasmInterpreter* interpreter() const { return interpreter_.get(); }
bool interpret() const { return interpreter_ != nullptr; } bool interpret() const { return interpreter_ != nullptr; }
LowerSimd lower_simd() const { return lower_simd_; } LowerSimd lower_simd() const { return lower_simd_; }
Isolate* isolate() const { return isolate_; } Isolate* isolate() const { return isolate_; }
...@@ -243,7 +243,7 @@ class TestingModuleBuilder { ...@@ -243,7 +243,7 @@ class TestingModuleBuilder {
byte* mem_start_ = nullptr; byte* mem_start_ = nullptr;
uint32_t mem_size_ = 0; uint32_t mem_size_ = 0;
alignas(16) byte globals_data_[kMaxGlobalsSize]; alignas(16) byte globals_data_[kMaxGlobalsSize];
WasmInterpreter* interpreter_ = nullptr; std::unique_ptr<WasmInterpreter> interpreter_;
ExecutionTier execution_tier_; ExecutionTier execution_tier_;
Handle<WasmInstanceObject> instance_object_; Handle<WasmInstanceObject> instance_object_;
NativeModule* native_module_ = nullptr; NativeModule* native_module_ = nullptr;
......
...@@ -126,12 +126,13 @@ bool InterpretWasmModuleForTesting(Isolate* isolate, ...@@ -126,12 +126,13 @@ bool InterpretWasmModuleForTesting(Isolate* isolate,
Zone zone(isolate->allocator(), ZONE_NAME); Zone zone(isolate->allocator(), ZONE_NAME);
WasmInterpreter* interpreter = WasmDebugInfo::SetupForTesting(instance); WasmInterpreter interpreter{
interpreter->Reset(); isolate, instance->module(),
ModuleWireBytes{instance->module_object().native_module()->wire_bytes()},
interpreter->InitFrame(&instance->module()->functions[function_index], instance};
arguments.get()); interpreter.InitFrame(&instance->module()->functions[function_index],
WasmInterpreter::State interpreter_result = interpreter->Run(kMaxNumSteps); arguments.get());
WasmInterpreter::State interpreter_result = interpreter.Run(kMaxNumSteps);
if (isolate->has_pending_exception()) { if (isolate->has_pending_exception()) {
// Stack overflow during interpretation. // Stack overflow during interpretation.
...@@ -197,26 +198,27 @@ WasmInterpretationResult InterpretWasmModule( ...@@ -197,26 +198,27 @@ WasmInterpretationResult InterpretWasmModule(
Zone zone(isolate->allocator(), ZONE_NAME); Zone zone(isolate->allocator(), ZONE_NAME);
v8::internal::HandleScope scope(isolate); v8::internal::HandleScope scope(isolate);
WasmInterpreter* interpreter = WasmDebugInfo::SetupForTesting(instance); WasmInterpreter interpreter{
interpreter->Reset(); isolate, instance->module(),
ModuleWireBytes{instance->module_object().native_module()->wire_bytes()},
interpreter->InitFrame(&instance->module()->functions[function_index], args); instance};
WasmInterpreter::State interpreter_result = interpreter->Run(kMaxNumSteps); interpreter.InitFrame(&instance->module()->functions[function_index], args);
WasmInterpreter::State interpreter_result = interpreter.Run(kMaxNumSteps);
bool stack_overflow = isolate->has_pending_exception(); bool stack_overflow = isolate->has_pending_exception();
isolate->clear_pending_exception(); isolate->clear_pending_exception();
if (stack_overflow) return WasmInterpretationResult::Stopped(); if (stack_overflow) return WasmInterpretationResult::Stopped();
if (interpreter->state() == WasmInterpreter::TRAPPED) { if (interpreter.state() == WasmInterpreter::TRAPPED) {
return WasmInterpretationResult::Trapped( return WasmInterpretationResult::Trapped(
interpreter->PossibleNondeterminism()); interpreter.PossibleNondeterminism());
} }
if (interpreter_result == WasmInterpreter::FINISHED) { if (interpreter_result == WasmInterpreter::FINISHED) {
return WasmInterpretationResult::Finished( return WasmInterpretationResult::Finished(
interpreter->GetReturnValue().to<int32_t>(), interpreter.GetReturnValue().to<int32_t>(),
interpreter->PossibleNondeterminism()); interpreter.PossibleNondeterminism());
} }
return WasmInterpretationResult::Stopped(); return WasmInterpretationResult::Stopped();
......
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