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

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

Issue 317633003: Revert "Support external startup data in V8." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
18 void Snapshot::ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer) { 55 void Snapshot::ReserveSpaceForLinkedInSnapshot(Deserializer* deserializer) {
19 deserializer->set_reservation(NEW_SPACE, new_space_used_); 56 deserializer->set_reservation(NEW_SPACE, new_space_used_);
20 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_space_used_); 57 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_space_used_);
21 deserializer->set_reservation(OLD_DATA_SPACE, data_space_used_); 58 deserializer->set_reservation(OLD_DATA_SPACE, data_space_used_);
22 deserializer->set_reservation(CODE_SPACE, code_space_used_); 59 deserializer->set_reservation(CODE_SPACE, code_space_used_);
23 deserializer->set_reservation(MAP_SPACE, map_space_used_); 60 deserializer->set_reservation(MAP_SPACE, map_space_used_);
24 deserializer->set_reservation(CELL_SPACE, cell_space_used_); 61 deserializer->set_reservation(CELL_SPACE, cell_space_used_);
25 deserializer->set_reservation(PROPERTY_CELL_SPACE, 62 deserializer->set_reservation(PROPERTY_CELL_SPACE,
26 property_cell_space_used_); 63 property_cell_space_used_);
27 } 64 }
28 65
29 66
30 bool Snapshot::Initialize() { 67 bool Snapshot::Initialize(const char* snapshot_file) {
31 if (size_ > 0) { 68 if (snapshot_file) {
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) {
32 ElapsedTimer timer; 82 ElapsedTimer timer;
33 if (FLAG_profile_deserialization) { 83 if (FLAG_profile_deserialization) {
34 timer.Start(); 84 timer.Start();
35 } 85 }
36 SnapshotByteSource source(raw_data_, raw_size_); 86 SnapshotByteSource source(raw_data_, raw_size_);
37 Deserializer deserializer(&source); 87 Deserializer deserializer(&source);
38 ReserveSpaceForLinkedInSnapshot(&deserializer); 88 ReserveSpaceForLinkedInSnapshot(&deserializer);
39 bool success = V8::Initialize(&deserializer); 89 bool success = V8::Initialize(&deserializer);
40 if (FLAG_profile_deserialization) { 90 if (FLAG_profile_deserialization) {
41 double ms = timer.Elapsed().InMillisecondsF(); 91 double ms = timer.Elapsed().InMillisecondsF();
(...skipping 24 matching lines...) Expand all
66 deserializer.set_reservation(CODE_SPACE, context_code_space_used_); 116 deserializer.set_reservation(CODE_SPACE, context_code_space_used_);
67 deserializer.set_reservation(MAP_SPACE, context_map_space_used_); 117 deserializer.set_reservation(MAP_SPACE, context_map_space_used_);
68 deserializer.set_reservation(CELL_SPACE, context_cell_space_used_); 118 deserializer.set_reservation(CELL_SPACE, context_cell_space_used_);
69 deserializer.set_reservation(PROPERTY_CELL_SPACE, 119 deserializer.set_reservation(PROPERTY_CELL_SPACE,
70 context_property_cell_space_used_); 120 context_property_cell_space_used_);
71 deserializer.DeserializePartial(isolate, &root); 121 deserializer.DeserializePartial(isolate, &root);
72 CHECK(root->IsContext()); 122 CHECK(root->IsContext());
73 return Handle<Context>(Context::cast(root)); 123 return Handle<Context>(Context::cast(root));
74 } 124 }
75 125
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
87 } } // namespace v8::internal 126 } } // 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