OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 455 |
456 THREADED_TEST(ScriptMakingExternalString) { | 456 THREADED_TEST(ScriptMakingExternalString) { |
457 int dispose_count = 0; | 457 int dispose_count = 0; |
458 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); | 458 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); |
459 { | 459 { |
460 LocalContext env; | 460 LocalContext env; |
461 v8::HandleScope scope(env->GetIsolate()); | 461 v8::HandleScope scope(env->GetIsolate()); |
462 Local<String> source = | 462 Local<String> source = |
463 String::NewFromTwoByte(env->GetIsolate(), two_byte_source); | 463 String::NewFromTwoByte(env->GetIsolate(), two_byte_source); |
464 // Trigger GCs so that the newly allocated string moves to old gen. | 464 // Trigger GCs so that the newly allocated string moves to old gen. |
465 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 465 CcTest::heap()->CollectGarbageNewSpace(); // in survivor space now |
466 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 466 CcTest::heap()->CollectGarbageNewSpace(); // in old gen now |
467 CHECK_EQ(source->IsExternal(), false); | 467 CHECK_EQ(source->IsExternal(), false); |
468 CHECK_EQ(source->IsExternalOneByte(), false); | 468 CHECK_EQ(source->IsExternalOneByte(), false); |
469 String::Encoding encoding = String::UNKNOWN_ENCODING; | 469 String::Encoding encoding = String::UNKNOWN_ENCODING; |
470 CHECK(!source->GetExternalStringResourceBase(&encoding)); | 470 CHECK(!source->GetExternalStringResourceBase(&encoding)); |
471 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); | 471 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); |
472 bool success = source->MakeExternal(new TestResource(two_byte_source, | 472 bool success = source->MakeExternal(new TestResource(two_byte_source, |
473 &dispose_count)); | 473 &dispose_count)); |
474 CHECK(success); | 474 CHECK(success); |
475 Local<Script> script = v8_compile(source); | 475 Local<Script> script = v8_compile(source); |
476 Local<Value> value = script->Run(); | 476 Local<Value> value = script->Run(); |
477 CHECK(value->IsNumber()); | 477 CHECK(value->IsNumber()); |
478 CHECK_EQ(7, value->Int32Value()); | 478 CHECK_EQ(7, value->Int32Value()); |
479 CcTest::heap()->CollectAllGarbage(); | 479 CcTest::heap()->CollectAllGarbage(); |
480 CHECK_EQ(0, dispose_count); | 480 CHECK_EQ(0, dispose_count); |
481 } | 481 } |
482 CcTest::i_isolate()->compilation_cache()->Clear(); | 482 CcTest::i_isolate()->compilation_cache()->Clear(); |
483 CcTest::heap()->CollectAllGarbage(); | 483 CcTest::heap()->CollectAllGarbage(); |
484 CHECK_EQ(1, dispose_count); | 484 CHECK_EQ(1, dispose_count); |
485 } | 485 } |
486 | 486 |
487 | 487 |
488 THREADED_TEST(ScriptMakingExternalOneByteString) { | 488 THREADED_TEST(ScriptMakingExternalOneByteString) { |
489 int dispose_count = 0; | 489 int dispose_count = 0; |
490 const char* c_source = "1 + 2 * 3"; | 490 const char* c_source = "1 + 2 * 3"; |
491 { | 491 { |
492 LocalContext env; | 492 LocalContext env; |
493 v8::HandleScope scope(env->GetIsolate()); | 493 v8::HandleScope scope(env->GetIsolate()); |
494 Local<String> source = v8_str(c_source); | 494 Local<String> source = v8_str(c_source); |
495 // Trigger GCs so that the newly allocated string moves to old gen. | 495 // Trigger GCs so that the newly allocated string moves to old gen. |
496 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 496 CcTest::heap()->CollectGarbageNewSpace(); // in survivor space now |
497 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 497 CcTest::heap()->CollectGarbageNewSpace(); // in old gen now |
498 bool success = source->MakeExternal( | 498 bool success = source->MakeExternal( |
499 new TestOneByteResource(i::StrDup(c_source), &dispose_count)); | 499 new TestOneByteResource(i::StrDup(c_source), &dispose_count)); |
500 CHECK(success); | 500 CHECK(success); |
501 Local<Script> script = v8_compile(source); | 501 Local<Script> script = v8_compile(source); |
502 Local<Value> value = script->Run(); | 502 Local<Value> value = script->Run(); |
503 CHECK(value->IsNumber()); | 503 CHECK(value->IsNumber()); |
504 CHECK_EQ(7, value->Int32Value()); | 504 CHECK_EQ(7, value->Int32Value()); |
505 CcTest::heap()->CollectAllGarbage(); | 505 CcTest::heap()->CollectAllGarbage(); |
506 CHECK_EQ(0, dispose_count); | 506 CHECK_EQ(0, dispose_count); |
507 } | 507 } |
508 CcTest::i_isolate()->compilation_cache()->Clear(); | 508 CcTest::i_isolate()->compilation_cache()->Clear(); |
509 CcTest::heap()->CollectAllGarbage(); | 509 CcTest::heap()->CollectAllGarbage(); |
510 CHECK_EQ(1, dispose_count); | 510 CHECK_EQ(1, dispose_count); |
511 } | 511 } |
512 | 512 |
513 | 513 |
514 TEST(MakingExternalStringConditions) { | 514 TEST(MakingExternalStringConditions) { |
515 LocalContext env; | 515 LocalContext env; |
516 v8::HandleScope scope(env->GetIsolate()); | 516 v8::HandleScope scope(env->GetIsolate()); |
517 | 517 |
518 // Free some space in the new space so that we can check freshness. | 518 // Free some space in the new space so that we can check freshness. |
519 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 519 CcTest::heap()->CollectGarbageNewSpace(); |
520 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 520 CcTest::heap()->CollectGarbageNewSpace(); |
521 | 521 |
522 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); | 522 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); |
523 Local<String> small_string = | 523 Local<String> small_string = |
524 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); | 524 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); |
525 i::DeleteArray(two_byte_string); | 525 i::DeleteArray(two_byte_string); |
526 | 526 |
527 // We should refuse to externalize small strings. | 527 // We should refuse to externalize small strings. |
528 CHECK(!small_string->CanMakeExternal()); | 528 CHECK(!small_string->CanMakeExternal()); |
529 // Trigger GCs so that the newly allocated string moves to old gen. | 529 // Trigger GCs so that the newly allocated string moves to old gen. |
530 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 530 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
(...skipping 18 matching lines...) Expand all Loading... |
549 // Large strings should be immediately accepted. | 549 // Large strings should be immediately accepted. |
550 CHECK(large_string->CanMakeExternal()); | 550 CHECK(large_string->CanMakeExternal()); |
551 } | 551 } |
552 | 552 |
553 | 553 |
554 TEST(MakingExternalOneByteStringConditions) { | 554 TEST(MakingExternalOneByteStringConditions) { |
555 LocalContext env; | 555 LocalContext env; |
556 v8::HandleScope scope(env->GetIsolate()); | 556 v8::HandleScope scope(env->GetIsolate()); |
557 | 557 |
558 // Free some space in the new space so that we can check freshness. | 558 // Free some space in the new space so that we can check freshness. |
559 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 559 CcTest::heap()->CollectGarbageNewSpace(); |
560 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 560 CcTest::heap()->CollectGarbageNewSpace(); |
561 | 561 |
562 Local<String> small_string = String::NewFromUtf8(env->GetIsolate(), "s1"); | 562 Local<String> small_string = String::NewFromUtf8(env->GetIsolate(), "s1"); |
563 // We should refuse to externalize small strings. | 563 // We should refuse to externalize small strings. |
564 CHECK(!small_string->CanMakeExternal()); | 564 CHECK(!small_string->CanMakeExternal()); |
565 // Trigger GCs so that the newly allocated string moves to old gen. | 565 // Trigger GCs so that the newly allocated string moves to old gen. |
566 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 566 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
567 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 567 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
568 // Old space strings should be accepted. | 568 // Old space strings should be accepted. |
569 CHECK(small_string->CanMakeExternal()); | 569 CHECK(small_string->CanMakeExternal()); |
570 | 570 |
(...skipping 16 matching lines...) Expand all Loading... |
587 "function slice(a) { return a.substring(1); }"); | 587 "function slice(a) { return a.substring(1); }"); |
588 // Create a cons string that will land in old pointer space. | 588 // Create a cons string that will land in old pointer space. |
589 Local<String> cons = Local<String>::Cast(CompileRun( | 589 Local<String> cons = Local<String>::Cast(CompileRun( |
590 "cons('abcdefghijklm', 'nopqrstuvwxyz');")); | 590 "cons('abcdefghijklm', 'nopqrstuvwxyz');")); |
591 // Create a sliced string that will land in old pointer space. | 591 // Create a sliced string that will land in old pointer space. |
592 Local<String> slice = Local<String>::Cast(CompileRun( | 592 Local<String> slice = Local<String>::Cast(CompileRun( |
593 "slice('abcdefghijklmnopqrstuvwxyz');")); | 593 "slice('abcdefghijklmnopqrstuvwxyz');")); |
594 | 594 |
595 // Trigger GCs so that the newly allocated string moves to old gen. | 595 // Trigger GCs so that the newly allocated string moves to old gen. |
596 SimulateFullSpace(CcTest::heap()->old_space()); | 596 SimulateFullSpace(CcTest::heap()->old_space()); |
597 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 597 CcTest::heap()->CollectGarbageNewSpace(); // in survivor space now |
598 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 598 CcTest::heap()->CollectGarbageNewSpace(); // in old gen now |
599 | 599 |
600 // Turn into external string with unaligned resource data. | 600 // Turn into external string with unaligned resource data. |
601 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz"; | 601 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz"; |
602 bool success = | 602 bool success = |
603 cons->MakeExternal(new TestOneByteResource(i::StrDup(c_cons), NULL, 1)); | 603 cons->MakeExternal(new TestOneByteResource(i::StrDup(c_cons), NULL, 1)); |
604 CHECK(success); | 604 CHECK(success); |
605 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz"; | 605 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz"; |
606 success = | 606 success = |
607 slice->MakeExternal(new TestOneByteResource(i::StrDup(c_slice), NULL, 1)); | 607 slice->MakeExternal(new TestOneByteResource(i::StrDup(c_slice), NULL, 1)); |
608 CHECK(success); | 608 CHECK(success); |
609 | 609 |
610 // Trigger GCs and force evacuation. | 610 // Trigger GCs and force evacuation. |
611 CcTest::heap()->CollectAllGarbage(); | 611 CcTest::heap()->CollectAllGarbage(); |
612 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); | 612 CcTest::heap()->CollectAllGarbage("MakingExternalUnalignedOneByteString", |
| 613 i::Heap::kReduceMemoryFootprintMask); |
613 } | 614 } |
614 | 615 |
615 | 616 |
616 THREADED_TEST(UsingExternalString) { | 617 THREADED_TEST(UsingExternalString) { |
617 i::Factory* factory = CcTest::i_isolate()->factory(); | 618 i::Factory* factory = CcTest::i_isolate()->factory(); |
618 { | 619 { |
619 v8::HandleScope scope(CcTest::isolate()); | 620 v8::HandleScope scope(CcTest::isolate()); |
620 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 621 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
621 Local<String> string = String::NewExternal( | 622 Local<String> string = String::NewExternal( |
622 CcTest::isolate(), new TestResource(two_byte_string)); | 623 CcTest::isolate(), new TestResource(two_byte_string)); |
623 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 624 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
624 // Trigger GCs so that the newly allocated string moves to old gen. | 625 // Trigger GCs so that the newly allocated string moves to old gen. |
625 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 626 CcTest::heap()->CollectGarbageNewSpace(); // in survivor space now |
626 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 627 CcTest::heap()->CollectGarbageNewSpace(); // in old gen now |
627 i::Handle<i::String> isymbol = | 628 i::Handle<i::String> isymbol = |
628 factory->InternalizeString(istring); | 629 factory->InternalizeString(istring); |
629 CHECK(isymbol->IsInternalizedString()); | 630 CHECK(isymbol->IsInternalizedString()); |
630 } | 631 } |
631 CcTest::heap()->CollectAllGarbage(); | 632 CcTest::heap()->CollectAllGarbage(); |
632 CcTest::heap()->CollectAllGarbage(); | 633 CcTest::heap()->CollectAllGarbage(); |
633 } | 634 } |
634 | 635 |
635 | 636 |
636 THREADED_TEST(UsingExternalOneByteString) { | 637 THREADED_TEST(UsingExternalOneByteString) { |
637 i::Factory* factory = CcTest::i_isolate()->factory(); | 638 i::Factory* factory = CcTest::i_isolate()->factory(); |
638 { | 639 { |
639 v8::HandleScope scope(CcTest::isolate()); | 640 v8::HandleScope scope(CcTest::isolate()); |
640 const char* one_byte_string = "test string"; | 641 const char* one_byte_string = "test string"; |
641 Local<String> string = String::NewExternal( | 642 Local<String> string = String::NewExternal( |
642 CcTest::isolate(), new TestOneByteResource(i::StrDup(one_byte_string))); | 643 CcTest::isolate(), new TestOneByteResource(i::StrDup(one_byte_string))); |
643 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 644 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
644 // Trigger GCs so that the newly allocated string moves to old gen. | 645 // Trigger GCs so that the newly allocated string moves to old gen. |
645 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 646 CcTest::heap()->CollectGarbageNewSpace(); // in survivor space now |
646 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 647 CcTest::heap()->CollectGarbageNewSpace(); // in old gen now |
647 i::Handle<i::String> isymbol = | 648 i::Handle<i::String> isymbol = |
648 factory->InternalizeString(istring); | 649 factory->InternalizeString(istring); |
649 CHECK(isymbol->IsInternalizedString()); | 650 CHECK(isymbol->IsInternalizedString()); |
650 } | 651 } |
651 CcTest::heap()->CollectAllGarbage(); | 652 CcTest::heap()->CollectAllGarbage(); |
652 CcTest::heap()->CollectAllGarbage(); | 653 CcTest::heap()->CollectAllGarbage(); |
653 } | 654 } |
654 | 655 |
655 | 656 |
656 class RandomLengthResource : public v8::String::ExternalStringResource { | 657 class RandomLengthResource : public v8::String::ExternalStringResource { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 i::FLAG_stress_compaction = false; | 705 i::FLAG_stress_compaction = false; |
705 i::FLAG_gc_global = false; | 706 i::FLAG_gc_global = false; |
706 int dispose_count = 0; | 707 int dispose_count = 0; |
707 bool in_new_space = false; | 708 bool in_new_space = false; |
708 { | 709 { |
709 v8::HandleScope scope(CcTest::isolate()); | 710 v8::HandleScope scope(CcTest::isolate()); |
710 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 711 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
711 Local<String> string = String::NewExternal( | 712 Local<String> string = String::NewExternal( |
712 CcTest::isolate(), new TestResource(two_byte_string, &dispose_count)); | 713 CcTest::isolate(), new TestResource(two_byte_string, &dispose_count)); |
713 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 714 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
714 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 715 CcTest::heap()->CollectGarbageNewSpace(); |
715 in_new_space = CcTest::heap()->InNewSpace(*istring); | 716 in_new_space = CcTest::heap()->InNewSpace(*istring); |
716 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); | 717 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); |
717 CHECK_EQ(0, dispose_count); | 718 CHECK_EQ(0, dispose_count); |
718 } | 719 } |
719 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); | 720 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); |
720 CHECK_EQ(1, dispose_count); | 721 CHECK_EQ(1, dispose_count); |
721 } | 722 } |
722 | 723 |
723 | 724 |
724 THREADED_TEST(ScavengeExternalOneByteString) { | 725 THREADED_TEST(ScavengeExternalOneByteString) { |
725 i::FLAG_stress_compaction = false; | 726 i::FLAG_stress_compaction = false; |
726 i::FLAG_gc_global = false; | 727 i::FLAG_gc_global = false; |
727 int dispose_count = 0; | 728 int dispose_count = 0; |
728 bool in_new_space = false; | 729 bool in_new_space = false; |
729 { | 730 { |
730 v8::HandleScope scope(CcTest::isolate()); | 731 v8::HandleScope scope(CcTest::isolate()); |
731 const char* one_byte_string = "test string"; | 732 const char* one_byte_string = "test string"; |
732 Local<String> string = String::NewExternal( | 733 Local<String> string = String::NewExternal( |
733 CcTest::isolate(), | 734 CcTest::isolate(), |
734 new TestOneByteResource(i::StrDup(one_byte_string), &dispose_count)); | 735 new TestOneByteResource(i::StrDup(one_byte_string), &dispose_count)); |
735 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 736 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
736 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 737 CcTest::heap()->CollectGarbageNewSpace(); |
737 in_new_space = CcTest::heap()->InNewSpace(*istring); | 738 in_new_space = CcTest::heap()->InNewSpace(*istring); |
738 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); | 739 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); |
739 CHECK_EQ(0, dispose_count); | 740 CHECK_EQ(0, dispose_count); |
740 } | 741 } |
741 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); | 742 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); |
742 CHECK_EQ(1, dispose_count); | 743 CHECK_EQ(1, dispose_count); |
743 } | 744 } |
744 | 745 |
745 | 746 |
746 class TestOneByteResourceWithDisposeControl : public TestOneByteResource { | 747 class TestOneByteResourceWithDisposeControl : public TestOneByteResource { |
(...skipping 2636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3383 Local<v8::Object> expected2 = NewObjectForIntKey(isolate, templ, 8); | 3384 Local<v8::Object> expected2 = NewObjectForIntKey(isolate, templ, 8); |
3384 removed = map.Set(8, v8::Global<v8::Object>(isolate, expected2), &ref); | 3385 removed = map.Set(8, v8::Global<v8::Object>(isolate, expected2), &ref); |
3385 CHECK_EQ(1, static_cast<int>(map.Size())); | 3386 CHECK_EQ(1, static_cast<int>(map.Size())); |
3386 CHECK(expected == removed); | 3387 CHECK(expected == removed); |
3387 CHECK(expected2->Equals(ref.NewLocal(isolate))); | 3388 CHECK(expected2->Equals(ref.NewLocal(isolate))); |
3388 } | 3389 } |
3389 } | 3390 } |
3390 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); | 3391 CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count()); |
3391 if (map.IsWeak()) { | 3392 if (map.IsWeak()) { |
3392 CcTest::i_isolate()->heap()->CollectAllGarbage( | 3393 CcTest::i_isolate()->heap()->CollectAllGarbage( |
3393 i::Heap::kAbortIncrementalMarkingMask); | 3394 "TestGlobalValueMap", i::Heap::kAbortIncrementalMarkingMask); |
3394 } else { | 3395 } else { |
3395 map.Clear(); | 3396 map.Clear(); |
3396 } | 3397 } |
3397 CHECK_EQ(0, static_cast<int>(map.Size())); | 3398 CHECK_EQ(0, static_cast<int>(map.Size())); |
3398 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); | 3399 CHECK_EQ(initial_handle_count, global_handles->global_handles_count()); |
3399 { | 3400 { |
3400 HandleScope scope(isolate); | 3401 HandleScope scope(isolate); |
3401 Local<v8::Object> value = NewObjectForIntKey(isolate, templ, 9); | 3402 Local<v8::Object> value = NewObjectForIntKey(isolate, templ, 9); |
3402 map.Set(9, value); | 3403 map.Set(9, value); |
3403 map.Clear(); | 3404 map.Clear(); |
(...skipping 3132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6536 Local<Object> b(v8::Object::New(iso)); | 6537 Local<Object> b(v8::Object::New(iso)); |
6537 object_a.handle.Reset(iso, a); | 6538 object_a.handle.Reset(iso, a); |
6538 object_b.handle.Reset(iso, b); | 6539 object_b.handle.Reset(iso, b); |
6539 if (interlinked) { | 6540 if (interlinked) { |
6540 a->Set(v8_str("x"), b); | 6541 a->Set(v8_str("x"), b); |
6541 b->Set(v8_str("x"), a); | 6542 b->Set(v8_str("x"), a); |
6542 } | 6543 } |
6543 if (global_gc) { | 6544 if (global_gc) { |
6544 CcTest::heap()->CollectAllGarbage(); | 6545 CcTest::heap()->CollectAllGarbage(); |
6545 } else { | 6546 } else { |
6546 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6547 CcTest::heap()->CollectGarbageNewSpace(); |
6547 } | 6548 } |
6548 // We are relying on this creating a big flag array and reserving the space | 6549 // We are relying on this creating a big flag array and reserving the space |
6549 // up front. | 6550 // up front. |
6550 v8::Handle<Value> big_array = CompileRun("new Array(50000)"); | 6551 v8::Handle<Value> big_array = CompileRun("new Array(50000)"); |
6551 a->Set(v8_str("y"), big_array); | 6552 a->Set(v8_str("y"), big_array); |
6552 big_heap_size = CcTest::heap()->SizeOfObjects(); | 6553 big_heap_size = CcTest::heap()->SizeOfObjects(); |
6553 } | 6554 } |
6554 | 6555 |
6555 object_a.flag = false; | 6556 object_a.flag = false; |
6556 object_b.flag = false; | 6557 object_b.flag = false; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6654 | 6655 |
6655 handle.SetWeak<v8::Persistent<v8::Object>>( | 6656 handle.SetWeak<v8::Persistent<v8::Object>>( |
6656 &handle, CheckInternalFields, v8::WeakCallbackType::kInternalFields); | 6657 &handle, CheckInternalFields, v8::WeakCallbackType::kInternalFields); |
6657 if (!global_gc) { | 6658 if (!global_gc) { |
6658 handle.MarkIndependent(); | 6659 handle.MarkIndependent(); |
6659 } | 6660 } |
6660 } | 6661 } |
6661 if (global_gc) { | 6662 if (global_gc) { |
6662 CcTest::heap()->CollectAllGarbage(); | 6663 CcTest::heap()->CollectAllGarbage(); |
6663 } else { | 6664 } else { |
6664 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6665 CcTest::heap()->CollectGarbageNewSpace(); |
6665 } | 6666 } |
6666 | 6667 |
6667 CHECK_EQ(1729, t1->x()); | 6668 CHECK_EQ(1729, t1->x()); |
6668 CHECK_EQ(33550336, t2->x()); | 6669 CHECK_EQ(33550336, t2->x()); |
6669 | 6670 |
6670 delete t1; | 6671 delete t1; |
6671 delete t2; | 6672 delete t2; |
6672 } | 6673 } |
6673 | 6674 |
6674 | 6675 |
(...skipping 24 matching lines...) Expand all Loading... |
6699 | 6700 |
6700 FlagAndPersistent object_a, object_b; | 6701 FlagAndPersistent object_a, object_b; |
6701 | 6702 |
6702 { | 6703 { |
6703 v8::HandleScope handle_scope(iso); | 6704 v8::HandleScope handle_scope(iso); |
6704 Local<Object> a(v8::Object::New(iso)); | 6705 Local<Object> a(v8::Object::New(iso)); |
6705 Local<Object> b(v8::Object::New(iso)); | 6706 Local<Object> b(v8::Object::New(iso)); |
6706 object_a.handle.Reset(iso, a); | 6707 object_a.handle.Reset(iso, a); |
6707 object_b.handle.Reset(iso, b); | 6708 object_b.handle.Reset(iso, b); |
6708 if (global_gc) { | 6709 if (global_gc) { |
6709 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 6710 CcTest::heap()->CollectAllGarbage("ResetWeakHandle", |
| 6711 Heap::kAbortIncrementalMarkingMask); |
6710 } else { | 6712 } else { |
6711 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6713 CcTest::heap()->CollectGarbageNewSpace(); |
6712 } | 6714 } |
6713 } | 6715 } |
6714 | 6716 |
6715 object_a.flag = false; | 6717 object_a.flag = false; |
6716 object_b.flag = false; | 6718 object_b.flag = false; |
6717 object_a.handle.SetWeak(&object_a, &ResetUseValueAndSetFlag, | 6719 object_a.handle.SetWeak(&object_a, &ResetUseValueAndSetFlag, |
6718 v8::WeakCallbackType::kParameter); | 6720 v8::WeakCallbackType::kParameter); |
6719 object_b.handle.SetWeak(&object_b, &ResetUseValueAndSetFlag, | 6721 object_b.handle.SetWeak(&object_b, &ResetUseValueAndSetFlag, |
6720 v8::WeakCallbackType::kParameter); | 6722 v8::WeakCallbackType::kParameter); |
6721 if (!global_gc) { | 6723 if (!global_gc) { |
6722 object_a.handle.MarkIndependent(); | 6724 object_a.handle.MarkIndependent(); |
6723 object_b.handle.MarkIndependent(); | 6725 object_b.handle.MarkIndependent(); |
6724 CHECK(object_b.handle.IsIndependent()); | 6726 CHECK(object_b.handle.IsIndependent()); |
6725 } | 6727 } |
6726 if (global_gc) { | 6728 if (global_gc) { |
6727 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 6729 CcTest::heap()->CollectAllGarbage("ResetWeakHandle", |
| 6730 Heap::kAbortIncrementalMarkingMask); |
6728 } else { | 6731 } else { |
6729 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 6732 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
6730 } | 6733 } |
6731 CHECK(object_a.flag); | 6734 CHECK(object_a.flag); |
6732 CHECK(object_b.flag); | 6735 CHECK(object_b.flag); |
6733 } | 6736 } |
6734 | 6737 |
6735 | 6738 |
6736 THREADED_HEAP_TEST(ResetWeakHandle) { | 6739 THREADED_HEAP_TEST(ResetWeakHandle) { |
6737 v8::internal::HeapTester::ResetWeakHandle(false); | 6740 v8::internal::HeapTester::ResetWeakHandle(false); |
6738 v8::internal::HeapTester::ResetWeakHandle(true); | 6741 v8::internal::HeapTester::ResetWeakHandle(true); |
6739 } | 6742 } |
6740 | 6743 |
6741 | 6744 |
6742 static void InvokeScavenge() { CcTest::heap()->CollectGarbage(i::NEW_SPACE); } | 6745 static void InvokeScavenge() { CcTest::heap()->CollectGarbageNewSpace(); } |
6743 | 6746 |
6744 | 6747 |
6745 static void InvokeMarkSweep() { CcTest::heap()->CollectAllGarbage(); } | 6748 static void InvokeMarkSweep() { CcTest::heap()->CollectAllGarbage(); } |
6746 | 6749 |
6747 | 6750 |
6748 static void ForceScavenge2( | 6751 static void ForceScavenge2( |
6749 const v8::WeakCallbackInfo<FlagAndPersistent>& data) { | 6752 const v8::WeakCallbackInfo<FlagAndPersistent>& data) { |
6750 data.GetParameter()->flag = true; | 6753 data.GetParameter()->flag = true; |
6751 InvokeScavenge(); | 6754 InvokeScavenge(); |
6752 } | 6755 } |
(...skipping 4952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11705 } | 11708 } |
11706 | 11709 |
11707 | 11710 |
11708 static void CheckSurvivingGlobalObjectsCount(int expected) { | 11711 static void CheckSurvivingGlobalObjectsCount(int expected) { |
11709 // We need to collect all garbage twice to be sure that everything | 11712 // We need to collect all garbage twice to be sure that everything |
11710 // has been collected. This is because inline caches are cleared in | 11713 // has been collected. This is because inline caches are cleared in |
11711 // the first garbage collection but some of the maps have already | 11714 // the first garbage collection but some of the maps have already |
11712 // been marked at that point. Therefore some of the maps are not | 11715 // been marked at that point. Therefore some of the maps are not |
11713 // collected until the second garbage collection. | 11716 // collected until the second garbage collection. |
11714 CcTest::heap()->CollectAllGarbage(); | 11717 CcTest::heap()->CollectAllGarbage(); |
11715 CcTest::heap()->CollectAllGarbage(i::Heap::kMakeHeapIterableMask); | 11718 CcTest::heap()->CollectAllGarbage("CheckSurvivingGlobalObjectsCount", |
| 11719 i::Heap::kMakeHeapIterableMask); |
11716 int count = GetGlobalObjectsCount(); | 11720 int count = GetGlobalObjectsCount(); |
11717 #ifdef DEBUG | 11721 #ifdef DEBUG |
11718 if (count != expected) CcTest::heap()->TracePathToGlobal(); | 11722 if (count != expected) CcTest::heap()->TracePathToGlobal(); |
11719 #endif | 11723 #endif |
11720 CHECK_EQ(expected, count); | 11724 CHECK_EQ(expected, count); |
11721 } | 11725 } |
11722 | 11726 |
11723 | 11727 |
11724 TEST(DontLeakGlobalObjects) { | 11728 TEST(DontLeakGlobalObjects) { |
11725 // Regression test for issues 1139850 and 1174891. | 11729 // Regression test for issues 1139850 and 1174891. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11804 { | 11808 { |
11805 v8::HandleScope scope(isolate); | 11809 v8::HandleScope scope(isolate); |
11806 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 11810 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
11807 obj->Set(v8_str("key"), v8::Integer::New(isolate, 231)); | 11811 obj->Set(v8_str("key"), v8::Integer::New(isolate, 231)); |
11808 v8::Persistent<v8::Object>* handle = | 11812 v8::Persistent<v8::Object>* handle = |
11809 new v8::Persistent<v8::Object>(isolate, obj); | 11813 new v8::Persistent<v8::Object>(isolate, obj); |
11810 handle->SetWeak<v8::Persistent<v8::Object>>( | 11814 handle->SetWeak<v8::Persistent<v8::Object>>( |
11811 handle, WeakApiCallback, v8::WeakCallbackType::kParameter); | 11815 handle, WeakApiCallback, v8::WeakCallbackType::kParameter); |
11812 } | 11816 } |
11813 reinterpret_cast<i::Isolate*>(isolate)->heap()->CollectAllGarbage( | 11817 reinterpret_cast<i::Isolate*>(isolate)->heap()->CollectAllGarbage( |
11814 i::Heap::kAbortIncrementalMarkingMask); | 11818 "WeakCallbackApi", i::Heap::kAbortIncrementalMarkingMask); |
11815 // Verify disposed. | 11819 // Verify disposed. |
11816 CHECK_EQ(initial_handles, globals->global_handles_count()); | 11820 CHECK_EQ(initial_handles, globals->global_handles_count()); |
11817 } | 11821 } |
11818 | 11822 |
11819 | 11823 |
11820 v8::Persistent<v8::Object> some_object; | 11824 v8::Persistent<v8::Object> some_object; |
11821 v8::Persistent<v8::Object> bad_handle; | 11825 v8::Persistent<v8::Object> bad_handle; |
11822 | 11826 |
11823 | 11827 |
11824 void NewPersistentHandleCallback2( | 11828 void NewPersistentHandleCallback2( |
(...skipping 3614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15439 } | 15443 } |
15440 intptr_t final_size = CcTest::heap()->SizeOfObjects(); | 15444 intptr_t final_size = CcTest::heap()->SizeOfObjects(); |
15441 CHECK(finished); | 15445 CHECK(finished); |
15442 CHECK_LT(final_size, initial_size + 1); | 15446 CHECK_LT(final_size, initial_size + 1); |
15443 } | 15447 } |
15444 | 15448 |
15445 | 15449 |
15446 TEST(Regress2333) { | 15450 TEST(Regress2333) { |
15447 LocalContext env; | 15451 LocalContext env; |
15448 for (int i = 0; i < 3; i++) { | 15452 for (int i = 0; i < 3; i++) { |
15449 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 15453 CcTest::heap()->CollectGarbageNewSpace(); |
15450 } | 15454 } |
15451 } | 15455 } |
15452 | 15456 |
15453 static uint32_t* stack_limit; | 15457 static uint32_t* stack_limit; |
15454 | 15458 |
15455 static void GetStackLimitCallback( | 15459 static void GetStackLimitCallback( |
15456 const v8::FunctionCallbackInfo<v8::Value>& args) { | 15460 const v8::FunctionCallbackInfo<v8::Value>& args) { |
15457 stack_limit = reinterpret_cast<uint32_t*>( | 15461 stack_limit = reinterpret_cast<uint32_t*>( |
15458 CcTest::i_isolate()->stack_guard()->real_climit()); | 15462 CcTest::i_isolate()->stack_guard()->real_climit()); |
15459 } | 15463 } |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16452 CHECK_EQ(flags, v8::kNoGCCallbackFlags); | 16456 CHECK_EQ(flags, v8::kNoGCCallbackFlags); |
16453 CHECK_EQ(gc_callbacks_isolate, isolate); | 16457 CHECK_EQ(gc_callbacks_isolate, isolate); |
16454 ++prologue_call_count_alloc; | 16458 ++prologue_call_count_alloc; |
16455 | 16459 |
16456 // Simulate full heap to see if we will reenter this callback | 16460 // Simulate full heap to see if we will reenter this callback |
16457 SimulateFullSpace(CcTest::heap()->new_space()); | 16461 SimulateFullSpace(CcTest::heap()->new_space()); |
16458 | 16462 |
16459 Local<Object> obj = Object::New(isolate); | 16463 Local<Object> obj = Object::New(isolate); |
16460 CHECK(!obj.IsEmpty()); | 16464 CHECK(!obj.IsEmpty()); |
16461 | 16465 |
16462 CcTest::heap()->CollectAllGarbage( | 16466 CcTest::heap()->CollectAllGarbage("PrologueCallbackAlloc", |
16463 i::Heap::kAbortIncrementalMarkingMask); | 16467 i::Heap::kAbortIncrementalMarkingMask); |
16464 } | 16468 } |
16465 | 16469 |
16466 | 16470 |
16467 void EpilogueCallbackAlloc(v8::Isolate* isolate, | 16471 void EpilogueCallbackAlloc(v8::Isolate* isolate, |
16468 v8::GCType, | 16472 v8::GCType, |
16469 v8::GCCallbackFlags flags) { | 16473 v8::GCCallbackFlags flags) { |
16470 v8::HandleScope scope(isolate); | 16474 v8::HandleScope scope(isolate); |
16471 | 16475 |
16472 CHECK_EQ(flags, v8::kNoGCCallbackFlags); | 16476 CHECK_EQ(flags, v8::kNoGCCallbackFlags); |
16473 CHECK_EQ(gc_callbacks_isolate, isolate); | 16477 CHECK_EQ(gc_callbacks_isolate, isolate); |
16474 ++epilogue_call_count_alloc; | 16478 ++epilogue_call_count_alloc; |
16475 | 16479 |
16476 // Simulate full heap to see if we will reenter this callback | 16480 // Simulate full heap to see if we will reenter this callback |
16477 SimulateFullSpace(CcTest::heap()->new_space()); | 16481 SimulateFullSpace(CcTest::heap()->new_space()); |
16478 | 16482 |
16479 Local<Object> obj = Object::New(isolate); | 16483 Local<Object> obj = Object::New(isolate); |
16480 CHECK(!obj.IsEmpty()); | 16484 CHECK(!obj.IsEmpty()); |
16481 | 16485 |
16482 CcTest::heap()->CollectAllGarbage( | 16486 CcTest::heap()->CollectAllGarbage("EpilogueCallbackAlloc", |
16483 i::Heap::kAbortIncrementalMarkingMask); | 16487 i::Heap::kAbortIncrementalMarkingMask); |
16484 } | 16488 } |
16485 | 16489 |
16486 | 16490 |
16487 TEST(GCCallbacksOld) { | 16491 TEST(GCCallbacksOld) { |
16488 LocalContext context; | 16492 LocalContext context; |
16489 | 16493 |
16490 v8::V8::AddGCPrologueCallback(PrologueCallback); | 16494 v8::V8::AddGCPrologueCallback(PrologueCallback); |
16491 v8::V8::AddGCEpilogueCallback(EpilogueCallback); | 16495 v8::V8::AddGCEpilogueCallback(EpilogueCallback); |
16492 CHECK_EQ(0, prologue_call_count); | 16496 CHECK_EQ(0, prologue_call_count); |
16493 CHECK_EQ(0, epilogue_call_count); | 16497 CHECK_EQ(0, epilogue_call_count); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16548 CcTest::heap()->CollectAllGarbage(); | 16552 CcTest::heap()->CollectAllGarbage(); |
16549 CHECK_EQ(2, prologue_call_count); | 16553 CHECK_EQ(2, prologue_call_count); |
16550 CHECK_EQ(2, epilogue_call_count); | 16554 CHECK_EQ(2, epilogue_call_count); |
16551 CHECK_EQ(2, prologue_call_count_second); | 16555 CHECK_EQ(2, prologue_call_count_second); |
16552 CHECK_EQ(2, epilogue_call_count_second); | 16556 CHECK_EQ(2, epilogue_call_count_second); |
16553 | 16557 |
16554 CHECK_EQ(0, prologue_call_count_alloc); | 16558 CHECK_EQ(0, prologue_call_count_alloc); |
16555 CHECK_EQ(0, epilogue_call_count_alloc); | 16559 CHECK_EQ(0, epilogue_call_count_alloc); |
16556 isolate->AddGCPrologueCallback(PrologueCallbackAlloc); | 16560 isolate->AddGCPrologueCallback(PrologueCallbackAlloc); |
16557 isolate->AddGCEpilogueCallback(EpilogueCallbackAlloc); | 16561 isolate->AddGCEpilogueCallback(EpilogueCallbackAlloc); |
16558 CcTest::heap()->CollectAllGarbage( | 16562 CcTest::heap()->CollectAllGarbage("GCCallbacks", |
16559 i::Heap::kAbortIncrementalMarkingMask); | 16563 i::Heap::kAbortIncrementalMarkingMask); |
16560 CHECK_EQ(1, prologue_call_count_alloc); | 16564 CHECK_EQ(1, prologue_call_count_alloc); |
16561 CHECK_EQ(1, epilogue_call_count_alloc); | 16565 CHECK_EQ(1, epilogue_call_count_alloc); |
16562 isolate->RemoveGCPrologueCallback(PrologueCallbackAlloc); | 16566 isolate->RemoveGCPrologueCallback(PrologueCallbackAlloc); |
16563 isolate->RemoveGCEpilogueCallback(EpilogueCallbackAlloc); | 16567 isolate->RemoveGCEpilogueCallback(EpilogueCallbackAlloc); |
16564 } | 16568 } |
16565 | 16569 |
16566 | 16570 |
16567 THREADED_TEST(TwoByteStringInOneByteCons) { | 16571 THREADED_TEST(TwoByteStringInOneByteCons) { |
16568 // See Chromium issue 47824. | 16572 // See Chromium issue 47824. |
16569 LocalContext context; | 16573 LocalContext context; |
(...skipping 5281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21851 timeout_thread.Join(); | 21855 timeout_thread.Join(); |
21852 } | 21856 } |
21853 | 21857 |
21854 | 21858 |
21855 TEST(EstimatedContextSize) { | 21859 TEST(EstimatedContextSize) { |
21856 v8::Isolate* isolate = CcTest::isolate(); | 21860 v8::Isolate* isolate = CcTest::isolate(); |
21857 v8::HandleScope scope(isolate); | 21861 v8::HandleScope scope(isolate); |
21858 LocalContext env; | 21862 LocalContext env; |
21859 CHECK(50000 < env->EstimatedSize()); | 21863 CHECK(50000 < env->EstimatedSize()); |
21860 } | 21864 } |
OLD | NEW |