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