Commit 67fa841b authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Turn {WasmDebugInfo} into a proper {Struct}.

This makes sure that the object can be identified by a unique instance
type and hence is not accidentally confused with other FixedArrays on
the heap.

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

Change-Id: I66e3d779ff9a323b64f5464bdd5fe02aefe468c6
Reviewed-on: https://chromium-review.googlesource.com/943442
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51665}
parent ed2e7dc6
......@@ -311,6 +311,7 @@ Type::bitset BitsetType::Lub(i::Map* map) {
case PROTOTYPE_INFO_TYPE:
case TUPLE2_TYPE:
case TUPLE3_TYPE:
case WASM_DEBUG_INFO_TYPE:
case LOAD_HANDLER_TYPE:
case STORE_HANDLER_TYPE:
case CONTEXT_EXTENSION_TYPE:
......
......@@ -27,6 +27,7 @@
#include "src/objects/shared-function-info.h"
#include "src/objects/string.h"
#include "src/regexp/jsregexp.h"
#include "src/wasm/wasm-objects.h"
namespace v8 {
namespace internal {
......
......@@ -23,6 +23,7 @@
#include "src/ostreams.h"
#include "src/regexp/jsregexp.h"
#include "src/transitions.h"
#include "src/wasm/wasm-objects-inl.h"
namespace v8 {
namespace internal {
......@@ -1423,6 +1424,19 @@ void Tuple3::Tuple3Verify() {
VerifyObjectField(kValue3Offset);
}
void WasmDebugInfo::WasmDebugInfoVerify() {
CHECK(IsWasmDebugInfo());
VerifyObjectField(kInstanceOffset);
CHECK(wasm_instance()->IsWasmInstanceObject());
VerifyObjectField(kInterpreterHandleOffset);
CHECK(interpreter_handle()->IsUndefined(GetIsolate()) ||
interpreter_handle()->IsForeign());
VerifyObjectField(kInterpretedFunctionsOffset);
VerifyObjectField(kLocalsNamesOffset);
VerifyObjectField(kCWasmEntriesOffset);
VerifyObjectField(kCWasmEntryMapOffset);
}
void DataHandler::DataHandlerVerify() {
CHECK(IsDataHandler());
CHECK_IMPLIES(!smi_handler()->IsSmi(),
......
......@@ -1464,6 +1464,12 @@ void Tuple3::Tuple3Print(std::ostream& os) { // NOLINT
os << "\n";
}
void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmDebugInfo");
os << "\n - wasm_instance: " << Brief(wasm_instance());
os << "\n";
}
void LoadHandler::LoadHandlerPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "LoadHandler");
// TODO(ishell): implement printing based on handler kind
......
......@@ -383,6 +383,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
V(STACK_FRAME_INFO_TYPE) \
V(TUPLE2_TYPE) \
V(TUPLE3_TYPE) \
V(WASM_DEBUG_INFO_TYPE) \
\
V(CALLABLE_TASK_TYPE) \
V(CALLBACK_TASK_TYPE) \
......@@ -583,6 +584,7 @@ const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
V(STACK_FRAME_INFO, StackFrameInfo, stack_frame_info) \
V(TUPLE2, Tuple2, tuple2) \
V(TUPLE3, Tuple3, tuple3) \
V(WASM_DEBUG_INFO, WasmDebugInfo, wasm_debug_info) \
V(CALLABLE_TASK, CallableTask, callable_task) \
V(CALLBACK_TASK, CallbackTask, callback_task) \
V(PROMISE_FULFILL_REACTION_JOB_TASK, PromiseFulfillReactionJobTask, \
......@@ -773,6 +775,7 @@ enum InstanceType : uint16_t {
STACK_FRAME_INFO_TYPE,
TUPLE2_TYPE,
TUPLE3_TYPE,
WASM_DEBUG_INFO_TYPE,
CALLABLE_TASK_TYPE, // FIRST_MICROTASK_TYPE
CALLBACK_TASK_TYPE,
......
......@@ -293,8 +293,7 @@ class InterpreterHandle {
// Check that this is indeed the instance which is connected to this
// interpreter.
DCHECK_EQ(this, Managed<wasm::InterpreterHandle>::cast(
instance_obj->debug_info()->get(
WasmDebugInfo::kInterpreterHandleIndex))
instance_obj->debug_info()->interpreter_handle())
->get());
return instance_obj;
}
......@@ -534,25 +533,24 @@ namespace {
wasm::InterpreterHandle* GetOrCreateInterpreterHandle(
Isolate* isolate, Handle<WasmDebugInfo> debug_info) {
Handle<Object> handle(debug_info->get(WasmDebugInfo::kInterpreterHandleIndex),
isolate);
Handle<Object> handle(debug_info->interpreter_handle(), isolate);
if (handle->IsUndefined(isolate)) {
handle = Managed<wasm::InterpreterHandle>::Allocate(isolate, isolate,
*debug_info);
debug_info->set(WasmDebugInfo::kInterpreterHandleIndex, *handle);
debug_info->set_interpreter_handle(*handle);
}
return Handle<Managed<wasm::InterpreterHandle>>::cast(handle)->get();
}
wasm::InterpreterHandle* GetInterpreterHandle(WasmDebugInfo* debug_info) {
Object* handle_obj = debug_info->get(WasmDebugInfo::kInterpreterHandleIndex);
Object* handle_obj = debug_info->interpreter_handle();
DCHECK(!handle_obj->IsUndefined(debug_info->GetIsolate()));
return Managed<wasm::InterpreterHandle>::cast(handle_obj)->get();
}
wasm::InterpreterHandle* GetInterpreterHandleOrNull(WasmDebugInfo* debug_info) {
Object* handle_obj = debug_info->get(WasmDebugInfo::kInterpreterHandleIndex);
Object* handle_obj = debug_info->interpreter_handle();
if (handle_obj->IsUndefined(debug_info->GetIsolate())) return nullptr;
return Managed<wasm::InterpreterHandle>::cast(handle_obj)->get();
}
......@@ -566,13 +564,12 @@ int GetNumFunctions(WasmInstanceObject* instance) {
Handle<FixedArray> GetOrCreateInterpretedFunctions(
Isolate* isolate, Handle<WasmDebugInfo> debug_info) {
Handle<Object> obj(debug_info->get(WasmDebugInfo::kInterpretedFunctionsIndex),
isolate);
Handle<Object> obj(debug_info->interpreted_functions(), isolate);
if (!obj->IsUndefined(isolate)) return Handle<FixedArray>::cast(obj);
Handle<FixedArray> new_arr = isolate->factory()->NewFixedArray(
GetNumFunctions(debug_info->wasm_instance()));
debug_info->set(WasmDebugInfo::kInterpretedFunctionsIndex, *new_arr);
debug_info->set_interpreted_functions(*new_arr);
return new_arr;
}
......@@ -667,9 +664,9 @@ void RedirectCallsitesInInstance(Isolate* isolate, WasmInstanceObject* instance,
Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
DCHECK(!instance->has_debug_info());
Factory* factory = instance->GetIsolate()->factory();
Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED);
arr->set(kInstanceIndex, *instance);
Handle<WasmDebugInfo> debug_info = Handle<WasmDebugInfo>::cast(arr);
Handle<WasmDebugInfo> debug_info = Handle<WasmDebugInfo>::cast(
factory->NewStruct(WASM_DEBUG_INFO_TYPE, TENURED));
debug_info->set_wasm_instance(*instance);
instance->set_debug_info(*debug_info);
return debug_info;
}
......@@ -680,33 +677,12 @@ wasm::WasmInterpreter* WasmDebugInfo::SetupForTesting(
Isolate* isolate = instance_obj->GetIsolate();
auto interp_handle =
Managed<wasm::InterpreterHandle>::Allocate(isolate, isolate, *debug_info);
debug_info->set(kInterpreterHandleIndex, *interp_handle);
debug_info->set_interpreter_handle(*interp_handle);
auto ret = interp_handle->get()->interpreter();
ret->SetCallIndirectTestMode();
return ret;
}
bool WasmDebugInfo::IsWasmDebugInfo(Object* object) {
if (!object->IsFixedArray()) return false;
FixedArray* arr = FixedArray::cast(object);
if (arr->length() != kFieldCount) return false;
if (!arr->get(kInstanceIndex)->IsWasmInstanceObject()) return false;
Isolate* isolate = arr->GetIsolate();
if (!arr->get(kInterpreterHandleIndex)->IsUndefined(isolate) &&
!arr->get(kInterpreterHandleIndex)->IsForeign())
return false;
return true;
}
WasmDebugInfo* WasmDebugInfo::cast(Object* object) {
DCHECK(IsWasmDebugInfo(object));
return reinterpret_cast<WasmDebugInfo*>(object);
}
WasmInstanceObject* WasmDebugInfo::wasm_instance() {
return WasmInstanceObject::cast(get(kInstanceIndex));
}
void WasmDebugInfo::SetBreakpoint(Handle<WasmDebugInfo> debug_info,
int func_index, int offset) {
Isolate* isolate = debug_info->GetIsolate();
......
......@@ -14,6 +14,7 @@ namespace internal {
// Has to be the last include (doesn't have include guards)
#include "src/objects/object-macros.h"
CAST_ACCESSOR(WasmDebugInfo)
CAST_ACCESSOR(WasmInstanceObject)
CAST_ACCESSOR(WasmMemoryObject)
CAST_ACCESSOR(WasmModuleObject)
......@@ -69,10 +70,14 @@ OPTIONAL_ACCESSORS(WasmSharedModuleData, asm_js_offset_table, ByteArray,
kAsmJsOffsetTableOffset)
OPTIONAL_ACCESSORS(WasmSharedModuleData, breakpoint_infos, FixedArray,
kBreakPointInfosOffset)
OPTIONAL_ACCESSORS(WasmSharedModuleData, lazy_compilation_orchestrator, Foreign,
kLazyCompilationOrchestratorOffset)
// WasmDebugInfo
ACCESSORS(WasmDebugInfo, wasm_instance, WasmInstanceObject, kInstanceOffset)
ACCESSORS(WasmDebugInfo, interpreter_handle, Object, kInterpreterHandleOffset)
ACCESSORS(WasmDebugInfo, interpreted_functions, Object,
kInterpretedFunctionsOffset)
OPTIONAL_ACCESSORS(WasmDebugInfo, locals_names, FixedArray, kLocalsNamesOffset)
OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entries, FixedArray,
kCWasmEntriesOffset)
......
......@@ -444,10 +444,6 @@ class WasmSharedModuleData : public FixedArray {
// we embed them as objects, and they may move.
class WasmCompiledModule : public FixedArray {
public:
enum { // --
kFieldCount
};
static WasmCompiledModule* cast(Object* fixed_array) {
SLOW_DCHECK(IsWasmCompiledModule(fixed_array));
return reinterpret_cast<WasmCompiledModule*>(fixed_array);
......@@ -589,33 +585,33 @@ class WasmCompiledModule : public FixedArray {
DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule);
};
class WasmDebugInfo : public FixedArray {
class WasmDebugInfo : public Struct {
public:
DECL_OOL_QUERY(WasmDebugInfo)
DECL_OOL_CAST(WasmDebugInfo)
DECL_GETTER(wasm_instance, WasmInstanceObject)
DECL_ACCESSORS(wasm_instance, WasmInstanceObject)
DECL_ACCESSORS(interpreter_handle, Object);
DECL_ACCESSORS(interpreted_functions, Object);
DECL_OPTIONAL_ACCESSORS(locals_names, FixedArray)
DECL_OPTIONAL_ACCESSORS(c_wasm_entries, FixedArray)
DECL_OPTIONAL_ACCESSORS(c_wasm_entry_map, Managed<wasm::SignatureMap>)
enum {
kInstanceIndex, // instance object.
kInterpreterHandleIndex, // managed object containing the interpreter.
kInterpretedFunctionsIndex, // array of interpreter entry code objects.
kLocalsNamesIndex, // array of array of local names.
kCWasmEntriesIndex, // array of C_WASM_ENTRY stubs.
kCWasmEntryMapIndex, // maps signature to index into CWasmEntries.
kFieldCount
};
DECL_CAST(WasmDebugInfo)
DEF_SIZE(FixedArray)
DEF_OFFSET(Instance)
DEF_OFFSET(InterpreterHandle)
DEF_OFFSET(InterpretedFunctions)
DEF_OFFSET(LocalsNames)
DEF_OFFSET(CWasmEntries)
DEF_OFFSET(CWasmEntryMap)
// Dispatched behavior.
DECL_PRINTER(WasmDebugInfo)
DECL_VERIFIER(WasmDebugInfo)
// Layout description.
#define WASM_DEBUG_INFO_FIELDS(V) \
V(kInstanceOffset, kPointerSize) \
V(kInterpreterHandleOffset, kPointerSize) \
V(kInterpretedFunctionsOffset, kPointerSize) \
V(kLocalsNamesOffset, kPointerSize) \
V(kCWasmEntriesOffset, kPointerSize) \
V(kCWasmEntryMapOffset, kPointerSize) \
V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, WASM_DEBUG_INFO_FIELDS)
#undef WASM_DEBUG_INFO_FIELDS
static Handle<WasmDebugInfo> New(Handle<WasmInstanceObject>);
......
......@@ -74,28 +74,29 @@ INSTANCE_TYPES = {
170: "STACK_FRAME_INFO_TYPE",
171: "TUPLE2_TYPE",
172: "TUPLE3_TYPE",
173: "CALLABLE_TASK_TYPE",
174: "CALLBACK_TASK_TYPE",
175: "PROMISE_FULFILL_REACTION_JOB_TASK_TYPE",
176: "PROMISE_REJECT_REACTION_JOB_TASK_TYPE",
177: "PROMISE_RESOLVE_THENABLE_JOB_TASK_TYPE",
178: "FIXED_ARRAY_TYPE",
179: "DESCRIPTOR_ARRAY_TYPE",
180: "HASH_TABLE_TYPE",
181: "SCOPE_INFO_TYPE",
182: "TRANSITION_ARRAY_TYPE",
183: "CELL_TYPE",
184: "CODE_DATA_CONTAINER_TYPE",
185: "FEEDBACK_CELL_TYPE",
186: "FEEDBACK_VECTOR_TYPE",
187: "LOAD_HANDLER_TYPE",
188: "PROPERTY_ARRAY_TYPE",
189: "PROPERTY_CELL_TYPE",
190: "SHARED_FUNCTION_INFO_TYPE",
191: "SMALL_ORDERED_HASH_MAP_TYPE",
192: "SMALL_ORDERED_HASH_SET_TYPE",
193: "STORE_HANDLER_TYPE",
194: "WEAK_CELL_TYPE",
173: "WASM_DEBUG_INFO_TYPE",
174: "CALLABLE_TASK_TYPE",
175: "CALLBACK_TASK_TYPE",
176: "PROMISE_FULFILL_REACTION_JOB_TASK_TYPE",
177: "PROMISE_REJECT_REACTION_JOB_TASK_TYPE",
178: "PROMISE_RESOLVE_THENABLE_JOB_TASK_TYPE",
179: "FIXED_ARRAY_TYPE",
180: "DESCRIPTOR_ARRAY_TYPE",
181: "HASH_TABLE_TYPE",
182: "SCOPE_INFO_TYPE",
183: "TRANSITION_ARRAY_TYPE",
184: "CELL_TYPE",
185: "CODE_DATA_CONTAINER_TYPE",
186: "FEEDBACK_CELL_TYPE",
187: "FEEDBACK_VECTOR_TYPE",
188: "LOAD_HANDLER_TYPE",
189: "PROPERTY_ARRAY_TYPE",
190: "PROPERTY_CELL_TYPE",
191: "SHARED_FUNCTION_INFO_TYPE",
192: "SMALL_ORDERED_HASH_MAP_TYPE",
193: "SMALL_ORDERED_HASH_SET_TYPE",
194: "STORE_HANDLER_TYPE",
195: "WEAK_CELL_TYPE",
1024: "JS_PROXY_TYPE",
1025: "JS_GLOBAL_OBJECT_TYPE",
1026: "JS_GLOBAL_PROXY_TYPE",
......@@ -180,8 +181,8 @@ KNOWN_MAPS = {
0x02201: (138, "FreeSpaceMap"),
0x02259: (132, "MetaMap"),
0x022b1: (131, "NullMap"),
0x02309: (179, "DescriptorArrayMap"),
0x02361: (178, "FixedArrayMap"),
0x02309: (180, "DescriptorArrayMap"),
0x02361: (179, "FixedArrayMap"),
0x023b9: (151, "OnePointerFillerMap"),
0x02411: (151, "TwoPointerFillerMap"),
0x02469: (131, "UninitializedMap"),
......@@ -191,57 +192,57 @@ KNOWN_MAPS = {
0x025c9: (131, "TheHoleMap"),
0x02621: (131, "BooleanMap"),
0x02679: (136, "ByteArrayMap"),
0x026d1: (178, "FixedCOWArrayMap"),
0x02729: (180, "HashTableMap"),
0x026d1: (179, "FixedCOWArrayMap"),
0x02729: (181, "HashTableMap"),
0x02781: (128, "SymbolMap"),
0x027d9: (72, "OneByteStringMap"),
0x02831: (181, "ScopeInfoMap"),
0x02889: (190, "SharedFunctionInfoMap"),
0x02831: (182, "ScopeInfoMap"),
0x02889: (191, "SharedFunctionInfoMap"),
0x028e1: (133, "CodeMap"),
0x02939: (178, "FunctionContextMap"),
0x02991: (183, "CellMap"),
0x029e9: (194, "WeakCellMap"),
0x02a41: (189, "GlobalPropertyCellMap"),
0x02939: (179, "FunctionContextMap"),
0x02991: (184, "CellMap"),
0x029e9: (195, "WeakCellMap"),
0x02a41: (190, "GlobalPropertyCellMap"),
0x02a99: (135, "ForeignMap"),
0x02af1: (182, "TransitionArrayMap"),
0x02b49: (186, "FeedbackVectorMap"),
0x02af1: (183, "TransitionArrayMap"),
0x02b49: (187, "FeedbackVectorMap"),
0x02ba1: (131, "ArgumentsMarkerMap"),
0x02bf9: (131, "ExceptionMap"),
0x02c51: (131, "TerminationExceptionMap"),
0x02ca9: (131, "OptimizedOutMap"),
0x02d01: (131, "StaleRegisterMap"),
0x02d59: (178, "NativeContextMap"),
0x02db1: (178, "ModuleContextMap"),
0x02e09: (178, "EvalContextMap"),
0x02e61: (178, "ScriptContextMap"),
0x02eb9: (178, "BlockContextMap"),
0x02f11: (178, "CatchContextMap"),
0x02f69: (178, "WithContextMap"),
0x02fc1: (178, "DebugEvaluateContextMap"),
0x03019: (178, "ScriptContextTableMap"),
0x03071: (178, "ArrayListMap"),
0x02d59: (179, "NativeContextMap"),
0x02db1: (179, "ModuleContextMap"),
0x02e09: (179, "EvalContextMap"),
0x02e61: (179, "ScriptContextMap"),
0x02eb9: (179, "BlockContextMap"),
0x02f11: (179, "CatchContextMap"),
0x02f69: (179, "WithContextMap"),
0x02fc1: (179, "DebugEvaluateContextMap"),
0x03019: (179, "ScriptContextTableMap"),
0x03071: (179, "ArrayListMap"),
0x030c9: (150, "FixedDoubleArrayMap"),
0x03121: (134, "MutableHeapNumberMap"),
0x03179: (180, "OrderedHashMapMap"),
0x031d1: (180, "OrderedHashSetMap"),
0x03229: (180, "NameDictionaryMap"),
0x03281: (180, "GlobalDictionaryMap"),
0x032d9: (180, "NumberDictionaryMap"),
0x03331: (180, "SimpleNumberDictionaryMap"),
0x03389: (180, "StringTableMap"),
0x033e1: (180, "WeakHashTableMap"),
0x03439: (178, "SloppyArgumentsElementsMap"),
0x03491: (191, "SmallOrderedHashMapMap"),
0x034e9: (192, "SmallOrderedHashSetMap"),
0x03541: (184, "CodeDataContainerMap"),
0x03179: (181, "OrderedHashMapMap"),
0x031d1: (181, "OrderedHashSetMap"),
0x03229: (181, "NameDictionaryMap"),
0x03281: (181, "GlobalDictionaryMap"),
0x032d9: (181, "NumberDictionaryMap"),
0x03331: (181, "SimpleNumberDictionaryMap"),
0x03389: (181, "StringTableMap"),
0x033e1: (181, "WeakHashTableMap"),
0x03439: (179, "SloppyArgumentsElementsMap"),
0x03491: (192, "SmallOrderedHashMapMap"),
0x034e9: (193, "SmallOrderedHashSetMap"),
0x03541: (185, "CodeDataContainerMap"),
0x03599: (1071, "JSMessageObjectMap"),
0x035f1: (1057, "ExternalMap"),
0x03649: (137, "BytecodeArrayMap"),
0x036a1: (178, "ModuleInfoMap"),
0x036f9: (185, "NoClosuresCellMap"),
0x03751: (185, "OneClosureCellMap"),
0x037a9: (185, "ManyClosuresCellMap"),
0x03801: (188, "PropertyArrayMap"),
0x036a1: (179, "ModuleInfoMap"),
0x036f9: (186, "NoClosuresCellMap"),
0x03751: (186, "OneClosureCellMap"),
0x037a9: (186, "ManyClosuresCellMap"),
0x03801: (189, "PropertyArrayMap"),
0x03859: (130, "BigIntMap"),
0x038b1: (106, "NativeSourceStringMap"),
0x03909: (64, "StringMap"),
......@@ -296,11 +297,12 @@ KNOWN_MAPS = {
0x049e1: (168, "PrototypeInfoMap"),
0x04a39: (170, "StackFrameInfoMap"),
0x04a91: (172, "Tuple3Map"),
0x04ae9: (173, "CallableTaskMap"),
0x04b41: (174, "CallbackTaskMap"),
0x04b99: (175, "PromiseFulfillReactionJobTaskMap"),
0x04bf1: (176, "PromiseRejectReactionJobTaskMap"),
0x04c49: (177, "PromiseResolveThenableJobTaskMap"),
0x04ae9: (173, "WasmDebugInfoMap"),
0x04b41: (174, "CallableTaskMap"),
0x04b99: (175, "CallbackTaskMap"),
0x04bf1: (176, "PromiseFulfillReactionJobTaskMap"),
0x04c49: (177, "PromiseRejectReactionJobTaskMap"),
0x04ca1: (178, "PromiseResolveThenableJobTaskMap"),
}
# List of known V8 objects.
......
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