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

Side by Side Diff: src/mksnapshot.cc

Issue 328693003: Revert "Support external startup data in V8." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix brace. 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 , startup_blob_file_(NULL) 51 , compressor_(NULL)
52 , compressor_(NULL) { 52 , omit_(false) {
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_);
60 } 59 }
61 60
62 void SetCompressor(Compressor* compressor) { 61 void SetCompressor(Compressor* compressor) {
63 compressor_ = compressor; 62 compressor_ = compressor;
64 } 63 }
65 64
65 void SetOmit(bool omit) {
66 omit_ = omit;
67 }
68
66 void SetRawFiles(const char* raw_file, const char* raw_context_file) { 69 void SetRawFiles(const char* raw_file, const char* raw_context_file) {
67 raw_file_ = GetFileDescriptorOrDie(raw_file); 70 raw_file_ = GetFileDescriptorOrDie(raw_file);
68 raw_context_file_ = GetFileDescriptorOrDie(raw_context_file); 71 raw_context_file_ = GetFileDescriptorOrDie(raw_context_file);
69 } 72 }
70 73
71 void SetStartupBlobFile(const char* startup_blob_file) {
72 if (startup_blob_file != NULL)
73 startup_blob_file_ = GetFileDescriptorOrDie(startup_blob_file);
74 }
75
76 void WriteSnapshot(const i::List<char>& snapshot_data, 74 void WriteSnapshot(const i::List<char>& snapshot_data,
77 const i::Serializer& serializer, 75 const i::Serializer& serializer,
78 const i::List<char>& context_snapshot_data, 76 const i::List<char>& context_snapshot_data,
79 const i::Serializer& context_serializer) const { 77 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 {
126 WriteFilePrefix(); 78 WriteFilePrefix();
127 WriteData("", snapshot_data, raw_file_); 79 WriteData("", snapshot_data, raw_file_);
128 WriteData("context_", context_snapshot_data, raw_context_file_); 80 WriteData("context_", context_snapshot_data, raw_context_file_);
129 WriteMeta("context_", context_serializer); 81 WriteMeta("context_", context_serializer);
130 WriteMeta("", serializer); 82 WriteMeta("", serializer);
131 WriteFileSuffix(); 83 WriteFileSuffix();
132 } 84 }
133 85
86 private:
134 void WriteFilePrefix() const { 87 void WriteFilePrefix() const {
135 fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n"); 88 fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n");
136 fprintf(fp_, "#include \"src/v8.h\"\n"); 89 fprintf(fp_, "#include \"src/v8.h\"\n");
137 fprintf(fp_, "#include \"src/platform.h\"\n\n"); 90 fprintf(fp_, "#include \"src/platform.h\"\n\n");
138 fprintf(fp_, "#include \"src/snapshot.h\"\n\n"); 91 fprintf(fp_, "#include \"src/snapshot.h\"\n\n");
139 fprintf(fp_, "namespace v8 {\n"); 92 fprintf(fp_, "namespace v8 {\n");
140 fprintf(fp_, "namespace internal {\n\n"); 93 fprintf(fp_, "namespace internal {\n\n");
141 } 94 }
142 95
143 void WriteFileSuffix() const { 96 void WriteFileSuffix() const {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 if (written != (size_t)data->length()) { 130 if (written != (size_t)data->length()) {
178 i::PrintF("Writing raw file failed.. Aborting.\n"); 131 i::PrintF("Writing raw file failed.. Aborting.\n");
179 exit(1); 132 exit(1);
180 } 133 }
181 } 134 }
182 135
183 void WriteData(const char* prefix, 136 void WriteData(const char* prefix,
184 const i::List<char>& source_data, 137 const i::List<char>& source_data,
185 const i::List<char>* data_to_be_written) const { 138 const i::List<char>* data_to_be_written) const {
186 fprintf(fp_, "const byte Snapshot::%sdata_[] = {\n", prefix); 139 fprintf(fp_, "const byte Snapshot::%sdata_[] = {\n", prefix);
187 WriteSnapshotData(data_to_be_written); 140 if (!omit_)
141 WriteSnapshotData(data_to_be_written);
188 fprintf(fp_, "};\n"); 142 fprintf(fp_, "};\n");
189 fprintf(fp_, "const int Snapshot::%ssize_ = %d;\n", prefix, 143 fprintf(fp_, "const int Snapshot::%ssize_ = %d;\n", prefix,
190 data_to_be_written->length()); 144 data_to_be_written->length());
191 145
192 if (data_to_be_written == &source_data) { 146 if (data_to_be_written == &source_data && !omit_) {
193 fprintf(fp_, "const byte* Snapshot::%sraw_data_ = Snapshot::%sdata_;\n", 147 fprintf(fp_, "const byte* Snapshot::%sraw_data_ = Snapshot::%sdata_;\n",
194 prefix, prefix); 148 prefix, prefix);
195 fprintf(fp_, "const int Snapshot::%sraw_size_ = Snapshot::%ssize_;\n", 149 fprintf(fp_, "const int Snapshot::%sraw_size_ = Snapshot::%ssize_;\n",
196 prefix, prefix); 150 prefix, prefix);
197 } else { 151 } else {
198 fprintf(fp_, "const byte* Snapshot::%sraw_data_ = NULL;\n", prefix); 152 fprintf(fp_, "const byte* Snapshot::%sraw_data_ = NULL;\n", prefix);
199 fprintf(fp_, "const int Snapshot::%sraw_size_ = %d;\n", 153 fprintf(fp_, "const int Snapshot::%sraw_size_ = %d;\n",
200 prefix, source_data.length()); 154 prefix, source_data.length());
201 } 155 }
202 fprintf(fp_, "\n"); 156 fprintf(fp_, "\n");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 if (fp == NULL) { 189 if (fp == NULL) {
236 i::PrintF("Unable to open file \"%s\" for writing.\n", filename); 190 i::PrintF("Unable to open file \"%s\" for writing.\n", filename);
237 exit(1); 191 exit(1);
238 } 192 }
239 return fp; 193 return fp;
240 } 194 }
241 195
242 FILE* fp_; 196 FILE* fp_;
243 FILE* raw_file_; 197 FILE* raw_file_;
244 FILE* raw_context_file_; 198 FILE* raw_context_file_;
245 FILE* startup_blob_file_;
246 Compressor* compressor_; 199 Compressor* compressor_;
200 bool omit_;
247 }; 201 };
248 202
249 203
250 #ifdef COMPRESS_STARTUP_DATA_BZ2 204 #ifdef COMPRESS_STARTUP_DATA_BZ2
251 class BZip2Compressor : public Compressor { 205 class BZip2Compressor : public Compressor {
252 public: 206 public:
253 BZip2Compressor() : output_(NULL) {} 207 BZip2Compressor() : output_(NULL) {}
254 virtual ~BZip2Compressor() { 208 virtual ~BZip2Compressor() {
255 delete output_; 209 delete output_;
256 } 210 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 ser.SerializeStrongReferences(); 374 ser.SerializeStrongReferences();
421 375
422 i::List<char> context_data; 376 i::List<char> context_data;
423 ListSnapshotSink contex_sink(&context_data); 377 ListSnapshotSink contex_sink(&context_data);
424 i::PartialSerializer context_ser(internal_isolate, &ser, &contex_sink); 378 i::PartialSerializer context_ser(internal_isolate, &ser, &contex_sink);
425 context_ser.Serialize(&raw_context); 379 context_ser.Serialize(&raw_context);
426 ser.SerializeWeakReferences(); 380 ser.SerializeWeakReferences();
427 381
428 { 382 {
429 SnapshotWriter writer(argv[1]); 383 SnapshotWriter writer(argv[1]);
384 writer.SetOmit(i::FLAG_omit);
430 if (i::FLAG_raw_file && i::FLAG_raw_context_file) 385 if (i::FLAG_raw_file && i::FLAG_raw_context_file)
431 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file); 386 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file);
432 if (i::FLAG_startup_blob)
433 writer.SetStartupBlobFile(i::FLAG_startup_blob);
434 #ifdef COMPRESS_STARTUP_DATA_BZ2 387 #ifdef COMPRESS_STARTUP_DATA_BZ2
435 BZip2Compressor bzip2; 388 BZip2Compressor bzip2;
436 writer.SetCompressor(&bzip2); 389 writer.SetCompressor(&bzip2);
437 #endif 390 #endif
438 writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser); 391 writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser);
439 } 392 }
440 } 393 }
441 394
442 isolate->Dispose(); 395 isolate->Dispose();
443 V8::Dispose(); 396 V8::Dispose();
444 return 0; 397 return 0;
445 } 398 }
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