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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 | 168 |
169 private: | 169 private: |
170 size_t m_count; | 170 size_t m_count; |
171 }; | 171 }; |
172 | 172 |
173 class SimpleObject : public GarbageCollected<SimpleObject> { | 173 class SimpleObject : public GarbageCollected<SimpleObject> { |
174 public: | 174 public: |
175 static SimpleObject* create() { return new SimpleObject(); } | 175 static SimpleObject* create() { return new SimpleObject(); } |
176 void trace(Visitor*) { } | 176 void trace(Visitor*) { } |
177 char getPayload(int i) { return payload[i]; } | 177 char getPayload(int i) { return payload[i]; } |
178 virtual void virtualMethod() { } | |
Mads Ager (chromium)
2014/04/02 18:13:56
I'll add a comment that this make sure that the ob
| |
178 protected: | 179 protected: |
179 SimpleObject() { } | 180 SimpleObject() { } |
180 char payload[64]; | 181 char payload[64]; |
181 }; | 182 }; |
182 | 183 |
183 #undef DEFINE_VISITOR_METHODS | 184 #undef DEFINE_VISITOR_METHODS |
184 | 185 |
185 class HeapTestSuperClass : public GarbageCollectedFinalized<HeapTestSuperClass> { | 186 class HeapTestSuperClass : public GarbageCollectedFinalized<HeapTestSuperClass> { |
186 public: | 187 public: |
187 static HeapTestSuperClass* create() | 188 static HeapTestSuperClass* create() |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1130 ++s_aliveCount; | 1131 ++s_aliveCount; |
1131 } | 1132 } |
1132 }; | 1133 }; |
1133 | 1134 |
1134 int TransitionRefCounted::s_aliveCount = 0; | 1135 int TransitionRefCounted::s_aliveCount = 0; |
1135 | 1136 |
1136 class Mixin : public GarbageCollectedMixin { | 1137 class Mixin : public GarbageCollectedMixin { |
1137 public: | 1138 public: |
1138 virtual void trace(Visitor* visitor) { } | 1139 virtual void trace(Visitor* visitor) { } |
1139 | 1140 |
1140 char getPayload(int i) { return m_padding[i]; } | 1141 virtual char getPayload(int i) { return m_padding[i]; } |
1141 | 1142 |
1142 protected: | 1143 protected: |
1143 // This is to force ptr diff for SimpleObject, Mixin, and UseMixin. | |
1144 int m_padding[8]; | 1144 int m_padding[8]; |
1145 }; | 1145 }; |
1146 | 1146 |
1147 class UseMixin : public SimpleObject, public Mixin { | 1147 class UseMixin : public SimpleObject, public Mixin { |
1148 USING_GARBAGE_COLLECTED_MIXIN(UseMixin) | 1148 USING_GARBAGE_COLLECTED_MIXIN(UseMixin) |
1149 public: | 1149 public: |
1150 static UseMixin* create() | 1150 static UseMixin* create() |
1151 { | 1151 { |
1152 return new UseMixin(); | 1152 return new UseMixin(); |
1153 } | 1153 } |
(...skipping 1822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2976 Persistent<HeapHashMap<void*, IntVector> > keepAlive(map); | 2976 Persistent<HeapHashMap<void*, IntVector> > keepAlive(map); |
2977 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 2977 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
2978 EXPECT_EQ(1u, map->get(key).size()); | 2978 EXPECT_EQ(1u, map->get(key).size()); |
2979 EXPECT_EQ(0, IntWrapper::s_destructorCalls); | 2979 EXPECT_EQ(0, IntWrapper::s_destructorCalls); |
2980 | 2980 |
2981 keepAlive = nullptr; | 2981 keepAlive = nullptr; |
2982 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 2982 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
2983 EXPECT_EQ(1, IntWrapper::s_destructorCalls); | 2983 EXPECT_EQ(1, IntWrapper::s_destructorCalls); |
2984 } | 2984 } |
2985 | 2985 |
2986 TEST(heap, GarbageCollectedMixin) | 2986 TEST(HeapTest, GarbageCollectedMixin) |
2987 { | 2987 { |
2988 HeapStats initialHeapStats; | 2988 HeapStats initialHeapStats; |
2989 clearOutOldGarbage(&initialHeapStats); | 2989 clearOutOldGarbage(&initialHeapStats); |
2990 | 2990 |
2991 Persistent<UseMixin> usemixin = UseMixin::create(); | 2991 Persistent<UseMixin> usemixin = UseMixin::create(); |
2992 ASSERT_EQ(0, UseMixin::s_traceCount); | 2992 EXPECT_EQ(0, UseMixin::s_traceCount); |
2993 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 2993 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
2994 ASSERT_EQ(1, UseMixin::s_traceCount); | 2994 EXPECT_EQ(1, UseMixin::s_traceCount); |
2995 | 2995 |
2996 Persistent<Mixin> mixin = usemixin; | 2996 Persistent<Mixin> mixin = usemixin; |
2997 usemixin = nullptr; | 2997 usemixin = nullptr; |
2998 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 2998 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
2999 ASSERT_EQ(2, UseMixin::s_traceCount); | 2999 EXPECT_EQ(2, UseMixin::s_traceCount); |
3000 | |
3001 PersistentHeapHashSet<WeakMember<Mixin> > weakMap; | |
3002 weakMap.add(UseMixin::create()); | |
3003 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | |
3004 EXPECT_EQ(0u, weakMap.size()); | |
3000 } | 3005 } |
3001 | 3006 |
3002 TEST(HeapTest, CollectionNesting2) | 3007 TEST(HeapTest, CollectionNesting2) |
3003 { | 3008 { |
3004 HeapStats initialStats; | 3009 HeapStats initialStats; |
3005 clearOutOldGarbage(&initialStats); | 3010 clearOutOldGarbage(&initialStats); |
3006 void* key = &IntWrapper::s_destructorCalls; | 3011 void* key = &IntWrapper::s_destructorCalls; |
3007 IntWrapper::s_destructorCalls = 0; | 3012 IntWrapper::s_destructorCalls = 0; |
3008 typedef HeapHashSet<Member<IntWrapper> > IntSet; | 3013 typedef HeapHashSet<Member<IntWrapper> > IntSet; |
3009 HeapHashMap<void*, IntSet>* map = new HeapHashMap<void*, IntSet>(); | 3014 HeapHashMap<void*, IntSet>* map = new HeapHashMap<void*, IntSet>(); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3216 { | 3221 { |
3217 HeapHashMap<SimpleClassWithDestructor*, OwnPtr<SimpleClassWithDestructor> > map; | 3222 HeapHashMap<SimpleClassWithDestructor*, OwnPtr<SimpleClassWithDestructor> > map; |
3218 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor(); | 3223 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor(); |
3219 map.add(hasDestructor, adoptPtr(hasDestructor)); | 3224 map.add(hasDestructor, adoptPtr(hasDestructor)); |
3220 SimpleClassWithDestructor::s_wasDestructed = false; | 3225 SimpleClassWithDestructor::s_wasDestructed = false; |
3221 map.clear(); | 3226 map.clear(); |
3222 ASSERT(SimpleClassWithDestructor::s_wasDestructed); | 3227 ASSERT(SimpleClassWithDestructor::s_wasDestructed); |
3223 } | 3228 } |
3224 | 3229 |
3225 } // WebCore namespace | 3230 } // WebCore namespace |
OLD | NEW |