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

Side by Side Diff: Source/heap/HeapTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698