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

Side by Side Diff: src/mksnapshot.cc

Issue 750543002: Rip out bzip compression for native sources. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: compressed_size Created 6 years, 1 month 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
« no previous file with comments | « src/d8.gyp ('k') | src/snapshot.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 <signal.h>
6 #include <stdio.h> 7 #include <stdio.h>
7 #ifdef COMPRESS_STARTUP_DATA_BZ2
8 #include <bzlib.h>
9 #endif
10 #include <signal.h>
11 8
12 #include "src/v8.h" 9 #include "src/v8.h"
13 10
14 #include "include/libplatform/libplatform.h" 11 #include "include/libplatform/libplatform.h"
15 #include "src/assembler.h" 12 #include "src/assembler.h"
16 #include "src/base/platform/platform.h" 13 #include "src/base/platform/platform.h"
17 #include "src/bootstrapper.h" 14 #include "src/bootstrapper.h"
18 #include "src/flags.h" 15 #include "src/flags.h"
19 #include "src/list.h" 16 #include "src/list.h"
20 #include "src/natives.h" 17 #include "src/natives.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 239 }
243 240
244 FILE* fp_; 241 FILE* fp_;
245 FILE* raw_file_; 242 FILE* raw_file_;
246 FILE* raw_context_file_; 243 FILE* raw_context_file_;
247 FILE* startup_blob_file_; 244 FILE* startup_blob_file_;
248 Compressor* compressor_; 245 Compressor* compressor_;
249 }; 246 };
250 247
251 248
252 #ifdef COMPRESS_STARTUP_DATA_BZ2
253 class BZip2Compressor : public Compressor {
254 public:
255 BZip2Compressor() : output_(NULL) {}
256 virtual ~BZip2Compressor() {
257 delete output_;
258 }
259 virtual bool Compress(i::Vector<char> input) {
260 delete output_;
261 output_ = new i::ScopedVector<char>((input.length() * 101) / 100 + 1000);
262 unsigned int output_length_ = output_->length();
263 int result = BZ2_bzBuffToBuffCompress(output_->start(), &output_length_,
264 input.start(), input.length(),
265 9, 1, 0);
266 if (result == BZ_OK) {
267 output_->Truncate(output_length_);
268 return true;
269 } else {
270 fprintf(stderr, "bzlib error code: %d\n", result);
271 return false;
272 }
273 }
274 virtual i::Vector<char>* output() { return output_; }
275
276 private:
277 i::ScopedVector<char>* output_;
278 };
279
280
281 class BZip2Decompressor : public StartupDataDecompressor {
282 public:
283 virtual ~BZip2Decompressor() { }
284
285 protected:
286 virtual int DecompressData(char* raw_data,
287 int* raw_data_size,
288 const char* compressed_data,
289 int compressed_data_size) {
290 DCHECK_EQ(StartupData::kBZip2,
291 V8::GetCompressedStartupDataAlgorithm());
292 unsigned int decompressed_size = *raw_data_size;
293 int result =
294 BZ2_bzBuffToBuffDecompress(raw_data,
295 &decompressed_size,
296 const_cast<char*>(compressed_data),
297 compressed_data_size,
298 0, 1);
299 if (result == BZ_OK) {
300 *raw_data_size = decompressed_size;
301 }
302 return result;
303 }
304 };
305 #endif
306
307
308 void DumpException(Handle<Message> message) { 249 void DumpException(Handle<Message> message) {
309 String::Utf8Value message_string(message->Get()); 250 String::Utf8Value message_string(message->Get());
310 String::Utf8Value message_line(message->GetSourceLine()); 251 String::Utf8Value message_line(message->GetSourceLine());
311 fprintf(stderr, "%s at line %d\n", *message_string, message->GetLineNumber()); 252 fprintf(stderr, "%s at line %d\n", *message_string, message->GetLineNumber());
312 fprintf(stderr, "%s\n", *message_line); 253 fprintf(stderr, "%s\n", *message_line);
313 for (int i = 0; i <= message->GetEndColumn(); ++i) { 254 for (int i = 0; i <= message->GetEndColumn(); ++i) {
314 fprintf(stderr, "%c", i < message->GetStartColumn() ? ' ' : '^'); 255 fprintf(stderr, "%c", i < message->GetStartColumn() ? ' ' : '^');
315 } 256 }
316 fprintf(stderr, "\n"); 257 fprintf(stderr, "\n");
317 } 258 }
(...skipping 11 matching lines...) Expand all
329 i::FlagList::PrintHelp(); 270 i::FlagList::PrintHelp();
330 return !i::FLAG_help; 271 return !i::FLAG_help;
331 } 272 }
332 273
333 i::CpuFeatures::Probe(true); 274 i::CpuFeatures::Probe(true);
334 V8::InitializeICU(); 275 V8::InitializeICU();
335 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); 276 v8::Platform* platform = v8::platform::CreateDefaultPlatform();
336 v8::V8::InitializePlatform(platform); 277 v8::V8::InitializePlatform(platform);
337 v8::V8::Initialize(); 278 v8::V8::Initialize();
338 279
339 #ifdef COMPRESS_STARTUP_DATA_BZ2
340 BZip2Decompressor natives_decompressor;
341 int bz2_result = natives_decompressor.Decompress();
342 if (bz2_result != BZ_OK) {
343 fprintf(stderr, "bzip error code: %d\n", bz2_result);
344 exit(1);
345 }
346 #endif
347 i::FLAG_logfile_per_isolate = false; 280 i::FLAG_logfile_per_isolate = false;
348 281
349 Isolate::CreateParams params; 282 Isolate::CreateParams params;
350 params.enable_serializer = true; 283 params.enable_serializer = true;
351 Isolate* isolate = v8::Isolate::New(params); 284 Isolate* isolate = v8::Isolate::New(params);
352 { Isolate::Scope isolate_scope(isolate); 285 { Isolate::Scope isolate_scope(isolate);
353 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 286 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
354 287
355 Persistent<Context> context; 288 Persistent<Context> context;
356 { 289 {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 363
431 context_ser.FinalizeAllocation(); 364 context_ser.FinalizeAllocation();
432 ser.FinalizeAllocation(); 365 ser.FinalizeAllocation();
433 366
434 { 367 {
435 SnapshotWriter writer(argv[1]); 368 SnapshotWriter writer(argv[1]);
436 if (i::FLAG_raw_file && i::FLAG_raw_context_file) 369 if (i::FLAG_raw_file && i::FLAG_raw_context_file)
437 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file); 370 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file);
438 if (i::FLAG_startup_blob) 371 if (i::FLAG_startup_blob)
439 writer.SetStartupBlobFile(i::FLAG_startup_blob); 372 writer.SetStartupBlobFile(i::FLAG_startup_blob);
440 #ifdef COMPRESS_STARTUP_DATA_BZ2
441 BZip2Compressor bzip2;
442 writer.SetCompressor(&bzip2);
443 #endif
444 writer.WriteSnapshot(snapshot_sink.data(), ser, context_sink.data(), 373 writer.WriteSnapshot(snapshot_sink.data(), ser, context_sink.data(),
445 context_ser); 374 context_ser);
446 } 375 }
447 } 376 }
448 377
449 isolate->Dispose(); 378 isolate->Dispose();
450 V8::Dispose(); 379 V8::Dispose();
451 V8::ShutdownPlatform(); 380 V8::ShutdownPlatform();
452 delete platform; 381 delete platform;
453 return 0; 382 return 0;
454 } 383 }
OLDNEW
« no previous file with comments | « src/d8.gyp ('k') | src/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698