Chromium Code Reviews| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 EXPECT_TRUE(scope.allThreadsParked()); | 226 EXPECT_TRUE(scope.allThreadsParked()); |
| 227 return Heap::objectPayloadSizeForTesting(); | 227 return Heap::objectPayloadSizeForTesting(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 #define DEFINE_VISITOR_METHODS(Type) \ | 230 #define DEFINE_VISITOR_METHODS(Type) \ |
| 231 virtual void mark(const Type* object, TraceCallback callback) override \ | 231 virtual void mark(const Type* object, TraceCallback callback) override \ |
| 232 { \ | 232 { \ |
| 233 if (object) \ | 233 if (object) \ |
| 234 m_count++; \ | 234 m_count++; \ |
| 235 } \ | 235 } \ |
| 236 virtual bool isMarked(const Type*) override { return false; } | 236 virtual bool isMarked(const Type*) override { return false; } \ |
| 237 virtual bool ensureMarked(const Type* objectPointer) override \ | |
| 238 { \ | |
| 239 if (!objectPointer || isMarked(objectPointer)) \ | |
| 240 return true; \ | |
|
haraken
2014/12/02 06:16:04
Shouldn't this be false?
sof
2014/12/02 09:52:15
Good catch; hadn't been updated after ensureMarked
| |
| 241 markNoTracing(objectPointer); \ | |
| 242 return false; \ | |
|
haraken
2014/12/02 06:16:04
Shouldn't this be true?
| |
| 243 } | |
| 237 | 244 |
| 238 class CountingVisitor : public Visitor { | 245 class CountingVisitor : public Visitor { |
| 239 public: | 246 public: |
| 240 CountingVisitor() | 247 CountingVisitor() |
| 241 : m_count(0) | 248 : m_count(0) |
| 242 { | 249 { |
| 243 } | 250 } |
| 244 | 251 |
| 245 virtual void mark(const void* object, TraceCallback) override | 252 virtual void mark(const void* object, TraceCallback) override |
| 246 { | 253 { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 261 } | 268 } |
| 262 | 269 |
| 263 virtual void registerDelayedMarkNoTracing(const void*) override { } | 270 virtual void registerDelayedMarkNoTracing(const void*) override { } |
| 264 virtual void registerWeakMembers(const void*, const void*, WeakPointerCallba ck) override { } | 271 virtual void registerWeakMembers(const void*, const void*, WeakPointerCallba ck) override { } |
| 265 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) override { } | 272 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall back) override { } |
| 266 #if ENABLE(ASSERT) | 273 #if ENABLE(ASSERT) |
| 267 virtual bool weakTableRegistered(const void*) override { return false; } | 274 virtual bool weakTableRegistered(const void*) override { return false; } |
| 268 #endif | 275 #endif |
| 269 virtual void registerWeakCell(void**, WeakPointerCallback) override { } | 276 virtual void registerWeakCell(void**, WeakPointerCallback) override { } |
| 270 virtual bool isMarked(const void*) override { return false; } | 277 virtual bool isMarked(const void*) override { return false; } |
| 278 virtual bool ensureMarked(const void* objectPointer) override | |
| 279 { | |
| 280 if (!objectPointer || isMarked(objectPointer)) | |
| 281 return true; | |
|
haraken
2014/12/02 06:16:04
Ditto.
| |
| 282 markNoTracing(objectPointer); | |
| 283 return false; | |
|
haraken
2014/12/02 06:16:05
Ditto.
| |
| 284 } | |
| 271 | 285 |
| 272 FOR_EACH_TYPED_HEAP(DEFINE_VISITOR_METHODS) | 286 FOR_EACH_TYPED_HEAP(DEFINE_VISITOR_METHODS) |
| 273 | 287 |
| 274 size_t count() { return m_count; } | 288 size_t count() { return m_count; } |
| 275 void reset() { m_count = 0; } | 289 void reset() { m_count = 0; } |
| 276 | 290 |
| 277 private: | 291 private: |
| 278 size_t m_count; | 292 size_t m_count; |
| 279 }; | 293 }; |
| 280 | 294 |
| (...skipping 4944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5225 | 5239 |
| 5226 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) | 5240 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) |
| 5227 { | 5241 { |
| 5228 new NonNodeAllocatingNodeInDestructor(); | 5242 new NonNodeAllocatingNodeInDestructor(); |
| 5229 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 5243 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 5230 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); | 5244 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); |
| 5231 delete NonNodeAllocatingNodeInDestructor::s_node; | 5245 delete NonNodeAllocatingNodeInDestructor::s_node; |
| 5232 NonNodeAllocatingNodeInDestructor::s_node = 0; | 5246 NonNodeAllocatingNodeInDestructor::s_node = 0; |
| 5233 } | 5247 } |
| 5234 | 5248 |
| 5249 class TraceTypeEagerly1 : public GarbageCollected<TraceTypeEagerly1> { }; | |
| 5250 WILL_BE_EAGERLY_TRACED(TraceTypeEagerly1); | |
| 5251 class TraceTypeEagerly2 : public TraceTypeEagerly1 { }; | |
| 5252 | |
| 5253 class TraceTypeEagerly3 { }; | |
| 5254 WILL_BE_EAGERLY_TRACED(TraceTypeEagerly3); | |
| 5255 | |
| 5256 class TraceTypeEagerly4 : public TraceTypeEagerly3 { }; | |
| 5257 | |
| 5258 class TraceTypeEagerly5 { }; | |
| 5259 WILL_BE_EAGERLY_TRACED_CLASS(TraceTypeEagerly5); | |
| 5260 | |
| 5261 class TraceTypeEagerly6 : public TraceTypeEagerly5 { }; | |
| 5262 | |
| 5263 class TraceTypeEagerly7 { }; | |
| 5264 | |
| 5265 class TraceTypeNonEagerly1 { }; | |
| 5266 WILL_NOT_BE_EAGERLY_TRACED(TraceTypeNonEagerly1); | |
| 5267 | |
| 5268 TEST(HeapTest, TraceTypesEagerly) | |
| 5269 { | |
| 5270 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly1>::value, ShouldBeTrue); | |
| 5271 COMPILE_ASSERT(TraceEagerlyTrait<Member<TraceTypeEagerly1>>::value, ShouldBe True); | |
| 5272 COMPILE_ASSERT(TraceEagerlyTrait<WeakMember<TraceTypeEagerly1>>::value, Shou ldBeTrue); | |
| 5273 COMPILE_ASSERT(!TraceEagerlyTrait<RawPtr<TraceTypeEagerly1>>::value, ShouldB eTrue); | |
| 5274 COMPILE_ASSERT(TraceEagerlyTrait<HeapVector<Member<TraceTypeEagerly1>>>::val ue, ShouldBeTrue); | |
| 5275 COMPILE_ASSERT(TraceEagerlyTrait<HeapVector<WeakMember<TraceTypeEagerly1>>>: :value, ShouldBeTrue); | |
| 5276 COMPILE_ASSERT(TraceEagerlyTrait<HeapHashSet<Member<TraceTypeEagerly1>>>::va lue, ShouldBeTrue); | |
| 5277 COMPILE_ASSERT(TraceEagerlyTrait<HeapHashSet<Member<TraceTypeEagerly1>>>::va lue, ShouldBeTrue); | |
| 5278 using HashMapIntToObj = HeapHashMap<int, Member<TraceTypeEagerly1>>; | |
| 5279 COMPILE_ASSERT(TraceEagerlyTrait<HashMapIntToObj>::value, ShouldBeTrue); | |
| 5280 using HashMapObjToInt = HeapHashMap<Member<TraceTypeEagerly1>, int>; | |
| 5281 COMPILE_ASSERT(TraceEagerlyTrait<HashMapObjToInt>::value, ShouldBeTrue); | |
| 5282 | |
| 5283 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly2>::value, ShouldBeTrue); | |
| 5284 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly3>::value, ShouldBeTrue); | |
| 5285 | |
| 5286 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly4>::value, ShouldBeTrue); | |
| 5287 | |
| 5288 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly5>::value, ShouldBeTrue); | |
| 5289 COMPILE_ASSERT(TraceEagerlyTrait<Member<TraceTypeEagerly5>>::value, ShouldBe True); | |
| 5290 | |
| 5291 COMPILE_ASSERT(!TraceEagerlyTrait<TraceTypeEagerly6>::value, ShouldBeTrue); | |
| 5292 COMPILE_ASSERT(!TraceEagerlyTrait<TraceTypeEagerly7>::value, ShouldBeTrue); | |
| 5293 | |
| 5294 COMPILE_ASSERT(!TraceEagerlyTrait<TraceTypeNonEagerly1>::value, ShouldBeTrue ); | |
| 5295 } | |
| 5296 | |
| 5235 } // namespace blink | 5297 } // namespace blink |
| OLD | NEW |