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

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: Final rebase (I hope) w/ various fixes. 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
« no previous file with comments | « src/snapshot.h ('k') | src/snapshot-external.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/serialize.h" 10 #include "src/serialize.h"
11 #include "src/snapshot.h" 11 #include "src/snapshot.h"
12 #include "src/platform.h" 12 #include "src/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();
(...skipping 24 matching lines...) Expand all
116 deserializer.set_reservation(CODE_SPACE, context_code_space_used_); 66 deserializer.set_reservation(CODE_SPACE, context_code_space_used_);
117 deserializer.set_reservation(MAP_SPACE, context_map_space_used_); 67 deserializer.set_reservation(MAP_SPACE, context_map_space_used_);
118 deserializer.set_reservation(CELL_SPACE, context_cell_space_used_); 68 deserializer.set_reservation(CELL_SPACE, context_cell_space_used_);
119 deserializer.set_reservation(PROPERTY_CELL_SPACE, 69 deserializer.set_reservation(PROPERTY_CELL_SPACE,
120 context_property_cell_space_used_); 70 context_property_cell_space_used_);
121 deserializer.DeserializePartial(isolate, &root); 71 deserializer.DeserializePartial(isolate, &root);
122 CHECK(root->IsContext()); 72 CHECK(root->IsContext());
123 return Handle<Context>(Context::cast(root)); 73 return Handle<Context>(Context::cast(root));
124 } 74 }
125 75
76
77 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
78 // Dummy implementations of Set*FromFile(..) APIs.
79 //
80 // These are meant for use with snapshot-external.cc. Should this file
81 // be compiled with those options we just supply these dummy implementations
82 // below. This happens when compiling the mksnapshot utility.
83 void SetNativesFromFile(StartupData* data) { CHECK(false); }
84 void SetSnapshotFromFile(StartupData* data) { CHECK(false); }
85 #endif // V8_USE_EXTERNAL_STARTUP_DATA
86
126 } } // namespace v8::internal 87 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/snapshot.h ('k') | src/snapshot-external.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698