Commit d5e8e352 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Introduce dedicated WasmExceptionTag type.

This introduces a dedicated instance type for exception tags. The main
motivation is to reduce their footprint and getting rid of a temporary
workaround that used the {JSObject} type for this purpose.

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

Change-Id: Id5678bce513f2ac086c7380bd803011b11d5050e
Reviewed-on: https://chromium-review.googlesource.com/c/1354464Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57943}
parent 520bc398
...@@ -299,6 +299,7 @@ class SymbolWrapper; ...@@ -299,6 +299,7 @@ class SymbolWrapper;
class Undetectable; class Undetectable;
class UniqueName; class UniqueName;
class WasmExceptionObject; class WasmExceptionObject;
class WasmExceptionTag;
class WasmExportedFunctionData; class WasmExportedFunctionData;
class WasmGlobalObject; class WasmGlobalObject;
class WasmMemoryObject; class WasmMemoryObject;
......
...@@ -352,6 +352,7 @@ Type::bitset BitsetType::Lub(const MapRefLike& map) { ...@@ -352,6 +352,7 @@ Type::bitset BitsetType::Lub(const MapRefLike& map) {
case TUPLE2_TYPE: case TUPLE2_TYPE:
case TUPLE3_TYPE: case TUPLE3_TYPE:
case WASM_DEBUG_INFO_TYPE: case WASM_DEBUG_INFO_TYPE:
case WASM_EXCEPTION_TAG_TYPE:
case WASM_EXPORTED_FUNCTION_DATA_TYPE: case WASM_EXPORTED_FUNCTION_DATA_TYPE:
case LOAD_HANDLER_TYPE: case LOAD_HANDLER_TYPE:
case STORE_HANDLER_TYPE: case STORE_HANDLER_TYPE:
......
...@@ -1799,6 +1799,11 @@ void WasmDebugInfo::WasmDebugInfoVerify(Isolate* isolate) { ...@@ -1799,6 +1799,11 @@ void WasmDebugInfo::WasmDebugInfoVerify(Isolate* isolate) {
VerifyObjectField(isolate, kCWasmEntryMapOffset); VerifyObjectField(isolate, kCWasmEntryMapOffset);
} }
void WasmExceptionTag::WasmExceptionTagVerify(Isolate* isolate) {
CHECK(IsWasmExceptionTag());
VerifySmiField(kIndexOffset);
}
void WasmInstanceObject::WasmInstanceObjectVerify(Isolate* isolate) { void WasmInstanceObject::WasmInstanceObjectVerify(Isolate* isolate) {
JSObjectVerify(isolate); JSObjectVerify(isolate);
CHECK(IsWasmInstanceObject()); CHECK(IsWasmInstanceObject());
......
...@@ -115,6 +115,7 @@ namespace internal { ...@@ -115,6 +115,7 @@ namespace internal {
V(TUPLE3_TYPE) \ V(TUPLE3_TYPE) \
V(ARRAY_BOILERPLATE_DESCRIPTION_TYPE) \ V(ARRAY_BOILERPLATE_DESCRIPTION_TYPE) \
V(WASM_DEBUG_INFO_TYPE) \ V(WASM_DEBUG_INFO_TYPE) \
V(WASM_EXCEPTION_TAG_TYPE) \
V(WASM_EXPORTED_FUNCTION_DATA_TYPE) \ V(WASM_EXPORTED_FUNCTION_DATA_TYPE) \
\ \
V(CALLABLE_TASK_TYPE) \ V(CALLABLE_TASK_TYPE) \
...@@ -340,6 +341,7 @@ namespace internal { ...@@ -340,6 +341,7 @@ namespace internal {
V(_, ARRAY_BOILERPLATE_DESCRIPTION_TYPE, ArrayBoilerplateDescription, \ V(_, ARRAY_BOILERPLATE_DESCRIPTION_TYPE, ArrayBoilerplateDescription, \
array_boilerplate_description) \ array_boilerplate_description) \
V(_, WASM_DEBUG_INFO_TYPE, WasmDebugInfo, wasm_debug_info) \ 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, \ V(_, WASM_EXPORTED_FUNCTION_DATA_TYPE, WasmExportedFunctionData, \
wasm_exported_function_data) \ wasm_exported_function_data) \
V(_, CALLABLE_TASK_TYPE, CallableTask, callable_task) \ V(_, CALLABLE_TASK_TYPE, CallableTask, callable_task) \
......
...@@ -1832,6 +1832,12 @@ void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT ...@@ -1832,6 +1832,12 @@ void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT
os << "\n"; os << "\n";
} }
void WasmExceptionTag::WasmExceptionTagPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmExceptionTag");
os << "\n - index: " << index();
os << "\n";
}
void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) { // NOLINT void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "WasmInstanceObject"); HeapObject::PrintHeader(os, "WasmInstanceObject");
os << "\n - module_object: " << Brief(module_object()); os << "\n - module_object: " << Brief(module_object());
......
...@@ -188,6 +188,7 @@ enum InstanceType : uint16_t { ...@@ -188,6 +188,7 @@ enum InstanceType : uint16_t {
TUPLE3_TYPE, TUPLE3_TYPE,
ARRAY_BOILERPLATE_DESCRIPTION_TYPE, ARRAY_BOILERPLATE_DESCRIPTION_TYPE,
WASM_DEBUG_INFO_TYPE, WASM_DEBUG_INFO_TYPE,
WASM_EXCEPTION_TAG_TYPE,
WASM_EXPORTED_FUNCTION_DATA_TYPE, WASM_EXPORTED_FUNCTION_DATA_TYPE,
CALLABLE_TASK_TYPE, // FIRST_MICROTASK_TYPE CALLABLE_TASK_TYPE, // FIRST_MICROTASK_TYPE
......
...@@ -2247,11 +2247,8 @@ void InstanceBuilder::InitializeExceptions( ...@@ -2247,11 +2247,8 @@ void InstanceBuilder::InitializeExceptions(
Handle<FixedArray> exceptions_table(instance->exceptions_table(), isolate_); Handle<FixedArray> exceptions_table(instance->exceptions_table(), isolate_);
for (int index = 0; index < exceptions_table->length(); ++index) { for (int index = 0; index < exceptions_table->length(); ++index) {
if (!exceptions_table->get(index)->IsUndefined(isolate_)) continue; if (!exceptions_table->get(index)->IsUndefined(isolate_)) continue;
// TODO(mstarzinger): Tags provide an object identity for each exception, Handle<WasmExceptionTag> exception_tag =
// using {JSObject} here is gigantic hack and we should use a dedicated WasmExceptionTag::New(isolate_, index);
// object with a much lighter footprint for this purpose here.
Handle<HeapObject> exception_tag =
isolate_->factory()->NewJSObjectWithNullProto();
exceptions_table->set(index, *exception_tag); exceptions_table->set(index, *exception_tag);
} }
} }
......
...@@ -23,6 +23,7 @@ namespace internal { ...@@ -23,6 +23,7 @@ namespace internal {
CAST_ACCESSOR(WasmDebugInfo) CAST_ACCESSOR(WasmDebugInfo)
CAST_ACCESSOR(WasmExceptionObject) CAST_ACCESSOR(WasmExceptionObject)
CAST_ACCESSOR(WasmExceptionTag)
CAST_ACCESSOR(WasmExportedFunctionData) CAST_ACCESSOR(WasmExportedFunctionData)
CAST_ACCESSOR(WasmGlobalObject) CAST_ACCESSOR(WasmGlobalObject)
CAST_ACCESSOR(WasmInstanceObject) CAST_ACCESSOR(WasmInstanceObject)
...@@ -248,6 +249,9 @@ uint32_t WasmTableObject::current_length() { return functions()->length(); } ...@@ -248,6 +249,9 @@ uint32_t WasmTableObject::current_length() { return functions()->length(); }
bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; } bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; }
// WasmExceptionTag
SMI_ACCESSORS(WasmExceptionTag, index, kIndexOffset)
// AsmWasmData // AsmWasmData
ACCESSORS(AsmWasmData, managed_native_module, Managed<wasm::NativeModule>, ACCESSORS(AsmWasmData, managed_native_module, Managed<wasm::NativeModule>,
kManagedNativeModuleOffset) kManagedNativeModuleOffset)
......
...@@ -1436,6 +1436,13 @@ wasm::FunctionSig* WasmExportedFunction::sig() { ...@@ -1436,6 +1436,13 @@ wasm::FunctionSig* WasmExportedFunction::sig() {
return instance()->module()->functions[function_index()].sig; return instance()->module()->functions[function_index()].sig;
} }
Handle<WasmExceptionTag> WasmExceptionTag::New(Isolate* isolate, int index) {
Handle<WasmExceptionTag> result = Handle<WasmExceptionTag>::cast(
isolate->factory()->NewStruct(WASM_EXCEPTION_TAG_TYPE, TENURED));
result->set_index(index);
return result;
}
Handle<AsmWasmData> AsmWasmData::New( Handle<AsmWasmData> AsmWasmData::New(
Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module, Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module,
Handle<FixedArray> export_wrappers, Handle<ByteArray> asm_js_offset_table, Handle<FixedArray> export_wrappers, Handle<ByteArray> asm_js_offset_table,
......
...@@ -648,6 +648,33 @@ class WasmDebugInfo : public Struct, public NeverReadOnlySpaceObject { ...@@ -648,6 +648,33 @@ class WasmDebugInfo : public Struct, public NeverReadOnlySpaceObject {
wasm::FunctionSig*); wasm::FunctionSig*);
}; };
// Tags provide an object identity for each exception defined in a wasm module
// header. They are referenced by the following fields:
// - {WasmExceptionObject::exception_tag} : The tag of the exception object.
// - {WasmInstanceObject::exceptions_table}: List of tags used by an instance.
class WasmExceptionTag : public Struct {
public:
static Handle<WasmExceptionTag> New(Isolate* isolate, int index);
// Note that this index is only useful for debugging purposes and it is not
// unique across modules. The GC however does not allow objects without at
// least one field, hence this also serves as a padding field for now.
DECL_INT_ACCESSORS(index);
DECL_CAST(WasmExceptionTag)
DECL_PRINTER(WasmExceptionTag)
DECL_VERIFIER(WasmExceptionTag)
// Layout description.
#define WASM_EXCEPTION_TAG_FIELDS(V) \
V(kIndexOffset, kPointerSize) \
/* Total size. */ \
V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, WASM_EXCEPTION_TAG_FIELDS)
#undef WASM_EXCEPTION_TAG_FIELDS
};
class AsmWasmData : public Struct { class AsmWasmData : public Struct {
public: public:
static Handle<AsmWasmData> New( static Handle<AsmWasmData> New(
......
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