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;
class Undetectable;
class UniqueName;
class WasmExceptionObject;
class WasmExceptionTag;
class WasmExportedFunctionData;
class WasmGlobalObject;
class WasmMemoryObject;
......
......@@ -352,6 +352,7 @@ Type::bitset BitsetType::Lub(const MapRefLike& map) {
case TUPLE2_TYPE:
case TUPLE3_TYPE:
case WASM_DEBUG_INFO_TYPE:
case WASM_EXCEPTION_TAG_TYPE:
case WASM_EXPORTED_FUNCTION_DATA_TYPE:
case LOAD_HANDLER_TYPE:
case STORE_HANDLER_TYPE:
......
......@@ -1799,6 +1799,11 @@ void WasmDebugInfo::WasmDebugInfoVerify(Isolate* isolate) {
VerifyObjectField(isolate, kCWasmEntryMapOffset);
}
void WasmExceptionTag::WasmExceptionTagVerify(Isolate* isolate) {
CHECK(IsWasmExceptionTag());
VerifySmiField(kIndexOffset);
}
void WasmInstanceObject::WasmInstanceObjectVerify(Isolate* isolate) {
JSObjectVerify(isolate);
CHECK(IsWasmInstanceObject());
......
......@@ -115,6 +115,7 @@ namespace internal {
V(TUPLE3_TYPE) \
V(ARRAY_BOILERPLATE_DESCRIPTION_TYPE) \
V(WASM_DEBUG_INFO_TYPE) \
V(WASM_EXCEPTION_TAG_TYPE) \
V(WASM_EXPORTED_FUNCTION_DATA_TYPE) \
\
V(CALLABLE_TASK_TYPE) \
......@@ -340,6 +341,7 @@ namespace internal {
V(_, ARRAY_BOILERPLATE_DESCRIPTION_TYPE, ArrayBoilerplateDescription, \
array_boilerplate_description) \
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) \
V(_, CALLABLE_TASK_TYPE, CallableTask, callable_task) \
......
......@@ -1832,6 +1832,12 @@ void WasmDebugInfo::WasmDebugInfoPrint(std::ostream& os) { // NOLINT
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
HeapObject::PrintHeader(os, "WasmInstanceObject");
os << "\n - module_object: " << Brief(module_object());
......
......@@ -188,6 +188,7 @@ enum InstanceType : uint16_t {
TUPLE3_TYPE,
ARRAY_BOILERPLATE_DESCRIPTION_TYPE,
WASM_DEBUG_INFO_TYPE,
WASM_EXCEPTION_TAG_TYPE,
WASM_EXPORTED_FUNCTION_DATA_TYPE,
CALLABLE_TASK_TYPE, // FIRST_MICROTASK_TYPE
......
......@@ -2247,11 +2247,8 @@ void InstanceBuilder::InitializeExceptions(
Handle<FixedArray> exceptions_table(instance->exceptions_table(), isolate_);
for (int index = 0; index < exceptions_table->length(); ++index) {
if (!exceptions_table->get(index)->IsUndefined(isolate_)) continue;
// TODO(mstarzinger): Tags provide an object identity for each exception,
// using {JSObject} here is gigantic hack and we should use a dedicated
// object with a much lighter footprint for this purpose here.
Handle<HeapObject> exception_tag =
isolate_->factory()->NewJSObjectWithNullProto();
Handle<WasmExceptionTag> exception_tag =
WasmExceptionTag::New(isolate_, index);
exceptions_table->set(index, *exception_tag);
}
}
......
......@@ -23,6 +23,7 @@ namespace internal {
CAST_ACCESSOR(WasmDebugInfo)
CAST_ACCESSOR(WasmExceptionObject)
CAST_ACCESSOR(WasmExceptionTag)
CAST_ACCESSOR(WasmExportedFunctionData)
CAST_ACCESSOR(WasmGlobalObject)
CAST_ACCESSOR(WasmInstanceObject)
......@@ -248,6 +249,9 @@ uint32_t WasmTableObject::current_length() { return functions()->length(); }
bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; }
// WasmExceptionTag
SMI_ACCESSORS(WasmExceptionTag, index, kIndexOffset)
// AsmWasmData
ACCESSORS(AsmWasmData, managed_native_module, Managed<wasm::NativeModule>,
kManagedNativeModuleOffset)
......
......@@ -1436,6 +1436,13 @@ wasm::FunctionSig* WasmExportedFunction::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(
Isolate* isolate, std::shared_ptr<wasm::NativeModule> native_module,
Handle<FixedArray> export_wrappers, Handle<ByteArray> asm_js_offset_table,
......
......@@ -648,6 +648,33 @@ class WasmDebugInfo : public Struct, public NeverReadOnlySpaceObject {
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 {
public:
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