OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 , m_weakBar(weakBar) | 554 , m_weakBar(weakBar) |
555 { | 555 { |
556 } | 556 } |
557 | 557 |
558 Member<Bar> m_strongBar; | 558 Member<Bar> m_strongBar; |
559 WeakMember<Bar> m_weakBar; | 559 WeakMember<Bar> m_weakBar; |
560 }; | 560 }; |
561 | 561 |
562 TEST(HeapTest, Threading) | 562 TEST(HeapTest, Threading) |
563 { | 563 { |
| 564 Heap::init(); |
564 ThreadedHeapTester::test(); | 565 ThreadedHeapTester::test(); |
| 566 Heap::shutdown(); |
| 567 } |
| 568 |
| 569 TEST(HeapTest, Init) |
| 570 { |
| 571 // FIXME: init and shutdown should be called via Blink |
| 572 // initialization in the test runner. This test can be removed |
| 573 // when that is done. |
| 574 Heap::init(); |
| 575 Heap::shutdown(); |
565 } | 576 } |
566 | 577 |
567 TEST(HeapTest, SimpleAllocation) | 578 TEST(HeapTest, SimpleAllocation) |
568 { | 579 { |
| 580 // FIXME: init and shutdown should be called via Blink |
| 581 // initialization in the test runner. |
| 582 Heap::init(); |
| 583 |
569 // Get initial heap stats. | 584 // Get initial heap stats. |
570 HeapStats initialHeapStats; | 585 HeapStats initialHeapStats; |
571 getHeapStats(&initialHeapStats); | 586 getHeapStats(&initialHeapStats); |
572 EXPECT_EQ(0ul, initialHeapStats.totalObjectSpace()); | 587 EXPECT_EQ(0ul, initialHeapStats.totalObjectSpace()); |
573 | 588 |
574 // Allocate an object in the heap. | 589 // Allocate an object in the heap. |
575 HeapAllocatedArray* array = new HeapAllocatedArray(); | 590 HeapAllocatedArray* array = new HeapAllocatedArray(); |
576 HeapStats statsAfterAllocation; | 591 HeapStats statsAfterAllocation; |
577 getHeapStats(&statsAfterAllocation); | 592 getHeapStats(&statsAfterAllocation); |
578 EXPECT_TRUE(statsAfterAllocation.totalObjectSpace() >= sizeof(HeapAllocatedA
rray)); | 593 EXPECT_TRUE(statsAfterAllocation.totalObjectSpace() >= sizeof(HeapAllocatedA
rray)); |
579 | 594 |
580 // Sanity check of the contents in the heap. | 595 // Sanity check of the contents in the heap. |
581 EXPECT_EQ(0, array->at(0)); | 596 EXPECT_EQ(0, array->at(0)); |
582 EXPECT_EQ(42, array->at(42)); | 597 EXPECT_EQ(42, array->at(42)); |
583 EXPECT_EQ(0, array->at(128)); | 598 EXPECT_EQ(0, array->at(128)); |
584 EXPECT_EQ(999 % 128, array->at(999)); | 599 EXPECT_EQ(999 % 128, array->at(999)); |
| 600 |
| 601 Heap::shutdown(); |
585 } | 602 } |
586 | 603 |
587 TEST(HeapTest, SimplePersistent) | 604 TEST(HeapTest, SimplePersistent) |
588 { | 605 { |
589 Persistent<TraceCounter> traceCounter = TraceCounter::create(); | 606 // FIXME: init and shutdown should be called via Blink |
590 EXPECT_EQ(0, traceCounter->traceCount()); | 607 // initialization in the test runner. |
| 608 Heap::init(); |
591 | 609 |
592 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 610 { |
593 EXPECT_EQ(1, traceCounter->traceCount()); | 611 Persistent<TraceCounter> traceCounter = TraceCounter::create(); |
| 612 EXPECT_EQ(0, traceCounter->traceCount()); |
594 | 613 |
595 Persistent<ClassWithMember> classWithMember = ClassWithMember::create(); | 614 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
596 EXPECT_EQ(0, classWithMember->traceCount()); | 615 EXPECT_EQ(1, traceCounter->traceCount()); |
597 | 616 |
598 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 617 Persistent<ClassWithMember> classWithMember = ClassWithMember::create(); |
599 EXPECT_EQ(1, classWithMember->traceCount()); | 618 EXPECT_EQ(0, classWithMember->traceCount()); |
600 EXPECT_EQ(2, traceCounter->traceCount()); | 619 |
| 620 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 621 EXPECT_EQ(1, classWithMember->traceCount()); |
| 622 EXPECT_EQ(2, traceCounter->traceCount()); |
| 623 } |
| 624 |
| 625 Heap::shutdown(); |
601 } | 626 } |
602 | 627 |
603 TEST(HeapTest, SimpleFinalization) | 628 TEST(HeapTest, SimpleFinalization) |
604 { | 629 { |
| 630 // FIXME: init and shutdown should be called via Blink |
| 631 // initialization in the test runner. |
| 632 Heap::init(); |
| 633 |
605 { | 634 { |
606 Persistent<SimpleFinalizedObject> finalized = SimpleFinalizedObject::cre
ate(); | 635 Persistent<SimpleFinalizedObject> finalized = SimpleFinalizedObject::cre
ate(); |
607 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 636 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
608 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 637 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
609 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); | 638 EXPECT_EQ(0, SimpleFinalizedObject::s_destructorCalls); |
610 } | 639 } |
611 | 640 |
612 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 641 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
613 EXPECT_EQ(1, SimpleFinalizedObject::s_destructorCalls); | 642 EXPECT_EQ(1, SimpleFinalizedObject::s_destructorCalls); |
| 643 |
| 644 Heap::shutdown(); |
614 } | 645 } |
615 | 646 |
616 TEST(HeapTest, TypedHeapSanity) | 647 TEST(HeapTest, TypedHeapSanity) |
617 { | 648 { |
618 // We use TraceCounter for allocating an object on the general heap. | 649 // FIXME: init and shutdown should be called via Blink |
619 Persistent<TraceCounter> generalHeapObject = TraceCounter::create(); | 650 // initialization in the test runner. |
620 Persistent<TestTypedHeapClass> typedHeapObject = TestTypedHeapClass::create(
); | 651 Heap::init(); |
621 EXPECT_NE(pageHeaderAddress(reinterpret_cast<Address>(generalHeapObject.raw(
))), | 652 |
622 pageHeaderAddress(reinterpret_cast<Address>(typedHeapObject.raw()))); | 653 { |
| 654 // We use TraceCounter for allocating an object on the general heap. |
| 655 Persistent<TraceCounter> generalHeapObject = TraceCounter::create(); |
| 656 Persistent<TestTypedHeapClass> typedHeapObject = TestTypedHeapClass::cre
ate(); |
| 657 EXPECT_NE(pageHeaderAddress(reinterpret_cast<Address>(generalHeapObject.
raw())), |
| 658 pageHeaderAddress(reinterpret_cast<Address>(typedHeapObject.raw())))
; |
| 659 } |
| 660 |
| 661 Heap::shutdown(); |
623 } | 662 } |
624 | 663 |
625 TEST(HeapTest, NoAllocation) | 664 TEST(HeapTest, NoAllocation) |
626 { | 665 { |
| 666 // FIXME: init and shutdown should be called via Blink |
| 667 // initialization in the test runner. |
| 668 Heap::init(); |
| 669 |
627 EXPECT_TRUE(ThreadState::current()->isAllocationAllowed()); | 670 EXPECT_TRUE(ThreadState::current()->isAllocationAllowed()); |
628 { | 671 { |
629 // Disallow allocation | 672 // Disallow allocation |
630 NoAllocationScope<AnyThread> noAllocationScope; | 673 NoAllocationScope<AnyThread> noAllocationScope; |
631 EXPECT_FALSE(ThreadState::current()->isAllocationAllowed()); | 674 EXPECT_FALSE(ThreadState::current()->isAllocationAllowed()); |
632 } | 675 } |
633 EXPECT_TRUE(ThreadState::current()->isAllocationAllowed()); | 676 EXPECT_TRUE(ThreadState::current()->isAllocationAllowed()); |
| 677 |
| 678 Heap::shutdown(); |
634 } | 679 } |
635 | 680 |
636 TEST(HeapTest, Members) | 681 TEST(HeapTest, Members) |
637 { | 682 { |
| 683 // FIXME: init and shutdown should be called via Blink |
| 684 // initialization in the test runner. |
| 685 Heap::init(); |
| 686 |
638 Bar::s_live = 0; | 687 Bar::s_live = 0; |
639 { | 688 { |
640 Persistent<Baz> h1; | 689 Persistent<Baz> h1; |
641 Persistent<Baz> h2; | 690 Persistent<Baz> h2; |
642 { | 691 { |
643 h1 = Baz::create(Bar::create()); | 692 h1 = Baz::create(Bar::create()); |
644 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 693 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
645 EXPECT_EQ(1u, Bar::s_live); | 694 EXPECT_EQ(1u, Bar::s_live); |
646 h2 = Baz::create(Bar::create()); | 695 h2 = Baz::create(Bar::create()); |
647 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 696 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
648 EXPECT_EQ(2u, Bar::s_live); | 697 EXPECT_EQ(2u, Bar::s_live); |
649 } | 698 } |
650 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 699 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
651 EXPECT_EQ(2u, Bar::s_live); | 700 EXPECT_EQ(2u, Bar::s_live); |
652 h1->clear(); | 701 h1->clear(); |
653 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 702 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
654 EXPECT_EQ(1u, Bar::s_live); | 703 EXPECT_EQ(1u, Bar::s_live); |
655 } | 704 } |
656 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 705 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
657 EXPECT_EQ(0u, Bar::s_live); | 706 EXPECT_EQ(0u, Bar::s_live); |
| 707 |
| 708 Heap::shutdown(); |
658 } | 709 } |
659 | 710 |
660 TEST(HeapTest, DeepTest) | 711 TEST(HeapTest, DeepTest) |
661 { | 712 { |
| 713 // FIXME: init and shutdown should be called via Blink |
| 714 // initialization in the test runner. |
| 715 Heap::init(); |
| 716 |
662 const unsigned depth = 100000; | 717 const unsigned depth = 100000; |
663 Bar::s_live = 0; | 718 Bar::s_live = 0; |
664 { | 719 { |
665 Bar* bar = Bar::create(); | 720 Bar* bar = Bar::create(); |
666 EXPECT_TRUE(ThreadState::current()->contains(bar)); | 721 EXPECT_TRUE(ThreadState::current()->contains(bar)); |
667 Foo* foo = Foo::create(bar); | 722 Foo* foo = Foo::create(bar); |
668 EXPECT_TRUE(ThreadState::current()->contains(foo)); | 723 EXPECT_TRUE(ThreadState::current()->contains(foo)); |
669 EXPECT_EQ(2u, Bar::s_live); | 724 EXPECT_EQ(2u, Bar::s_live); |
670 for (unsigned i = 0; i < depth; i++) { | 725 for (unsigned i = 0; i < depth; i++) { |
671 Foo* foo2 = Foo::create(foo); | 726 Foo* foo2 = Foo::create(foo); |
672 foo = foo2; | 727 foo = foo2; |
673 EXPECT_TRUE(ThreadState::current()->contains(foo)); | 728 EXPECT_TRUE(ThreadState::current()->contains(foo)); |
674 } | 729 } |
675 EXPECT_EQ(depth + 2, Bar::s_live); | 730 EXPECT_EQ(depth + 2, Bar::s_live); |
676 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | 731 Heap::collectGarbage(ThreadState::HeapPointersOnStack); |
677 EXPECT_EQ(depth + 2, Bar::s_live); | 732 EXPECT_EQ(depth + 2, Bar::s_live); |
678 } | 733 } |
679 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 734 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
680 EXPECT_EQ(0u, Bar::s_live); | 735 EXPECT_EQ(0u, Bar::s_live); |
| 736 |
| 737 Heap::shutdown(); |
681 } | 738 } |
682 | 739 |
683 TEST(HeapTest, WideTest) | 740 TEST(HeapTest, WideTest) |
684 { | 741 { |
| 742 // FIXME: init and shutdown should be called via Blink |
| 743 // initialization in the test runner. |
| 744 Heap::init(); |
| 745 |
685 Bar::s_live = 0; | 746 Bar::s_live = 0; |
686 { | 747 { |
687 Bars* bars = Bars::create(); | 748 Bars* bars = Bars::create(); |
688 unsigned width = Bars::width; | 749 unsigned width = Bars::width; |
689 EXPECT_EQ(width + 1, Bar::s_live); | 750 EXPECT_EQ(width + 1, Bar::s_live); |
690 Heap::collectGarbage(ThreadState::HeapPointersOnStack); | 751 Heap::collectGarbage(ThreadState::HeapPointersOnStack); |
691 EXPECT_EQ(width + 1, Bar::s_live); | 752 EXPECT_EQ(width + 1, Bar::s_live); |
692 // Use bars here to make sure that it will be on the stack | 753 // Use bars here to make sure that it will be on the stack |
693 // for the conservative stack scan to find. | 754 // for the conservative stack scan to find. |
694 EXPECT_EQ(width, bars->getWidth()); | 755 EXPECT_EQ(width, bars->getWidth()); |
695 } | 756 } |
696 EXPECT_EQ(Bars::width + 1, Bar::s_live); | 757 EXPECT_EQ(Bars::width + 1, Bar::s_live); |
697 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 758 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
698 EXPECT_EQ(0u, Bar::s_live); | 759 EXPECT_EQ(0u, Bar::s_live); |
| 760 |
| 761 Heap::shutdown(); |
699 } | 762 } |
700 | 763 |
701 TEST(HeapTest, HashMapOfMembers) | 764 TEST(HeapTest, HashMapOfMembers) |
702 { | 765 { |
| 766 // FIXME: init and shutdown should be called via Blink |
| 767 // initialization in the test runner. |
| 768 Heap::init(); |
| 769 |
703 HeapStats initialHeapSize; | 770 HeapStats initialHeapSize; |
704 IntWrapper::s_destructorCalls = 0; | 771 IntWrapper::s_destructorCalls = 0; |
705 | 772 |
706 clearOutOldGarbage(&initialHeapSize); | 773 clearOutOldGarbage(&initialHeapSize); |
707 { | 774 { |
708 typedef HashMap< | 775 typedef HashMap< |
709 Member<IntWrapper>, | 776 Member<IntWrapper>, |
710 Member<IntWrapper>, | 777 Member<IntWrapper>, |
711 DefaultHash<Member<IntWrapper> >::Hash, | 778 DefaultHash<Member<IntWrapper> >::Hash, |
712 HashTraits<Member<IntWrapper> >, | 779 HashTraits<Member<IntWrapper> >, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 getHeapStats(&afterGC3); | 842 getHeapStats(&afterGC3); |
776 EXPECT_TRUE(afterGC3.totalObjectSpace() < afterAdding1000.totalObjectSpa
ce()); | 843 EXPECT_TRUE(afterGC3.totalObjectSpace() < afterAdding1000.totalObjectSpa
ce()); |
777 } | 844 } |
778 | 845 |
779 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 846 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
780 // The objects 'one', anotherOne, and the 999 other pairs. | 847 // The objects 'one', anotherOne, and the 999 other pairs. |
781 EXPECT_EQ(IntWrapper::s_destructorCalls, 2000); | 848 EXPECT_EQ(IntWrapper::s_destructorCalls, 2000); |
782 HeapStats afterGC4; | 849 HeapStats afterGC4; |
783 getHeapStats(&afterGC4); | 850 getHeapStats(&afterGC4); |
784 EXPECT_EQ(afterGC4.totalObjectSpace(), initialHeapSize.totalObjectSpace()); | 851 EXPECT_EQ(afterGC4.totalObjectSpace(), initialHeapSize.totalObjectSpace()); |
| 852 |
| 853 Heap::shutdown(); |
785 } | 854 } |
786 | 855 |
787 TEST(HeapTest, NestedAllocation) | 856 TEST(HeapTest, NestedAllocation) |
788 { | 857 { |
| 858 // FIXME: init and shutdown should be called via Blink |
| 859 // initialization in the test runner. |
| 860 Heap::init(); |
| 861 |
789 HeapStats initialHeapSize; | 862 HeapStats initialHeapSize; |
790 clearOutOldGarbage(&initialHeapSize); | 863 clearOutOldGarbage(&initialHeapSize); |
791 { | 864 { |
792 Persistent<ConstructorAllocation> constructorAllocation = ConstructorAll
ocation::create(); | 865 Persistent<ConstructorAllocation> constructorAllocation = ConstructorAll
ocation::create(); |
793 } | 866 } |
794 HeapStats afterFree; | 867 HeapStats afterFree; |
795 clearOutOldGarbage(&afterFree); | 868 clearOutOldGarbage(&afterFree); |
796 EXPECT_TRUE(initialHeapSize == afterFree); | 869 EXPECT_TRUE(initialHeapSize == afterFree); |
| 870 |
| 871 Heap::shutdown(); |
797 } | 872 } |
798 | 873 |
799 TEST(HeapTest, LargeObjects) | 874 TEST(HeapTest, LargeObjects) |
800 { | 875 { |
| 876 // FIXME: init and shutdown should be called via Blink |
| 877 // initialization in the test runner. |
| 878 Heap::init(); |
| 879 |
801 HeapStats initialHeapSize; | 880 HeapStats initialHeapSize; |
802 clearOutOldGarbage(&initialHeapSize); | 881 clearOutOldGarbage(&initialHeapSize); |
803 IntWrapper::s_destructorCalls = 0; | 882 IntWrapper::s_destructorCalls = 0; |
804 LargeObject::s_destructorCalls = 0; | 883 LargeObject::s_destructorCalls = 0; |
805 { | 884 { |
806 int slack = 8; // LargeObject points to an IntWrapper that is also alloc
ated. | 885 int slack = 8; // LargeObject points to an IntWrapper that is also alloc
ated. |
807 Persistent<LargeObject> object = LargeObject::create(); | 886 Persistent<LargeObject> object = LargeObject::create(); |
808 HeapStats afterAllocation; | 887 HeapStats afterAllocation; |
809 clearOutOldGarbage(&afterAllocation); | 888 clearOutOldGarbage(&afterAllocation); |
810 { | 889 { |
(...skipping 25 matching lines...) Expand all Loading... |
836 EXPECT_TRUE(oneLargeObject == afterAllocation); | 915 EXPECT_TRUE(oneLargeObject == afterAllocation); |
837 EXPECT_EQ(10, IntWrapper::s_destructorCalls); | 916 EXPECT_EQ(10, IntWrapper::s_destructorCalls); |
838 EXPECT_EQ(10, LargeObject::s_destructorCalls); | 917 EXPECT_EQ(10, LargeObject::s_destructorCalls); |
839 } | 918 } |
840 HeapStats backToInitial; | 919 HeapStats backToInitial; |
841 clearOutOldGarbage(&backToInitial); | 920 clearOutOldGarbage(&backToInitial); |
842 EXPECT_TRUE(initialHeapSize == backToInitial); | 921 EXPECT_TRUE(initialHeapSize == backToInitial); |
843 EXPECT_EQ(11, IntWrapper::s_destructorCalls); | 922 EXPECT_EQ(11, IntWrapper::s_destructorCalls); |
844 EXPECT_EQ(11, LargeObject::s_destructorCalls); | 923 EXPECT_EQ(11, LargeObject::s_destructorCalls); |
845 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 924 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 925 |
| 926 Heap::shutdown(); |
846 } | 927 } |
847 | 928 |
848 TEST(HeapTest, RefCountedGarbageCollected) | 929 TEST(HeapTest, RefCountedGarbageCollected) |
849 { | 930 { |
| 931 // FIXME: init and shutdown should be called via Blink |
| 932 // initialization in the test runner. |
| 933 Heap::init(); |
| 934 |
850 RefCountedAndGarbageCollected::s_destructorCalls = 0; | 935 RefCountedAndGarbageCollected::s_destructorCalls = 0; |
851 { | 936 { |
852 RefPtr<RefCountedAndGarbageCollected> refPtr3; | 937 RefPtr<RefCountedAndGarbageCollected> refPtr3; |
853 { | 938 { |
854 Persistent<RefCountedAndGarbageCollected> persistent; | 939 Persistent<RefCountedAndGarbageCollected> persistent; |
855 { | 940 { |
856 RefPtr<RefCountedAndGarbageCollected> refPtr1 = RefCountedAndGar
bageCollected::create(); | 941 RefPtr<RefCountedAndGarbageCollected> refPtr1 = RefCountedAndGar
bageCollected::create(); |
857 RefPtr<RefCountedAndGarbageCollected> refPtr2 = RefCountedAndGar
bageCollected::create(); | 942 RefPtr<RefCountedAndGarbageCollected> refPtr2 = RefCountedAndGar
bageCollected::create(); |
858 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 943 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
859 EXPECT_EQ(0, RefCountedAndGarbageCollected::s_destructorCalls); | 944 EXPECT_EQ(0, RefCountedAndGarbageCollected::s_destructorCalls); |
860 persistent = refPtr1.get(); | 945 persistent = refPtr1.get(); |
861 } | 946 } |
862 // Reference count is zero for both objects but one of | 947 // Reference count is zero for both objects but one of |
863 // them is kept alive by a persistent handle. | 948 // them is kept alive by a persistent handle. |
864 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 949 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
865 EXPECT_EQ(1, RefCountedAndGarbageCollected::s_destructorCalls); | 950 EXPECT_EQ(1, RefCountedAndGarbageCollected::s_destructorCalls); |
866 refPtr3 = persistent; | 951 refPtr3 = persistent; |
867 } | 952 } |
868 // The persistent handle is gone but the ref count has been | 953 // The persistent handle is gone but the ref count has been |
869 // increased to 1. | 954 // increased to 1. |
870 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 955 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
871 EXPECT_EQ(1, RefCountedAndGarbageCollected::s_destructorCalls); | 956 EXPECT_EQ(1, RefCountedAndGarbageCollected::s_destructorCalls); |
872 } | 957 } |
873 // Both persistent handle is gone and ref count is zero so the | 958 // Both persistent handle is gone and ref count is zero so the |
874 // object can be collected. | 959 // object can be collected. |
875 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 960 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
876 EXPECT_EQ(2, RefCountedAndGarbageCollected::s_destructorCalls); | 961 EXPECT_EQ(2, RefCountedAndGarbageCollected::s_destructorCalls); |
| 962 |
| 963 Heap::shutdown(); |
877 } | 964 } |
878 | 965 |
879 TEST(HeapTest, WeakMembers) | 966 TEST(HeapTest, WeakMembers) |
880 { | 967 { |
| 968 // FIXME: init and shutdown should be called via Blink |
| 969 // initialization in the test runner. |
| 970 Heap::init(); |
| 971 |
881 Bar::s_live = 0; | 972 Bar::s_live = 0; |
882 { | 973 { |
883 Persistent<Bar> h1 = Bar::create(); | 974 Persistent<Bar> h1 = Bar::create(); |
884 Persistent<Weak> h4; | 975 Persistent<Weak> h4; |
885 Persistent<WithWeakMember> h5; | 976 Persistent<WithWeakMember> h5; |
886 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 977 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
887 ASSERT_EQ(1u, Bar::s_live); // h1 is live. | 978 ASSERT_EQ(1u, Bar::s_live); // h1 is live. |
888 { | 979 { |
889 Bar* h2 = Bar::create(); | 980 Bar* h2 = Bar::create(); |
890 Bar* h3 = Bar::create(); | 981 Bar* h3 = Bar::create(); |
(...skipping 15 matching lines...) Expand all Loading... |
906 EXPECT_FALSE(h5->weakIsThere()); // h3 is gone from weak pointer. | 997 EXPECT_FALSE(h5->weakIsThere()); // h3 is gone from weak pointer. |
907 h1.clear(); // Zero out h1. | 998 h1.clear(); // Zero out h1. |
908 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 999 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
909 EXPECT_EQ(3u, Bar::s_live); // Only h4, h5 and h2 are left. | 1000 EXPECT_EQ(3u, Bar::s_live); // Only h4, h5 and h2 are left. |
910 EXPECT_TRUE(h4->strongIsThere()); // h2 is still pointed to from h4. | 1001 EXPECT_TRUE(h4->strongIsThere()); // h2 is still pointed to from h4. |
911 EXPECT_TRUE(h5->strongIsThere()); // h2 is still pointed to from h5. | 1002 EXPECT_TRUE(h5->strongIsThere()); // h2 is still pointed to from h5. |
912 } | 1003 } |
913 // h4 and h5 have gone out of scope now and they were keeping h2 alive. | 1004 // h4 and h5 have gone out of scope now and they were keeping h2 alive. |
914 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1005 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
915 EXPECT_EQ(0u, Bar::s_live); // All gone. | 1006 EXPECT_EQ(0u, Bar::s_live); // All gone. |
| 1007 |
| 1008 Heap::shutdown(); |
916 } | 1009 } |
917 | 1010 |
918 DEFINE_GC_INFO(Bar); | 1011 DEFINE_GC_INFO(Bar); |
919 DEFINE_GC_INFO(Baz); | 1012 DEFINE_GC_INFO(Baz); |
920 DEFINE_GC_INFO(ClassWithMember); | 1013 DEFINE_GC_INFO(ClassWithMember); |
921 DEFINE_GC_INFO(ConstructorAllocation); | 1014 DEFINE_GC_INFO(ConstructorAllocation); |
922 DEFINE_GC_INFO(HeapAllocatedArray); | 1015 DEFINE_GC_INFO(HeapAllocatedArray); |
923 DEFINE_GC_INFO(IntWrapper); | 1016 DEFINE_GC_INFO(IntWrapper); |
924 DEFINE_GC_INFO(LargeObject); | 1017 DEFINE_GC_INFO(LargeObject); |
925 DEFINE_GC_INFO(RefCountedAndGarbageCollected); | 1018 DEFINE_GC_INFO(RefCountedAndGarbageCollected); |
926 DEFINE_GC_INFO(SimpleFinalizedObject); | 1019 DEFINE_GC_INFO(SimpleFinalizedObject); |
927 DEFINE_GC_INFO(TestTypedHeapClass); | 1020 DEFINE_GC_INFO(TestTypedHeapClass); |
928 DEFINE_GC_INFO(TraceCounter); | 1021 DEFINE_GC_INFO(TraceCounter); |
929 | 1022 |
930 } // namespace | 1023 } // namespace |
OLD | NEW |