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

Side by Side Diff: test/cctest/test-serialize.cc

Issue 949623006: Attach snapshot data blob to the isolate. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
OLDNEW
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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 CopyChars(source + head.length() + repeats * body.length(), tail.start(), 169 CopyChars(source + head.length() + repeats * body.length(), tail.start(),
170 tail.length()); 170 tail.length());
171 return Vector<const uint8_t>(const_cast<const uint8_t*>(source), 171 return Vector<const uint8_t>(const_cast<const uint8_t*>(source),
172 source_length); 172 source_length);
173 } 173 }
174 174
175 175
176 // Test that the whole heap can be serialized. 176 // Test that the whole heap can be serialized.
177 UNINITIALIZED_TEST(Serialize) { 177 UNINITIALIZED_TEST(Serialize) {
178 if (!Snapshot::HaveASnapshotToStartFrom()) { 178 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
179 v8::Isolate::CreateParams params; 179 v8::Isolate::CreateParams params;
180 params.enable_serializer = true; 180 params.enable_serializer = true;
181 v8::Isolate* isolate = v8::Isolate::New(params); 181 v8::Isolate* isolate = v8::Isolate::New(params);
182 Serialize(isolate); 182 Serialize(isolate);
183 } 183 }
184 } 184 }
185 185
186 186
187 // Test that heap serialization is non-destructive. 187 // Test that heap serialization is non-destructive.
188 UNINITIALIZED_TEST(SerializeTwice) { 188 UNINITIALIZED_TEST(SerializeTwice) {
189 if (!Snapshot::HaveASnapshotToStartFrom()) { 189 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
190 v8::Isolate::CreateParams params; 190 v8::Isolate::CreateParams params;
191 params.enable_serializer = true; 191 params.enable_serializer = true;
192 v8::Isolate* isolate = v8::Isolate::New(params); 192 v8::Isolate* isolate = v8::Isolate::New(params);
193 Serialize(isolate); 193 Serialize(isolate);
194 Serialize(isolate); 194 Serialize(isolate);
195 } 195 }
196 } 196 }
197 197
198 198
199 //---------------------------------------------------------------------------- 199 //----------------------------------------------------------------------------
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 CHECK(isolate->native_context()->IsContext()); 234 CHECK(isolate->native_context()->IsContext());
235 CHECK(isolate->heap()->string_table()->IsStringTable()); 235 CHECK(isolate->heap()->string_table()->IsStringTable());
236 isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty")); 236 isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Empty"));
237 } 237 }
238 238
239 239
240 UNINITIALIZED_DEPENDENT_TEST(Deserialize, Serialize) { 240 UNINITIALIZED_DEPENDENT_TEST(Deserialize, Serialize) {
241 // The serialize-deserialize tests only work if the VM is built without 241 // The serialize-deserialize tests only work if the VM is built without
242 // serialization. That doesn't matter. We don't need to be able to 242 // serialization. That doesn't matter. We don't need to be able to
243 // serialize a snapshot in a VM that is booted from a snapshot. 243 // serialize a snapshot in a VM that is booted from a snapshot.
244 if (!Snapshot::HaveASnapshotToStartFrom()) { 244 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
245 v8::Isolate* isolate = Deserialize(); 245 v8::Isolate* isolate = Deserialize();
246 { 246 {
247 v8::HandleScope handle_scope(isolate); 247 v8::HandleScope handle_scope(isolate);
248 v8::Isolate::Scope isolate_scope(isolate); 248 v8::Isolate::Scope isolate_scope(isolate);
249 249
250 v8::Local<v8::Context> env = v8::Context::New(isolate); 250 v8::Local<v8::Context> env = v8::Context::New(isolate);
251 env->Enter(); 251 env->Enter();
252 252
253 SanityCheck(isolate); 253 SanityCheck(isolate);
254 } 254 }
255 isolate->Dispose(); 255 isolate->Dispose();
256 } 256 }
257 } 257 }
258 258
259 259
260 UNINITIALIZED_DEPENDENT_TEST(DeserializeFromSecondSerialization, 260 UNINITIALIZED_DEPENDENT_TEST(DeserializeFromSecondSerialization,
261 SerializeTwice) { 261 SerializeTwice) {
262 if (!Snapshot::HaveASnapshotToStartFrom()) { 262 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
263 v8::Isolate* isolate = Deserialize(); 263 v8::Isolate* isolate = Deserialize();
264 { 264 {
265 v8::Isolate::Scope isolate_scope(isolate); 265 v8::Isolate::Scope isolate_scope(isolate);
266 v8::HandleScope handle_scope(isolate); 266 v8::HandleScope handle_scope(isolate);
267 267
268 v8::Local<v8::Context> env = v8::Context::New(isolate); 268 v8::Local<v8::Context> env = v8::Context::New(isolate);
269 env->Enter(); 269 env->Enter();
270 270
271 SanityCheck(isolate); 271 SanityCheck(isolate);
272 } 272 }
273 isolate->Dispose(); 273 isolate->Dispose();
274 } 274 }
275 } 275 }
276 276
277 277
278 UNINITIALIZED_DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { 278 UNINITIALIZED_DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
279 if (!Snapshot::HaveASnapshotToStartFrom()) { 279 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
280 v8::Isolate* isolate = Deserialize(); 280 v8::Isolate* isolate = Deserialize();
281 { 281 {
282 v8::Isolate::Scope isolate_scope(isolate); 282 v8::Isolate::Scope isolate_scope(isolate);
283 v8::HandleScope handle_scope(isolate); 283 v8::HandleScope handle_scope(isolate);
284 284
285 285
286 v8::Local<v8::Context> env = v8::Context::New(isolate); 286 v8::Local<v8::Context> env = v8::Context::New(isolate);
287 env->Enter(); 287 env->Enter();
288 288
289 const char* c_source = "\"1234\".length"; 289 const char* c_source = "\"1234\".length";
290 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source); 290 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source);
291 v8::Local<v8::Script> script = v8::Script::Compile(source); 291 v8::Local<v8::Script> script = v8::Script::Compile(source);
292 CHECK_EQ(4, script->Run()->Int32Value()); 292 CHECK_EQ(4, script->Run()->Int32Value());
293 } 293 }
294 isolate->Dispose(); 294 isolate->Dispose();
295 } 295 }
296 } 296 }
297 297
298 298
299 UNINITIALIZED_DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, 299 UNINITIALIZED_DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
300 SerializeTwice) { 300 SerializeTwice) {
301 if (!Snapshot::HaveASnapshotToStartFrom()) { 301 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
302 v8::Isolate* isolate = Deserialize(); 302 v8::Isolate* isolate = Deserialize();
303 { 303 {
304 v8::Isolate::Scope isolate_scope(isolate); 304 v8::Isolate::Scope isolate_scope(isolate);
305 v8::HandleScope handle_scope(isolate); 305 v8::HandleScope handle_scope(isolate);
306 306
307 v8::Local<v8::Context> env = v8::Context::New(isolate); 307 v8::Local<v8::Context> env = v8::Context::New(isolate);
308 env->Enter(); 308 env->Enter();
309 309
310 const char* c_source = "\"1234\".length"; 310 const char* c_source = "\"1234\".length";
311 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source); 311 v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, c_source);
312 v8::Local<v8::Script> script = v8::Script::Compile(source); 312 v8::Local<v8::Script> script = v8::Script::Compile(source);
313 CHECK_EQ(4, script->Run()->Int32Value()); 313 CHECK_EQ(4, script->Run()->Int32Value());
314 } 314 }
315 isolate->Dispose(); 315 isolate->Dispose();
316 } 316 }
317 } 317 }
318 318
319 319
320 UNINITIALIZED_TEST(PartialSerialization) { 320 UNINITIALIZED_TEST(PartialSerialization) {
321 if (!Snapshot::HaveASnapshotToStartFrom()) { 321 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
322 v8::Isolate::CreateParams params; 322 v8::Isolate::CreateParams params;
323 params.enable_serializer = true; 323 params.enable_serializer = true;
324 v8::Isolate* v8_isolate = v8::Isolate::New(params); 324 v8::Isolate* v8_isolate = v8::Isolate::New(params);
325 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); 325 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
326 v8_isolate->Enter(); 326 v8_isolate->Enter();
327 { 327 {
328 Heap* heap = isolate->heap(); 328 Heap* heap = isolate->heap();
329 329
330 v8::Persistent<v8::Context> env; 330 v8::Persistent<v8::Context> env;
331 { 331 {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 startup_name.Dispose(); 385 startup_name.Dispose();
386 } 386 }
387 v8_isolate->Exit(); 387 v8_isolate->Exit();
388 v8_isolate->Dispose(); 388 v8_isolate->Dispose();
389 } 389 }
390 } 390 }
391 391
392 392
393 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { 393 UNINITIALIZED_DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
394 if (!Snapshot::HaveASnapshotToStartFrom()) { 394 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
395 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 395 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
396 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); 396 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
397 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); 397 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
398 398
399 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start()); 399 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start());
400 CHECK(v8_isolate); 400 CHECK(v8_isolate);
401 startup_name.Dispose(); 401 startup_name.Dispose();
402 { 402 {
403 v8::Isolate::Scope isolate_scope(v8_isolate); 403 v8::Isolate::Scope isolate_scope(v8_isolate);
404 404
(...skipping 29 matching lines...) Expand all
434 CHECK(root2->IsString()); 434 CHECK(root2->IsString());
435 CHECK(root.is_identical_to(root2)); 435 CHECK(root.is_identical_to(root2));
436 } 436 }
437 } 437 }
438 v8_isolate->Dispose(); 438 v8_isolate->Dispose();
439 } 439 }
440 } 440 }
441 441
442 442
443 UNINITIALIZED_TEST(ContextSerialization) { 443 UNINITIALIZED_TEST(ContextSerialization) {
444 if (!Snapshot::HaveASnapshotToStartFrom()) { 444 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
445 v8::Isolate::CreateParams params; 445 v8::Isolate::CreateParams params;
446 params.enable_serializer = true; 446 params.enable_serializer = true;
447 v8::Isolate* v8_isolate = v8::Isolate::New(params); 447 v8::Isolate* v8_isolate = v8::Isolate::New(params);
448 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); 448 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
449 Heap* heap = isolate->heap(); 449 Heap* heap = isolate->heap();
450 { 450 {
451 v8::Isolate::Scope isolate_scope(v8_isolate); 451 v8::Isolate::Scope isolate_scope(v8_isolate);
452 452
453 v8::Persistent<v8::Context> env; 453 v8::Persistent<v8::Context> env;
454 { 454 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 WritePayload(startup_snapshot.RawData(), startup_name.start()); 501 WritePayload(startup_snapshot.RawData(), startup_name.start());
502 502
503 startup_name.Dispose(); 503 startup_name.Dispose();
504 } 504 }
505 v8_isolate->Dispose(); 505 v8_isolate->Dispose();
506 } 506 }
507 } 507 }
508 508
509 509
510 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { 510 UNINITIALIZED_DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
511 if (!Snapshot::HaveASnapshotToStartFrom()) { 511 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
512 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 512 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
513 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); 513 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
514 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); 514 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
515 515
516 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start()); 516 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start());
517 CHECK(v8_isolate); 517 CHECK(v8_isolate);
518 startup_name.Dispose(); 518 startup_name.Dispose();
519 { 519 {
520 v8::Isolate::Scope isolate_scope(v8_isolate); 520 v8::Isolate::Scope isolate_scope(v8_isolate);
521 521
(...skipping 29 matching lines...) Expand all
551 CHECK(root2->IsContext()); 551 CHECK(root2->IsContext());
552 CHECK(!root.is_identical_to(root2)); 552 CHECK(!root.is_identical_to(root2));
553 } 553 }
554 } 554 }
555 v8_isolate->Dispose(); 555 v8_isolate->Dispose();
556 } 556 }
557 } 557 }
558 558
559 559
560 UNINITIALIZED_TEST(CustomContextSerialization) { 560 UNINITIALIZED_TEST(CustomContextSerialization) {
561 if (!Snapshot::HaveASnapshotToStartFrom()) { 561 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
562 v8::Isolate::CreateParams params; 562 v8::Isolate::CreateParams params;
563 params.enable_serializer = true; 563 params.enable_serializer = true;
564 v8::Isolate* v8_isolate = v8::Isolate::New(params); 564 v8::Isolate* v8_isolate = v8::Isolate::New(params);
565 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); 565 Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
566 { 566 {
567 v8::Isolate::Scope isolate_scope(v8_isolate); 567 v8::Isolate::Scope isolate_scope(v8_isolate);
568 568
569 v8::Persistent<v8::Context> env; 569 v8::Persistent<v8::Context> env;
570 { 570 {
571 HandleScope scope(isolate); 571 HandleScope scope(isolate);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 startup_name.Dispose(); 639 startup_name.Dispose();
640 } 640 }
641 v8_isolate->Dispose(); 641 v8_isolate->Dispose();
642 } 642 }
643 } 643 }
644 644
645 645
646 UNINITIALIZED_DEPENDENT_TEST(CustomContextDeserialization, 646 UNINITIALIZED_DEPENDENT_TEST(CustomContextDeserialization,
647 CustomContextSerialization) { 647 CustomContextSerialization) {
648 FLAG_crankshaft = false; 648 FLAG_crankshaft = false;
649 if (!Snapshot::HaveASnapshotToStartFrom()) { 649 if (!Snapshot::HaveASnapshotToStartFrom(CcTest::i_isolate())) {
650 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 650 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
651 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); 651 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
652 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); 652 SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
653 653
654 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start()); 654 v8::Isolate* v8_isolate = InitializeFromFile(startup_name.start());
655 CHECK(v8_isolate); 655 CHECK(v8_isolate);
656 startup_name.Dispose(); 656 startup_name.Dispose();
657 { 657 {
658 v8::Isolate::Scope isolate_scope(v8_isolate); 658 v8::Isolate::Scope isolate_scope(v8_isolate);
659 659
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 CHECK_EQ(100001, a); 697 CHECK_EQ(100001, a);
698 int b = CompileRun("b.length")->ToNumber(v8_isolate)->Int32Value(); 698 int b = CompileRun("b.length")->ToNumber(v8_isolate)->Int32Value();
699 CHECK_EQ(100002, b); 699 CHECK_EQ(100002, b);
700 } 700 }
701 } 701 }
702 v8_isolate->Dispose(); 702 v8_isolate->Dispose();
703 } 703 }
704 } 704 }
705 705
706 706
707 TEST(PerIsolateSnapshotBlobs) {
708 // Disable experimental natives that are loaded after desrialization.
vogelheim 2015/02/24 15:16:31 nitpick: desrialization => deserialization
Yang 2015/02/25 08:19:20 Done.
709 FLAG_harmony_shipping = false;
710 FlagList::EnforceFlagImplications();
711
712 const char* source1 = "function f() { return 42; }";
713 const char* source2 =
714 "function f() { return g() * 2; }"
715 "function g() { return 43; }";
716
717 v8::StartupData data1 = v8::V8::CreateSnapshotDataBlob(source1);
718 v8::StartupData data2 = v8::V8::CreateSnapshotDataBlob(source2);
719
720 v8::Isolate::CreateParams params1;
721 params1.snapshot_blob = &data1;
722 v8::Isolate* isolate1 = v8::Isolate::New(params1);
723 {
724 v8::Isolate::Scope i_scope(isolate1);
725 v8::HandleScope h_scope(isolate1);
726 v8::Local<v8::Context> context = v8::Context::New(isolate1);
727 delete data1.data; // We can dispose of the snapshot blob now.
728 v8::Context::Scope c_scope(context);
729 CHECK_EQ(42, CompileRun("f()")->ToInt32(isolate1)->Int32Value());
730 CHECK(CompileRun("this.g")->IsUndefined());
731 }
732 isolate1->Dispose();
733
734 v8::Isolate::CreateParams params2;
735 params2.snapshot_blob = &data2;
736 v8::Isolate* isolate2 = v8::Isolate::New(params2);
737 {
738 v8::Isolate::Scope i_scope(isolate2);
739 v8::HandleScope h_scope(isolate2);
740 v8::Local<v8::Context> context = v8::Context::New(isolate2);
741 delete data2.data; // We can dispose of the snapshot blob now.
742 v8::Context::Scope c_scope(context);
743 CHECK_EQ(86, CompileRun("f()")->ToInt32(isolate2)->Int32Value());
744 CHECK_EQ(43, CompileRun("g()")->ToInt32(isolate2)->Int32Value());
745 }
746 isolate2->Dispose();
747 }
748
749
707 TEST(TestThatAlwaysSucceeds) { 750 TEST(TestThatAlwaysSucceeds) {
708 } 751 }
709 752
710 753
711 TEST(TestThatAlwaysFails) { 754 TEST(TestThatAlwaysFails) {
712 bool ArtificialFailure = false; 755 bool ArtificialFailure = false;
713 CHECK(ArtificialFailure); 756 CHECK(ArtificialFailure);
714 } 757 }
715 758
716 759
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 { 1459 {
1417 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2)); 1460 DisallowCompilation no_compile(reinterpret_cast<Isolate*>(isolate2));
1418 script = v8::ScriptCompiler::CompileUnbound( 1461 script = v8::ScriptCompiler::CompileUnbound(
1419 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache); 1462 isolate2, &source, v8::ScriptCompiler::kConsumeCodeCache);
1420 } 1463 }
1421 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run(); 1464 v8::Local<v8::Value> result = script->BindToCurrentContext()->Run();
1422 CHECK(result->ToString(isolate2)->Equals(v8_str("XY"))); 1465 CHECK(result->ToString(isolate2)->Equals(v8_str("XY")));
1423 } 1466 }
1424 isolate2->Dispose(); 1467 isolate2->Dispose();
1425 } 1468 }
OLDNEW
« src/snapshot.h ('K') | « test/cctest/test-heap.cc ('k') | test/cctest/test-spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698