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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 ThreadState::resumeThreads(); | 255 ThreadState::resumeThreads(); |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 private: | 259 private: |
260 ThreadState* m_state; | 260 ThreadState* m_state; |
261 SafePointScope m_safePointScope; | 261 SafePointScope m_safePointScope; |
262 bool m_parkedAllThreads; // False if we fail to park all threads | 262 bool m_parkedAllThreads; // False if we fail to park all threads |
263 }; | 263 }; |
264 | 264 |
265 #define DEFINE_VISITOR_METHODS(Type) \ | 265 #define DEFINE_VISITOR_METHODS(Type) \ |
266 virtual void mark(const Type* object, TraceCallback callback) override \ | 266 void mark(const Type* object, TraceCallback callback) override \ |
267 { \ | 267 { \ |
268 if (object) \ | 268 if (object) \ |
269 m_count++; \ | 269 m_count++; \ |
270 } \ | 270 } \ |
271 virtual bool isMarked(const Type*) override { return false; } \ | 271 bool isMarked(const Type*) override { return false; } \ |
272 virtual bool ensureMarked(const Type* objectPointer) override \ | 272 bool ensureMarked(const Type* objectPointer) override \ |
273 { \ | 273 { \ |
274 return ensureMarked(objectPointer); \ | 274 return ensureMarked(objectPointer); \ |
275 } | 275 } |
276 | 276 |
277 class CountingVisitor : public Visitor { | 277 class CountingVisitor : public Visitor { |
278 public: | 278 public: |
279 CountingVisitor() | 279 CountingVisitor() |
280 : Visitor(Visitor::ThreadLocalMarking) | 280 : Visitor(Visitor::ThreadLocalMarking) |
281 , m_count(0) | 281 , m_count(0) |
282 { | 282 { |
283 } | 283 } |
284 | 284 |
285 virtual void mark(const void* object, TraceCallback) override | 285 void mark(const void* object, TraceCallback) override |
286 { | 286 { |
287 if (object) | 287 if (object) |
288 m_count++; | 288 m_count++; |
289 } | 289 } |
290 | 290 |
291 virtual void markHeader(HeapObjectHeader* header, TraceCallback callback) ov
erride | 291 void markHeader(HeapObjectHeader* header, TraceCallback callback) override |
292 { | 292 { |
293 ASSERT(header->payload()); | 293 ASSERT(header->payload()); |
294 m_count++; | 294 m_count++; |
295 } | 295 } |
296 | 296 |
297 virtual void registerDelayedMarkNoTracing(const void*) override { } | 297 void registerDelayedMarkNoTracing(const void*) override { } |
298 virtual void registerWeakMembers(const void*, const void*, WeakCallback) ove
rride { } | 298 void registerWeakMembers(const void*, const void*, WeakCallback) override {
} |
299 virtual void registerWeakTable(const void*, EphemeronCallback, EphemeronCall
back) override { } | 299 void registerWeakTable(const void*, EphemeronCallback, EphemeronCallback) ov
erride { } |
300 #if ENABLE(ASSERT) | 300 #if ENABLE(ASSERT) |
301 virtual bool weakTableRegistered(const void*) override { return false; } | 301 bool weakTableRegistered(const void*) override { return false; } |
302 #endif | 302 #endif |
303 virtual void registerWeakCellWithCallback(void**, WeakCallback) override { } | 303 void registerWeakCellWithCallback(void**, WeakCallback) override { } |
304 virtual bool ensureMarked(const void* objectPointer) override | 304 bool ensureMarked(const void* objectPointer) override |
305 { | 305 { |
306 if (!objectPointer || HeapObjectHeader::fromPayload(objectPointer)->isMa
rked()) | 306 if (!objectPointer || HeapObjectHeader::fromPayload(objectPointer)->isMa
rked()) |
307 return false; | 307 return false; |
308 markNoTracing(objectPointer); | 308 markNoTracing(objectPointer); |
309 return true; | 309 return true; |
310 } | 310 } |
311 | 311 |
312 size_t count() { return m_count; } | 312 size_t count() { return m_count; } |
313 void reset() { m_count = 0; } | 313 void reset() { m_count = 0; } |
314 | 314 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 364 |
365 static const size_t classMagic = 0xABCDDBCA; | 365 static const size_t classMagic = 0xABCDDBCA; |
366 | 366 |
367 class HeapTestSubClass : public HeapTestOtherSuperClass, public HeapTestSuperCla
ss { | 367 class HeapTestSubClass : public HeapTestOtherSuperClass, public HeapTestSuperCla
ss { |
368 public: | 368 public: |
369 static HeapTestSubClass* create() | 369 static HeapTestSubClass* create() |
370 { | 370 { |
371 return new HeapTestSubClass(); | 371 return new HeapTestSubClass(); |
372 } | 372 } |
373 | 373 |
374 virtual ~HeapTestSubClass() | 374 ~HeapTestSubClass() override |
375 { | 375 { |
376 EXPECT_EQ(classMagic, m_magic); | 376 EXPECT_EQ(classMagic, m_magic); |
377 ++s_destructorCalls; | 377 ++s_destructorCalls; |
378 } | 378 } |
379 | 379 |
380 static int s_destructorCalls; | 380 static int s_destructorCalls; |
381 | 381 |
382 private: | 382 private: |
383 | 383 |
384 HeapTestSubClass() : m_magic(classMagic) { } | 384 HeapTestSubClass() : m_magic(classMagic) { } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 }; | 492 }; |
493 | 493 |
494 class ThreadedHeapTester : public ThreadedTesterBase { | 494 class ThreadedHeapTester : public ThreadedTesterBase { |
495 public: | 495 public: |
496 static void test() | 496 static void test() |
497 { | 497 { |
498 ThreadedTesterBase::test(new ThreadedHeapTester); | 498 ThreadedTesterBase::test(new ThreadedHeapTester); |
499 } | 499 } |
500 | 500 |
501 protected: | 501 protected: |
502 virtual void runThread() override | 502 void runThread() override |
503 { | 503 { |
504 ThreadState::attach(); | 504 ThreadState::attach(); |
505 | 505 |
506 int gcCount = 0; | 506 int gcCount = 0; |
507 while (!done()) { | 507 while (!done()) { |
508 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack
); | 508 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack
); |
509 { | 509 { |
510 Persistent<IntWrapper> wrapper; | 510 Persistent<IntWrapper> wrapper; |
511 | 511 |
512 typedef CrossThreadPersistent<IntWrapper> GlobalIntWrapperPersis
tent; | 512 typedef CrossThreadPersistent<IntWrapper> GlobalIntWrapperPersis
tent; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 }; | 544 }; |
545 | 545 |
546 class ThreadedWeaknessTester : public ThreadedTesterBase { | 546 class ThreadedWeaknessTester : public ThreadedTesterBase { |
547 public: | 547 public: |
548 static void test() | 548 static void test() |
549 { | 549 { |
550 ThreadedTesterBase::test(new ThreadedWeaknessTester); | 550 ThreadedTesterBase::test(new ThreadedWeaknessTester); |
551 } | 551 } |
552 | 552 |
553 private: | 553 private: |
554 virtual void runThread() override | 554 void runThread() override |
555 { | 555 { |
556 ThreadState::attach(); | 556 ThreadState::attach(); |
557 | 557 |
558 int gcCount = 0; | 558 int gcCount = 0; |
559 while (!done()) { | 559 while (!done()) { |
560 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack
); | 560 ThreadState::current()->safePoint(ThreadState::NoHeapPointersOnStack
); |
561 { | 561 { |
562 Persistent<HeapHashMap<ThreadMarker, WeakMember<IntWrapper>>> we
akMap = new HeapHashMap<ThreadMarker, WeakMember<IntWrapper>>; | 562 Persistent<HeapHashMap<ThreadMarker, WeakMember<IntWrapper>>> we
akMap = new HeapHashMap<ThreadMarker, WeakMember<IntWrapper>>; |
563 PersistentHeapHashMap<ThreadMarker, WeakMember<IntWrapper>> weak
Map2; | 563 PersistentHeapHashMap<ThreadMarker, WeakMember<IntWrapper>> weak
Map2; |
564 | 564 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 638 |
639 private: | 639 private: |
640 explicit PersistentChain(int count) | 640 explicit PersistentChain(int count) |
641 { | 641 { |
642 m_refCountedChain = adoptRef(RefCountedChain::create(count)); | 642 m_refCountedChain = adoptRef(RefCountedChain::create(count)); |
643 } | 643 } |
644 | 644 |
645 RefPtr<RefCountedChain> m_refCountedChain; | 645 RefPtr<RefCountedChain> m_refCountedChain; |
646 }; | 646 }; |
647 | 647 |
648 virtual void runThread() override | 648 void runThread() override |
649 { | 649 { |
650 ThreadState::attach(); | 650 ThreadState::attach(); |
651 | 651 |
652 PersistentChain::create(100); | 652 PersistentChain::create(100); |
653 | 653 |
654 // Upon thread detach, GCs will run until all persistents have been | 654 // Upon thread detach, GCs will run until all persistents have been |
655 // released. We verify that the draining of persistents proceeds | 655 // released. We verify that the draining of persistents proceeds |
656 // as expected by dropping one Persistent<> per GC until there | 656 // as expected by dropping one Persistent<> per GC until there |
657 // are none left. | 657 // are none left. |
658 ThreadState::detach(); | 658 ThreadState::detach(); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 static int s_destructorCalls; | 997 static int s_destructorCalls; |
998 | 998 |
999 private: | 999 private: |
1000 RefCountedAndGarbageCollected2() | 1000 RefCountedAndGarbageCollected2() |
1001 { | 1001 { |
1002 } | 1002 } |
1003 }; | 1003 }; |
1004 | 1004 |
1005 int RefCountedAndGarbageCollected2::s_destructorCalls = 0; | 1005 int RefCountedAndGarbageCollected2::s_destructorCalls = 0; |
1006 | 1006 |
1007 #define DEFINE_VISITOR_METHODS(Type) \ | 1007 #define DEFINE_VISITOR_METHODS(Type) \ |
1008 virtual void mark(const Type* object, TraceCallback callback) override \ | 1008 void mark(const Type* object, TraceCallback callback) override \ |
1009 { \ | 1009 { \ |
1010 mark(object); \ | 1010 mark(object); \ |
1011 } \ | 1011 } \ |
1012 | 1012 |
1013 class RefCountedGarbageCollectedVisitor : public CountingVisitor { | 1013 class RefCountedGarbageCollectedVisitor : public CountingVisitor { |
1014 public: | 1014 public: |
1015 RefCountedGarbageCollectedVisitor(int expected, void** objects) | 1015 RefCountedGarbageCollectedVisitor(int expected, void** objects) |
1016 : m_count(0) | 1016 : m_count(0) |
1017 , m_expectedCount(expected) | 1017 , m_expectedCount(expected) |
1018 , m_expectedObjects(objects) | 1018 , m_expectedObjects(objects) |
1019 { | 1019 { |
1020 } | 1020 } |
1021 | 1021 |
1022 void mark(const void* ptr) { markNoTrace(ptr); } | 1022 void mark(const void* ptr) { markNoTrace(ptr); } |
1023 | 1023 |
1024 virtual void markNoTrace(const void* ptr) | 1024 virtual void markNoTrace(const void* ptr) |
1025 { | 1025 { |
1026 if (!ptr) | 1026 if (!ptr) |
1027 return; | 1027 return; |
1028 if (m_count < m_expectedCount) | 1028 if (m_count < m_expectedCount) |
1029 EXPECT_TRUE(expectedObject(ptr)); | 1029 EXPECT_TRUE(expectedObject(ptr)); |
1030 else | 1030 else |
1031 EXPECT_FALSE(expectedObject(ptr)); | 1031 EXPECT_FALSE(expectedObject(ptr)); |
1032 m_count++; | 1032 m_count++; |
1033 } | 1033 } |
1034 | 1034 |
1035 virtual void mark(const void* ptr, TraceCallback) override | 1035 void mark(const void* ptr, TraceCallback) override |
1036 { | 1036 { |
1037 mark(ptr); | 1037 mark(ptr); |
1038 } | 1038 } |
1039 | 1039 |
1040 virtual void markHeader(HeapObjectHeader* header, TraceCallback callback) ov
erride | 1040 void markHeader(HeapObjectHeader* header, TraceCallback callback) override |
1041 { | 1041 { |
1042 mark(header->payload()); | 1042 mark(header->payload()); |
1043 } | 1043 } |
1044 | 1044 |
1045 bool validate() { return m_count >= m_expectedCount; } | 1045 bool validate() { return m_count >= m_expectedCount; } |
1046 void reset() { m_count = 0; } | 1046 void reset() { m_count = 0; } |
1047 | 1047 |
1048 private: | 1048 private: |
1049 bool expectedObject(const void* ptr) | 1049 bool expectedObject(const void* ptr) |
1050 { | 1050 { |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 | 1429 |
1430 int SubData::s_aliveCount = 0; | 1430 int SubData::s_aliveCount = 0; |
1431 | 1431 |
1432 class SubClass : public SuperClass { | 1432 class SubClass : public SuperClass { |
1433 public: | 1433 public: |
1434 static PassRefPtrWillBeRawPtr<SubClass> create(PassRefPtrWillBeRawPtr<Points
Back> pointsBack) | 1434 static PassRefPtrWillBeRawPtr<SubClass> create(PassRefPtrWillBeRawPtr<Points
Back> pointsBack) |
1435 { | 1435 { |
1436 return adoptRefWillBeNoop(new SubClass(pointsBack)); | 1436 return adoptRefWillBeNoop(new SubClass(pointsBack)); |
1437 } | 1437 } |
1438 | 1438 |
1439 virtual ~SubClass() | 1439 ~SubClass() override |
1440 { | 1440 { |
1441 --s_aliveCount; | 1441 --s_aliveCount; |
1442 } | 1442 } |
1443 | 1443 |
1444 DEFINE_INLINE_VIRTUAL_TRACE() | 1444 DEFINE_INLINE_VIRTUAL_TRACE() |
1445 { | 1445 { |
1446 visitor->trace(m_data); | 1446 visitor->trace(m_data); |
1447 SuperClass::trace(visitor); | 1447 SuperClass::trace(visitor); |
1448 } | 1448 } |
1449 | 1449 |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 SimpleFinalizedEagerObjectBase() { } | 1999 SimpleFinalizedEagerObjectBase() { } |
2000 }; | 2000 }; |
2001 | 2001 |
2002 class SimpleFinalizedEagerObject : public SimpleFinalizedEagerObjectBase { | 2002 class SimpleFinalizedEagerObject : public SimpleFinalizedEagerObjectBase { |
2003 public: | 2003 public: |
2004 static SimpleFinalizedEagerObject* create() | 2004 static SimpleFinalizedEagerObject* create() |
2005 { | 2005 { |
2006 return new SimpleFinalizedEagerObject(); | 2006 return new SimpleFinalizedEagerObject(); |
2007 } | 2007 } |
2008 | 2008 |
2009 virtual ~SimpleFinalizedEagerObject() | 2009 ~SimpleFinalizedEagerObject() override |
2010 { | 2010 { |
2011 ++s_destructorCalls; | 2011 ++s_destructorCalls; |
2012 } | 2012 } |
2013 | 2013 |
2014 static int s_destructorCalls; | 2014 static int s_destructorCalls; |
2015 private: | 2015 private: |
2016 SimpleFinalizedEagerObject() { } | 2016 SimpleFinalizedEagerObject() { } |
2017 }; | 2017 }; |
2018 | 2018 |
2019 template<typename T> | 2019 template<typename T> |
(...skipping 4259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6279 { | 6279 { |
6280 Persistent<ClassWithMember> object = ClassWithMember::create(); | 6280 Persistent<ClassWithMember> object = ClassWithMember::create(); |
6281 EXPECT_EQ(0, object->traceCount()); | 6281 EXPECT_EQ(0, object->traceCount()); |
6282 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); | 6282 TestMixinAllocatingObject* mixin = TestMixinAllocatingObject::create(object.
get()); |
6283 EXPECT_TRUE(mixin); | 6283 EXPECT_TRUE(mixin); |
6284 EXPECT_GT(object->traceCount(), 0); | 6284 EXPECT_GT(object->traceCount(), 0); |
6285 EXPECT_GT(mixin->traceCount(), 0); | 6285 EXPECT_GT(mixin->traceCount(), 0); |
6286 } | 6286 } |
6287 | 6287 |
6288 } // namespace blink | 6288 } // namespace blink |
OLD | NEW |