Commit 953f3732 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Access "undefined" and "null" from the root set.

This removes two shortcuts ("UndefinedValue" and "NullValue") from the
instance object and instead loads those values via the root set which is
also referenced from the instance. It makes instance objects smaller.

Note that this also contains an optimization to make sure "undefined" is
only loaded once and then re-used within a single wrapper.

R=clemensh@chromium.org

Change-Id: I421f202230e91790fa9c8263770b4e4bbd3c47bd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1710670Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62860}
parent c3e7eb19
......@@ -277,8 +277,9 @@ Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects,
}
Node* WasmGraphBuilder::RefNull() {
return LOAD_INSTANCE_FIELD(NullValue,
MachineType::TypeCompressedTaggedPointer());
Node* isolate_root = LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer());
return LOAD_TAGGED_POINTER(
isolate_root, IsolateData::root_slot_offset(RootIndex::kNullValue));
}
Node* WasmGraphBuilder::RefFunc(uint32_t function_index) {
......@@ -3316,13 +3317,6 @@ Node* WasmGraphBuilder::CurrentMemoryPages() {
return result;
}
Node* WasmGraphBuilder::BuildLoadBuiltinFromInstance(int builtin_index) {
DCHECK(Builtins::IsBuiltinId(builtin_index));
Node* isolate_root = LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer());
return LOAD_TAGGED_POINTER(isolate_root,
IsolateData::builtin_slot_offset(builtin_index));
}
// Only call this function for code which is not reused across instantiations,
// as we do not patch the embedded js_context.
Node* WasmGraphBuilder::BuildCallToRuntimeWithContext(
......@@ -5070,6 +5064,34 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
return mcgraph()->IntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag);
}
Node* BuildLoadUndefinedValueFromInstance() {
if (undefined_value_node_ == nullptr) {
Node* isolate_root = graph()->NewNode(
mcgraph()->machine()->Load(MachineType::Pointer()),
instance_node_.get(),
mcgraph()->Int32Constant(WASM_INSTANCE_OBJECT_OFFSET(IsolateRoot)),
graph()->start(), graph()->start());
undefined_value_node_ = InsertDecompressionIfNeeded(
MachineType::TypeCompressedTaggedPointer(),
graph()->NewNode(
mcgraph()->machine()->Load(
MachineType::TypeCompressedTaggedPointer()),
isolate_root,
mcgraph()->Int32Constant(
IsolateData::root_slot_offset(RootIndex::kUndefinedValue)),
isolate_root, graph()->start()));
}
return undefined_value_node_.get();
}
Node* BuildLoadBuiltinFromInstance(int builtin_index) {
DCHECK(Builtins::IsBuiltinId(builtin_index));
Node* isolate_root =
LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer());
return LOAD_TAGGED_POINTER(isolate_root,
IsolateData::builtin_slot_offset(builtin_index));
}
Node* BuildChangeInt32ToTagged(Node* value) {
MachineOperatorBuilder* machine = mcgraph()->machine();
CommonOperatorBuilder* common = mcgraph()->common();
......@@ -5240,8 +5262,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
SetControl(is_heap_object.if_true);
Node* orig_effect = Effect();
Node* undefined_node = LOAD_INSTANCE_FIELD(
UndefinedValue, MachineType::TypeCompressedTaggedPointer());
Node* undefined_node = BuildLoadUndefinedValueFromInstance();
Node* check_undefined =
graph()->NewNode(machine->WordEqual(), value, undefined_node);
Node* effect_tagged = Effect();
......@@ -5585,8 +5606,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
// The callable is passed as the last parameter, after WASM arguments.
Node* callable_node = Param(wasm_count + 1);
Node* undefined_node = LOAD_INSTANCE_FIELD(
UndefinedValue, MachineType::TypeCompressedTaggedPointer());
Node* undefined_node = BuildLoadUndefinedValueFromInstance();
Node* call = nullptr;
bool sloppy_receiver = true;
......@@ -6014,6 +6034,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Isolate* const isolate_;
JSGraph* jsgraph_;
StubCallMode stub_mode_;
SetOncePointer<Node> undefined_value_node_;
SetOncePointer<const Operator> allocate_heap_number_operator_;
wasm::WasmFeatures enabled_features_;
};
......
......@@ -602,8 +602,6 @@ class WasmGraphBuilder {
return buf;
}
Node* BuildLoadBuiltinFromInstance(int builtin_index);
//-----------------------------------------------------------------------
// Operations involving the CEntry, a dependency we want to remove
// to get off the GC heap.
......
......@@ -261,8 +261,6 @@ OPTIONAL_ACCESSORS(WasmInstanceObject, managed_native_allocations, Foreign,
kManagedNativeAllocationsOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, exceptions_table, FixedArray,
kExceptionsTableOffset)
ACCESSORS(WasmInstanceObject, undefined_value, Oddball, kUndefinedValueOffset)
ACCESSORS(WasmInstanceObject, null_value, Oddball, kNullValueOffset)
ACCESSORS(WasmInstanceObject, centry_stub, Code, kCEntryStubOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, wasm_exported_functions, FixedArray,
kWasmExportedFunctionsOffset)
......
......@@ -1702,8 +1702,6 @@ Handle<WasmInstanceObject> WasmInstanceObject::New(
instance->set_indirect_function_table_targets(nullptr);
instance->set_native_context(*isolate->native_context());
instance->set_module_object(*module_object);
instance->set_undefined_value(ReadOnlyRoots(isolate).undefined_value());
instance->set_null_value(ReadOnlyRoots(isolate).null_value());
instance->set_jump_table_start(
module_object->native_module()->jump_table_start());
......
......@@ -447,8 +447,6 @@ class WasmInstanceObject : public JSObject {
DECL_OPTIONAL_ACCESSORS(indirect_function_table_refs, FixedArray)
DECL_OPTIONAL_ACCESSORS(managed_native_allocations, Foreign)
DECL_OPTIONAL_ACCESSORS(exceptions_table, FixedArray)
DECL_ACCESSORS(undefined_value, Oddball)
DECL_ACCESSORS(null_value, Oddball)
DECL_ACCESSORS(centry_stub, Code)
DECL_OPTIONAL_ACCESSORS(wasm_exported_functions, FixedArray)
DECL_PRIMITIVE_ACCESSORS(memory_start, byte*)
......@@ -494,7 +492,6 @@ class WasmInstanceObject : public JSObject {
V(kOptionalPaddingOffset, POINTER_SIZE_PADDING(kOptionalPaddingOffset)) \
V(kGlobalsStartOffset, kSystemPointerSize) \
V(kImportedMutableGlobalsOffset, kSystemPointerSize) \
V(kUndefinedValueOffset, kTaggedSize) \
V(kIsolateRootOffset, kSystemPointerSize) \
V(kJumpTableStartOffset, kSystemPointerSize) \
/* End of often-accessed fields. */ \
......@@ -510,7 +507,6 @@ class WasmInstanceObject : public JSObject {
V(kIndirectFunctionTablesOffset, kTaggedSize) \
V(kManagedNativeAllocationsOffset, kTaggedSize) \
V(kExceptionsTableOffset, kTaggedSize) \
V(kNullValueOffset, kTaggedSize) \
V(kCEntryStubOffset, kTaggedSize) \
V(kWasmExportedFunctionsOffset, kTaggedSize) \
V(kRealStackLimitAddressOffset, kSystemPointerSize) \
......@@ -539,7 +535,6 @@ class WasmInstanceObject : public JSObject {
static constexpr uint16_t kTaggedFieldOffsets[] = {
kImportedFunctionRefsOffset,
kIndirectFunctionTableRefsOffset,
kUndefinedValueOffset,
kModuleObjectOffset,
kExportsObjectOffset,
kNativeContextOffset,
......@@ -552,7 +547,6 @@ class WasmInstanceObject : public JSObject {
kIndirectFunctionTablesOffset,
kManagedNativeAllocationsOffset,
kExceptionsTableOffset,
kNullValueOffset,
kCEntryStubOffset,
kWasmExportedFunctionsOffset};
......
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