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

[web snapshot] Make ValueSerializer an inline member

We can avoid a pointer deref if the ValueSerializer is inlined in
WebSnapshotDeserializer.

Bug: v8:11525
Change-Id: I92d8cac37af3fdbe04a66465f97761bf5a9fd705
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3417433Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78830}
parent 874b21f8
...@@ -2087,8 +2087,10 @@ MaybeLocal<Value> Script::Run(Local<Context> context, ...@@ -2087,8 +2087,10 @@ MaybeLocal<Value> Script::Run(Local<Context> context,
handle(fun->shared().script(), isolate); handle(fun->shared().script(), isolate);
if (maybe_script->IsScript() && if (maybe_script->IsScript() &&
i::Script::cast(*maybe_script).type() == i::Script::TYPE_WEB_SNAPSHOT) { i::Script::cast(*maybe_script).type() == i::Script::TYPE_WEB_SNAPSHOT) {
i::WebSnapshotDeserializer deserializer(v8_isolate); i::WebSnapshotDeserializer deserializer(
deserializer.UseWebSnapshot(i::Handle<i::Script>::cast(maybe_script)); reinterpret_cast<i::Isolate*>(v8_isolate),
i::Handle<i::Script>::cast(maybe_script));
deserializer.Deserialize();
RETURN_ON_FAILED_EXECUTION(Value); RETURN_ON_FAILED_EXECUTION(Value);
Local<Value> result = v8::Undefined(v8_isolate); Local<Value> result = v8::Undefined(v8_isolate);
RETURN_ESCAPED(result); RETURN_ESCAPED(result);
......
...@@ -1443,9 +1443,9 @@ bool Shell::ExecuteWebSnapshot(Isolate* isolate, const char* file_name) { ...@@ -1443,9 +1443,9 @@ bool Shell::ExecuteWebSnapshot(Isolate* isolate, const char* file_name) {
if (length == 0) { if (length == 0) {
isolate->ThrowError("Could not read the web snapshot file"); isolate->ThrowError("Could not read the web snapshot file");
} else { } else {
i::WebSnapshotDeserializer deserializer(isolate); i::WebSnapshotDeserializer deserializer(isolate, snapshot_data.get(),
success = deserializer.UseWebSnapshot(snapshot_data.get(), static_cast<size_t>(length));
static_cast<size_t>(length)); success = deserializer.Deserialize();
} }
if (!success) { if (!success) {
CHECK(try_catch.HasCaught()); CHECK(try_catch.HasCaught());
...@@ -2003,9 +2003,10 @@ void Shell::RealmUseWebSnapshot( ...@@ -2003,9 +2003,10 @@ void Shell::RealmUseWebSnapshot(
// Deserialize the snapshot in the specified Realm. // Deserialize the snapshot in the specified Realm.
{ {
PerIsolateData::ExplicitRealmScope realm_scope(data, index); PerIsolateData::ExplicitRealmScope realm_scope(data, index);
i::WebSnapshotDeserializer deserializer(isolate); i::WebSnapshotDeserializer deserializer(isolate,
bool success = deserializer.UseWebSnapshot( snapshot_data_shared->buffer,
snapshot_data_shared->buffer, snapshot_data_shared->buffer_size); snapshot_data_shared->buffer_size);
bool success = deserializer.Deserialize();
args.GetReturnValue().Set(success); args.GetReturnValue().Set(success);
} }
} }
......
This diff is collapsed.
...@@ -228,10 +228,11 @@ class V8_EXPORT WebSnapshotSerializer ...@@ -228,10 +228,11 @@ class V8_EXPORT WebSnapshotSerializer
class V8_EXPORT WebSnapshotDeserializer class V8_EXPORT WebSnapshotDeserializer
: public WebSnapshotSerializerDeserializer { : public WebSnapshotSerializerDeserializer {
public: public:
explicit WebSnapshotDeserializer(v8::Isolate* v8_isolate); WebSnapshotDeserializer(v8::Isolate* v8_isolate, const uint8_t* data,
size_t buffer_size);
WebSnapshotDeserializer(Isolate* isolate, Handle<Script> snapshot_as_script);
~WebSnapshotDeserializer(); ~WebSnapshotDeserializer();
bool UseWebSnapshot(const uint8_t* data, size_t buffer_size); bool Deserialize();
bool UseWebSnapshot(Handle<Script> snapshot_as_script);
// For inspecting the state after deserializing a snapshot. // For inspecting the state after deserializing a snapshot.
uint32_t string_count() const { return string_count_; } uint32_t string_count() const { return string_count_; }
...@@ -243,7 +244,10 @@ class V8_EXPORT WebSnapshotDeserializer ...@@ -243,7 +244,10 @@ class V8_EXPORT WebSnapshotDeserializer
uint32_t object_count() const { return object_count_; } uint32_t object_count() const { return object_count_; }
private: private:
bool Deserialize(); WebSnapshotDeserializer(Isolate* isolate, Handle<Object> script_name,
base::Vector<const uint8_t> buffer);
base::Vector<const uint8_t> ExtractScriptBuffer(
Isolate* isolate, Handle<Script> snapshot_as_script);
bool DeserializeSnapshot(); bool DeserializeSnapshot();
bool DeserializeScript(); bool DeserializeScript();
...@@ -305,7 +309,7 @@ class V8_EXPORT WebSnapshotDeserializer ...@@ -305,7 +309,7 @@ class V8_EXPORT WebSnapshotDeserializer
uint32_t object_count_ = 0; uint32_t object_count_ = 0;
uint32_t current_object_count_ = 0; uint32_t current_object_count_ = 0;
std::unique_ptr<ValueDeserializer> deserializer_; ValueDeserializer deserializer_;
bool deserialized_ = false; bool deserialized_ = false;
}; };
......
...@@ -47,9 +47,9 @@ void TestWebSnapshotExtensive( ...@@ -47,9 +47,9 @@ void TestWebSnapshotExtensive(
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::Local<v8::Context> new_context = CcTest::NewContext(); v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context); v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate); WebSnapshotDeserializer deserializer(isolate, snapshot_data.buffer,
CHECK(deserializer.UseWebSnapshot(snapshot_data.buffer, snapshot_data.buffer_size);
snapshot_data.buffer_size)); CHECK(deserializer.Deserialize());
CHECK(!deserializer.has_error()); CHECK(!deserializer.has_error());
tester(isolate, new_context); tester(isolate, new_context);
CHECK_EQ(string_count, deserializer.string_count()); CHECK_EQ(string_count, deserializer.string_count());
...@@ -343,9 +343,9 @@ TEST(SFIDeduplication) { ...@@ -343,9 +343,9 @@ TEST(SFIDeduplication) {
{ {
v8::Local<v8::Context> new_context = CcTest::NewContext(); v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context); v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate); WebSnapshotDeserializer deserializer(isolate, snapshot_data.buffer,
CHECK(deserializer.UseWebSnapshot(snapshot_data.buffer, snapshot_data.buffer_size);
snapshot_data.buffer_size)); CHECK(deserializer.Deserialize());
CHECK(!deserializer.has_error()); CHECK(!deserializer.has_error());
const char* get_inner = "foo.inner"; const char* get_inner = "foo.inner";
...@@ -399,9 +399,9 @@ TEST(SFIDeduplicationClasses) { ...@@ -399,9 +399,9 @@ TEST(SFIDeduplicationClasses) {
{ {
v8::Local<v8::Context> new_context = CcTest::NewContext(); v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context); v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate); WebSnapshotDeserializer deserializer(isolate, snapshot_data.buffer,
CHECK(deserializer.UseWebSnapshot(snapshot_data.buffer, snapshot_data.buffer_size);
snapshot_data.buffer_size)); CHECK(deserializer.Deserialize());
CHECK(!deserializer.has_error()); CHECK(!deserializer.has_error());
const char* get_class = "foo.class"; const char* get_class = "foo.class";
...@@ -464,9 +464,9 @@ TEST(SFIDeduplicationAfterBytecodeFlushing) { ...@@ -464,9 +464,9 @@ TEST(SFIDeduplicationAfterBytecodeFlushing) {
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::Local<v8::Context> new_context = CcTest::NewContext(); v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context); v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate); WebSnapshotDeserializer deserializer(isolate, snapshot_data.buffer,
CHECK(deserializer.UseWebSnapshot(snapshot_data.buffer, snapshot_data.buffer_size);
snapshot_data.buffer_size)); CHECK(deserializer.Deserialize());
CHECK(!deserializer.has_error()); CHECK(!deserializer.has_error());
const char* get_outer = "foo.outer"; const char* get_outer = "foo.outer";
...@@ -549,9 +549,9 @@ TEST(SFIDeduplicationAfterBytecodeFlushingClasses) { ...@@ -549,9 +549,9 @@ TEST(SFIDeduplicationAfterBytecodeFlushingClasses) {
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::Local<v8::Context> new_context = CcTest::NewContext(); v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context); v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate); WebSnapshotDeserializer deserializer(isolate, snapshot_data.buffer,
CHECK(deserializer.UseWebSnapshot(snapshot_data.buffer, snapshot_data.buffer_size);
snapshot_data.buffer_size)); CHECK(deserializer.Deserialize());
CHECK(!deserializer.has_error()); CHECK(!deserializer.has_error());
const char* get_create = "foo.create"; const char* get_create = "foo.create";
...@@ -626,9 +626,9 @@ TEST(SFIDeduplicationOfFunctionsNotInSnapshot) { ...@@ -626,9 +626,9 @@ TEST(SFIDeduplicationOfFunctionsNotInSnapshot) {
{ {
v8::Local<v8::Context> new_context = CcTest::NewContext(); v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context); v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate); WebSnapshotDeserializer deserializer(isolate, snapshot_data.buffer,
CHECK(deserializer.UseWebSnapshot(snapshot_data.buffer, snapshot_data.buffer_size);
snapshot_data.buffer_size)); CHECK(deserializer.Deserialize());
CHECK(!deserializer.has_error()); CHECK(!deserializer.has_error());
const char* create_new_inner = "foo.outer()"; const char* create_new_inner = "foo.outer()";
...@@ -738,8 +738,8 @@ TEST(Concatenation) { ...@@ -738,8 +738,8 @@ TEST(Concatenation) {
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::Local<v8::Context> new_context = CcTest::NewContext(); v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context); v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate); WebSnapshotDeserializer deserializer(isolate, buffer.get(), buffer_size);
CHECK(deserializer.UseWebSnapshot(buffer.get(), buffer_size)); CHECK(deserializer.Deserialize());
CHECK(!deserializer.has_error()); CHECK(!deserializer.has_error());
CHECK_EQ(kObjectCount, deserializer.object_count()); CHECK_EQ(kObjectCount, deserializer.object_count());
...@@ -785,8 +785,8 @@ TEST(ConcatenationErrors) { ...@@ -785,8 +785,8 @@ TEST(ConcatenationErrors) {
v8::HandleScope scope(isolate); v8::HandleScope scope(isolate);
v8::Local<v8::Context> new_context = CcTest::NewContext(); v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context); v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate); WebSnapshotDeserializer deserializer(isolate, buffer.get(), buffer_size);
CHECK(!deserializer.UseWebSnapshot(buffer.get(), buffer_size)); CHECK(!deserializer.Deserialize());
} }
} }
...@@ -819,9 +819,9 @@ TEST(CompactedSourceCode) { ...@@ -819,9 +819,9 @@ TEST(CompactedSourceCode) {
{ {
v8::Local<v8::Context> new_context = CcTest::NewContext(); v8::Local<v8::Context> new_context = CcTest::NewContext();
v8::Context::Scope context_scope(new_context); v8::Context::Scope context_scope(new_context);
WebSnapshotDeserializer deserializer(isolate); WebSnapshotDeserializer deserializer(isolate, snapshot_data.buffer,
CHECK(deserializer.UseWebSnapshot(snapshot_data.buffer, snapshot_data.buffer_size);
snapshot_data.buffer_size)); CHECK(deserializer.Deserialize());
CHECK(!deserializer.has_error()); CHECK(!deserializer.has_error());
const char* get_function = "e[0]"; const char* get_function = "e[0]";
......
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