Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: src/api.cc

Issue 2076083002: [snapshot] support including templates in the snapshot. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@externalref
Patch Set: fix build Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | src/heap/heap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 1de62f2e4cc5c0346292ec8e0fc20b4d7df7371a..e72abc87de14ecf523fe5d892b694287db3cbc26 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -386,7 +386,10 @@ bool RunExtraCode(Isolate* isolate, Local<Context> context,
struct SnapshotCreatorData {
explicit SnapshotCreatorData(Isolate* isolate)
- : isolate_(isolate), contexts_(isolate), created_(false) {}
+ : isolate_(isolate),
+ contexts_(isolate),
+ templates_(isolate),
+ created_(false) {}
static SnapshotCreatorData* cast(void* data) {
return reinterpret_cast<SnapshotCreatorData*>(data);
@@ -395,6 +398,7 @@ struct SnapshotCreatorData {
ArrayBufferAllocator allocator_;
Isolate* isolate_;
PersistentValueVector<Context> contexts_;
+ PersistentValueVector<Template> templates_;
bool created_;
};
@@ -442,12 +446,35 @@ size_t SnapshotCreator::AddContext(Local<Context> context) {
return index;
}
+size_t SnapshotCreator::AddTemplate(Local<Template> template_obj) {
+ DCHECK(!template_obj.IsEmpty());
+ SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
+ DCHECK(!data->created_);
+ DCHECK_EQ(reinterpret_cast<i::Isolate*>(data->isolate_),
+ Utils::OpenHandle(*template_obj)->GetIsolate());
+ size_t index = static_cast<int>(data->templates_.Size());
+ data->templates_.Append(template_obj);
+ return index;
+}
+
StartupData SnapshotCreator::CreateBlob(
SnapshotCreator::FunctionCodeHandling function_code_handling) {
SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_);
DCHECK(!data->created_);
+ {
+ int num_templates = static_cast<int>(data->templates_.Size());
+ i::HandleScope scope(isolate);
+ i::Handle<i::FixedArray> templates =
+ isolate->factory()->NewFixedArray(num_templates, i::TENURED);
+ for (int i = 0; i < num_templates; i++) {
+ templates->set(i, *v8::Utils::OpenHandle(*data->templates_.Get(i)));
+ }
+ isolate->heap()->SetSerializedTemplates(*templates);
+ data->templates_.Clear();
+ }
+
// If we don't do this then we end up with a stray root pointing at the
// context even after we have disposed of the context.
isolate->heap()->CollectAllAvailableGarbage("mksnapshot");
@@ -1173,6 +1200,20 @@ Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate,
length, false);
}
+Local<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate,
+ size_t index) {
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ i::FixedArray* templates = i_isolate->heap()->serialized_templates();
+ int int_index = static_cast<int>(index);
+ if (int_index < templates->length()) {
+ i::Object* info = i_isolate->heap()->serialized_templates()->get(int_index);
+ if (info->IsFunctionTemplateInfo()) {
+ return Utils::ToLocal(i::Handle<i::FunctionTemplateInfo>(
+ i::FunctionTemplateInfo::cast(info)));
+ }
+ }
+ return Local<FunctionTemplate>();
+}
Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler(
Isolate* isolate, FunctionCallback callback,
@@ -1384,6 +1425,21 @@ Local<ObjectTemplate> ObjectTemplate::New(
return ObjectTemplateNew(isolate, constructor, false);
}
+Local<ObjectTemplate> ObjectTemplate::FromSnapshot(Isolate* isolate,
+ size_t index) {
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ i::FixedArray* templates = i_isolate->heap()->serialized_templates();
+ int int_index = static_cast<int>(index);
+ if (int_index < templates->length()) {
+ i::Object* info = i_isolate->heap()->serialized_templates()->get(int_index);
+ if (info->IsObjectTemplateInfo()) {
+ return Utils::ToLocal(
+ i::Handle<i::ObjectTemplateInfo>(i::ObjectTemplateInfo::cast(info)));
+ }
+ }
+ return Local<ObjectTemplate>();
+}
+
// Ensure that the object template has a constructor. If no
// constructor is available we create one.
static i::Handle<i::FunctionTemplateInfo> EnsureConstructor(
« no previous file with comments | « include/v8.h ('k') | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698