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

Side by Side Diff: test/cctest/test-serialize.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 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 Heap::Verify(); 282 Heap::Verify();
283 #endif 283 #endif
284 CHECK(Top::global()->IsJSObject()); 284 CHECK(Top::global()->IsJSObject());
285 CHECK(Top::global_context()->IsContext()); 285 CHECK(Top::global_context()->IsContext());
286 CHECK(Heap::symbol_table()->IsSymbolTable()); 286 CHECK(Heap::symbol_table()->IsSymbolTable());
287 CHECK(!Factory::LookupAsciiSymbol("Empty")->IsFailure()); 287 CHECK(!Factory::LookupAsciiSymbol("Empty")->IsFailure());
288 } 288 }
289 289
290 290
291 DEPENDENT_TEST(Deserialize, Serialize) { 291 DEPENDENT_TEST(Deserialize, Serialize) {
292 v8::HandleScope scope; 292 // The serialize-deserialize tests only work if the VM is built without
293 // serialization. That doesn't matter. We don't need to be able to
294 // serialize a snapshot in a VM that is booted from a snapshot.
295 if (!Snapshot::IsEnabled()) {
296 v8::HandleScope scope;
293 297
294 Deserialize(); 298 Deserialize();
295 299
296 v8::Persistent<v8::Context> env = v8::Context::New(); 300 v8::Persistent<v8::Context> env = v8::Context::New();
297 env->Enter(); 301 env->Enter();
298 302
299 SanityCheck(); 303 SanityCheck();
304 }
300 } 305 }
301 306
302 307
303 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) { 308 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) {
304 // BUG(632): Disable this test until the partial_snapshots branch is 309 if (!Snapshot::IsEnabled()) {
305 // merged back. 310 v8::HandleScope scope;
306 return;
307 311
308 v8::HandleScope scope; 312 Deserialize();
309 313
310 Deserialize(); 314 v8::Persistent<v8::Context> env = v8::Context::New();
315 env->Enter();
311 316
312 v8::Persistent<v8::Context> env = v8::Context::New(); 317 SanityCheck();
313 env->Enter(); 318 }
314
315 SanityCheck();
316 } 319 }
317 320
318 321
319 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { 322 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
320 v8::HandleScope scope; 323 if (!Snapshot::IsEnabled()) {
324 v8::HandleScope scope;
321 325
322 Deserialize(); 326 Deserialize();
323 327
324 v8::Persistent<v8::Context> env = v8::Context::New(); 328 v8::Persistent<v8::Context> env = v8::Context::New();
325 env->Enter(); 329 env->Enter();
326 330
327 const char* c_source = "\"1234\".length"; 331 const char* c_source = "\"1234\".length";
328 v8::Local<v8::String> source = v8::String::New(c_source); 332 v8::Local<v8::String> source = v8::String::New(c_source);
329 v8::Local<v8::Script> script = v8::Script::Compile(source); 333 v8::Local<v8::Script> script = v8::Script::Compile(source);
330 CHECK_EQ(4, script->Run()->Int32Value()); 334 CHECK_EQ(4, script->Run()->Int32Value());
335 }
331 } 336 }
332 337
333 338
334 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2, 339 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
335 SerializeTwice) { 340 SerializeTwice) {
336 // BUG(632): Disable this test until the partial_snapshots branch is 341 if (!Snapshot::IsEnabled()) {
337 // merged back. 342 v8::HandleScope scope;
338 return;
339 343
340 v8::HandleScope scope; 344 Deserialize();
341 345
342 Deserialize(); 346 v8::Persistent<v8::Context> env = v8::Context::New();
347 env->Enter();
343 348
344 v8::Persistent<v8::Context> env = v8::Context::New(); 349 const char* c_source = "\"1234\".length";
345 env->Enter(); 350 v8::Local<v8::String> source = v8::String::New(c_source);
346 351 v8::Local<v8::Script> script = v8::Script::Compile(source);
347 const char* c_source = "\"1234\".length"; 352 CHECK_EQ(4, script->Run()->Int32Value());
348 v8::Local<v8::String> source = v8::String::New(c_source); 353 }
349 v8::Local<v8::Script> script = v8::Script::Compile(source);
350 CHECK_EQ(4, script->Run()->Int32Value());
351 } 354 }
352 355
353 356
354 TEST(PartialSerialization) { 357 TEST(PartialSerialization) {
355 Serializer::Enable(); 358 Serializer::Enable();
356 v8::V8::Initialize(); 359 v8::V8::Initialize();
357 360
358 v8::Persistent<v8::Context> env = v8::Context::New(); 361 v8::Persistent<v8::Context> env = v8::Context::New();
359 ASSERT(!env.IsEmpty()); 362 ASSERT(!env.IsEmpty());
360 env->Enter(); 363 env->Enter();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE), 396 partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE),
394 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), 397 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
395 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), 398 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
396 p_ser.CurrentAllocationAddress(CODE_SPACE), 399 p_ser.CurrentAllocationAddress(CODE_SPACE),
397 p_ser.CurrentAllocationAddress(MAP_SPACE), 400 p_ser.CurrentAllocationAddress(MAP_SPACE),
398 p_ser.CurrentAllocationAddress(CELL_SPACE), 401 p_ser.CurrentAllocationAddress(CELL_SPACE),
399 p_ser.CurrentAllocationAddress(LO_SPACE)); 402 p_ser.CurrentAllocationAddress(LO_SPACE));
400 } 403 }
401 404
402 405
403 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { 406 static void ReserveSpaceForPartialSnapshot(const char* file_name) {
404 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 407 int file_name_length = StrLength(file_name) + 10;
405 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
406 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
407
408 CHECK(Snapshot::Initialize(startup_name.start()));
409
410 const char* file_name = FLAG_testing_serialization_file;
411 Vector<char> name = Vector<char>::New(file_name_length + 1); 408 Vector<char> name = Vector<char>::New(file_name_length + 1);
412 OS::SNPrintF(name, "%s.size", file_name); 409 OS::SNPrintF(name, "%s.size", file_name);
413 FILE* fp = OS::FOpen(name.start(), "r"); 410 FILE* fp = OS::FOpen(name.start(), "r");
414 int new_size, pointer_size, data_size, code_size, map_size, cell_size; 411 int new_size, pointer_size, data_size, code_size, map_size, cell_size;
415 int large_size; 412 int large_size;
416 #ifdef _MSC_VER 413 #ifdef _MSC_VER
417 // Avoid warning about unsafe fscanf from MSVC. 414 // Avoid warning about unsafe fscanf from MSVC.
418 // Please note that this is only fine if %c and %s are not being used. 415 // Please note that this is only fine if %c and %s are not being used.
419 #define fscanf fscanf_s 416 #define fscanf fscanf_s
420 #endif 417 #endif
421 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); 418 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size));
422 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); 419 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size));
423 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); 420 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
424 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); 421 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
425 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); 422 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
426 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); 423 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
427 CHECK_EQ(1, fscanf(fp, "large %d\n", &large_size)); 424 CHECK_EQ(1, fscanf(fp, "large %d\n", &large_size));
428 #ifdef _MSC_VER 425 #ifdef _MSC_VER
429 #undef fscanf 426 #undef fscanf
430 #endif 427 #endif
431 fclose(fp); 428 fclose(fp);
432 Heap::ReserveSpace(new_size, 429 Heap::ReserveSpace(new_size,
433 pointer_size, 430 pointer_size,
434 data_size, 431 data_size,
435 code_size, 432 code_size,
436 map_size, 433 map_size,
437 cell_size, 434 cell_size,
438 large_size); 435 large_size);
439 int snapshot_size = 0; 436 }
440 byte* snapshot = ReadBytes(file_name, &snapshot_size);
441 437
442 Object* root; 438
443 { 439 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
444 SnapshotByteSource source(snapshot, snapshot_size); 440 if (!Snapshot::IsEnabled()) {
445 Deserializer deserializer(&source); 441 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
446 deserializer.DeserializePartial(&root); 442 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
447 CHECK(root->IsString()); 443 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
444
445 CHECK(Snapshot::Initialize(startup_name.start()));
446
447 const char* file_name = FLAG_testing_serialization_file;
448 ReserveSpaceForPartialSnapshot(file_name);
449
450 int snapshot_size = 0;
451 byte* snapshot = ReadBytes(file_name, &snapshot_size);
452
453 Object* root;
454 {
455 SnapshotByteSource source(snapshot, snapshot_size);
456 Deserializer deserializer(&source);
457 deserializer.DeserializePartial(&root);
458 CHECK(root->IsString());
459 }
460 v8::HandleScope handle_scope;
461 Handle<Object>root_handle(root);
462
463 Object* root2;
464 {
465 SnapshotByteSource source(snapshot, snapshot_size);
466 Deserializer deserializer(&source);
467 deserializer.DeserializePartial(&root2);
468 CHECK(root2->IsString());
469 CHECK(*root_handle == root2);
470 }
448 } 471 }
449 v8::HandleScope handle_scope; 472 }
450 Handle<Object>root_handle(root);
451 473
452 Object* root2; 474
453 { 475 TEST(ContextSerialization) {
454 SnapshotByteSource source(snapshot, snapshot_size); 476 Serializer::Enable();
455 Deserializer deserializer(&source); 477 v8::V8::Initialize();
456 deserializer.DeserializePartial(&root2); 478
457 CHECK(root2->IsString()); 479 v8::Persistent<v8::Context> env = v8::Context::New();
458 CHECK(*root_handle == root2); 480 ASSERT(!env.IsEmpty());
481 env->Enter();
482 // Make sure all builtin scripts are cached.
483 { HandleScope scope;
484 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) {
485 Bootstrapper::NativesSourceLookup(i);
486 }
487 }
488 // If we don't do this then we end up with a stray root pointing at the
489 // context even after we have disposed of env.
490 Heap::CollectAllGarbage(true);
491
492 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
493 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
494 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
495
496 env->Exit();
497
498 Object* raw_context = *(v8::Utils::OpenHandle(*env));
499
500 env.Dispose();
501
502 FileByteSink startup_sink(startup_name.start());
503 StartupSerializer startup_serializer(&startup_sink);
504 startup_serializer.SerializeStrongReferences();
505
506 FileByteSink partial_sink(FLAG_testing_serialization_file);
507 PartialSerializer p_ser(&startup_serializer, &partial_sink);
508 p_ser.Serialize(&raw_context);
509 startup_serializer.SerializeWeakReferences();
510 partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE),
511 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE),
512 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE),
513 p_ser.CurrentAllocationAddress(CODE_SPACE),
514 p_ser.CurrentAllocationAddress(MAP_SPACE),
515 p_ser.CurrentAllocationAddress(CELL_SPACE),
516 p_ser.CurrentAllocationAddress(LO_SPACE));
517 }
518
519
520 DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
521 if (!Snapshot::IsEnabled()) {
522 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
523 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
524 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
525
526 CHECK(Snapshot::Initialize(startup_name.start()));
527
528 const char* file_name = FLAG_testing_serialization_file;
529 ReserveSpaceForPartialSnapshot(file_name);
530
531 int snapshot_size = 0;
532 byte* snapshot = ReadBytes(file_name, &snapshot_size);
533
534 Object* root;
535 {
536 SnapshotByteSource source(snapshot, snapshot_size);
537 Deserializer deserializer(&source);
538 deserializer.DeserializePartial(&root);
539 CHECK(root->IsContext());
540 }
541 v8::HandleScope handle_scope;
542 Handle<Object>root_handle(root);
543
544 Object* root2;
545 {
546 SnapshotByteSource source(snapshot, snapshot_size);
547 Deserializer deserializer(&source);
548 deserializer.DeserializePartial(&root2);
549 CHECK(root2->IsContext());
550 CHECK(*root_handle != root2);
551 }
459 } 552 }
460 } 553 }
461 554
462 555
463 TEST(LinearAllocation) { 556 TEST(LinearAllocation) {
464 v8::V8::Initialize(); 557 v8::V8::Initialize();
465 int new_space_max = 512 * KB; 558 int new_space_max = 512 * KB;
559
466 for (int size = 1000; size < 5 * MB; size += size >> 1) { 560 for (int size = 1000; size < 5 * MB; size += size >> 1) {
467 int new_space_size = (size < new_space_max) ? size : new_space_max; 561 int new_space_size = (size < new_space_max) ? size : new_space_max;
468 Heap::ReserveSpace( 562 Heap::ReserveSpace(
469 new_space_size, 563 new_space_size,
470 size, // Old pointer space. 564 size, // Old pointer space.
471 size, // Old data space. 565 size, // Old data space.
472 size, // Code space. 566 size, // Code space.
473 size, // Map space. 567 size, // Map space.
474 size, // Cell space. 568 size, // Cell space.
475 size); // Large object space. 569 size); // Large object space.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 TEST(TestThatAlwaysFails) { 662 TEST(TestThatAlwaysFails) {
569 bool ArtificialFailure = false; 663 bool ArtificialFailure = false;
570 CHECK(ArtificialFailure); 664 CHECK(ArtificialFailure);
571 } 665 }
572 666
573 667
574 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { 668 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) {
575 bool ArtificialFailure2 = false; 669 bool ArtificialFailure2 = false;
576 CHECK(ArtificialFailure2); 670 CHECK(ArtificialFailure2);
577 } 671 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698