Commit c64c060b authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Remove WasmDebugInfo and InterpreterHandle

The interpreter is only used for testing, and is now instantiated and
invoked directly instead of via the {WasmDebugInfo}, holding the
{InterpreterHandle}.

This CL removes both classes.

R=ahaas@chromium.org

Bug: v8:10389
Change-Id: Iede3feea413decae1edc28146b871a819e204768
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2237132Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68271}
parent ba688c6e
......@@ -73,7 +73,6 @@ class PromiseFulfillReactionJobTask;
class PromiseReaction;
class PromiseReactionJobTask;
class PromiseRejectReactionJobTask;
class WasmDebugInfo;
class Zone;
#define MAKE_FORWARD_DECLARATION(Name) class Name;
TORQUE_INTERNAL_CLASS_LIST(MAKE_FORWARD_DECLARATION)
......
......@@ -357,7 +357,6 @@ Type::bitset BitsetType::Lub(const MapRefLike& map) {
case ENUM_CACHE_TYPE:
case WASM_CAPI_FUNCTION_DATA_TYPE:
case WASM_INDIRECT_FUNCTION_TABLE_TYPE:
case WASM_DEBUG_INFO_TYPE:
case WASM_EXCEPTION_TAG_TYPE:
case WASM_EXPORTED_FUNCTION_DATA_TYPE:
case WASM_JS_FUNCTION_DATA_TYPE:
......
......@@ -138,7 +138,8 @@ enum CWasmEntryParameters {
// Compiles a stub with C++ linkage, to be called from Execution::CallWasm,
// which knows how to feed it its parameters.
MaybeHandle<Code> CompileCWasmEntry(Isolate*, const wasm::FunctionSig*);
V8_EXPORT_PRIVATE MaybeHandle<Code> CompileCWasmEntry(Isolate*,
const wasm::FunctionSig*);
// Values from the instance object are cached between Wasm-level function calls.
// This struct allows the SSA environment handling this cache to be defined
......
......@@ -1426,8 +1426,6 @@ void ObjectBoilerplateDescription::ObjectBoilerplateDescriptionVerify(
USE_TORQUE_VERIFIER(AsmWasmData)
USE_TORQUE_VERIFIER(WasmDebugInfo)
void WasmInstanceObject::WasmInstanceObjectVerify(Isolate* isolate) {
JSObjectVerify(isolate);
CHECK(IsWasmInstanceObject());
......
......@@ -1728,12 +1728,6 @@ void WasmArray::WasmArrayPrint(std::ostream& os) { // NOLINT
os << "\n";
}
void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "WasmDebugInfo");
os << "\n - wasm_instance: " << Brief(wasm_instance());
os << "\n";
}
void WasmExceptionTag::WasmExceptionTagPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "WasmExceptionTag");
os << "\n - index: " << index();
......@@ -1758,9 +1752,6 @@ void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) { // NOLINT
os << "\n - imported_mutable_globals_buffers: "
<< Brief(imported_mutable_globals_buffers());
}
if (has_debug_info()) {
os << "\n - debug_info: " << Brief(debug_info());
}
for (int i = 0; i < tables().length(); i++) {
os << "\n - table " << i << ": " << Brief(tables().get(i));
}
......
......@@ -29,7 +29,6 @@ class RootVisitor;
class StackFrameIteratorBase;
class StringStream;
class ThreadLocalTop;
class WasmDebugInfo;
class WasmInstanceObject;
class WasmModuleObject;
......
......@@ -151,7 +151,6 @@ namespace internal {
V(_, TUPLE2_TYPE, Tuple2, tuple2) \
V(_, WASM_CAPI_FUNCTION_DATA_TYPE, WasmCapiFunctionData, \
wasm_capi_function_data) \
V(_, WASM_DEBUG_INFO_TYPE, WasmDebugInfo, wasm_debug_info) \
V(_, WASM_EXCEPTION_TAG_TYPE, WasmExceptionTag, wasm_exception_tag) \
V(_, WASM_EXPORTED_FUNCTION_DATA_TYPE, WasmExportedFunctionData, \
wasm_exported_function_data) \
......
......@@ -9,6 +9,7 @@
#include "src/api/api-inl.h"
#include "src/codegen/machine-type.h"
#include "src/compiler/wasm-compiler.h"
#include "src/execution/frames-inl.h"
#include "src/wasm/value-type.h"
#include "src/wasm/wasm-arguments.h"
......@@ -350,10 +351,11 @@ Maybe<std::string> DebugEvaluateImpl(
Handle<WasmExportedFunction> entry_point =
Handle<WasmExportedFunction>::cast(entry_point_obj);
Handle<WasmDebugInfo> debug_info =
WasmInstanceObject::GetOrCreateDebugInfo(evaluator_instance);
// TODO(wasm): Cache this code.
Handle<Code> wasm_entry =
WasmDebugInfo::GetCWasmEntry(debug_info, entry_point->sig());
compiler::CompileCWasmEntry(isolate, entry_point->sig())
.ToHandleChecked();
CWasmArgumentsPacker packer(4 /* uint32_t return value, no parameters. */);
Execution::CallWasm(isolate, wasm_entry, entry_point->GetWasmCallTarget(),
evaluator_instance, packer.argv());
......
......@@ -155,99 +155,6 @@ MaybeHandle<String> GetLocalNameString(Isolate* isolate,
return isolate->factory()->NewStringFromUtf8(name);
}
class InterpreterHandle {
Isolate* isolate_;
const WasmModule* module_;
WasmInterpreter interpreter_;
std::unordered_map<Address, uint32_t> activations_;
static ModuleWireBytes GetBytes(WasmDebugInfo debug_info) {
// Return raw pointer into heap. The WasmInterpreter will make its own copy
// of this data anyway, and there is no heap allocation in-between.
NativeModule* native_module =
debug_info.wasm_instance().module_object().native_module();
return ModuleWireBytes{native_module->wire_bytes()};
}
public:
InterpreterHandle(Isolate* isolate, Handle<WasmDebugInfo> debug_info)
: isolate_(isolate),
module_(debug_info->wasm_instance().module_object().module()),
interpreter_(isolate, module_, GetBytes(*debug_info),
handle(debug_info->wasm_instance(), isolate)) {}
WasmInterpreter* interpreter() { return &interpreter_; }
const WasmModule* module() const { return module_; }
// Returns true if exited regularly, false if a trap/exception occurred and
// was not handled inside this activation. In the latter case, a pending
// exception will have been set on the isolate.
bool Execute(Handle<WasmInstanceObject> instance_object, uint32_t func_index,
Vector<WasmValue> argument_values,
Vector<WasmValue> return_values) {
DCHECK_GE(module()->functions.size(), func_index);
const FunctionSig* sig = module()->functions[func_index].sig;
DCHECK_EQ(sig->parameter_count(), argument_values.size());
DCHECK_EQ(sig->return_count(), return_values.size());
WasmCodeRefScope code_ref_scope;
interpreter_.InitFrame(&module()->functions[func_index],
argument_values.begin());
bool finished = false;
while (!finished) {
// TODO(clemensb): Add occasional StackChecks.
WasmInterpreter::State state = interpreter_.Run();
switch (state) {
case WasmInterpreter::State::PAUSED:
UNREACHABLE();
case WasmInterpreter::State::FINISHED:
// Perfect, just break the switch and exit the loop.
finished = true;
break;
case WasmInterpreter::State::TRAPPED: {
MessageTemplate message_id =
WasmOpcodes::TrapReasonToMessageId(interpreter_.GetTrapReason());
Handle<JSObject> exception =
isolate_->factory()->NewWasmRuntimeError(message_id);
JSObject::AddProperty(isolate_, exception,
isolate_->factory()->wasm_uncatchable_symbol(),
isolate_->factory()->true_value(), NONE);
auto result = interpreter_.RaiseException(isolate_, exception);
if (result == WasmInterpreter::HANDLED) break;
// If no local handler was found, we fall-thru to {STOPPED}.
DCHECK_EQ(WasmInterpreter::State::STOPPED, interpreter_.state());
V8_FALLTHROUGH;
}
case WasmInterpreter::State::STOPPED:
// An exception happened, and the current activation was unwound
// without hitting a local exception handler. Let the exception
// propagate.
DCHECK(isolate_->has_pending_exception());
return false;
// RUNNING should never occur here.
case WasmInterpreter::State::RUNNING:
UNREACHABLE();
}
}
// Copy back the return value.
#ifdef DEBUG
const int max_count = WasmFeatures::FromIsolate(isolate_).has_mv()
? kV8MaxWasmFunctionMultiReturns
: kV8MaxWasmFunctionReturns;
#endif
DCHECK_GE(max_count, sig->return_count());
for (unsigned i = 0; i < sig->return_count(); ++i) {
return_values[i] = interpreter_.GetReturnValue(i);
}
return true;
}
private:
DISALLOW_COPY_AND_ASSIGN(InterpreterHandle);
};
// Generate a sorted and deduplicated list of byte offsets for this function's
// current positions on the stack.
std::vector<int> StackFramePositions(int func_index, Isolate* isolate) {
......@@ -1014,47 +921,6 @@ void DebugInfo::RemoveIsolate(Isolate* isolate) {
} // namespace wasm
Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
DCHECK(!instance->has_debug_info());
Factory* factory = instance->GetIsolate()->factory();
Handle<WasmDebugInfo> debug_info = Handle<WasmDebugInfo>::cast(
factory->NewStruct(WASM_DEBUG_INFO_TYPE, AllocationType::kOld));
debug_info->set_wasm_instance(*instance);
instance->set_debug_info(*debug_info);
return debug_info;
}
// static
Handle<Code> WasmDebugInfo::GetCWasmEntry(Handle<WasmDebugInfo> debug_info,
const wasm::FunctionSig* sig) {
Isolate* isolate = debug_info->GetIsolate();
DCHECK_EQ(debug_info->has_c_wasm_entries(),
debug_info->has_c_wasm_entry_map());
if (!debug_info->has_c_wasm_entries()) {
auto entries = isolate->factory()->NewFixedArray(4, AllocationType::kOld);
debug_info->set_c_wasm_entries(*entries);
size_t map_size = 0; // size estimate not so important here.
auto managed_map = Managed<wasm::SignatureMap>::Allocate(isolate, map_size);
debug_info->set_c_wasm_entry_map(*managed_map);
}
Handle<FixedArray> entries(debug_info->c_wasm_entries(), isolate);
wasm::SignatureMap* map = debug_info->c_wasm_entry_map().raw();
int32_t index = map->Find(*sig);
if (index == -1) {
index = static_cast<int32_t>(map->FindOrInsert(*sig));
if (index == entries->length()) {
entries =
isolate->factory()->CopyFixedArrayAndGrow(entries, entries->length());
debug_info->set_c_wasm_entries(*entries);
}
DCHECK(entries->get(index).IsUndefined(isolate));
Handle<Code> new_entry_code =
compiler::CompileCWasmEntry(isolate, sig).ToHandleChecked();
entries->set(index, *new_entry_code);
}
return handle(Code::cast(entries->get(index)), isolate);
}
namespace {
// Return the next breakable position at or after {offset_in_func} in function
......
......@@ -30,7 +30,6 @@ namespace internal {
OBJECT_CONSTRUCTORS_IMPL(WasmExceptionObject, JSObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(WasmExceptionTag)
OBJECT_CONSTRUCTORS_IMPL(WasmExportedFunctionData, Struct)
OBJECT_CONSTRUCTORS_IMPL(WasmDebugInfo, Struct)
OBJECT_CONSTRUCTORS_IMPL(WasmGlobalObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(WasmInstanceObject, JSObject)
OBJECT_CONSTRUCTORS_IMPL(WasmMemoryObject, JSObject)
......@@ -40,9 +39,6 @@ OBJECT_CONSTRUCTORS_IMPL(AsmWasmData, Struct)
TQ_OBJECT_CONSTRUCTORS_IMPL(WasmStruct)
TQ_OBJECT_CONSTRUCTORS_IMPL(WasmArray)
NEVER_READ_ONLY_SPACE_IMPL(WasmDebugInfo)
CAST_ACCESSOR(WasmDebugInfo)
CAST_ACCESSOR(WasmExceptionObject)
CAST_ACCESSOR(WasmExportedFunctionData)
CAST_ACCESSOR(WasmGlobalObject)
......@@ -253,8 +249,6 @@ OPTIONAL_ACCESSORS(WasmInstanceObject, tagged_globals_buffer, FixedArray,
kTaggedGlobalsBufferOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, imported_mutable_globals_buffers,
FixedArray, kImportedMutableGlobalsBuffersOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo,
kDebugInfoOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, tables, FixedArray, kTablesOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, indirect_function_tables, FixedArray,
kIndirectFunctionTablesOffset)
......@@ -391,14 +385,6 @@ OPTIONAL_ACCESSORS(WasmIndirectFunctionTable, managed_native_allocations,
Foreign, kManagedNativeAllocationsOffset)
ACCESSORS(WasmIndirectFunctionTable, refs, FixedArray, kRefsOffset)
// WasmDebugInfo
ACCESSORS(WasmDebugInfo, wasm_instance, WasmInstanceObject, kInstanceOffset)
ACCESSORS(WasmDebugInfo, interpreter_handle, Object, kInterpreterHandleOffset)
OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entries, FixedArray,
kCWasmEntriesOffset)
OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
kCWasmEntryMapOffset)
#undef OPTIONAL_ACCESSORS
#undef READ_PRIMITIVE_FIELD
#undef WRITE_PRIMITIVE_FIELD
......
......@@ -1175,16 +1175,6 @@ const WasmModule* WasmInstanceObject::module() {
return module_object().module();
}
Handle<WasmDebugInfo> WasmInstanceObject::GetOrCreateDebugInfo(
Handle<WasmInstanceObject> instance) {
if (instance->has_debug_info()) {
return handle(instance->debug_info(), instance->GetIsolate());
}
Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(instance);
DCHECK(instance->has_debug_info());
return new_info;
}
Handle<WasmInstanceObject> WasmInstanceObject::New(
Isolate* isolate, Handle<WasmModuleObject> module_object) {
Handle<JSFunction> instance_cons(
......
......@@ -42,7 +42,6 @@ class BreakPoint;
class JSArrayBuffer;
class SeqOneByteString;
class WasmCapiFunction;
class WasmDebugInfo;
class WasmExceptionTag;
class WasmExportedFunction;
class WasmExternalFunction;
......@@ -379,7 +378,6 @@ class WasmInstanceObject : public JSObject {
DECL_OPTIONAL_ACCESSORS(untagged_globals_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS(tagged_globals_buffer, FixedArray)
DECL_OPTIONAL_ACCESSORS(imported_mutable_globals_buffers, FixedArray)
DECL_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo)
DECL_OPTIONAL_ACCESSORS(tables, FixedArray)
DECL_OPTIONAL_ACCESSORS(indirect_function_tables, FixedArray)
DECL_ACCESSORS(imported_function_refs, FixedArray)
......@@ -441,7 +439,6 @@ class WasmInstanceObject : public JSObject {
V(kUntaggedGlobalsBufferOffset, kTaggedSize) \
V(kTaggedGlobalsBufferOffset, kTaggedSize) \
V(kImportedMutableGlobalsBuffersOffset, kTaggedSize) \
V(kDebugInfoOffset, kTaggedSize) \
V(kTablesOffset, kTaggedSize) \
V(kIndirectFunctionTablesOffset, kTaggedSize) \
V(kManagedNativeAllocationsOffset, kTaggedSize) \
......@@ -480,7 +477,6 @@ class WasmInstanceObject : public JSObject {
kUntaggedGlobalsBufferOffset,
kTaggedGlobalsBufferOffset,
kImportedMutableGlobalsBuffersOffset,
kDebugInfoOffset,
kTablesOffset,
kIndirectFunctionTablesOffset,
kManagedNativeAllocationsOffset,
......@@ -496,11 +492,6 @@ class WasmInstanceObject : public JSObject {
V8_EXPORT_PRIVATE void SetRawMemory(byte* mem_start, size_t mem_size);
// Get the debug info associated with the given wasm object.
// If no debug info exists yet, it is created automatically.
V8_EXPORT_PRIVATE static Handle<WasmDebugInfo> GetOrCreateDebugInfo(
Handle<WasmInstanceObject>);
V8_EXPORT_PRIVATE static Handle<WasmInstanceObject> New(
Isolate*, Handle<WasmModuleObject>);
......@@ -817,35 +808,6 @@ class WasmJSFunctionData : public Struct {
OBJECT_CONSTRUCTORS(WasmJSFunctionData, Struct);
};
// Debug info used for wasm debugging in the interpreter. For Liftoff debugging,
// all information is held off-heap in {wasm::DebugInfo}.
// TODO(clemensb): Remove this object.
class WasmDebugInfo : public Struct {
public:
NEVER_READ_ONLY_SPACE
DECL_ACCESSORS(wasm_instance, WasmInstanceObject)
DECL_ACCESSORS(interpreter_handle, Object) // Foreign or undefined
DECL_OPTIONAL_ACCESSORS(c_wasm_entries, FixedArray)
DECL_OPTIONAL_ACCESSORS(c_wasm_entry_map, Managed<wasm::SignatureMap>)
DECL_CAST(WasmDebugInfo)
// Dispatched behavior.
DECL_PRINTER(WasmDebugInfo)
DECL_VERIFIER(WasmDebugInfo)
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
TORQUE_GENERATED_WASM_DEBUG_INFO_FIELDS)
static Handle<WasmDebugInfo> New(Handle<WasmInstanceObject>);
V8_EXPORT_PRIVATE static Handle<Code> GetCWasmEntry(Handle<WasmDebugInfo>,
const wasm::FunctionSig*);
OBJECT_CONSTRUCTORS(WasmDebugInfo, Struct);
};
class WasmScript : public AllStatic {
public:
// Set a breakpoint on the given byte position inside the given module.
......
......@@ -41,13 +41,6 @@ extern class WasmIndirectFunctionTable extends Struct {
refs: FixedArray;
}
extern class WasmDebugInfo extends Struct {
instance: WasmInstanceObject;
interpreter_handle: Foreign|Undefined;
c_wasm_entries: FixedArray|Undefined;
c_wasm_entry_map: Foreign|Undefined; // Managed<wasm::SignatureMap>
}
@generateCppClass
extern class WasmExceptionTag extends Struct {
// Note that this index is only useful for debugging purposes and it is not
......
......@@ -40,9 +40,8 @@ class CWasmEntryArgTester {
runner_.Build(code.data(), code.data() + code.size());
wasm_code_ = runner_.builder().GetFunctionCode(0);
Handle<WasmInstanceObject> instance(runner_.builder().instance_object());
Handle<WasmDebugInfo> debug_info =
WasmInstanceObject::GetOrCreateDebugInfo(instance);
c_wasm_entry_ = WasmDebugInfo::GetCWasmEntry(debug_info, sig_);
c_wasm_entry_ =
compiler::CompileCWasmEntry(isolate_, sig_).ToHandleChecked();
}
template <typename... Rest>
......
This diff is collapsed.
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