[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/+/2235543
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68258}
This commit is contained in:
Clemens Backes 2020-06-08 22:47:45 +02:00 committed by Commit Bot
parent 206a88ba86
commit 6e903d93e6
5 changed files with 22 additions and 40 deletions

View File

@ -1024,21 +1024,6 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
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
Handle<Code> WasmDebugInfo::GetCWasmEntry(Handle<WasmDebugInfo> debug_info,
const wasm::FunctionSig* sig) {

View File

@ -840,13 +840,6 @@ class WasmDebugInfo : public Struct {
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>,
const wasm::FunctionSig*);

View File

@ -67,7 +67,9 @@ TestingModuleBuilder::TestingModuleBuilder(
}
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_);
}
}

View File

@ -204,7 +204,7 @@ class TestingModuleBuilder {
return &test_module_->functions[index];
}
WasmInterpreter* interpreter() const { return interpreter_; }
WasmInterpreter* interpreter() const { return interpreter_.get(); }
bool interpret() const { return interpreter_ != nullptr; }
LowerSimd lower_simd() const { return lower_simd_; }
Isolate* isolate() const { return isolate_; }
@ -243,7 +243,7 @@ class TestingModuleBuilder {
byte* mem_start_ = nullptr;
uint32_t mem_size_ = 0;
alignas(16) byte globals_data_[kMaxGlobalsSize];
WasmInterpreter* interpreter_ = nullptr;
std::unique_ptr<WasmInterpreter> interpreter_;
ExecutionTier execution_tier_;
Handle<WasmInstanceObject> instance_object_;
NativeModule* native_module_ = nullptr;

View File

@ -126,12 +126,13 @@ bool InterpretWasmModuleForTesting(Isolate* isolate,
Zone zone(isolate->allocator(), ZONE_NAME);
WasmInterpreter* interpreter = WasmDebugInfo::SetupForTesting(instance);
interpreter->Reset();
interpreter->InitFrame(&instance->module()->functions[function_index],
arguments.get());
WasmInterpreter::State interpreter_result = interpreter->Run(kMaxNumSteps);
WasmInterpreter interpreter{
isolate, instance->module(),
ModuleWireBytes{instance->module_object().native_module()->wire_bytes()},
instance};
interpreter.InitFrame(&instance->module()->functions[function_index],
arguments.get());
WasmInterpreter::State interpreter_result = interpreter.Run(kMaxNumSteps);
if (isolate->has_pending_exception()) {
// Stack overflow during interpretation.
@ -197,26 +198,27 @@ WasmInterpretationResult InterpretWasmModule(
Zone zone(isolate->allocator(), ZONE_NAME);
v8::internal::HandleScope scope(isolate);
WasmInterpreter* interpreter = WasmDebugInfo::SetupForTesting(instance);
interpreter->Reset();
interpreter->InitFrame(&instance->module()->functions[function_index], args);
WasmInterpreter::State interpreter_result = interpreter->Run(kMaxNumSteps);
WasmInterpreter interpreter{
isolate, instance->module(),
ModuleWireBytes{instance->module_object().native_module()->wire_bytes()},
instance};
interpreter.InitFrame(&instance->module()->functions[function_index], args);
WasmInterpreter::State interpreter_result = interpreter.Run(kMaxNumSteps);
bool stack_overflow = isolate->has_pending_exception();
isolate->clear_pending_exception();
if (stack_overflow) return WasmInterpretationResult::Stopped();
if (interpreter->state() == WasmInterpreter::TRAPPED) {
if (interpreter.state() == WasmInterpreter::TRAPPED) {
return WasmInterpretationResult::Trapped(
interpreter->PossibleNondeterminism());
interpreter.PossibleNondeterminism());
}
if (interpreter_result == WasmInterpreter::FINISHED) {
return WasmInterpretationResult::Finished(
interpreter->GetReturnValue().to<int32_t>(),
interpreter->PossibleNondeterminism());
interpreter.GetReturnValue().to<int32_t>(),
interpreter.PossibleNondeterminism());
}
return WasmInterpretationResult::Stopped();