From 77b09f965417de7f9fbed9c65785a88dabd226ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marja=20H=C3=B6ltt=C3=A4?= Date: Tue, 7 Dec 2021 14:20:30 +0100 Subject: [PATCH] [web snapshots] De-handlify object ID lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: v8:11525 Change-Id: Ida18808fd299f0f5754a2693b1e6dbc93b263d77 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3320424 Reviewed-by: Camillo Bruni Reviewed-by: Leszek Swirski Commit-Queue: Marja Hölttä Cr-Commit-Position: refs/heads/main@{#78284} --- src/snapshot/serializer.h | 2 +- src/web-snapshot/web-snapshot.cc | 41 +++++++++++++++++--------------- src/web-snapshot/web-snapshot.h | 10 ++++---- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/snapshot/serializer.h b/src/snapshot/serializer.h index 953790795d..b049af5776 100644 --- a/src/snapshot/serializer.h +++ b/src/snapshot/serializer.h @@ -152,7 +152,7 @@ class ObjectCacheIndexMap { return find_result.already_exists; } - bool Lookup(Handle obj, int* index_out) const { + bool Lookup(HeapObject obj, int* index_out) const { int* index = map_.Find(obj); if (index == nullptr) { return false; diff --git a/src/web-snapshot/web-snapshot.cc b/src/web-snapshot/web-snapshot.cc index 54933ca7d3..0d8a4e9d82 100644 --- a/src/web-snapshot/web-snapshot.cc +++ b/src/web-snapshot/web-snapshot.cc @@ -487,13 +487,16 @@ void WebSnapshotSerializer::SerializeFunctionInfo(ValueSerializer* serializer, return; } - Handle context(function->context(), isolate_); - if (context->IsNativeContext() || context->IsScriptContext()) { - serializer->WriteUint32(0); - } else { - DCHECK(context->IsFunctionContext() || context->IsBlockContext()); - uint32_t context_id = GetContextId(context); - serializer->WriteUint32(context_id + 1); + { + DisallowGarbageCollection no_gc; + Context context = function->context(); + if (context.IsNativeContext() || context.IsScriptContext()) { + serializer->WriteUint32(0); + } else { + DCHECK(context.IsFunctionContext() || context.IsBlockContext()); + uint32_t context_id = GetContextId(context); + serializer->WriteUint32(context_id + 1); + } } SerializeSource(serializer, function); @@ -503,8 +506,8 @@ void WebSnapshotSerializer::SerializeFunctionInfo(ValueSerializer* serializer, FunctionKindToFunctionFlags(function->shared().kind())); if (function->has_prototype_slot() && function->has_instance_prototype()) { - Handle prototype = Handle::cast( - handle(function->instance_prototype(), isolate_)); + DisallowGarbageCollection no_gc; + JSObject prototype = JSObject::cast(function->instance_prototype()); uint32_t prototype_id = GetObjectId(prototype); serializer->WriteUint32(prototype_id + 1); } else { @@ -717,7 +720,7 @@ void WebSnapshotSerializer::SerializeContext(Handle context) { uint32_t parent_context_id = 0; if (!context->previous().IsNativeContext() && !context->previous().IsScriptContext()) { - parent_context_id = GetContextId(handle(context->previous(), isolate_)) + 1; + parent_context_id = GetContextId(context->previous()) + 1; } // TODO(v8:11525): Use less space for encoding the context type. @@ -854,19 +857,19 @@ void WebSnapshotSerializer::WriteValue(Handle object, break; case JS_FUNCTION_TYPE: serializer.WriteUint32(ValueType::FUNCTION_ID); - serializer.WriteUint32(GetFunctionId(Handle::cast(object))); + serializer.WriteUint32(GetFunctionId(JSFunction::cast(*object))); break; case JS_CLASS_CONSTRUCTOR_TYPE: serializer.WriteUint32(ValueType::CLASS_ID); - serializer.WriteUint32(GetClassId(Handle::cast(object))); + serializer.WriteUint32(GetClassId(JSFunction::cast(*object))); break; case JS_OBJECT_TYPE: serializer.WriteUint32(ValueType::OBJECT_ID); - serializer.WriteUint32(GetObjectId(Handle::cast(object))); + serializer.WriteUint32(GetObjectId(JSObject::cast(*object))); break; case JS_ARRAY_TYPE: serializer.WriteUint32(ValueType::ARRAY_ID); - serializer.WriteUint32(GetArrayId(Handle::cast(object))); + serializer.WriteUint32(GetArrayId(JSArray::cast(*object))); break; case JS_REG_EXP_TYPE: { Handle regexp = Handle::cast(object); @@ -897,7 +900,7 @@ void WebSnapshotSerializer::WriteValue(Handle object, // TODO(v8:11525): Support more types. } -uint32_t WebSnapshotSerializer::GetFunctionId(Handle function) { +uint32_t WebSnapshotSerializer::GetFunctionId(JSFunction function) { int id; bool return_value = function_ids_.Lookup(function, &id); DCHECK(return_value); @@ -905,7 +908,7 @@ uint32_t WebSnapshotSerializer::GetFunctionId(Handle function) { return static_cast(id); } -uint32_t WebSnapshotSerializer::GetClassId(Handle function) { +uint32_t WebSnapshotSerializer::GetClassId(JSFunction function) { int id; bool return_value = class_ids_.Lookup(function, &id); DCHECK(return_value); @@ -913,7 +916,7 @@ uint32_t WebSnapshotSerializer::GetClassId(Handle function) { return static_cast(id); } -uint32_t WebSnapshotSerializer::GetContextId(Handle context) { +uint32_t WebSnapshotSerializer::GetContextId(Context context) { int id; bool return_value = context_ids_.Lookup(context, &id); DCHECK(return_value); @@ -921,7 +924,7 @@ uint32_t WebSnapshotSerializer::GetContextId(Handle context) { return static_cast(id); } -uint32_t WebSnapshotSerializer::GetArrayId(Handle array) { +uint32_t WebSnapshotSerializer::GetArrayId(JSArray array) { int id; bool return_value = array_ids_.Lookup(array, &id); DCHECK(return_value); @@ -929,7 +932,7 @@ uint32_t WebSnapshotSerializer::GetArrayId(Handle array) { return static_cast(id); } -uint32_t WebSnapshotSerializer::GetObjectId(Handle object) { +uint32_t WebSnapshotSerializer::GetObjectId(JSObject object) { int id; bool return_value = object_ids_.Lookup(object, &id); DCHECK(return_value); diff --git a/src/web-snapshot/web-snapshot.h b/src/web-snapshot/web-snapshot.h index c19aa40695..25a76f3572 100644 --- a/src/web-snapshot/web-snapshot.h +++ b/src/web-snapshot/web-snapshot.h @@ -181,11 +181,11 @@ class V8_EXPORT WebSnapshotSerializer void SerializeExport(Handle object, Handle export_name); void WriteValue(Handle object, ValueSerializer& serializer); - uint32_t GetFunctionId(Handle function); - uint32_t GetClassId(Handle function); - uint32_t GetContextId(Handle context); - uint32_t GetArrayId(Handle array); - uint32_t GetObjectId(Handle object); + uint32_t GetFunctionId(JSFunction function); + uint32_t GetClassId(JSFunction function); + uint32_t GetContextId(Context context); + uint32_t GetArrayId(JSArray array); + uint32_t GetObjectId(JSObject object); ValueSerializer string_serializer_; ValueSerializer map_serializer_;