| 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 return ensureMarked(objectPointer); \ |
| 240 } |
| 237 | 241 |
| 238 class CountingVisitor : public Visitor { | 242 class CountingVisitor : public Visitor { |
| 239 public: | 243 public: |
| 240 CountingVisitor() | 244 CountingVisitor() |
| 241 : m_count(0) | 245 : m_count(0) |
| 242 { | 246 { |
| 243 } | 247 } |
| 244 | 248 |
| 245 virtual void mark(const void* object, TraceCallback) override | 249 virtual void mark(const void* object, TraceCallback) override |
| 246 { | 250 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 261 } | 265 } |
| 262 | 266 |
| 263 virtual void registerDelayedMarkNoTracing(const void*) override { } | 267 virtual void registerDelayedMarkNoTracing(const void*) override { } |
| 264 virtual void registerWeakMembers(const void*, const void*, WeakPointerCallba
ck) override { } | 268 virtual void registerWeakMembers(const void*, const void*, WeakPointerCallba
ck) override { } |
| 265 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall
back) override { } | 269 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall
back) override { } |
| 266 #if ENABLE(ASSERT) | 270 #if ENABLE(ASSERT) |
| 267 virtual bool weakTableRegistered(const void*) override { return false; } | 271 virtual bool weakTableRegistered(const void*) override { return false; } |
| 268 #endif | 272 #endif |
| 269 virtual void registerWeakCell(void**, WeakPointerCallback) override { } | 273 virtual void registerWeakCell(void**, WeakPointerCallback) override { } |
| 270 virtual bool isMarked(const void*) override { return false; } | 274 virtual bool isMarked(const void*) override { return false; } |
| 275 virtual bool ensureMarked(const void* objectPointer) override |
| 276 { |
| 277 if (!objectPointer || isMarked(objectPointer)) |
| 278 return false; |
| 279 markNoTracing(objectPointer); |
| 280 return true; |
| 281 } |
| 271 | 282 |
| 272 FOR_EACH_TYPED_HEAP(DEFINE_VISITOR_METHODS) | 283 FOR_EACH_TYPED_HEAP(DEFINE_VISITOR_METHODS) |
| 273 | 284 |
| 274 size_t count() { return m_count; } | 285 size_t count() { return m_count; } |
| 275 void reset() { m_count = 0; } | 286 void reset() { m_count = 0; } |
| 276 | 287 |
| 277 private: | 288 private: |
| 278 size_t m_count; | 289 size_t m_count; |
| 279 }; | 290 }; |
| 280 | 291 |
| 292 #undef DEFINE_VISITOR_METHODS |
| 293 |
| 281 class SimpleObject : public GarbageCollected<SimpleObject> { | 294 class SimpleObject : public GarbageCollected<SimpleObject> { |
| 282 public: | 295 public: |
| 283 static SimpleObject* create() { return new SimpleObject(); } | 296 static SimpleObject* create() { return new SimpleObject(); } |
| 284 void trace(Visitor*) { } | 297 void trace(Visitor*) { } |
| 285 char getPayload(int i) { return payload[i]; } | 298 char getPayload(int i) { return payload[i]; } |
| 286 // This virtual method is unused but it is here to make sure | 299 // This virtual method is unused but it is here to make sure |
| 287 // that this object has a vtable. This object is used | 300 // that this object has a vtable. This object is used |
| 288 // as the super class for objects that also have garbage | 301 // as the super class for objects that also have garbage |
| 289 // collected mixins and having a virtual here makes sure | 302 // collected mixins and having a virtual here makes sure |
| 290 // that adjustment is needed both for marking and for isAlive | 303 // that adjustment is needed both for marking and for isAlive |
| 291 // checks. | 304 // checks. |
| 292 virtual void virtualMethod() { } | 305 virtual void virtualMethod() { } |
| 293 protected: | 306 protected: |
| 294 SimpleObject() { } | 307 SimpleObject() { } |
| 295 char payload[64]; | 308 char payload[64]; |
| 296 }; | 309 }; |
| 297 | 310 |
| 298 #undef DEFINE_VISITOR_METHODS | |
| 299 | |
| 300 class HeapTestSuperClass : public GarbageCollectedFinalized<HeapTestSuperClass>
{ | 311 class HeapTestSuperClass : public GarbageCollectedFinalized<HeapTestSuperClass>
{ |
| 301 public: | 312 public: |
| 302 static HeapTestSuperClass* create() | 313 static HeapTestSuperClass* create() |
| 303 { | 314 { |
| 304 return new HeapTestSuperClass(); | 315 return new HeapTestSuperClass(); |
| 305 } | 316 } |
| 306 | 317 |
| 307 virtual ~HeapTestSuperClass() | 318 virtual ~HeapTestSuperClass() |
| 308 { | 319 { |
| 309 ++s_destructorCalls; | 320 ++s_destructorCalls; |
| (...skipping 4916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5226 | 5237 |
| 5227 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) | 5238 TEST(HeapTest, NonNodeAllocatingNodeInDestructor) |
| 5228 { | 5239 { |
| 5229 new NonNodeAllocatingNodeInDestructor(); | 5240 new NonNodeAllocatingNodeInDestructor(); |
| 5230 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); | 5241 Heap::collectGarbage(ThreadState::NoHeapPointersOnStack); |
| 5231 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); | 5242 EXPECT_EQ(10, (*NonNodeAllocatingNodeInDestructor::s_node)->value()); |
| 5232 delete NonNodeAllocatingNodeInDestructor::s_node; | 5243 delete NonNodeAllocatingNodeInDestructor::s_node; |
| 5233 NonNodeAllocatingNodeInDestructor::s_node = 0; | 5244 NonNodeAllocatingNodeInDestructor::s_node = 0; |
| 5234 } | 5245 } |
| 5235 | 5246 |
| 5247 class TraceTypeEagerly1 : public GarbageCollected<TraceTypeEagerly1> { }; |
| 5248 WILL_BE_EAGERLY_TRACED(TraceTypeEagerly1); |
| 5249 class TraceTypeEagerly2 : public TraceTypeEagerly1 { }; |
| 5250 |
| 5251 class TraceTypeEagerly3 { }; |
| 5252 WILL_BE_EAGERLY_TRACED(TraceTypeEagerly3); |
| 5253 |
| 5254 class TraceTypeEagerly4 : public TraceTypeEagerly3 { }; |
| 5255 |
| 5256 class TraceTypeEagerly5 { }; |
| 5257 WILL_BE_EAGERLY_TRACED_CLASS(TraceTypeEagerly5); |
| 5258 |
| 5259 class TraceTypeEagerly6 : public TraceTypeEagerly5 { }; |
| 5260 |
| 5261 class TraceTypeEagerly7 { }; |
| 5262 |
| 5263 class TraceTypeNonEagerly1 { }; |
| 5264 WILL_NOT_BE_EAGERLY_TRACED(TraceTypeNonEagerly1); |
| 5265 |
| 5266 TEST(HeapTest, TraceTypesEagerly) |
| 5267 { |
| 5268 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly1>::value, ShouldBeTrue); |
| 5269 COMPILE_ASSERT(TraceEagerlyTrait<Member<TraceTypeEagerly1>>::value, ShouldBe
True); |
| 5270 COMPILE_ASSERT(TraceEagerlyTrait<WeakMember<TraceTypeEagerly1>>::value, Shou
ldBeTrue); |
| 5271 COMPILE_ASSERT(!TraceEagerlyTrait<RawPtr<TraceTypeEagerly1>>::value, ShouldB
eTrue); |
| 5272 COMPILE_ASSERT(TraceEagerlyTrait<HeapVector<Member<TraceTypeEagerly1>>>::val
ue, ShouldBeTrue); |
| 5273 COMPILE_ASSERT(TraceEagerlyTrait<HeapVector<WeakMember<TraceTypeEagerly1>>>:
:value, ShouldBeTrue); |
| 5274 COMPILE_ASSERT(TraceEagerlyTrait<HeapHashSet<Member<TraceTypeEagerly1>>>::va
lue, ShouldBeTrue); |
| 5275 COMPILE_ASSERT(TraceEagerlyTrait<HeapHashSet<Member<TraceTypeEagerly1>>>::va
lue, ShouldBeTrue); |
| 5276 using HashMapIntToObj = HeapHashMap<int, Member<TraceTypeEagerly1>>; |
| 5277 COMPILE_ASSERT(TraceEagerlyTrait<HashMapIntToObj>::value, ShouldBeTrue); |
| 5278 using HashMapObjToInt = HeapHashMap<Member<TraceTypeEagerly1>, int>; |
| 5279 COMPILE_ASSERT(TraceEagerlyTrait<HashMapObjToInt>::value, ShouldBeTrue); |
| 5280 |
| 5281 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly2>::value, ShouldBeTrue); |
| 5282 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly3>::value, ShouldBeTrue); |
| 5283 |
| 5284 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly4>::value, ShouldBeTrue); |
| 5285 |
| 5286 COMPILE_ASSERT(TraceEagerlyTrait<TraceTypeEagerly5>::value, ShouldBeTrue); |
| 5287 COMPILE_ASSERT(TraceEagerlyTrait<Member<TraceTypeEagerly5>>::value, ShouldBe
True); |
| 5288 |
| 5289 COMPILE_ASSERT(!TraceEagerlyTrait<TraceTypeEagerly6>::value, ShouldBeTrue); |
| 5290 COMPILE_ASSERT(!TraceEagerlyTrait<TraceTypeEagerly7>::value, ShouldBeTrue); |
| 5291 |
| 5292 COMPILE_ASSERT(!TraceEagerlyTrait<TraceTypeNonEagerly1>::value, ShouldBeTrue
); |
| 5293 } |
| 5294 |
| 5236 } // namespace blink | 5295 } // namespace blink |
| OLD | NEW |