| 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 2157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2168 visitor->trace(dequeUW); | 2168 visitor->trace(dequeUW); |
| 2169 } | 2169 } |
| 2170 }; | 2170 }; |
| 2171 | 2171 |
| 2172 struct ShouldBeTraced { | 2172 struct ShouldBeTraced { |
| 2173 explicit ShouldBeTraced(IntWrapper* wrapper) : m_wrapper(wrapper) { } | 2173 explicit ShouldBeTraced(IntWrapper* wrapper) : m_wrapper(wrapper) { } |
| 2174 DEFINE_INLINE_TRACE() { visitor->trace(m_wrapper); } | 2174 DEFINE_INLINE_TRACE() { visitor->trace(m_wrapper); } |
| 2175 Member<IntWrapper> m_wrapper; | 2175 Member<IntWrapper> m_wrapper; |
| 2176 }; | 2176 }; |
| 2177 | 2177 |
| 2178 class OffHeapContainer : public GarbageCollectedFinalized<OffHeapContainer> { | |
| 2179 public: | |
| 2180 static OffHeapContainer* create() { return new OffHeapContainer(); } | |
| 2181 | |
| 2182 static const int iterations = 300; | |
| 2183 static const int deadWrappers = 600; | |
| 2184 | |
| 2185 OffHeapContainer() | |
| 2186 { | |
| 2187 for (int i = 0; i < iterations; i++) { | |
| 2188 m_deque1.append(ShouldBeTraced(IntWrapper::create(i))); | |
| 2189 m_vector1.append(ShouldBeTraced(IntWrapper::create(i))); | |
| 2190 } | |
| 2191 | |
| 2192 Deque<ShouldBeTraced>::iterator d1Iterator(m_deque1.begin()); | |
| 2193 Vector<ShouldBeTraced>::iterator v1Iterator(m_vector1.begin()); | |
| 2194 | |
| 2195 for (int i = 0; i < iterations; i++) { | |
| 2196 EXPECT_EQ(i, m_vector1[i].m_wrapper->value()); | |
| 2197 EXPECT_EQ(i, d1Iterator->m_wrapper->value()); | |
| 2198 EXPECT_EQ(i, v1Iterator->m_wrapper->value()); | |
| 2199 ++d1Iterator; | |
| 2200 ++v1Iterator; | |
| 2201 } | |
| 2202 EXPECT_EQ(d1Iterator, m_deque1.end()); | |
| 2203 EXPECT_EQ(v1Iterator, m_vector1.end()); | |
| 2204 } | |
| 2205 | |
| 2206 DEFINE_INLINE_TRACE() | |
| 2207 { | |
| 2208 visitor->trace(m_deque1); | |
| 2209 visitor->trace(m_vector1); | |
| 2210 } | |
| 2211 | |
| 2212 Deque<ShouldBeTraced> m_deque1; | |
| 2213 Vector<ShouldBeTraced> m_vector1; | |
| 2214 }; | |
| 2215 | |
| 2216 const int OffHeapContainer::iterations; | |
| 2217 const int OffHeapContainer::deadWrappers; | |
| 2218 | |
| 2219 // These class definitions test compile-time asserts with transition | 2178 // These class definitions test compile-time asserts with transition |
| 2220 // types. They are therefore unused in test code and just need to | 2179 // types. They are therefore unused in test code and just need to |
| 2221 // compile. This is intentional; do not delete the A and B classes below. | 2180 // compile. This is intentional; do not delete the A and B classes below. |
| 2222 class A : public WillBeGarbageCollectedMixin { | 2181 class A : public WillBeGarbageCollectedMixin { |
| 2223 }; | 2182 }; |
| 2224 | 2183 |
| 2225 class B : public NoBaseWillBeGarbageCollected<B>, public A { | 2184 class B : public NoBaseWillBeGarbageCollected<B>, public A { |
| 2226 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(B); | 2185 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(B); |
| 2227 public: | 2186 public: |
| 2228 DEFINE_INLINE_TRACE() { } | 2187 DEFINE_INLINE_TRACE() { } |
| (...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3616 EXPECT_EQ(0ul, visitor.count()); | 3575 EXPECT_EQ(0ul, visitor.count()); |
| 3617 Heap::checkAndMarkPointer(&visitor, largeObjectAddress); | 3576 Heap::checkAndMarkPointer(&visitor, largeObjectAddress); |
| 3618 Heap::checkAndMarkPointer(&visitor, largeObjectEndAddress); | 3577 Heap::checkAndMarkPointer(&visitor, largeObjectEndAddress); |
| 3619 EXPECT_EQ(0ul, visitor.count()); | 3578 EXPECT_EQ(0ul, visitor.count()); |
| 3620 } | 3579 } |
| 3621 // This round of GC is important to make sure that the object start | 3580 // This round of GC is important to make sure that the object start |
| 3622 // bitmap are cleared out and that the free lists are rebuild. | 3581 // bitmap are cleared out and that the free lists are rebuild. |
| 3623 clearOutOldGarbage(); | 3582 clearOutOldGarbage(); |
| 3624 } | 3583 } |
| 3625 | 3584 |
| 3626 TEST(HeapTest, VisitOffHeapCollections) | |
| 3627 { | |
| 3628 clearOutOldGarbage(); | |
| 3629 IntWrapper::s_destructorCalls = 0; | |
| 3630 Persistent<OffHeapContainer> container = OffHeapContainer::create(); | |
| 3631 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | |
| 3632 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | |
| 3633 container = nullptr; | |
| 3634 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack, ThreadState::GCWith
Sweep, Heap::ForcedGC); | |
| 3635 EXPECT_EQ(OffHeapContainer::deadWrappers, IntWrapper::s_destructorCalls); | |
| 3636 } | |
| 3637 | |
| 3638 TEST(HeapTest, PersistentHeapCollectionTypes) | 3585 TEST(HeapTest, PersistentHeapCollectionTypes) |
| 3639 { | 3586 { |
| 3640 IntWrapper::s_destructorCalls = 0; | 3587 IntWrapper::s_destructorCalls = 0; |
| 3641 | 3588 |
| 3642 typedef HeapVector<Member<IntWrapper>> Vec; | 3589 typedef HeapVector<Member<IntWrapper>> Vec; |
| 3643 typedef PersistentHeapVector<Member<IntWrapper>> PVec; | 3590 typedef PersistentHeapVector<Member<IntWrapper>> PVec; |
| 3644 typedef PersistentHeapHashSet<Member<IntWrapper>> PSet; | 3591 typedef PersistentHeapHashSet<Member<IntWrapper>> PSet; |
| 3645 typedef PersistentHeapListHashSet<Member<IntWrapper>> PListSet; | 3592 typedef PersistentHeapListHashSet<Member<IntWrapper>> PListSet; |
| 3646 typedef PersistentHeapLinkedHashSet<Member<IntWrapper>> PLinkedSet; | 3593 typedef PersistentHeapLinkedHashSet<Member<IntWrapper>> PLinkedSet; |
| 3647 typedef PersistentHeapHashMap<Member<IntWrapper>, Member<IntWrapper>> PMap; | 3594 typedef PersistentHeapHashMap<Member<IntWrapper>, Member<IntWrapper>> PMap; |
| (...skipping 2408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6056 { | 6003 { |
| 6057 Persistent<ClassWithMember> object = ClassWithMember::create(); | 6004 Persistent<ClassWithMember> object = ClassWithMember::create(); |
| 6058 EXPECT_EQ(0, object->traceCount()); | 6005 EXPECT_EQ(0, object->traceCount()); |
| 6059 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); | 6006 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); |
| 6060 EXPECT_TRUE(mixin); | 6007 EXPECT_TRUE(mixin); |
| 6061 EXPECT_GT(object->traceCount(), 0); | 6008 EXPECT_GT(object->traceCount(), 0); |
| 6062 EXPECT_GT(mixin->traceCount(), 0); | 6009 EXPECT_GT(mixin->traceCount(), 0); |
| 6063 } | 6010 } |
| 6064 | 6011 |
| 6065 } // namespace blink | 6012 } // namespace blink |
| OLD | NEW |