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

Side by Side Diff: src/mksnapshot.cc

Issue 7066048: Compress sources of JS libraries in addition to the snapshot. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 char at(int i) { return data_[i]; } 129 char at(int i) { return data_[i]; }
130 bool Compress(Compressor* compressor) { 130 bool Compress(Compressor* compressor) {
131 ASSERT_EQ(-1, raw_size_); 131 ASSERT_EQ(-1, raw_size_);
132 raw_size_ = data_.length(); 132 raw_size_ = data_.length();
133 if (!compressor->Compress(data_.ToVector())) return false; 133 if (!compressor->Compress(data_.ToVector())) return false;
134 data_.Clear(); 134 data_.Clear();
135 data_.AddAll(*compressor->output()); 135 data_.AddAll(*compressor->output());
136 return true; 136 return true;
137 } 137 }
138 int raw_size() { return raw_size_; } 138 int raw_size() { return raw_size_; }
139
139 private: 140 private:
140 i::List<char> data_; 141 i::List<char> data_;
141 int raw_size_; 142 int raw_size_;
142 }; 143 };
143 144
144 145
145 class CppByteSink : public PartialSnapshotSink { 146 class CppByteSink : public PartialSnapshotSink {
146 public: 147 public:
147 explicit CppByteSink(const char* snapshot_file) { 148 explicit CppByteSink(const char* snapshot_file) {
148 fp_ = i::OS::FOpen(snapshot_file, "wb"); 149 fp_ = i::OS::FOpen(snapshot_file, "wb");
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } else { 259 } else {
259 fprintf(stderr, "bzlib error code: %d\n", result); 260 fprintf(stderr, "bzlib error code: %d\n", result);
260 return false; 261 return false;
261 } 262 }
262 } 263 }
263 virtual i::Vector<char>* output() { return output_; } 264 virtual i::Vector<char>* output() { return output_; }
264 265
265 private: 266 private:
266 i::ScopedVector<char>* output_; 267 i::ScopedVector<char>* output_;
267 }; 268 };
269
270 class BZip2Decompressor {
271 public:
272 BZip2Decompressor()
273 : libraries(i::NewArray<char*>(i::Natives::GetBuiltinsCount())) {
274 }
275 ~BZip2Decompressor() {
276 for (int i = 0; i < i::Natives::GetBuiltinsCount(); ++i) {
277 i::DeleteArray(libraries[i]);
278 }
279 i::DeleteArray(libraries);
280 }
281 void DecompressNatives() {
282 for (int i = 0; i < i::Natives::GetBuiltinsCount(); ++i) {
Vitaly Repeshko 2011/06/06 10:08:23 Hmm, it seems annoying to repeat this code with th
mnaganov (inactive) 2011/06/06 13:40:18 Converted to API usage (as Soeren suggested), and
283 unsigned int decompressed_size = i::Natives::GetRawScriptSize(i);
284 libraries[i] = i::NewArray<char>(decompressed_size);
285 i::Vector<const i::byte> compressed = i::Natives::GetScriptSource(i);
286 int result =
287 BZ2_bzBuffToBuffDecompress(libraries[i],
288 &decompressed_size,
289 reinterpret_cast<char*>(
290 const_cast<i::byte*>(
291 compressed.start())),
292 compressed.length(),
293 0, 1);
294 if (result != BZ_OK) {
295 fprintf(stderr, "libraries: bzip error code: %d\n", result);
296 exit(1);
297 }
298 i::Natives::SetRawScriptSource(
299 i, i::Vector<const char>(libraries[i], decompressed_size));
300 }
301 }
302
303 private:
304 char** libraries;
305 };
268 #endif 306 #endif
269 307
270 308
271 int main(int argc, char** argv) { 309 int main(int argc, char** argv) {
272 #ifdef ENABLE_LOGGING_AND_PROFILING 310 #ifdef ENABLE_LOGGING_AND_PROFILING
273 // By default, log code create information in the snapshot. 311 // By default, log code create information in the snapshot.
274 i::FLAG_log_code = true; 312 i::FLAG_log_code = true;
275 #endif 313 #endif
276 // Print the usage if an error occurs when parsing the command line 314 // Print the usage if an error occurs when parsing the command line
277 // flags or if the help flag is set. 315 // flags or if the help flag is set.
278 int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); 316 int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
279 if (result > 0 || argc != 2 || i::FLAG_help) { 317 if (result > 0 || argc != 2 || i::FLAG_help) {
280 ::printf("Usage: %s [flag] ... outfile\n", argv[0]); 318 ::printf("Usage: %s [flag] ... outfile\n", argv[0]);
281 i::FlagList::PrintHelp(); 319 i::FlagList::PrintHelp();
282 return !i::FLAG_help; 320 return !i::FLAG_help;
283 } 321 }
322 #ifdef COMPRESS_STARTUP_DATA_BZ2
Søren Thygesen Gjesse 2011/06/06 09:22:01 Can't we use the normal V8 API here?
mnaganov (inactive) 2011/06/06 13:40:18 Done.
323 BZip2Decompressor natives_decompressor;
324 natives_decompressor.DecompressNatives();
325 #endif
284 i::Serializer::Enable(); 326 i::Serializer::Enable();
285 Persistent<Context> context = v8::Context::New(); 327 Persistent<Context> context = v8::Context::New();
286 ASSERT(!context.IsEmpty()); 328 ASSERT(!context.IsEmpty());
287 // Make sure all builtin scripts are cached. 329 // Make sure all builtin scripts are cached.
288 { HandleScope scope; 330 { HandleScope scope;
289 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { 331 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
290 i::Isolate::Current()->bootstrapper()->NativesSourceLookup(i); 332 i::Isolate::Current()->bootstrapper()->NativesSourceLookup(i);
291 } 333 }
292 } 334 }
293 // If we don't do this then we end up with a stray root pointing at the 335 // If we don't do this then we end up with a stray root pointing at the
(...skipping 25 matching lines...) Expand all
319 sink.WriteSpaceUsed( 361 sink.WriteSpaceUsed(
320 partial_ser.CurrentAllocationAddress(i::NEW_SPACE), 362 partial_ser.CurrentAllocationAddress(i::NEW_SPACE),
321 partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE), 363 partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE),
322 partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE), 364 partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE),
323 partial_ser.CurrentAllocationAddress(i::CODE_SPACE), 365 partial_ser.CurrentAllocationAddress(i::CODE_SPACE),
324 partial_ser.CurrentAllocationAddress(i::MAP_SPACE), 366 partial_ser.CurrentAllocationAddress(i::MAP_SPACE),
325 partial_ser.CurrentAllocationAddress(i::CELL_SPACE), 367 partial_ser.CurrentAllocationAddress(i::CELL_SPACE),
326 partial_ser.CurrentAllocationAddress(i::LO_SPACE)); 368 partial_ser.CurrentAllocationAddress(i::LO_SPACE));
327 return 0; 369 return 0;
328 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698