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

Side by Side Diff: src/mksnapshot.cc

Issue 334913004: Support external startup data in V8. (retry) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase + style fix 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/heap.cc ('k') | src/natives.h » ('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 #include <errno.h> 5 #include <errno.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #ifdef COMPRESS_STARTUP_DATA_BZ2 7 #ifdef COMPRESS_STARTUP_DATA_BZ2
8 #include <bzlib.h> 8 #include <bzlib.h>
9 #endif 9 #endif
10 #include <signal.h> 10 #include <signal.h>
(...skipping 30 matching lines...) Expand all
41 i::List<char>* data_; 41 i::List<char>* data_;
42 }; 42 };
43 43
44 44
45 class SnapshotWriter { 45 class SnapshotWriter {
46 public: 46 public:
47 explicit SnapshotWriter(const char* snapshot_file) 47 explicit SnapshotWriter(const char* snapshot_file)
48 : fp_(GetFileDescriptorOrDie(snapshot_file)) 48 : fp_(GetFileDescriptorOrDie(snapshot_file))
49 , raw_file_(NULL) 49 , raw_file_(NULL)
50 , raw_context_file_(NULL) 50 , raw_context_file_(NULL)
51 , compressor_(NULL) 51 , startup_blob_file_(NULL)
52 , omit_(false) { 52 , compressor_(NULL) {
53 } 53 }
54 54
55 ~SnapshotWriter() { 55 ~SnapshotWriter() {
56 fclose(fp_); 56 fclose(fp_);
57 if (raw_file_) fclose(raw_file_); 57 if (raw_file_) fclose(raw_file_);
58 if (raw_context_file_) fclose(raw_context_file_); 58 if (raw_context_file_) fclose(raw_context_file_);
59 if (startup_blob_file_) fclose(startup_blob_file_);
59 } 60 }
60 61
61 void SetCompressor(Compressor* compressor) { 62 void SetCompressor(Compressor* compressor) {
62 compressor_ = compressor; 63 compressor_ = compressor;
63 } 64 }
64 65
65 void SetOmit(bool omit) {
66 omit_ = omit;
67 }
68
69 void SetRawFiles(const char* raw_file, const char* raw_context_file) { 66 void SetRawFiles(const char* raw_file, const char* raw_context_file) {
70 raw_file_ = GetFileDescriptorOrDie(raw_file); 67 raw_file_ = GetFileDescriptorOrDie(raw_file);
71 raw_context_file_ = GetFileDescriptorOrDie(raw_context_file); 68 raw_context_file_ = GetFileDescriptorOrDie(raw_context_file);
72 } 69 }
73 70
71 void SetStartupBlobFile(const char* startup_blob_file) {
72 if (startup_blob_file != NULL)
73 startup_blob_file_ = GetFileDescriptorOrDie(startup_blob_file);
74 }
75
74 void WriteSnapshot(const i::List<char>& snapshot_data, 76 void WriteSnapshot(const i::List<char>& snapshot_data,
75 const i::Serializer& serializer, 77 const i::Serializer& serializer,
76 const i::List<char>& context_snapshot_data, 78 const i::List<char>& context_snapshot_data,
77 const i::Serializer& context_serializer) const { 79 const i::Serializer& context_serializer) const {
80 WriteSnapshotFile(snapshot_data, serializer,
81 context_snapshot_data, context_serializer);
82 MaybeWriteStartupBlob(snapshot_data, serializer,
83 context_snapshot_data, context_serializer);
84 }
85
86 private:
87 void MaybeWriteStartupBlob(const i::List<char>& snapshot_data,
88 const i::Serializer& serializer,
89 const i::List<char>& context_snapshot_data,
90 const i::Serializer& context_serializer) const {
91 if (!startup_blob_file_)
92 return;
93
94 i::List<char> startup_blob;
95 ListSnapshotSink sink(&startup_blob);
96
97 int spaces[] = {
98 i::NEW_SPACE, i::OLD_POINTER_SPACE, i::OLD_DATA_SPACE, i::CODE_SPACE,
99 i::MAP_SPACE, i::CELL_SPACE, i::PROPERTY_CELL_SPACE
100 };
101
102 i::byte* snapshot_bytes = reinterpret_cast<i::byte*>(snapshot_data.begin());
103 sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot");
104 for (size_t i = 0; i < ARRAY_SIZE(spaces); ++i)
105 sink.PutInt(serializer.CurrentAllocationAddress(spaces[i]), "spaces");
106
107 i::byte* context_bytes =
108 reinterpret_cast<i::byte*>(context_snapshot_data.begin());
109 sink.PutBlob(context_bytes, context_snapshot_data.length(), "context");
110 for (size_t i = 0; i < ARRAY_SIZE(spaces); ++i)
111 sink.PutInt(context_serializer.CurrentAllocationAddress(spaces[i]),
112 "spaces");
113
114 size_t written = fwrite(startup_blob.begin(), 1, startup_blob.length(),
115 startup_blob_file_);
116 if (written != (size_t)startup_blob.length()) {
117 i::PrintF("Writing snapshot file failed.. Aborting.\n");
118 exit(1);
119 }
120 }
121
122 void WriteSnapshotFile(const i::List<char>& snapshot_data,
123 const i::Serializer& serializer,
124 const i::List<char>& context_snapshot_data,
125 const i::Serializer& context_serializer) const {
78 WriteFilePrefix(); 126 WriteFilePrefix();
79 WriteData("", snapshot_data, raw_file_); 127 WriteData("", snapshot_data, raw_file_);
80 WriteData("context_", context_snapshot_data, raw_context_file_); 128 WriteData("context_", context_snapshot_data, raw_context_file_);
81 WriteMeta("context_", context_serializer); 129 WriteMeta("context_", context_serializer);
82 WriteMeta("", serializer); 130 WriteMeta("", serializer);
83 WriteFileSuffix(); 131 WriteFileSuffix();
84 } 132 }
85 133
86 private:
87 void WriteFilePrefix() const { 134 void WriteFilePrefix() const {
88 fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n"); 135 fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n");
89 fprintf(fp_, "#include \"src/v8.h\"\n"); 136 fprintf(fp_, "#include \"src/v8.h\"\n");
90 fprintf(fp_, "#include \"src/platform.h\"\n\n"); 137 fprintf(fp_, "#include \"src/platform.h\"\n\n");
91 fprintf(fp_, "#include \"src/snapshot.h\"\n\n"); 138 fprintf(fp_, "#include \"src/snapshot.h\"\n\n");
92 fprintf(fp_, "namespace v8 {\n"); 139 fprintf(fp_, "namespace v8 {\n");
93 fprintf(fp_, "namespace internal {\n\n"); 140 fprintf(fp_, "namespace internal {\n\n");
94 } 141 }
95 142
96 void WriteFileSuffix() const { 143 void WriteFileSuffix() const {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (written != (size_t)data->length()) { 177 if (written != (size_t)data->length()) {
131 i::PrintF("Writing raw file failed.. Aborting.\n"); 178 i::PrintF("Writing raw file failed.. Aborting.\n");
132 exit(1); 179 exit(1);
133 } 180 }
134 } 181 }
135 182
136 void WriteData(const char* prefix, 183 void WriteData(const char* prefix,
137 const i::List<char>& source_data, 184 const i::List<char>& source_data,
138 const i::List<char>* data_to_be_written) const { 185 const i::List<char>* data_to_be_written) const {
139 fprintf(fp_, "const byte Snapshot::%sdata_[] = {\n", prefix); 186 fprintf(fp_, "const byte Snapshot::%sdata_[] = {\n", prefix);
140 if (!omit_) 187 WriteSnapshotData(data_to_be_written);
141 WriteSnapshotData(data_to_be_written);
142 fprintf(fp_, "};\n"); 188 fprintf(fp_, "};\n");
143 fprintf(fp_, "const int Snapshot::%ssize_ = %d;\n", prefix, 189 fprintf(fp_, "const int Snapshot::%ssize_ = %d;\n", prefix,
144 data_to_be_written->length()); 190 data_to_be_written->length());
145 191
146 if (data_to_be_written == &source_data && !omit_) { 192 if (data_to_be_written == &source_data) {
147 fprintf(fp_, "const byte* Snapshot::%sraw_data_ = Snapshot::%sdata_;\n", 193 fprintf(fp_, "const byte* Snapshot::%sraw_data_ = Snapshot::%sdata_;\n",
148 prefix, prefix); 194 prefix, prefix);
149 fprintf(fp_, "const int Snapshot::%sraw_size_ = Snapshot::%ssize_;\n", 195 fprintf(fp_, "const int Snapshot::%sraw_size_ = Snapshot::%ssize_;\n",
150 prefix, prefix); 196 prefix, prefix);
151 } else { 197 } else {
152 fprintf(fp_, "const byte* Snapshot::%sraw_data_ = NULL;\n", prefix); 198 fprintf(fp_, "const byte* Snapshot::%sraw_data_ = NULL;\n", prefix);
153 fprintf(fp_, "const int Snapshot::%sraw_size_ = %d;\n", 199 fprintf(fp_, "const int Snapshot::%sraw_size_ = %d;\n",
154 prefix, source_data.length()); 200 prefix, source_data.length());
155 } 201 }
156 fprintf(fp_, "\n"); 202 fprintf(fp_, "\n");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (fp == NULL) { 235 if (fp == NULL) {
190 i::PrintF("Unable to open file \"%s\" for writing.\n", filename); 236 i::PrintF("Unable to open file \"%s\" for writing.\n", filename);
191 exit(1); 237 exit(1);
192 } 238 }
193 return fp; 239 return fp;
194 } 240 }
195 241
196 FILE* fp_; 242 FILE* fp_;
197 FILE* raw_file_; 243 FILE* raw_file_;
198 FILE* raw_context_file_; 244 FILE* raw_context_file_;
245 FILE* startup_blob_file_;
199 Compressor* compressor_; 246 Compressor* compressor_;
200 bool omit_;
201 }; 247 };
202 248
203 249
204 #ifdef COMPRESS_STARTUP_DATA_BZ2 250 #ifdef COMPRESS_STARTUP_DATA_BZ2
205 class BZip2Compressor : public Compressor { 251 class BZip2Compressor : public Compressor {
206 public: 252 public:
207 BZip2Compressor() : output_(NULL) {} 253 BZip2Compressor() : output_(NULL) {}
208 virtual ~BZip2Compressor() { 254 virtual ~BZip2Compressor() {
209 delete output_; 255 delete output_;
210 } 256 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 ser.SerializeStrongReferences(); 420 ser.SerializeStrongReferences();
375 421
376 i::List<char> context_data; 422 i::List<char> context_data;
377 ListSnapshotSink contex_sink(&context_data); 423 ListSnapshotSink contex_sink(&context_data);
378 i::PartialSerializer context_ser(internal_isolate, &ser, &contex_sink); 424 i::PartialSerializer context_ser(internal_isolate, &ser, &contex_sink);
379 context_ser.Serialize(&raw_context); 425 context_ser.Serialize(&raw_context);
380 ser.SerializeWeakReferences(); 426 ser.SerializeWeakReferences();
381 427
382 { 428 {
383 SnapshotWriter writer(argv[1]); 429 SnapshotWriter writer(argv[1]);
384 writer.SetOmit(i::FLAG_omit);
385 if (i::FLAG_raw_file && i::FLAG_raw_context_file) 430 if (i::FLAG_raw_file && i::FLAG_raw_context_file)
386 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file); 431 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file);
432 if (i::FLAG_startup_blob)
433 writer.SetStartupBlobFile(i::FLAG_startup_blob);
387 #ifdef COMPRESS_STARTUP_DATA_BZ2 434 #ifdef COMPRESS_STARTUP_DATA_BZ2
388 BZip2Compressor bzip2; 435 BZip2Compressor bzip2;
389 writer.SetCompressor(&bzip2); 436 writer.SetCompressor(&bzip2);
390 #endif 437 #endif
391 writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser); 438 writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser);
392 } 439 }
393 } 440 }
394 441
395 isolate->Dispose(); 442 isolate->Dispose();
396 V8::Dispose(); 443 V8::Dispose();
397 return 0; 444 return 0;
398 } 445 }
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698