| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 static Baz* create(Bar* bar) | 331 static Baz* create(Bar* bar) |
| 332 { | 332 { |
| 333 return new Baz(bar); | 333 return new Baz(bar); |
| 334 } | 334 } |
| 335 | 335 |
| 336 void trace(Visitor* visitor) | 336 void trace(Visitor* visitor) |
| 337 { | 337 { |
| 338 visitor->trace(m_bar); | 338 visitor->trace(m_bar); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void clear() { m_bar.clear(); } | 341 void clear() { m_bar.release(); } |
| 342 | 342 |
| 343 private: | 343 private: |
| 344 explicit Baz(Bar* bar) | 344 explicit Baz(Bar* bar) |
| 345 : m_bar(bar) | 345 : m_bar(bar) |
| 346 { | 346 { |
| 347 } | 347 } |
| 348 | 348 |
| 349 Member<Bar> m_bar; | 349 Member<Bar> m_bar; |
| 350 }; | 350 }; |
| 351 | 351 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 TEST(HeapTest, TypedHeapSanity) | 646 TEST(HeapTest, TypedHeapSanity) |
| 647 { | 647 { |
| 648 // FIXME: init and shutdown should be called via Blink | 648 // FIXME: init and shutdown should be called via Blink |
| 649 // initialization in the test runner. | 649 // initialization in the test runner. |
| 650 Heap::init(); | 650 Heap::init(); |
| 651 | 651 |
| 652 { | 652 { |
| 653 // We use TraceCounter for allocating an object on the general heap. | 653 // We use TraceCounter for allocating an object on the general heap. |
| 654 Persistent<TraceCounter> generalHeapObject = TraceCounter::create(); | 654 Persistent<TraceCounter> generalHeapObject = TraceCounter::create(); |
| 655 Persistent<TestTypedHeapClass> typedHeapObject = TestTypedHeapClass::cre
ate(); | 655 Persistent<TestTypedHeapClass> typedHeapObject = TestTypedHeapClass::cre
ate(); |
| 656 EXPECT_NE(pageHeaderAddress(reinterpret_cast<Address>(generalHeapObject.
raw())), | 656 EXPECT_NE(pageHeaderAddress(reinterpret_cast<Address>(generalHeapObject.
get())), |
| 657 pageHeaderAddress(reinterpret_cast<Address>(typedHeapObject.raw())))
; | 657 pageHeaderAddress(reinterpret_cast<Address>(typedHeapObject.get())))
; |
| 658 } | 658 } |
| 659 | 659 |
| 660 Heap::shutdown(); | 660 Heap::shutdown(); |
| 661 } | 661 } |
| 662 | 662 |
| 663 TEST(HeapTest, NoAllocation) | 663 TEST(HeapTest, NoAllocation) |
| 664 { | 664 { |
| 665 // FIXME: init and shutdown should be called via Blink | 665 // FIXME: init and shutdown should be called via Blink |
| 666 // initialization in the test runner. | 666 // initialization in the test runner. |
| 667 Heap::init(); | 667 Heap::init(); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 EXPECT_TRUE(h5->strongIsThere()); | 987 EXPECT_TRUE(h5->strongIsThere()); |
| 988 EXPECT_TRUE(h5->weakIsThere()); | 988 EXPECT_TRUE(h5->weakIsThere()); |
| 989 } | 989 } |
| 990 // h3 is collected, weak pointers from h4 and h5 don't keep it alive. | 990 // h3 is collected, weak pointers from h4 and h5 don't keep it alive. |
| 991 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 991 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 992 EXPECT_EQ(4u, Bar::s_live); | 992 EXPECT_EQ(4u, Bar::s_live); |
| 993 EXPECT_TRUE(h4->strongIsThere()); | 993 EXPECT_TRUE(h4->strongIsThere()); |
| 994 EXPECT_FALSE(h4->weakIsThere()); // h3 is gone from weak pointer. | 994 EXPECT_FALSE(h4->weakIsThere()); // h3 is gone from weak pointer. |
| 995 EXPECT_TRUE(h5->strongIsThere()); | 995 EXPECT_TRUE(h5->strongIsThere()); |
| 996 EXPECT_FALSE(h5->weakIsThere()); // h3 is gone from weak pointer. | 996 EXPECT_FALSE(h5->weakIsThere()); // h3 is gone from weak pointer. |
| 997 h1.clear(); // Zero out h1. | 997 h1.release(); // Zero out h1. |
| 998 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 998 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 999 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. |
| 1000 EXPECT_TRUE(h4->strongIsThere()); // h2 is still pointed to from h4. | 1000 EXPECT_TRUE(h4->strongIsThere()); // h2 is still pointed to from h4. |
| 1001 EXPECT_TRUE(h5->strongIsThere()); // h2 is still pointed to from h5. | 1001 EXPECT_TRUE(h5->strongIsThere()); // h2 is still pointed to from h5. |
| 1002 } | 1002 } |
| 1003 // 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. |
| 1004 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 1004 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 1005 EXPECT_EQ(0u, Bar::s_live); // All gone. | 1005 EXPECT_EQ(0u, Bar::s_live); // All gone. |
| 1006 | 1006 |
| 1007 Heap::shutdown(); | 1007 Heap::shutdown(); |
| 1008 } | 1008 } |
| 1009 | 1009 |
| 1010 TEST(HeapTest, Comparisons) |
| 1011 { |
| 1012 Heap::init(); |
| 1013 |
| 1014 { |
| 1015 Persistent<Bar> barPersistent = Bar::create(); |
| 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(); |
| 1023 } |
| 1024 |
| 1010 DEFINE_GC_INFO(Bar); | 1025 DEFINE_GC_INFO(Bar); |
| 1011 DEFINE_GC_INFO(Baz); | 1026 DEFINE_GC_INFO(Baz); |
| 1012 DEFINE_GC_INFO(ClassWithMember); | 1027 DEFINE_GC_INFO(ClassWithMember); |
| 1013 DEFINE_GC_INFO(ConstructorAllocation); | 1028 DEFINE_GC_INFO(ConstructorAllocation); |
| 1014 DEFINE_GC_INFO(HeapAllocatedArray); | 1029 DEFINE_GC_INFO(HeapAllocatedArray); |
| 1015 DEFINE_GC_INFO(IntWrapper); | 1030 DEFINE_GC_INFO(IntWrapper); |
| 1016 DEFINE_GC_INFO(LargeObject); | 1031 DEFINE_GC_INFO(LargeObject); |
| 1017 DEFINE_GC_INFO(RefCountedAndGarbageCollected); | 1032 DEFINE_GC_INFO(RefCountedAndGarbageCollected); |
| 1018 DEFINE_GC_INFO(SimpleFinalizedObject); | 1033 DEFINE_GC_INFO(SimpleFinalizedObject); |
| 1019 DEFINE_GC_INFO(TestTypedHeapClass); | 1034 DEFINE_GC_INFO(TestTypedHeapClass); |
| 1020 DEFINE_GC_INFO(TraceCounter); | 1035 DEFINE_GC_INFO(TraceCounter); |
| 1021 | 1036 |
| 1022 } // namespace | 1037 } // namespace |
| OLD | NEW |