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

Side by Side Diff: src/mksnapshot.cc

Issue 1094014: Merge the partial_snapshots branch back into bleeding_edge. For... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 9 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 17 matching lines...) Expand all
28 #include <signal.h> 28 #include <signal.h>
29 #include <string> 29 #include <string>
30 #include <map> 30 #include <map>
31 31
32 #include "v8.h" 32 #include "v8.h"
33 33
34 #include "bootstrapper.h" 34 #include "bootstrapper.h"
35 #include "natives.h" 35 #include "natives.h"
36 #include "platform.h" 36 #include "platform.h"
37 #include "serialize.h" 37 #include "serialize.h"
38 #include "list.h"
38 39
39 // use explicit namespace to avoid clashing with types in namespace v8 40 // use explicit namespace to avoid clashing with types in namespace v8
40 namespace i = v8::internal; 41 namespace i = v8::internal;
41 using namespace v8; 42 using namespace v8;
42 43
43 static const unsigned int kMaxCounters = 256; 44 static const unsigned int kMaxCounters = 256;
44 45
45 // A single counter in a counter collection. 46 // A single counter in a counter collection.
46 class Counter { 47 class Counter {
47 public: 48 public:
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 static CounterCollection local_counters; 90 static CounterCollection local_counters;
90 91
91 92
92 typedef std::map<std::string, int*> CounterMap; 93 typedef std::map<std::string, int*> CounterMap;
93 typedef std::map<std::string, int*>::iterator CounterMapIterator; 94 typedef std::map<std::string, int*>::iterator CounterMapIterator;
94 static CounterMap counter_table_; 95 static CounterMap counter_table_;
95 96
96 97
97 class CppByteSink : public i::SnapshotByteSink { 98 class CppByteSink : public i::SnapshotByteSink {
98 public: 99 public:
99 explicit CppByteSink(const char* snapshot_file) : bytes_written_(0) { 100 explicit CppByteSink(const char* snapshot_file)
101 : bytes_written_(0),
102 partial_sink_(this) {
Erik Corry 2010/03/23 12:01:50 This one may trigger a warning on Windows...
100 fp_ = i::OS::FOpen(snapshot_file, "wb"); 103 fp_ = i::OS::FOpen(snapshot_file, "wb");
101 if (fp_ == NULL) { 104 if (fp_ == NULL) {
102 i::PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file); 105 i::PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file);
103 exit(1); 106 exit(1);
104 } 107 }
105 fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n"); 108 fprintf(fp_, "// Autogenerated snapshot file. Do not edit.\n\n");
106 fprintf(fp_, "#include \"v8.h\"\n"); 109 fprintf(fp_, "#include \"v8.h\"\n");
107 fprintf(fp_, "#include \"platform.h\"\n\n"); 110 fprintf(fp_, "#include \"platform.h\"\n\n");
108 fprintf(fp_, "#include \"snapshot.h\"\n\n"); 111 fprintf(fp_, "#include \"snapshot.h\"\n\n");
109 fprintf(fp_, "namespace v8 {\nnamespace internal {\n\n"); 112 fprintf(fp_, "namespace v8 {\nnamespace internal {\n\n");
110 fprintf(fp_, "const byte Snapshot::data_[] = {"); 113 fprintf(fp_, "const byte Snapshot::data_[] = {");
111 } 114 }
112 115
113 virtual ~CppByteSink() { 116 virtual ~CppByteSink() {
114 if (fp_ != NULL) { 117 fprintf(fp_, "const int Snapshot::size_ = %d;\n\n", bytes_written_);
115 fprintf(fp_, "};\n\n"); 118 fprintf(fp_, "} } // namespace v8::internal\n");
116 fprintf(fp_, "int Snapshot::size_ = %d;\n\n", bytes_written_); 119 fclose(fp_);
117 fprintf(fp_, "} } // namespace v8::internal\n"); 120 }
118 fclose(fp_); 121
122 void WriteSpaceUsed(
123 int new_space_used,
124 int pointer_space_used,
125 int data_space_used,
126 int code_space_used,
127 int map_space_used,
128 int cell_space_used,
129 int large_space_used) {
130 fprintf(fp_, "};\n\n");
131 fprintf(fp_, "const int Snapshot::new_space_used_ = %d;\n", new_space_used);
132 fprintf(fp_,
133 "const int Snapshot::pointer_space_used_ = %d;\n",
134 pointer_space_used);
135 fprintf(fp_,
136 "const int Snapshot::data_space_used_ = %d;\n",
137 data_space_used);
138 fprintf(fp_,
139 "const int Snapshot::code_space_used_ = %d;\n",
140 code_space_used);
141 fprintf(fp_, "const int Snapshot::map_space_used_ = %d;\n", map_space_used);
142 fprintf(fp_,
143 "const int Snapshot::cell_space_used_ = %d;\n",
144 cell_space_used);
145 fprintf(fp_,
146 "const int Snapshot::large_space_used_ = %d;\n",
147 large_space_used);
148 }
149
150 void WritePartialSnapshot() {
151 int length = partial_sink_.Position();
152 fprintf(fp_, "};\n\n");
153 fprintf(fp_, "const int Snapshot::context_size_ = %d;\n", length);
154 fprintf(fp_, "const byte Snapshot::context_data_[] = {\n");
155 for (int j = 0; j < length; j++) {
156 if ((j & 0x1f) == 0x1f) {
157 fprintf(fp_, "\n");
158 }
159 char byte = partial_sink_.at(j);
160 if (j != 0) {
161 fprintf(fp_, ",");
162 }
163 fprintf(fp_, "%d", byte);
119 } 164 }
120 } 165 }
121 166
122 virtual void Put(int byte, const char* description) { 167 virtual void Put(int byte, const char* description) {
123 if (bytes_written_ != 0) { 168 if (bytes_written_ != 0) {
124 fprintf(fp_, ","); 169 fprintf(fp_, ",");
125 } 170 }
126 fprintf(fp_, "%d", byte); 171 fprintf(fp_, "%d", byte);
127 bytes_written_++; 172 bytes_written_++;
128 if ((bytes_written_ & 0x3f) == 0) { 173 if ((bytes_written_ & 0x1f) == 0) {
129 fprintf(fp_, "\n"); 174 fprintf(fp_, "\n");
130 } 175 }
131 } 176 }
132 177
133 virtual int Position() { 178 virtual int Position() {
134 return bytes_written_; 179 return bytes_written_;
135 } 180 }
136 181
182 i::SnapshotByteSink* partial_sink() { return &partial_sink_; }
183
184 class PartialSnapshotSink : public i::SnapshotByteSink {
185 public:
186 explicit PartialSnapshotSink(CppByteSink* parent)
187 : parent_(parent),
188 data_() { }
189 virtual ~PartialSnapshotSink() { data_.Free(); }
190 virtual void Put(int byte, const char* description) {
191 data_.Add(byte);
192 }
193 virtual int Position() { return data_.length(); }
194 char at(int i) { return data_[i]; }
195 private:
196 CppByteSink* parent_;
197 i::List<char> data_;
198 };
199
137 private: 200 private:
138 FILE* fp_; 201 FILE* fp_;
139 int bytes_written_; 202 int bytes_written_;
203 PartialSnapshotSink partial_sink_;
140 }; 204 };
141 205
142 206
143 int main(int argc, char** argv) { 207 int main(int argc, char** argv) {
144 #ifdef ENABLE_LOGGING_AND_PROFILING 208 #ifdef ENABLE_LOGGING_AND_PROFILING
145 // By default, log code create information in the snapshot. 209 // By default, log code create information in the snapshot.
146 i::FLAG_log_code = true; 210 i::FLAG_log_code = true;
147 #endif 211 #endif
148 // Print the usage if an error occurs when parsing the command line 212 // Print the usage if an error occurs when parsing the command line
149 // flags or if the help flag is set. 213 // flags or if the help flag is set.
150 int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); 214 int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
151 if (result > 0 || argc != 2 || i::FLAG_help) { 215 if (result > 0 || argc != 2 || i::FLAG_help) {
152 ::printf("Usage: %s [flag] ... outfile\n", argv[0]); 216 ::printf("Usage: %s [flag] ... outfile\n", argv[0]);
153 i::FlagList::PrintHelp(); 217 i::FlagList::PrintHelp();
154 return !i::FLAG_help; 218 return !i::FLAG_help;
155 } 219 }
156 i::Serializer::Enable(); 220 i::Serializer::Enable();
157 Persistent<Context> context = v8::Context::New(); 221 Persistent<Context> context = v8::Context::New();
158 ASSERT(!context.IsEmpty()); 222 ASSERT(!context.IsEmpty());
159 // Make sure all builtin scripts are cached. 223 // Make sure all builtin scripts are cached.
160 { HandleScope scope; 224 { HandleScope scope;
161 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { 225 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
162 i::Bootstrapper::NativesSourceLookup(i); 226 i::Bootstrapper::NativesSourceLookup(i);
163 } 227 }
164 } 228 }
229 // If we don't do this then we end up with a stray root pointing at the
230 // context even after we have disposed of the context.
231 i::Heap::CollectAllGarbage(true);
232 i::Object* raw_context = *(v8::Utils::OpenHandle(*context));
165 context.Dispose(); 233 context.Dispose();
166 CppByteSink sink(argv[1]); 234 CppByteSink sink(argv[1]);
167 // This results in a somewhat smaller snapshot, probably because it gets rid 235 // This results in a somewhat smaller snapshot, probably because it gets rid
168 // of some things that are cached between garbage collections. 236 // of some things that are cached between garbage collections.
169 i::Heap::CollectAllGarbage(true);
170 i::StartupSerializer ser(&sink); 237 i::StartupSerializer ser(&sink);
171 ser.Serialize(); 238 ser.SerializeStrongReferences();
239
240 i::PartialSerializer partial_ser(&ser, sink.partial_sink());
241 partial_ser.Serialize(&raw_context);
242
243 ser.SerializeWeakReferences();
244
245 sink.WritePartialSnapshot();
246
247 sink.WriteSpaceUsed(
248 partial_ser.CurrentAllocationAddress(i::NEW_SPACE),
249 partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE),
250 partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE),
251 partial_ser.CurrentAllocationAddress(i::CODE_SPACE),
252 partial_ser.CurrentAllocationAddress(i::MAP_SPACE),
253 partial_ser.CurrentAllocationAddress(i::CELL_SPACE),
254 partial_ser.CurrentAllocationAddress(i::LO_SPACE));
172 return 0; 255 return 0;
173 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698