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

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

Issue 138203002: Rename a few Member and Persistent methods to make the transition (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 static Baz* create(Bar* bar) 332 static Baz* create(Bar* bar)
333 { 333 {
334 return new Baz(bar); 334 return new Baz(bar);
335 } 335 }
336 336
337 void trace(Visitor* visitor) 337 void trace(Visitor* visitor)
338 { 338 {
339 visitor->trace(m_bar); 339 visitor->trace(m_bar);
340 } 340 }
341 341
342 void clear() { m_bar.clear(); } 342 void clear() { m_bar.release(); }
343 343
344 private: 344 private:
345 explicit Baz(Bar* bar) 345 explicit Baz(Bar* bar)
346 : m_bar(bar) 346 : m_bar(bar)
347 { 347 {
348 } 348 }
349 349
350 Member<Bar> m_bar; 350 Member<Bar> m_bar;
351 }; 351 };
352 352
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 TEST(HeapTest, TypedHeapSanity) 647 TEST(HeapTest, TypedHeapSanity)
648 { 648 {
649 // FIXME: init and shutdown should be called via Blink 649 // FIXME: init and shutdown should be called via Blink
650 // initialization in the test runner. 650 // initialization in the test runner.
651 Heap::init(); 651 Heap::init();
652 652
653 { 653 {
654 // We use TraceCounter for allocating an object on the general heap. 654 // We use TraceCounter for allocating an object on the general heap.
655 Persistent<TraceCounter> generalHeapObject = TraceCounter::create(); 655 Persistent<TraceCounter> generalHeapObject = TraceCounter::create();
656 Persistent<TestTypedHeapClass> typedHeapObject = TestTypedHeapClass::cre ate(); 656 Persistent<TestTypedHeapClass> typedHeapObject = TestTypedHeapClass::cre ate();
657 EXPECT_NE(pageHeaderAddress(reinterpret_cast<Address>(generalHeapObject. raw())), 657 EXPECT_NE(pageHeaderAddress(reinterpret_cast<Address>(generalHeapObject. get())),
658 pageHeaderAddress(reinterpret_cast<Address>(typedHeapObject.raw()))) ; 658 pageHeaderAddress(reinterpret_cast<Address>(typedHeapObject.get()))) ;
659 } 659 }
660 660
661 Heap::shutdown(); 661 Heap::shutdown();
662 } 662 }
663 663
664 TEST(HeapTest, NoAllocation) 664 TEST(HeapTest, NoAllocation)
665 { 665 {
666 // FIXME: init and shutdown should be called via Blink 666 // FIXME: init and shutdown should be called via Blink
667 // initialization in the test runner. 667 // initialization in the test runner.
668 Heap::init(); 668 Heap::init();
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 EXPECT_TRUE(h5->strongIsThere()); 988 EXPECT_TRUE(h5->strongIsThere());
989 EXPECT_TRUE(h5->weakIsThere()); 989 EXPECT_TRUE(h5->weakIsThere());
990 } 990 }
991 // h3 is collected, weak pointers from h4 and h5 don't keep it alive. 991 // h3 is collected, weak pointers from h4 and h5 don't keep it alive.
992 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 992 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
993 EXPECT_EQ(4u, Bar::s_live); 993 EXPECT_EQ(4u, Bar::s_live);
994 EXPECT_TRUE(h4->strongIsThere()); 994 EXPECT_TRUE(h4->strongIsThere());
995 EXPECT_FALSE(h4->weakIsThere()); // h3 is gone from weak pointer. 995 EXPECT_FALSE(h4->weakIsThere()); // h3 is gone from weak pointer.
996 EXPECT_TRUE(h5->strongIsThere()); 996 EXPECT_TRUE(h5->strongIsThere());
997 EXPECT_FALSE(h5->weakIsThere()); // h3 is gone from weak pointer. 997 EXPECT_FALSE(h5->weakIsThere()); // h3 is gone from weak pointer.
998 h1.clear(); // Zero out h1. 998 h1.release(); // Zero out h1.
999 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 999 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
1000 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.
1001 EXPECT_TRUE(h4->strongIsThere()); // h2 is still pointed to from h4. 1001 EXPECT_TRUE(h4->strongIsThere()); // h2 is still pointed to from h4.
1002 EXPECT_TRUE(h5->strongIsThere()); // h2 is still pointed to from h5. 1002 EXPECT_TRUE(h5->strongIsThere()); // h2 is still pointed to from h5.
1003 } 1003 }
1004 // 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.
1005 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); 1005 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack);
1006 EXPECT_EQ(0u, Bar::s_live); // All gone. 1006 EXPECT_EQ(0u, Bar::s_live); // All gone.
1007 1007
1008 Heap::shutdown(); 1008 Heap::shutdown();
1009 } 1009 }
1010 1010
1011 TEST(HeapTest, Comparisons)
1012 {
1013 Heap::init();
haraken 2014/01/14 13:57:10 This will be removed in wibling's CL, which is cur
Mads Ager (chromium) 2014/01/14 14:03:13 Yes. I'll wait for Gustav's changes, rebase and pu
1014
1015 {
1016 Persistent<Bar> barPersistent = Bar::create();
1017 Persistent<Foo> fooPersistent = Foo::create(barPersistent);
1018 EXPECT_TRUE(barPersistent != fooPersistent);
1019 barPersistent = fooPersistent;
1020 EXPECT_TRUE(barPersistent == fooPersistent);
1021 }
1022
1023 Heap::shutdown();
haraken 2014/01/14 13:57:10 Ditto.
1024 }
1025
1011 DEFINE_GC_INFO(Bar); 1026 DEFINE_GC_INFO(Bar);
1012 DEFINE_GC_INFO(Baz); 1027 DEFINE_GC_INFO(Baz);
1013 DEFINE_GC_INFO(ClassWithMember); 1028 DEFINE_GC_INFO(ClassWithMember);
1014 DEFINE_GC_INFO(ConstructorAllocation); 1029 DEFINE_GC_INFO(ConstructorAllocation);
1015 DEFINE_GC_INFO(HeapAllocatedArray); 1030 DEFINE_GC_INFO(HeapAllocatedArray);
1016 DEFINE_GC_INFO(IntWrapper); 1031 DEFINE_GC_INFO(IntWrapper);
1017 DEFINE_GC_INFO(LargeObject); 1032 DEFINE_GC_INFO(LargeObject);
1018 DEFINE_GC_INFO(RefCountedAndGarbageCollected); 1033 DEFINE_GC_INFO(RefCountedAndGarbageCollected);
1019 DEFINE_GC_INFO(SimpleFinalizedObject); 1034 DEFINE_GC_INFO(SimpleFinalizedObject);
1020 DEFINE_GC_INFO(TestTypedHeapClass); 1035 DEFINE_GC_INFO(TestTypedHeapClass);
1021 DEFINE_GC_INFO(TraceCounter); 1036 DEFINE_GC_INFO(TraceCounter);
1022 1037
1023 } // namespace 1038 } // namespace
OLDNEW
« Source/heap/Handle.h ('K') | « Source/heap/Heap.h ('k') | Source/heap/Visitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698