| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 bool operator==(const IntWrapper& other) const { return other.value() == val
ue(); } | 77 bool operator==(const IntWrapper& other) const { return other.value() == val
ue(); } |
| 78 | 78 |
| 79 unsigned hash() { return IntHash<int>::hash(m_x); } | 79 unsigned hash() { return IntHash<int>::hash(m_x); } |
| 80 | 80 |
| 81 IntWrapper(int x) : m_x(x) { } | 81 IntWrapper(int x) : m_x(x) { } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 IntWrapper(); | 84 IntWrapper(); |
| 85 int m_x; | 85 int m_x; |
| 86 }; | 86 }; |
| 87 static_assert(WTF::NeedsTracing<IntWrapper>::value, "NeedsTracing macro failed t
o recognize trace method."); | 87 static_assert(WTF::IsTraceable<IntWrapper>::value, "IsTraceable<> template faile
d to recognize trace method."); |
| 88 | 88 |
| 89 struct SameSizeAsPersistent { | 89 struct SameSizeAsPersistent { |
| 90 void* m_pointer[4]; | 90 void* m_pointer[4]; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 static_assert(sizeof(Persistent<IntWrapper>) <= sizeof(SameSizeAsPersistent), "P
ersistent handle should stay small"); | 93 static_assert(sizeof(Persistent<IntWrapper>) <= sizeof(SameSizeAsPersistent), "P
ersistent handle should stay small"); |
| 94 | 94 |
| 95 class ThreadMarker { | 95 class ThreadMarker { |
| 96 public: | 96 public: |
| 97 ThreadMarker() : m_creatingThread(reinterpret_cast<ThreadState*>(0)), m_num(
0) { } | 97 ThreadMarker() : m_creatingThread(reinterpret_cast<ThreadState*>(0)), m_num(
0) { } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 template<typename T> struct WeakHandlingHashTraits : WTF::SimpleClassHashTraits<
T> { | 171 template<typename T> struct WeakHandlingHashTraits : WTF::SimpleClassHashTraits<
T> { |
| 172 // We want to treat the object as a weak object in the sense that it can | 172 // We want to treat the object as a weak object in the sense that it can |
| 173 // disappear from hash sets and hash maps. | 173 // disappear from hash sets and hash maps. |
| 174 static const WTF::WeakHandlingFlag weakHandlingFlag = WTF::WeakHandlingInCol
lections; | 174 static const WTF::WeakHandlingFlag weakHandlingFlag = WTF::WeakHandlingInCol
lections; |
| 175 // Normally whether or not an object needs tracing is inferred | 175 // Normally whether or not an object needs tracing is inferred |
| 176 // automatically from the presence of the trace method, but we don't | 176 // automatically from the presence of the trace method, but we don't |
| 177 // necessarily have a trace method, and we may not need one because T | 177 // necessarily have a trace method, and we may not need one because T |
| 178 // can perhaps only be allocated inside collections, never as independent | 178 // can perhaps only be allocated inside collections, never as independent |
| 179 // objects. Explicitly mark this as needing tracing and it will be traced | 179 // objects. Explicitly mark this as needing tracing and it will be traced |
| 180 // in collections using the traceInCollection method, which it must have. | 180 // in collections using the traceInCollection method, which it must have. |
| 181 template<typename U = void> struct NeedsTracingLazily { | 181 template<typename U = void> struct IsTraceableInCollection { |
| 182 static const bool value = true; | 182 static const bool value = true; |
| 183 }; | 183 }; |
| 184 // The traceInCollection method traces differently depending on whether we | 184 // The traceInCollection method traces differently depending on whether we |
| 185 // are strongifying the trace operation. We strongify the trace operation | 185 // are strongifying the trace operation. We strongify the trace operation |
| 186 // when there are active iterators on the object. In this case all | 186 // when there are active iterators on the object. In this case all |
| 187 // WeakMembers are marked like strong members so that elements do not | 187 // WeakMembers are marked like strong members so that elements do not |
| 188 // suddenly disappear during iteration. Returns true if weak pointers to | 188 // suddenly disappear during iteration. Returns true if weak pointers to |
| 189 // dead objects were found: In this case any strong pointers were not yet | 189 // dead objects were found: In this case any strong pointers were not yet |
| 190 // traced and the entry should be removed from the collection. | 190 // traced and the entry should be removed from the collection. |
| 191 template<typename VisitorDispatcher> | 191 template<typename VisitorDispatcher> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 // memset to zero, and we use -1 in the first part of the pair to represent | 227 // memset to zero, and we use -1 in the first part of the pair to represent |
| 228 // deleted slots. | 228 // deleted slots. |
| 229 template<> struct HashTraits<blink::PairWithWeakHandling> : blink::WeakHandlingH
ashTraits<blink::PairWithWeakHandling> { | 229 template<> struct HashTraits<blink::PairWithWeakHandling> : blink::WeakHandlingH
ashTraits<blink::PairWithWeakHandling> { |
| 230 static const bool hasIsEmptyValueFunction = true; | 230 static const bool hasIsEmptyValueFunction = true; |
| 231 static bool isEmptyValue(const blink::PairWithWeakHandling& value) { return
!value.first; } | 231 static bool isEmptyValue(const blink::PairWithWeakHandling& value) { return
!value.first; } |
| 232 static void constructDeletedValue(blink::PairWithWeakHandling& slot, bool) {
new (NotNull, &slot) blink::PairWithWeakHandling(HashTableDeletedValue); } | 232 static void constructDeletedValue(blink::PairWithWeakHandling& slot, bool) {
new (NotNull, &slot) blink::PairWithWeakHandling(HashTableDeletedValue); } |
| 233 static bool isDeletedValue(const blink::PairWithWeakHandling& value) { retur
n value.isHashTableDeletedValue(); } | 233 static bool isDeletedValue(const blink::PairWithWeakHandling& value) { retur
n value.isHashTableDeletedValue(); } |
| 234 }; | 234 }; |
| 235 | 235 |
| 236 template<> | 236 template<> |
| 237 struct NeedsTracing<blink::PairWithWeakHandling> { | 237 struct IsTraceable<blink::PairWithWeakHandling> { |
| 238 static const bool value = NeedsTracing<blink::StrongWeakPair>::value; | 238 static const bool value = IsTraceable<blink::StrongWeakPair>::value; |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 } // namespace WTF | 241 } // namespace WTF |
| 242 | 242 |
| 243 namespace blink { | 243 namespace blink { |
| 244 | 244 |
| 245 class TestGCScope { | 245 class TestGCScope { |
| 246 public: | 246 public: |
| 247 explicit TestGCScope(BlinkGC::StackState state) | 247 explicit TestGCScope(BlinkGC::StackState state) |
| 248 : m_state(ThreadState::current()) | 248 : m_state(ThreadState::current()) |
| (...skipping 3960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4209 | 4209 |
| 4210 TEST(HeapTest, CollectionNesting) | 4210 TEST(HeapTest, CollectionNesting) |
| 4211 { | 4211 { |
| 4212 clearOutOldGarbage(); | 4212 clearOutOldGarbage(); |
| 4213 int* key = &IntWrapper::s_destructorCalls; | 4213 int* key = &IntWrapper::s_destructorCalls; |
| 4214 IntWrapper::s_destructorCalls = 0; | 4214 IntWrapper::s_destructorCalls = 0; |
| 4215 typedef HeapVector<Member<IntWrapper>> IntVector; | 4215 typedef HeapVector<Member<IntWrapper>> IntVector; |
| 4216 typedef HeapDeque<Member<IntWrapper>> IntDeque; | 4216 typedef HeapDeque<Member<IntWrapper>> IntDeque; |
| 4217 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>(); | 4217 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>(); |
| 4218 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>(); | 4218 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>(); |
| 4219 static_assert(WTF::NeedsTracing<IntVector>::value, "Failed to recognize Heap
Vector as NeedsTracing"); | 4219 static_assert(WTF::IsTraceable<IntVector>::value, "Failed to recognize HeapV
ector as traceable"); |
| 4220 static_assert(WTF::NeedsTracing<IntDeque>::value, "Failed to recognize HeapD
eque as NeedsTracing"); | 4220 static_assert(WTF::IsTraceable<IntDeque>::value, "Failed to recognize HeapDe
que as traceable"); |
| 4221 | 4221 |
| 4222 map->add(key, IntVector()); | 4222 map->add(key, IntVector()); |
| 4223 map2->add(key, IntDeque()); | 4223 map2->add(key, IntDeque()); |
| 4224 | 4224 |
| 4225 HeapHashMap<void*, IntVector>::iterator it = map->find(key); | 4225 HeapHashMap<void*, IntVector>::iterator it = map->find(key); |
| 4226 EXPECT_EQ(0u, map->get(key).size()); | 4226 EXPECT_EQ(0u, map->get(key).size()); |
| 4227 | 4227 |
| 4228 HeapHashMap<void*, IntDeque>::iterator it2 = map2->find(key); | 4228 HeapHashMap<void*, IntDeque>::iterator it2 = map2->find(key); |
| 4229 EXPECT_EQ(0u, map2->get(key).size()); | 4229 EXPECT_EQ(0u, map2->get(key).size()); |
| 4230 | 4230 |
| (...skipping 2691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6922 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe
r>>>::value, "HeapLinkedHashSet"); | 6922 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe
r>>>::value, "HeapLinkedHashSet"); |
| 6923 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper>
>>::value, "HeapListHashSet"); | 6923 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper>
>>::value, "HeapListHashSet"); |
| 6924 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp
er>>>::value, "HeapHashCountedSet"); | 6924 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp
er>>>::value, "HeapHashCountedSet"); |
| 6925 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper
>>>::value, "HeapHashMap"); | 6925 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper
>>>::value, "HeapHashMap"); |
| 6926 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v
alue, "HeapVector"); | 6926 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v
alue, "HeapVector"); |
| 6927 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va
lue, "HeapDeque"); | 6927 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va
lue, "HeapDeque"); |
| 6928 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap
per>>>::value, "HeapTerminatedArray"); | 6928 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap
per>>>::value, "HeapTerminatedArray"); |
| 6929 } | 6929 } |
| 6930 | 6930 |
| 6931 } // namespace blink | 6931 } // namespace blink |
| OLD | NEW |