Commit 9b074afb authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[web snapshot] Reduce instance type check overhead

- Use more HeapObject instead of Object
- Use raw instance_type

Bug: v8:11525
Change-Id: I5f1b8ea95fa14acc9c94555a95e8586f3c7e8888
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3422637Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78835}
parent ebdeedf4
...@@ -1801,7 +1801,7 @@ void WebSnapshotDeserializer::DeserializeExports() { ...@@ -1801,7 +1801,7 @@ void WebSnapshotDeserializer::DeserializeExports() {
void WebSnapshotDeserializer::ReadValue( void WebSnapshotDeserializer::ReadValue(
Handle<Object>& value, Representation& representation, Handle<Object>& value, Representation& representation,
Handle<Object> object_for_deferred_reference, Handle<HeapObject> object_for_deferred_reference,
uint32_t index_for_deferred_reference) { uint32_t index_for_deferred_reference) {
uint32_t value_type; uint32_t value_type;
Factory* factory = isolate_->factory(); Factory* factory = isolate_->factory();
...@@ -2001,7 +2001,7 @@ bool WebSnapshotDeserializer::SetFunctionPrototype(JSFunction function, ...@@ -2001,7 +2001,7 @@ bool WebSnapshotDeserializer::SetFunctionPrototype(JSFunction function,
// TODO(v8:11525): Enforce the invariant that no two prototypes share a map. // TODO(v8:11525): Enforce the invariant that no two prototypes share a map.
Map map = prototype.map(); Map map = prototype.map();
map.set_is_prototype_map(true); map.set_is_prototype_map(true);
if (!map.constructor_or_back_pointer().IsNullOrUndefined()) { if (!map.constructor_or_back_pointer().IsNullOrUndefined(isolate_)) {
return false; return false;
} }
map.set_constructor_or_back_pointer(function); map.set_constructor_or_back_pointer(function);
...@@ -2009,7 +2009,7 @@ bool WebSnapshotDeserializer::SetFunctionPrototype(JSFunction function, ...@@ -2009,7 +2009,7 @@ bool WebSnapshotDeserializer::SetFunctionPrototype(JSFunction function,
return true; return true;
} }
void WebSnapshotDeserializer::AddDeferredReference(Handle<Object> container, void WebSnapshotDeserializer::AddDeferredReference(Handle<HeapObject> container,
uint32_t index, uint32_t index,
ValueType target_type, ValueType target_type,
uint32_t target_index) { uint32_t target_index) {
...@@ -2038,7 +2038,7 @@ void WebSnapshotDeserializer::ProcessDeferredReferences() { ...@@ -2038,7 +2038,7 @@ void WebSnapshotDeserializer::ProcessDeferredReferences() {
// Deferred references is a list of (object, index, target type, target index) // Deferred references is a list of (object, index, target type, target index)
// tuples. // tuples.
for (int i = 0; i < raw_deferred_references.Length() - 3; i += 4) { for (int i = 0; i < raw_deferred_references.Length() - 3; i += 4) {
Object container = raw_deferred_references.Get(i); HeapObject container = HeapObject::cast(raw_deferred_references.Get(i));
int index = raw_deferred_references.Get(i + 1).ToSmi().value(); int index = raw_deferred_references.Get(i + 1).ToSmi().value();
ValueType target_type = ValueType target_type =
ValueType(raw_deferred_references.Get(i + 2).ToSmi().value()); ValueType(raw_deferred_references.Get(i + 2).ToSmi().value());
...@@ -2082,13 +2082,14 @@ void WebSnapshotDeserializer::ProcessDeferredReferences() { ...@@ -2082,13 +2082,14 @@ void WebSnapshotDeserializer::ProcessDeferredReferences() {
default: default:
UNREACHABLE(); UNREACHABLE();
} }
if (container.IsPropertyArray()) { InstanceType instance_type = container.map().instance_type();
if (InstanceTypeChecker::IsPropertyArray(instance_type)) {
PropertyArray::cast(container).set(index, target); PropertyArray::cast(container).set(index, target);
} else if (container.IsContext()) { } else if (InstanceTypeChecker::IsContext(instance_type)) {
Context::cast(container).set(index, target); Context::cast(container).set(index, target);
} else if (container.IsFixedArray()) { } else if (InstanceTypeChecker::IsFixedArray(instance_type)) {
FixedArray::cast(container).set(index, target); FixedArray::cast(container).set(index, target);
} else if (container.IsJSFunction()) { } else if (InstanceTypeChecker::IsJSFunction(instance_type)) {
// The only deferred reference allowed for a JSFunction is the function // The only deferred reference allowed for a JSFunction is the function
// prototype. // prototype.
DCHECK_EQ(index, 0); DCHECK_EQ(index, 0);
...@@ -2099,7 +2100,7 @@ void WebSnapshotDeserializer::ProcessDeferredReferences() { ...@@ -2099,7 +2100,7 @@ void WebSnapshotDeserializer::ProcessDeferredReferences() {
Throw("Can't reuse function prototype"); Throw("Can't reuse function prototype");
return; return;
} }
} else if (container.IsMap()) { } else if (InstanceTypeChecker::IsMap(instance_type)) {
// The only deferred reference allowed for a Map is the __proto__. // The only deferred reference allowed for a Map is the __proto__.
DCHECK_EQ(index, 0); DCHECK_EQ(index, 0);
DCHECK(target.IsJSReceiver()); DCHECK(target.IsJSReceiver());
......
...@@ -271,12 +271,12 @@ class V8_EXPORT WebSnapshotDeserializer ...@@ -271,12 +271,12 @@ class V8_EXPORT WebSnapshotDeserializer
void DeserializeExports(); void DeserializeExports();
void ReadValue( void ReadValue(
Handle<Object>& value, Representation& representation, Handle<Object>& value, Representation& representation,
Handle<Object> object_for_deferred_reference = Handle<Object>(), Handle<HeapObject> object_for_deferred_reference = Handle<HeapObject>(),
uint32_t index_for_deferred_reference = 0); uint32_t index_for_deferred_reference = 0);
void ReadFunctionPrototype(Handle<JSFunction> function); void ReadFunctionPrototype(Handle<JSFunction> function);
bool SetFunctionPrototype(JSFunction function, JSReceiver prototype); bool SetFunctionPrototype(JSFunction function, JSReceiver prototype);
void AddDeferredReference(Handle<Object> container, uint32_t index, void AddDeferredReference(Handle<HeapObject> container, uint32_t index,
ValueType target_type, ValueType target_type,
uint32_t target_object_index); uint32_t target_object_index);
void ProcessDeferredReferences(); void ProcessDeferredReferences();
......
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