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

Side by Side Diff: src/snapshot-common.cc

Issue 293993021: Support external startup data in V8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: review feedback Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The common functionality when building with or without snapshots. 5 // The common functionality when building with or without snapshots.
6 6
7 #include "v8.h" 7 #include "v8.h"
8 8
9 #include "api.h" 9 #include "api.h"
10 #include "serialize.h" 10 #include "serialize.h"
11 #include "snapshot.h" 11 #include "snapshot.h"
12 #include "platform.h" 12 #include "platform.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 17
18 static void ReserveSpaceForSnapshot(Deserializer* deserializer,
19 const char* file_name) {
20 int file_name_length = StrLength(file_name) + 10;
21 Vector<char> name = Vector<char>::New(file_name_length + 1);
22 OS::SNPrintF(name, "%s.size", file_name);
23 FILE* fp = OS::FOpen(name.start(), "r");
24 CHECK_NE(NULL, fp);
25 int new_size, pointer_size, data_size, code_size, map_size, cell_size,
26 property_cell_size;
27 #ifdef _MSC_VER
28 // Avoid warning about unsafe fscanf from MSVC.
29 // Please note that this is only fine if %c and %s are not being used.
30 #define fscanf fscanf_s
31 #endif
32 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size));
33 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size));
34 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
35 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
36 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
37 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
38 CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size));
39 #ifdef _MSC_VER
40 #undef fscanf
41 #endif
42 fclose(fp);
43 deserializer->set_reservation(NEW_SPACE, new_size);
44 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size);
45 deserializer->set_reservation(OLD_DATA_SPACE, data_size);
46 deserializer->set_reservation(CODE_SPACE, code_size);
47 deserializer->set_reservation(MAP_SPACE, map_size);
48 deserializer->set_reservation(CELL_SPACE, cell_size);
49 deserializer->set_reservation(PROPERTY_CELL_SPACE,
50 property_cell_size);
51 name.Dispose();
52 }
53
54
55 void Snapshot::ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer) { 18 void Snapshot::ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer) {
56 deserializer->set_reservation(NEW_SPACE, new_space_used_); 19 deserializer->set_reservation(NEW_SPACE, new_space_used_);
57 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_space_used_); 20 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_space_used_);
58 deserializer->set_reservation(OLD_DATA_SPACE, data_space_used_); 21 deserializer->set_reservation(OLD_DATA_SPACE, data_space_used_);
59 deserializer->set_reservation(CODE_SPACE, code_space_used_); 22 deserializer->set_reservation(CODE_SPACE, code_space_used_);
60 deserializer->set_reservation(MAP_SPACE, map_space_used_); 23 deserializer->set_reservation(MAP_SPACE, map_space_used_);
61 deserializer->set_reservation(CELL_SPACE, cell_space_used_); 24 deserializer->set_reservation(CELL_SPACE, cell_space_used_);
62 deserializer->set_reservation(PROPERTY_CELL_SPACE, 25 deserializer->set_reservation(PROPERTY_CELL_SPACE,
63 property_cell_space_used_); 26 property_cell_space_used_);
64 } 27 }
65 28
66 29
67 bool Snapshot::Initialize(const char* snapshot_file) { 30 bool Snapshot::Initialize() {
68 if (snapshot_file) { 31 if (size_ > 0) {
69 int len;
70 byte* str = ReadBytes(snapshot_file, &len);
71 if (!str) return false;
72 bool success;
73 {
74 SnapshotByteSource source(str, len);
75 Deserializer deserializer(&source);
76 ReserveSpaceForSnapshot(&deserializer, snapshot_file);
77 success = V8::Initialize(&deserializer);
78 }
79 DeleteArray(str);
80 return success;
81 } else if (size_ > 0) {
82 ElapsedTimer timer; 32 ElapsedTimer timer;
83 if (FLAG_profile_deserialization) { 33 if (FLAG_profile_deserialization) {
84 timer.Start(); 34 timer.Start();
85 } 35 }
86 SnapshotByteSource source(raw_data_, raw_size_); 36 SnapshotByteSource source(raw_data_, raw_size_);
87 Deserializer deserializer(&source); 37 Deserializer deserializer(&source);
88 ReserveSpaceForLinkedInSnapshot(&deserializer); 38 ReserveSpaceForLinkedInSnapshot(&deserializer);
89 bool success = V8::Initialize(&deserializer); 39 bool success = V8::Initialize(&deserializer);
90 if (FLAG_profile_deserialization) { 40 if (FLAG_profile_deserialization) {
91 double ms = timer.Elapsed().InMillisecondsF(); 41 double ms = timer.Elapsed().InMillisecondsF();
92 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); 42 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
93 } 43 }
94 return success; 44 return success;
95 } 45 }
96 return false; 46 return false;
97 } 47 }
98 48
99 49
100 bool Snapshot::HaveASnapshotToStartFrom() { 50 bool Snapshot::HaveASnapshotToStartFrom() {
101 return size_ != 0; 51 return size_ != 0;
102 } 52 }
103 53
104 54
55 bool Snapshot::IsEnabled() {
Benedikt Meurer 2014/05/27 04:09:59 Nit: IsEnabled() should be marked as const. Why do
vogelheim 2014/05/27 15:20:23 Removed IsEnabled; it's the exact same thing as Ha
56 return size_ != 0;
57 }
58
59
105 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { 60 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
106 if (context_size_ == 0) { 61 if (context_size_ == 0) {
107 return Handle<Context>(); 62 return Handle<Context>();
108 } 63 }
109 SnapshotByteSource source(context_raw_data_, 64 SnapshotByteSource source(context_raw_data_,
110 context_raw_size_); 65 context_raw_size_);
111 Deserializer deserializer(&source); 66 Deserializer deserializer(&source);
112 Object* root; 67 Object* root;
113 deserializer.set_reservation(NEW_SPACE, context_new_space_used_); 68 deserializer.set_reservation(NEW_SPACE, context_new_space_used_);
114 deserializer.set_reservation(OLD_POINTER_SPACE, context_pointer_space_used_); 69 deserializer.set_reservation(OLD_POINTER_SPACE, context_pointer_space_used_);
115 deserializer.set_reservation(OLD_DATA_SPACE, context_data_space_used_); 70 deserializer.set_reservation(OLD_DATA_SPACE, context_data_space_used_);
116 deserializer.set_reservation(CODE_SPACE, context_code_space_used_); 71 deserializer.set_reservation(CODE_SPACE, context_code_space_used_);
117 deserializer.set_reservation(MAP_SPACE, context_map_space_used_); 72 deserializer.set_reservation(MAP_SPACE, context_map_space_used_);
118 deserializer.set_reservation(CELL_SPACE, context_cell_space_used_); 73 deserializer.set_reservation(CELL_SPACE, context_cell_space_used_);
119 deserializer.set_reservation(PROPERTY_CELL_SPACE, 74 deserializer.set_reservation(PROPERTY_CELL_SPACE,
120 context_property_cell_space_used_); 75 context_property_cell_space_used_);
121 deserializer.DeserializePartial(isolate, &root); 76 deserializer.DeserializePartial(isolate, &root);
122 CHECK(root->IsContext()); 77 CHECK(root->IsContext());
123 return Handle<Context>(Context::cast(root)); 78 return Handle<Context>(Context::cast(root));
124 } 79 }
125 80
81
82 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
83 // Dummy implementations of Set*FromFile(..) APIs.
84 //
85 // These are meant for use with snapshot-external.cc. Should this file
86 // be compiled with those options we just supply these dummy implementations
87 // below. This happens when compiling the mksnapshot utility.
88 void SetNativesFromFile(StartupData* data) { CHECK(false); }
89 void SetSnapshotFromFile(StartupData* data) { CHECK(false); }
90 #endif // V8_USE_EXTERNAL_STARTUP_DATA
91
126 } } // namespace v8::internal 92 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698