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

Side by Side Diff: src/mksnapshot.cc

Issue 373713006: Introduce code serializer/deserializer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments and rebased Created 6 years, 5 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/full-codegen.cc ('k') | src/parser.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 14 matching lines...) Expand all
25 25
26 26
27 class Compressor { 27 class Compressor {
28 public: 28 public:
29 virtual ~Compressor() {} 29 virtual ~Compressor() {}
30 virtual bool Compress(i::Vector<char> input) = 0; 30 virtual bool Compress(i::Vector<char> input) = 0;
31 virtual i::Vector<char>* output() = 0; 31 virtual i::Vector<char>* output() = 0;
32 }; 32 };
33 33
34 34
35 class ListSnapshotSink : public i::SnapshotByteSink {
36 public:
37 explicit ListSnapshotSink(i::List<char>* data) : data_(data) { }
38 virtual ~ListSnapshotSink() {}
39 virtual void Put(int byte, const char* description) { data_->Add(byte); }
40 virtual int Position() { return data_->length(); }
41 private:
42 i::List<char>* data_;
43 };
44
45
46 class SnapshotWriter { 35 class SnapshotWriter {
47 public: 36 public:
48 explicit SnapshotWriter(const char* snapshot_file) 37 explicit SnapshotWriter(const char* snapshot_file)
49 : fp_(GetFileDescriptorOrDie(snapshot_file)) 38 : fp_(GetFileDescriptorOrDie(snapshot_file))
50 , raw_file_(NULL) 39 , raw_file_(NULL)
51 , raw_context_file_(NULL) 40 , raw_context_file_(NULL)
52 , startup_blob_file_(NULL) 41 , startup_blob_file_(NULL)
53 , compressor_(NULL) { 42 , compressor_(NULL) {
54 } 43 }
55 44
(...skipping 30 matching lines...) Expand all
86 75
87 private: 76 private:
88 void MaybeWriteStartupBlob(const i::List<char>& snapshot_data, 77 void MaybeWriteStartupBlob(const i::List<char>& snapshot_data,
89 const i::Serializer& serializer, 78 const i::Serializer& serializer,
90 const i::List<char>& context_snapshot_data, 79 const i::List<char>& context_snapshot_data,
91 const i::Serializer& context_serializer) const { 80 const i::Serializer& context_serializer) const {
92 if (!startup_blob_file_) 81 if (!startup_blob_file_)
93 return; 82 return;
94 83
95 i::List<char> startup_blob; 84 i::List<char> startup_blob;
96 ListSnapshotSink sink(&startup_blob); 85 i::ListSnapshotSink sink(&startup_blob);
97 86
98 int spaces[] = { 87 int spaces[] = {
99 i::NEW_SPACE, i::OLD_POINTER_SPACE, i::OLD_DATA_SPACE, i::CODE_SPACE, 88 i::NEW_SPACE, i::OLD_POINTER_SPACE, i::OLD_DATA_SPACE, i::CODE_SPACE,
100 i::MAP_SPACE, i::CELL_SPACE, i::PROPERTY_CELL_SPACE 89 i::MAP_SPACE, i::CELL_SPACE, i::PROPERTY_CELL_SPACE
101 }; 90 };
102 91
103 i::byte* snapshot_bytes = reinterpret_cast<i::byte*>(snapshot_data.begin()); 92 i::byte* snapshot_bytes = reinterpret_cast<i::byte*>(snapshot_data.begin());
104 sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot"); 93 sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot");
105 for (size_t i = 0; i < ARRAY_SIZE(spaces); ++i) 94 for (size_t i = 0; i < ARRAY_SIZE(spaces); ++i)
106 sink.PutInt(serializer.CurrentAllocationAddress(spaces[i]), "spaces"); 95 sink.PutInt(serializer.CurrentAllocationAddress(spaces[i]), "spaces");
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // If we don't do this then we end up with a stray root pointing at the 399 // If we don't do this then we end up with a stray root pointing at the
411 // context even after we have disposed of the context. 400 // context even after we have disposed of the context.
412 internal_isolate->heap()->CollectAllGarbage( 401 internal_isolate->heap()->CollectAllGarbage(
413 i::Heap::kNoGCFlags, "mksnapshot"); 402 i::Heap::kNoGCFlags, "mksnapshot");
414 i::Object* raw_context = *v8::Utils::OpenPersistent(context); 403 i::Object* raw_context = *v8::Utils::OpenPersistent(context);
415 context.Reset(); 404 context.Reset();
416 405
417 // This results in a somewhat smaller snapshot, probably because it gets 406 // This results in a somewhat smaller snapshot, probably because it gets
418 // rid of some things that are cached between garbage collections. 407 // rid of some things that are cached between garbage collections.
419 i::List<char> snapshot_data; 408 i::List<char> snapshot_data;
420 ListSnapshotSink snapshot_sink(&snapshot_data); 409 i::ListSnapshotSink snapshot_sink(&snapshot_data);
421 i::StartupSerializer ser(internal_isolate, &snapshot_sink); 410 i::StartupSerializer ser(internal_isolate, &snapshot_sink);
422 ser.SerializeStrongReferences(); 411 ser.SerializeStrongReferences();
423 412
424 i::List<char> context_data; 413 i::List<char> context_data;
425 ListSnapshotSink contex_sink(&context_data); 414 i::ListSnapshotSink contex_sink(&context_data);
426 i::PartialSerializer context_ser(internal_isolate, &ser, &contex_sink); 415 i::PartialSerializer context_ser(internal_isolate, &ser, &contex_sink);
427 context_ser.Serialize(&raw_context); 416 context_ser.Serialize(&raw_context);
428 ser.SerializeWeakReferences(); 417 ser.SerializeWeakReferences();
429 418
430 { 419 {
431 SnapshotWriter writer(argv[1]); 420 SnapshotWriter writer(argv[1]);
432 if (i::FLAG_raw_file && i::FLAG_raw_context_file) 421 if (i::FLAG_raw_file && i::FLAG_raw_context_file)
433 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file); 422 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file);
434 if (i::FLAG_startup_blob) 423 if (i::FLAG_startup_blob)
435 writer.SetStartupBlobFile(i::FLAG_startup_blob); 424 writer.SetStartupBlobFile(i::FLAG_startup_blob);
436 #ifdef COMPRESS_STARTUP_DATA_BZ2 425 #ifdef COMPRESS_STARTUP_DATA_BZ2
437 BZip2Compressor bzip2; 426 BZip2Compressor bzip2;
438 writer.SetCompressor(&bzip2); 427 writer.SetCompressor(&bzip2);
439 #endif 428 #endif
440 writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser); 429 writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser);
441 } 430 }
442 } 431 }
443 432
444 isolate->Dispose(); 433 isolate->Dispose();
445 V8::Dispose(); 434 V8::Dispose();
446 V8::ShutdownPlatform(); 435 V8::ShutdownPlatform();
447 delete platform; 436 delete platform;
448 return 0; 437 return 0;
449 } 438 }
OLDNEW
« no previous file with comments | « src/full-codegen.cc ('k') | src/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698