OLD | NEW |
1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 decoder.Decode(make_code(UNCLASSIFIED, 2))); | 107 decoder.Decode(make_code(UNCLASSIFIED, 2))); |
108 CHECK_EQ(ExternalReference::address_of_real_stack_limit(isolate).address(), | 108 CHECK_EQ(ExternalReference::address_of_real_stack_limit(isolate).address(), |
109 decoder.Decode(make_code(UNCLASSIFIED, 3))); | 109 decoder.Decode(make_code(UNCLASSIFIED, 3))); |
110 CHECK_EQ(ExternalReference::debug_break(isolate).address(), | 110 CHECK_EQ(ExternalReference::debug_break(isolate).address(), |
111 decoder.Decode(make_code(UNCLASSIFIED, 8))); | 111 decoder.Decode(make_code(UNCLASSIFIED, 8))); |
112 CHECK_EQ(ExternalReference::new_space_start(isolate).address(), | 112 CHECK_EQ(ExternalReference::new_space_start(isolate).address(), |
113 decoder.Decode(make_code(UNCLASSIFIED, 4))); | 113 decoder.Decode(make_code(UNCLASSIFIED, 4))); |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 class FileByteSink : public SnapshotByteSink { | 117 void WritePayload(const List<byte>& payload, const char* file_name) { |
118 public: | 118 FILE* file = v8::base::OS::FOpen(file_name, "wb"); |
119 explicit FileByteSink(const char* snapshot_file) { | 119 if (file == NULL) { |
120 fp_ = v8::base::OS::FOpen(snapshot_file, "wb"); | 120 PrintF("Unable to write to snapshot file \"%s\"\n", file_name); |
121 file_name_ = snapshot_file; | 121 exit(1); |
122 if (fp_ == NULL) { | |
123 PrintF("Unable to write to snapshot file \"%s\"\n", snapshot_file); | |
124 exit(1); | |
125 } | |
126 } | 122 } |
127 virtual ~FileByteSink() { | 123 size_t written = fwrite(payload.begin(), 1, payload.length(), file); |
128 if (fp_ != NULL) { | 124 if (written != static_cast<size_t>(payload.length())) { |
129 fclose(fp_); | 125 i::PrintF("Writing snapshot file failed.. Aborting.\n"); |
130 } | 126 exit(1); |
131 } | 127 } |
132 virtual void Put(byte b, const char* description) { | 128 fclose(file); |
133 if (fp_ != NULL) { | 129 } |
134 fputc(b, fp_); | |
135 } | |
136 } | |
137 virtual int Position() { | |
138 return ftell(fp_); | |
139 } | |
140 void WriteSpaceUsed(Serializer* serializer); | |
141 | |
142 private: | |
143 FILE* fp_; | |
144 const char* file_name_; | |
145 }; | |
146 | 130 |
147 | 131 |
148 void FileByteSink::WriteSpaceUsed(Serializer* ser) { | 132 void WriteSpaceUsed(Serializer* ser, const char* file_name) { |
149 int file_name_length = StrLength(file_name_) + 10; | 133 int file_name_length = StrLength(file_name) + 10; |
150 Vector<char> name = Vector<char>::New(file_name_length + 1); | 134 Vector<char> name = Vector<char>::New(file_name_length + 1); |
151 SNPrintF(name, "%s.size", file_name_); | 135 SNPrintF(name, "%s.size", file_name); |
152 FILE* fp = v8::base::OS::FOpen(name.start(), "w"); | 136 FILE* fp = v8::base::OS::FOpen(name.start(), "w"); |
153 name.Dispose(); | 137 name.Dispose(); |
154 | 138 |
155 Vector<const uint32_t> chunks = ser->FinalAllocationChunks(NEW_SPACE); | 139 Vector<const uint32_t> chunks = ser->FinalAllocationChunks(NEW_SPACE); |
156 CHECK_EQ(1, chunks.length()); | 140 CHECK_EQ(1, chunks.length()); |
157 fprintf(fp, "new %d\n", chunks[0]); | 141 fprintf(fp, "new %d\n", chunks[0]); |
158 chunks = ser->FinalAllocationChunks(OLD_POINTER_SPACE); | 142 chunks = ser->FinalAllocationChunks(OLD_POINTER_SPACE); |
159 CHECK_EQ(1, chunks.length()); | 143 CHECK_EQ(1, chunks.length()); |
160 fprintf(fp, "pointer %d\n", chunks[0]); | 144 fprintf(fp, "pointer %d\n", chunks[0]); |
161 chunks = ser->FinalAllocationChunks(OLD_DATA_SPACE); | 145 chunks = ser->FinalAllocationChunks(OLD_DATA_SPACE); |
(...skipping 12 matching lines...) Expand all Loading... |
174 CHECK_EQ(1, chunks.length()); | 158 CHECK_EQ(1, chunks.length()); |
175 fprintf(fp, "property cell %d\n", chunks[0]); | 159 fprintf(fp, "property cell %d\n", chunks[0]); |
176 chunks = ser->FinalAllocationChunks(LO_SPACE); | 160 chunks = ser->FinalAllocationChunks(LO_SPACE); |
177 CHECK_EQ(1, chunks.length()); | 161 CHECK_EQ(1, chunks.length()); |
178 fprintf(fp, "lo %d\n", chunks[0]); | 162 fprintf(fp, "lo %d\n", chunks[0]); |
179 fclose(fp); | 163 fclose(fp); |
180 } | 164 } |
181 | 165 |
182 | 166 |
183 static bool WriteToFile(Isolate* isolate, const char* snapshot_file) { | 167 static bool WriteToFile(Isolate* isolate, const char* snapshot_file) { |
184 FileByteSink file(snapshot_file); | 168 SnapshotByteSink sink; |
185 StartupSerializer ser(isolate, &file); | 169 StartupSerializer ser(isolate, &sink); |
186 ser.Serialize(); | 170 ser.Serialize(); |
187 ser.FinalizeAllocation(); | 171 ser.FinalizeAllocation(); |
188 | 172 |
189 file.WriteSpaceUsed(&ser); | 173 WritePayload(sink.data(), snapshot_file); |
| 174 WriteSpaceUsed(&ser, snapshot_file); |
190 | 175 |
191 return true; | 176 return true; |
192 } | 177 } |
193 | 178 |
194 | 179 |
195 static void Serialize(v8::Isolate* isolate) { | 180 static void Serialize(v8::Isolate* isolate) { |
196 // We have to create one context. One reason for this is so that the builtins | 181 // We have to create one context. One reason for this is so that the builtins |
197 // can be loaded from v8natives.js and their addresses can be processed. This | 182 // can be loaded from v8natives.js and their addresses can be processed. This |
198 // will clear the pending fixups array, which would otherwise contain GC roots | 183 // will clear the pending fixups array, which would otherwise contain GC roots |
199 // that would confuse the serialization/deserialization process. | 184 // that would confuse the serialization/deserialization process. |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 418 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
434 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 419 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
435 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 420 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
436 | 421 |
437 { | 422 { |
438 v8::HandleScope handle_scope(v8_isolate); | 423 v8::HandleScope handle_scope(v8_isolate); |
439 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 424 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
440 } | 425 } |
441 env.Reset(); | 426 env.Reset(); |
442 | 427 |
443 FileByteSink startup_sink(startup_name.start()); | 428 SnapshotByteSink startup_sink; |
444 StartupSerializer startup_serializer(isolate, &startup_sink); | 429 StartupSerializer startup_serializer(isolate, &startup_sink); |
445 startup_serializer.SerializeStrongReferences(); | 430 startup_serializer.SerializeStrongReferences(); |
446 | 431 |
447 FileByteSink partial_sink(FLAG_testing_serialization_file); | 432 SnapshotByteSink partial_sink; |
448 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); | 433 PartialSerializer partial_serializer(isolate, &startup_serializer, |
449 p_ser.Serialize(&raw_foo); | 434 &partial_sink); |
| 435 partial_serializer.Serialize(&raw_foo); |
| 436 |
450 startup_serializer.SerializeWeakReferences(); | 437 startup_serializer.SerializeWeakReferences(); |
451 | 438 |
452 p_ser.FinalizeAllocation(); | 439 partial_serializer.FinalizeAllocation(); |
453 startup_serializer.FinalizeAllocation(); | 440 startup_serializer.FinalizeAllocation(); |
454 | 441 |
455 partial_sink.WriteSpaceUsed(&p_ser); | 442 WritePayload(partial_sink.data(), FLAG_testing_serialization_file); |
| 443 WritePayload(startup_sink.data(), startup_name.start()); |
456 | 444 |
457 startup_sink.WriteSpaceUsed(&startup_serializer); | 445 WriteSpaceUsed(&partial_serializer, FLAG_testing_serialization_file); |
| 446 WriteSpaceUsed(&startup_serializer, startup_name.start()); |
| 447 |
458 startup_name.Dispose(); | 448 startup_name.Dispose(); |
459 } | 449 } |
460 v8_isolate->Exit(); | 450 v8_isolate->Exit(); |
461 v8_isolate->Dispose(); | 451 v8_isolate->Dispose(); |
462 } | 452 } |
463 } | 453 } |
464 | 454 |
465 | 455 |
466 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { | 456 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { |
467 if (!Snapshot::HaveASnapshotToStartFrom()) { | 457 if (!Snapshot::HaveASnapshotToStartFrom()) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 535 |
546 { | 536 { |
547 v8::HandleScope handle_scope(v8_isolate); | 537 v8::HandleScope handle_scope(v8_isolate); |
548 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 538 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
549 } | 539 } |
550 | 540 |
551 i::Object* raw_context = *v8::Utils::OpenPersistent(env); | 541 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
552 | 542 |
553 env.Reset(); | 543 env.Reset(); |
554 | 544 |
555 FileByteSink startup_sink(startup_name.start()); | 545 SnapshotByteSink startup_sink; |
556 StartupSerializer startup_serializer(isolate, &startup_sink); | 546 StartupSerializer startup_serializer(isolate, &startup_sink); |
557 startup_serializer.SerializeStrongReferences(); | 547 startup_serializer.SerializeStrongReferences(); |
558 | 548 |
559 FileByteSink partial_sink(FLAG_testing_serialization_file); | 549 SnapshotByteSink partial_sink; |
560 PartialSerializer p_ser(isolate, &startup_serializer, &partial_sink); | 550 PartialSerializer partial_serializer(isolate, &startup_serializer, |
561 p_ser.Serialize(&raw_context); | 551 &partial_sink); |
| 552 partial_serializer.Serialize(&raw_context); |
562 startup_serializer.SerializeWeakReferences(); | 553 startup_serializer.SerializeWeakReferences(); |
563 | 554 |
564 p_ser.FinalizeAllocation(); | 555 partial_serializer.FinalizeAllocation(); |
565 startup_serializer.FinalizeAllocation(); | 556 startup_serializer.FinalizeAllocation(); |
566 | 557 |
567 partial_sink.WriteSpaceUsed(&p_ser); | 558 WritePayload(partial_sink.data(), FLAG_testing_serialization_file); |
| 559 WritePayload(startup_sink.data(), startup_name.start()); |
568 | 560 |
569 startup_sink.WriteSpaceUsed(&startup_serializer); | 561 WriteSpaceUsed(&partial_serializer, FLAG_testing_serialization_file); |
| 562 WriteSpaceUsed(&startup_serializer, startup_name.start()); |
| 563 |
570 startup_name.Dispose(); | 564 startup_name.Dispose(); |
571 } | 565 } |
572 v8_isolate->Dispose(); | 566 v8_isolate->Dispose(); |
573 } | 567 } |
574 } | 568 } |
575 | 569 |
576 | 570 |
577 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { | 571 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { |
578 if (!Snapshot::HaveASnapshotToStartFrom()) { | 572 if (!Snapshot::HaveASnapshotToStartFrom()) { |
579 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 573 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 { | 1266 { |
1273 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); | 1267 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); |
1274 script = v8::ScriptCompiler::CompileUnbound( | 1268 script = v8::ScriptCompiler::CompileUnbound( |
1275 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); | 1269 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); |
1276 } | 1270 } |
1277 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); | 1271 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); |
1278 CHECK(result->ToString()->Equals(v8_str("XY"))); | 1272 CHECK(result->ToString()->Equals(v8_str("XY"))); |
1279 } | 1273 } |
1280 isolate2->Dispose(); | 1274 isolate2->Dispose(); |
1281 } | 1275 } |
OLD | NEW |