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

Side by Side Diff: src/mksnapshot.cc

Issue 669133003: De-virtualize snapshot sink. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comment 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 | Annotate | Revision Log
« no previous file with comments | « src/flag-definitions.h ('k') | src/serialize.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 context_snapshot_data, context_serializer); 71 context_snapshot_data, context_serializer);
72 MaybeWriteStartupBlob(snapshot_data, serializer, 72 MaybeWriteStartupBlob(snapshot_data, serializer,
73 context_snapshot_data, context_serializer); 73 context_snapshot_data, context_serializer);
74 } 74 }
75 75
76 private: 76 private:
77 void MaybeWriteStartupBlob(const i::List<i::byte>& snapshot_data, 77 void MaybeWriteStartupBlob(const i::List<i::byte>& snapshot_data,
78 const i::Serializer& serializer, 78 const i::Serializer& serializer,
79 const i::List<i::byte>& context_snapshot_data, 79 const i::List<i::byte>& context_snapshot_data,
80 const i::Serializer& context_serializer) const { 80 const i::Serializer& context_serializer) const {
81 if (!startup_blob_file_) 81 if (!startup_blob_file_) return;
82 return;
83 82
84 i::List<i::byte> startup_blob; 83 i::SnapshotByteSink sink;
85 i::ListSnapshotSink sink(&startup_blob);
86 84
87 int spaces[] = {i::NEW_SPACE, i::OLD_POINTER_SPACE, 85 int spaces[] = {i::NEW_SPACE, i::OLD_POINTER_SPACE,
88 i::OLD_DATA_SPACE, i::CODE_SPACE, 86 i::OLD_DATA_SPACE, i::CODE_SPACE,
89 i::MAP_SPACE, i::CELL_SPACE, 87 i::MAP_SPACE, i::CELL_SPACE,
90 i::PROPERTY_CELL_SPACE, i::LO_SPACE}; 88 i::PROPERTY_CELL_SPACE, i::LO_SPACE};
91 89
92 i::byte* snapshot_bytes = snapshot_data.begin(); 90 i::byte* snapshot_bytes = snapshot_data.begin();
93 sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot"); 91 sink.PutBlob(snapshot_bytes, snapshot_data.length(), "snapshot");
94 for (size_t i = 0; i < arraysize(spaces); ++i) { 92 for (size_t i = 0; i < arraysize(spaces); ++i) {
95 i::Vector<const uint32_t> chunks = 93 i::Vector<const uint32_t> chunks =
96 serializer.FinalAllocationChunks(spaces[i]); 94 serializer.FinalAllocationChunks(spaces[i]);
97 // For the start-up snapshot, none of the reservations has more than 95 // For the start-up snapshot, none of the reservations has more than
98 // one chunk (reservation for each space fits onto a single page). 96 // one chunk (reservation for each space fits onto a single page).
99 CHECK_EQ(1, chunks.length()); 97 CHECK_EQ(1, chunks.length());
100 sink.PutInt(chunks[0], "spaces"); 98 sink.PutInt(chunks[0], "spaces");
101 } 99 }
102 100
103 i::byte* context_bytes = context_snapshot_data.begin(); 101 i::byte* context_bytes = context_snapshot_data.begin();
104 sink.PutBlob(context_bytes, context_snapshot_data.length(), "context"); 102 sink.PutBlob(context_bytes, context_snapshot_data.length(), "context");
105 for (size_t i = 0; i < arraysize(spaces); ++i) { 103 for (size_t i = 0; i < arraysize(spaces); ++i) {
106 i::Vector<const uint32_t> chunks = 104 i::Vector<const uint32_t> chunks =
107 context_serializer.FinalAllocationChunks(spaces[i]); 105 context_serializer.FinalAllocationChunks(spaces[i]);
108 // For the context snapshot, none of the reservations has more than 106 // For the context snapshot, none of the reservations has more than
109 // one chunk (reservation for each space fits onto a single page). 107 // one chunk (reservation for each space fits onto a single page).
110 CHECK_EQ(1, chunks.length()); 108 CHECK_EQ(1, chunks.length());
111 sink.PutInt(chunks[0], "spaces"); 109 sink.PutInt(chunks[0], "spaces");
112 } 110 }
113 111
112 const i::List<i::byte>& startup_blob = sink.data();
114 size_t written = fwrite(startup_blob.begin(), 1, startup_blob.length(), 113 size_t written = fwrite(startup_blob.begin(), 1, startup_blob.length(),
115 startup_blob_file_); 114 startup_blob_file_);
116 if (written != (size_t)startup_blob.length()) { 115 if (written != static_cast<size_t>(startup_blob.length())) {
117 i::PrintF("Writing snapshot file failed.. Aborting.\n"); 116 i::PrintF("Writing snapshot file failed.. Aborting.\n");
118 exit(1); 117 exit(1);
119 } 118 }
120 } 119 }
121 120
122 void WriteSnapshotFile(const i::List<i::byte>& snapshot_data, 121 void WriteSnapshotFile(const i::List<i::byte>& snapshot_data,
123 const i::Serializer& serializer, 122 const i::Serializer& serializer,
124 const i::List<i::byte>& context_snapshot_data, 123 const i::List<i::byte>& context_snapshot_data,
125 const i::Serializer& context_serializer) const { 124 const i::Serializer& context_serializer) const {
126 WriteFilePrefix(); 125 WriteFilePrefix();
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } 412 }
414 } 413 }
415 // If we don't do this then we end up with a stray root pointing at the 414 // If we don't do this then we end up with a stray root pointing at the
416 // context even after we have disposed of the context. 415 // context even after we have disposed of the context.
417 internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot"); 416 internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot");
418 i::Object* raw_context = *v8::Utils::OpenPersistent(context); 417 i::Object* raw_context = *v8::Utils::OpenPersistent(context);
419 context.Reset(); 418 context.Reset();
420 419
421 // This results in a somewhat smaller snapshot, probably because it gets 420 // This results in a somewhat smaller snapshot, probably because it gets
422 // rid of some things that are cached between garbage collections. 421 // rid of some things that are cached between garbage collections.
423 i::List<i::byte> snapshot_data; 422 i::SnapshotByteSink snapshot_sink;
424 i::ListSnapshotSink snapshot_sink(&snapshot_data);
425 i::StartupSerializer ser(internal_isolate, &snapshot_sink); 423 i::StartupSerializer ser(internal_isolate, &snapshot_sink);
426 ser.SerializeStrongReferences(); 424 ser.SerializeStrongReferences();
427 425
428 i::List<i::byte> context_data; 426 i::SnapshotByteSink context_sink;
429 i::ListSnapshotSink contex_sink(&context_data); 427 i::PartialSerializer context_ser(internal_isolate, &ser, &context_sink);
430 i::PartialSerializer context_ser(internal_isolate, &ser, &contex_sink);
431 context_ser.Serialize(&raw_context); 428 context_ser.Serialize(&raw_context);
432 ser.SerializeWeakReferences(); 429 ser.SerializeWeakReferences();
433 430
434 context_ser.FinalizeAllocation(); 431 context_ser.FinalizeAllocation();
435 ser.FinalizeAllocation(); 432 ser.FinalizeAllocation();
436 433
437 { 434 {
438 SnapshotWriter writer(argv[1]); 435 SnapshotWriter writer(argv[1]);
439 if (i::FLAG_raw_file && i::FLAG_raw_context_file) 436 if (i::FLAG_raw_file && i::FLAG_raw_context_file)
440 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file); 437 writer.SetRawFiles(i::FLAG_raw_file, i::FLAG_raw_context_file);
441 if (i::FLAG_startup_blob) 438 if (i::FLAG_startup_blob)
442 writer.SetStartupBlobFile(i::FLAG_startup_blob); 439 writer.SetStartupBlobFile(i::FLAG_startup_blob);
443 #ifdef COMPRESS_STARTUP_DATA_BZ2 440 #ifdef COMPRESS_STARTUP_DATA_BZ2
444 BZip2Compressor bzip2; 441 BZip2Compressor bzip2;
445 writer.SetCompressor(&bzip2); 442 writer.SetCompressor(&bzip2);
446 #endif 443 #endif
447 writer.WriteSnapshot(snapshot_data, ser, context_data, context_ser); 444 writer.WriteSnapshot(snapshot_sink.data(), ser, context_sink.data(),
445 context_ser);
448 } 446 }
449 } 447 }
450 448
451 isolate->Dispose(); 449 isolate->Dispose();
452 V8::Dispose(); 450 V8::Dispose();
453 V8::ShutdownPlatform(); 451 V8::ShutdownPlatform();
454 delete platform; 452 delete platform;
455 return 0; 453 return 0;
456 } 454 }
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/serialize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698