Commit 290cd816 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[serializer] Serialize empty embedder fields by default

When running mksnapshot standalone, no callback is registered to
serialize embedder fields. In this case they are most probably empty as
there is no embedder to set them, so provide a default serialization
that keeps them as nullptr.

Bug: v8:8822
Change-Id: I9219f2755488aa1473959c3ee75e9d4f47202359
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1507677
Auto-Submit: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60094}
parent 5ed3c81e
......@@ -143,7 +143,6 @@ bool PartialSerializer::SerializeJSObjectWithEmbedderFields(Object obj) {
int embedder_fields_count = js_obj->GetEmbedderFieldCount();
if (embedder_fields_count == 0) return false;
CHECK_GT(embedder_fields_count, 0);
DCHECK_NOT_NULL(serialize_embedder_fields_.callback);
DCHECK(!js_obj->NeedsRehashing());
DisallowHeapAllocation no_gc;
......@@ -169,11 +168,19 @@ bool PartialSerializer::SerializeJSObjectWithEmbedderFields(Object obj) {
DCHECK(isolate()->heap()->Contains(HeapObject::cast(object)));
serialized_data.push_back({nullptr, 0});
} else {
// If no serializer is provided and the field was empty, we serialize it
// by default to nullptr.
if (serialize_embedder_fields_.callback == nullptr &&
object->ptr() == 0) {
serialized_data.push_back({nullptr, 0});
} else {
DCHECK_NOT_NULL(serialize_embedder_fields_.callback);
StartupData data = serialize_embedder_fields_.callback(
api_obj, i, serialize_embedder_fields_.data);
serialized_data.push_back(data);
}
}
}
// 2) Embedder fields for which the embedder callback produced non-zero
// serialized data should be considered aligned pointers to objects owned
......
......@@ -1257,6 +1257,44 @@ UNINITIALIZED_TEST(CustomSnapshotDataBlobOnOrOffHeapTypedArray) {
FreeCurrentEmbeddedBlob();
}
UNINITIALIZED_TEST(CustomSnapshotDataBlobTypedArrayNoEmbedderFieldCallback) {
const char* code = "var x = new Uint8Array(8);";
DisableAlwaysOpt();
i::FLAG_allow_natives_syntax = true;
DisableEmbeddedBlobRefcounting();
v8::StartupData blob;
{
v8::SnapshotCreator creator;
v8::Isolate* isolate = creator.GetIsolate();
{
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
CompileRun(code);
creator.SetDefaultContext(context, v8::SerializeInternalFieldsCallback());
}
blob =
creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
}
v8::Isolate::CreateParams create_params;
create_params.snapshot_blob = &blob;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = TestSerializer::NewIsolate(create_params);
{
v8::Isolate::Scope i_scope(isolate);
v8::HandleScope h_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(
isolate, nullptr, v8::MaybeLocal<v8::ObjectTemplate>(),
v8::MaybeLocal<v8::Value>(), v8::DeserializeInternalFieldsCallback());
v8::Context::Scope c_scope(context);
}
isolate->Dispose();
delete[] blob.data; // We can dispose of the snapshot blob now.
FreeCurrentEmbeddedBlob();
}
UNINITIALIZED_TEST(CustomSnapshotDataBlob2) {
DisableAlwaysOpt();
const char* source2 =
......
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