| 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 26 matching lines...) Expand all Loading... |
| 37 #include "platform/heap/SelfKeepAlive.h" | 37 #include "platform/heap/SelfKeepAlive.h" |
| 38 #include "platform/heap/ThreadState.h" | 38 #include "platform/heap/ThreadState.h" |
| 39 #include "platform/heap/Visitor.h" | 39 #include "platform/heap/Visitor.h" |
| 40 #include "platform/testing/UnitTestHelpers.h" | 40 #include "platform/testing/UnitTestHelpers.h" |
| 41 #include "public/platform/Platform.h" | 41 #include "public/platform/Platform.h" |
| 42 #include "public/platform/WebTaskRunner.h" | 42 #include "public/platform/WebTaskRunner.h" |
| 43 #include "public/platform/WebTraceLocation.h" | 43 #include "public/platform/WebTraceLocation.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "wtf/HashTraits.h" | 45 #include "wtf/HashTraits.h" |
| 46 #include "wtf/LinkedHashSet.h" | 46 #include "wtf/LinkedHashSet.h" |
| 47 #include "wtf/PtrUtil.h" |
| 48 #include <memory> |
| 47 | 49 |
| 48 namespace blink { | 50 namespace blink { |
| 49 | 51 |
| 50 static void preciselyCollectGarbage() | 52 static void preciselyCollectGarbage() |
| 51 { | 53 { |
| 52 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw
eep, BlinkGC::ForcedGC); | 54 ThreadHeap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSw
eep, BlinkGC::ForcedGC); |
| 53 } | 55 } |
| 54 | 56 |
| 55 static void conservativelyCollectGarbage() | 57 static void conservativelyCollectGarbage() |
| 56 { | 58 { |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 int m_x; | 460 int m_x; |
| 459 }; | 461 }; |
| 460 | 462 |
| 461 int IntWrapper::s_destructorCalls = 0; | 463 int IntWrapper::s_destructorCalls = 0; |
| 462 int OffHeapInt::s_destructorCalls = 0; | 464 int OffHeapInt::s_destructorCalls = 0; |
| 463 | 465 |
| 464 class ThreadedTesterBase { | 466 class ThreadedTesterBase { |
| 465 protected: | 467 protected: |
| 466 static void test(ThreadedTesterBase* tester) | 468 static void test(ThreadedTesterBase* tester) |
| 467 { | 469 { |
| 468 Vector<OwnPtr<WebThread>, numberOfThreads> m_threads; | 470 Vector<std::unique_ptr<WebThread>, numberOfThreads> m_threads; |
| 469 for (int i = 0; i < numberOfThreads; i++) { | 471 for (int i = 0; i < numberOfThreads; i++) { |
| 470 m_threads.append(adoptPtr(Platform::current()->createThread("blink g
c testing thread"))); | 472 m_threads.append(wrapUnique(Platform::current()->createThread("blink
gc testing thread"))); |
| 471 m_threads.last()->getWebTaskRunner()->postTask(BLINK_FROM_HERE, thre
adSafeBind(threadFunc, AllowCrossThreadAccess(tester))); | 473 m_threads.last()->getWebTaskRunner()->postTask(BLINK_FROM_HERE, thre
adSafeBind(threadFunc, AllowCrossThreadAccess(tester))); |
| 472 } | 474 } |
| 473 while (tester->m_threadsToFinish) { | 475 while (tester->m_threadsToFinish) { |
| 474 SafePointScope scope(BlinkGC::NoHeapPointersOnStack); | 476 SafePointScope scope(BlinkGC::NoHeapPointersOnStack); |
| 475 testing::yieldCurrentThread(); | 477 testing::yieldCurrentThread(); |
| 476 } | 478 } |
| 477 delete tester; | 479 delete tester; |
| 478 } | 480 } |
| 479 | 481 |
| 480 virtual void runThread() = 0; | 482 virtual void runThread() = 0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 for (auto& globalIntWrapper : m_crossPersistents) { | 524 for (auto& globalIntWrapper : m_crossPersistents) { |
| 523 ASSERT(globalIntWrapper.get()); | 525 ASSERT(globalIntWrapper.get()); |
| 524 EXPECT_FALSE(globalIntWrapper.get()->get()); | 526 EXPECT_FALSE(globalIntWrapper.get()->get()); |
| 525 } | 527 } |
| 526 } | 528 } |
| 527 | 529 |
| 528 protected: | 530 protected: |
| 529 using GlobalIntWrapperPersistent = CrossThreadPersistent<IntWrapper>; | 531 using GlobalIntWrapperPersistent = CrossThreadPersistent<IntWrapper>; |
| 530 | 532 |
| 531 Mutex m_mutex; | 533 Mutex m_mutex; |
| 532 Vector<OwnPtr<GlobalIntWrapperPersistent>> m_crossPersistents; | 534 Vector<std::unique_ptr<GlobalIntWrapperPersistent>> m_crossPersistents; |
| 533 | 535 |
| 534 PassOwnPtr<GlobalIntWrapperPersistent> createGlobalPersistent(int value) | 536 std::unique_ptr<GlobalIntWrapperPersistent> createGlobalPersistent(int value
) |
| 535 { | 537 { |
| 536 return adoptPtr(new GlobalIntWrapperPersistent(IntWrapper::create(value)
)); | 538 return wrapUnique(new GlobalIntWrapperPersistent(IntWrapper::create(valu
e))); |
| 537 } | 539 } |
| 538 | 540 |
| 539 void addGlobalPersistent() | 541 void addGlobalPersistent() |
| 540 { | 542 { |
| 541 MutexLocker lock(m_mutex); | 543 MutexLocker lock(m_mutex); |
| 542 m_crossPersistents.append(createGlobalPersistent(0x2a2a2a2a)); | 544 m_crossPersistents.append(createGlobalPersistent(0x2a2a2a2a)); |
| 543 } | 545 } |
| 544 | 546 |
| 545 void runThread() override | 547 void runThread() override |
| 546 { | 548 { |
| 547 ThreadState::attachCurrentThread(false); | 549 ThreadState::attachCurrentThread(false); |
| 548 | 550 |
| 549 // Add a cross-thread persistent from this thread; the test object | 551 // Add a cross-thread persistent from this thread; the test object |
| 550 // verifies that it will have been cleared out after the threads | 552 // verifies that it will have been cleared out after the threads |
| 551 // have all detached, running their termination GCs while doing so. | 553 // have all detached, running their termination GCs while doing so. |
| 552 addGlobalPersistent(); | 554 addGlobalPersistent(); |
| 553 | 555 |
| 554 int gcCount = 0; | 556 int gcCount = 0; |
| 555 while (!done()) { | 557 while (!done()) { |
| 556 ThreadState::current()->safePoint(BlinkGC::NoHeapPointersOnStack); | 558 ThreadState::current()->safePoint(BlinkGC::NoHeapPointersOnStack); |
| 557 { | 559 { |
| 558 Persistent<IntWrapper> wrapper; | 560 Persistent<IntWrapper> wrapper; |
| 559 | 561 |
| 560 OwnPtr<GlobalIntWrapperPersistent> globalPersistent = createGlob
alPersistent(0x0ed0cabb); | 562 std::unique_ptr<GlobalIntWrapperPersistent> globalPersistent = c
reateGlobalPersistent(0x0ed0cabb); |
| 561 | 563 |
| 562 for (int i = 0; i < numberOfAllocations; i++) { | 564 for (int i = 0; i < numberOfAllocations; i++) { |
| 563 wrapper = IntWrapper::create(0x0bbac0de); | 565 wrapper = IntWrapper::create(0x0bbac0de); |
| 564 if (!(i % 10)) { | 566 if (!(i % 10)) { |
| 565 globalPersistent = createGlobalPersistent(0x0ed0cabb); | 567 globalPersistent = createGlobalPersistent(0x0ed0cabb); |
| 566 } | 568 } |
| 567 SafePointScope scope(BlinkGC::NoHeapPointersOnStack); | 569 SafePointScope scope(BlinkGC::NoHeapPointersOnStack); |
| 568 testing::yieldCurrentThread(); | 570 testing::yieldCurrentThread(); |
| 569 } | 571 } |
| 570 | 572 |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 , m_didCallWillFinalize(false) | 1383 , m_didCallWillFinalize(false) |
| 1382 { | 1384 { |
| 1383 } | 1385 } |
| 1384 | 1386 |
| 1385 WeakMember<T> m_data; | 1387 WeakMember<T> m_data; |
| 1386 bool m_didCallWillFinalize; | 1388 bool m_didCallWillFinalize; |
| 1387 }; | 1389 }; |
| 1388 | 1390 |
| 1389 class FinalizationObserverWithHashMap { | 1391 class FinalizationObserverWithHashMap { |
| 1390 public: | 1392 public: |
| 1391 typedef HeapHashMap<WeakMember<Observable>, OwnPtr<FinalizationObserverWithH
ashMap>> ObserverMap; | 1393 typedef HeapHashMap<WeakMember<Observable>, std::unique_ptr<FinalizationObse
rverWithHashMap>> ObserverMap; |
| 1392 | 1394 |
| 1393 explicit FinalizationObserverWithHashMap(Observable& target) : m_target(targ
et) { } | 1395 explicit FinalizationObserverWithHashMap(Observable& target) : m_target(targ
et) { } |
| 1394 ~FinalizationObserverWithHashMap() | 1396 ~FinalizationObserverWithHashMap() |
| 1395 { | 1397 { |
| 1396 m_target.willFinalize(); | 1398 m_target.willFinalize(); |
| 1397 s_didCallWillFinalize = true; | 1399 s_didCallWillFinalize = true; |
| 1398 } | 1400 } |
| 1399 | 1401 |
| 1400 static ObserverMap& observe(Observable& target) | 1402 static ObserverMap& observe(Observable& target) |
| 1401 { | 1403 { |
| 1402 ObserverMap& map = observers(); | 1404 ObserverMap& map = observers(); |
| 1403 ObserverMap::AddResult result = map.add(&target, nullptr); | 1405 ObserverMap::AddResult result = map.add(&target, nullptr); |
| 1404 if (result.isNewEntry) | 1406 if (result.isNewEntry) |
| 1405 result.storedValue->value = adoptPtr(new FinalizationObserverWithHas
hMap(target)); | 1407 result.storedValue->value = wrapUnique(new FinalizationObserverWithH
ashMap(target)); |
| 1406 else | 1408 else |
| 1407 ASSERT(result.storedValue->value); | 1409 ASSERT(result.storedValue->value); |
| 1408 return map; | 1410 return map; |
| 1409 } | 1411 } |
| 1410 | 1412 |
| 1411 static void clearObservers() | 1413 static void clearObservers() |
| 1412 { | 1414 { |
| 1413 delete s_observerMap; | 1415 delete s_observerMap; |
| 1414 s_observerMap = nullptr; | 1416 s_observerMap = nullptr; |
| 1415 } | 1417 } |
| (...skipping 3371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4787 } | 4789 } |
| 4788 } | 4790 } |
| 4789 | 4791 |
| 4790 EXPECT_FALSE(RefCountedWithDestructor::s_wasDestructed); | 4792 EXPECT_FALSE(RefCountedWithDestructor::s_wasDestructed); |
| 4791 set.clear(); | 4793 set.clear(); |
| 4792 EXPECT_TRUE(RefCountedWithDestructor::s_wasDestructed); | 4794 EXPECT_TRUE(RefCountedWithDestructor::s_wasDestructed); |
| 4793 } | 4795 } |
| 4794 | 4796 |
| 4795 TEST(HeapTest, DestructorsCalled) | 4797 TEST(HeapTest, DestructorsCalled) |
| 4796 { | 4798 { |
| 4797 HeapHashMap<Member<IntWrapper>, OwnPtr<SimpleClassWithDestructor>> map; | 4799 HeapHashMap<Member<IntWrapper>, std::unique_ptr<SimpleClassWithDestructor>>
map; |
| 4798 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor(); | 4800 SimpleClassWithDestructor* hasDestructor = new SimpleClassWithDestructor(); |
| 4799 map.add(IntWrapper::create(1), adoptPtr(hasDestructor)); | 4801 map.add(IntWrapper::create(1), wrapUnique(hasDestructor)); |
| 4800 SimpleClassWithDestructor::s_wasDestructed = false; | 4802 SimpleClassWithDestructor::s_wasDestructed = false; |
| 4801 map.clear(); | 4803 map.clear(); |
| 4802 EXPECT_TRUE(SimpleClassWithDestructor::s_wasDestructed); | 4804 EXPECT_TRUE(SimpleClassWithDestructor::s_wasDestructed); |
| 4803 } | 4805 } |
| 4804 | 4806 |
| 4805 class MixinA : public GarbageCollectedMixin { | 4807 class MixinA : public GarbageCollectedMixin { |
| 4806 public: | 4808 public: |
| 4807 MixinA() : m_obj(IntWrapper::create(100)) { } | 4809 MixinA() : m_obj(IntWrapper::create(100)) { } |
| 4808 DEFINE_INLINE_VIRTUAL_TRACE() | 4810 DEFINE_INLINE_VIRTUAL_TRACE() |
| 4809 { | 4811 { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4934 EXPECT_EQ(2, MixinA::s_traceCount); | 4936 EXPECT_EQ(2, MixinA::s_traceCount); |
| 4935 } | 4937 } |
| 4936 preciselyCollectGarbage(); | 4938 preciselyCollectGarbage(); |
| 4937 EXPECT_EQ(2, MixinA::s_traceCount); | 4939 EXPECT_EQ(2, MixinA::s_traceCount); |
| 4938 } | 4940 } |
| 4939 | 4941 |
| 4940 class GCParkingThreadTester { | 4942 class GCParkingThreadTester { |
| 4941 public: | 4943 public: |
| 4942 static void test() | 4944 static void test() |
| 4943 { | 4945 { |
| 4944 OwnPtr<WebThread> sleepingThread = adoptPtr(Platform::current()->createT
hread("SleepingThread")); | 4946 std::unique_ptr<WebThread> sleepingThread = wrapUnique(Platform::current
()->createThread("SleepingThread")); |
| 4945 sleepingThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafe
Bind(sleeperMainFunc)); | 4947 sleepingThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafe
Bind(sleeperMainFunc)); |
| 4946 | 4948 |
| 4947 // Wait for the sleeper to run. | 4949 // Wait for the sleeper to run. |
| 4948 while (!s_sleeperRunning) { | 4950 while (!s_sleeperRunning) { |
| 4949 testing::yieldCurrentThread(); | 4951 testing::yieldCurrentThread(); |
| 4950 } | 4952 } |
| 4951 | 4953 |
| 4952 { | 4954 { |
| 4953 // Expect the first attempt to park the sleeping thread to fail | 4955 // Expect the first attempt to park the sleeping thread to fail |
| 4954 TestGCScope scope(BlinkGC::NoHeapPointersOnStack); | 4956 TestGCScope scope(BlinkGC::NoHeapPointersOnStack); |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5599 workerThreadCondition().signal(); | 5601 workerThreadCondition().signal(); |
| 5600 } | 5602 } |
| 5601 | 5603 |
| 5602 class DeadBitTester { | 5604 class DeadBitTester { |
| 5603 public: | 5605 public: |
| 5604 static void test() | 5606 static void test() |
| 5605 { | 5607 { |
| 5606 IntWrapper::s_destructorCalls = 0; | 5608 IntWrapper::s_destructorCalls = 0; |
| 5607 | 5609 |
| 5608 MutexLocker locker(mainThreadMutex()); | 5610 MutexLocker locker(mainThreadMutex()); |
| 5609 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); | 5611 std::unique_ptr<WebThread> workerThread = wrapUnique(Platform::current()
->createThread("Test Worker Thread")); |
| 5610 workerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBi
nd(workerThreadMain)); | 5612 workerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBi
nd(workerThreadMain)); |
| 5611 | 5613 |
| 5612 // Wait for the worker thread to have done its initialization, | 5614 // Wait for the worker thread to have done its initialization, |
| 5613 // IE. the worker allocates an object and then throw aways any | 5615 // IE. the worker allocates an object and then throw aways any |
| 5614 // pointers to it. | 5616 // pointers to it. |
| 5615 parkMainThread(); | 5617 parkMainThread(); |
| 5616 | 5618 |
| 5617 // Now do a GC. This will not find the worker threads object since it | 5619 // Now do a GC. This will not find the worker threads object since it |
| 5618 // is not referred from any of the threads. Even a conservative | 5620 // is not referred from any of the threads. Even a conservative |
| 5619 // GC will not find it. | 5621 // GC will not find it. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5702 DeadBitTester::test(); | 5704 DeadBitTester::test(); |
| 5703 } | 5705 } |
| 5704 | 5706 |
| 5705 class ThreadedStrongificationTester { | 5707 class ThreadedStrongificationTester { |
| 5706 public: | 5708 public: |
| 5707 static void test() | 5709 static void test() |
| 5708 { | 5710 { |
| 5709 IntWrapper::s_destructorCalls = 0; | 5711 IntWrapper::s_destructorCalls = 0; |
| 5710 | 5712 |
| 5711 MutexLocker locker(mainThreadMutex()); | 5713 MutexLocker locker(mainThreadMutex()); |
| 5712 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); | 5714 std::unique_ptr<WebThread> workerThread = wrapUnique(Platform::current()
->createThread("Test Worker Thread")); |
| 5713 workerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBi
nd(workerThreadMain)); | 5715 workerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBi
nd(workerThreadMain)); |
| 5714 | 5716 |
| 5715 // Wait for the worker thread initialization. The worker | 5717 // Wait for the worker thread initialization. The worker |
| 5716 // allocates a weak collection where both collection and | 5718 // allocates a weak collection where both collection and |
| 5717 // contents are kept alive via persistent pointers. | 5719 // contents are kept alive via persistent pointers. |
| 5718 parkMainThread(); | 5720 parkMainThread(); |
| 5719 | 5721 |
| 5720 // Perform two garbage collections where the worker thread does | 5722 // Perform two garbage collections where the worker thread does |
| 5721 // not wake up in between. This will cause us to remove marks | 5723 // not wake up in between. This will cause us to remove marks |
| 5722 // and mark unmarked objects dead. The collection on the worker | 5724 // and mark unmarked objects dead. The collection on the worker |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5905 | 5907 |
| 5906 int DestructorLockingObject::s_destructorCalls = 0; | 5908 int DestructorLockingObject::s_destructorCalls = 0; |
| 5907 | 5909 |
| 5908 class RecursiveLockingTester { | 5910 class RecursiveLockingTester { |
| 5909 public: | 5911 public: |
| 5910 static void test() | 5912 static void test() |
| 5911 { | 5913 { |
| 5912 DestructorLockingObject::s_destructorCalls = 0; | 5914 DestructorLockingObject::s_destructorCalls = 0; |
| 5913 | 5915 |
| 5914 MutexLocker locker(mainThreadMutex()); | 5916 MutexLocker locker(mainThreadMutex()); |
| 5915 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); | 5917 std::unique_ptr<WebThread> workerThread = wrapUnique(Platform::current()
->createThread("Test Worker Thread")); |
| 5916 workerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBi
nd(workerThreadMain)); | 5918 workerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBi
nd(workerThreadMain)); |
| 5917 | 5919 |
| 5918 // Park the main thread until the worker thread has initialized. | 5920 // Park the main thread until the worker thread has initialized. |
| 5919 parkMainThread(); | 5921 parkMainThread(); |
| 5920 | 5922 |
| 5921 { | 5923 { |
| 5922 SafePointAwareMutexLocker recursiveLocker(recursiveMutex()); | 5924 SafePointAwareMutexLocker recursiveLocker(recursiveMutex()); |
| 5923 | 5925 |
| 5924 // Let the worker try to acquire the above mutex. It won't get it | 5926 // Let the worker try to acquire the above mutex. It won't get it |
| 5925 // until the main thread has done its GC. | 5927 // until the main thread has done its GC. |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6610 public: | 6612 public: |
| 6611 explicit WeakPersistentHolder(IntWrapper* object) : m_object(object) { } | 6613 explicit WeakPersistentHolder(IntWrapper* object) : m_object(object) { } |
| 6612 IntWrapper* object() const { return m_object; } | 6614 IntWrapper* object() const { return m_object; } |
| 6613 private: | 6615 private: |
| 6614 WeakPersistent<IntWrapper> m_object; | 6616 WeakPersistent<IntWrapper> m_object; |
| 6615 }; | 6617 }; |
| 6616 | 6618 |
| 6617 TEST(HeapTest, WeakPersistent) | 6619 TEST(HeapTest, WeakPersistent) |
| 6618 { | 6620 { |
| 6619 Persistent<IntWrapper> object = new IntWrapper(20); | 6621 Persistent<IntWrapper> object = new IntWrapper(20); |
| 6620 OwnPtr<WeakPersistentHolder> holder = adoptPtr(new WeakPersistentHolder(obje
ct)); | 6622 std::unique_ptr<WeakPersistentHolder> holder = wrapUnique(new WeakPersistent
Holder(object)); |
| 6621 preciselyCollectGarbage(); | 6623 preciselyCollectGarbage(); |
| 6622 EXPECT_TRUE(holder->object()); | 6624 EXPECT_TRUE(holder->object()); |
| 6623 object = nullptr; | 6625 object = nullptr; |
| 6624 preciselyCollectGarbage(); | 6626 preciselyCollectGarbage(); |
| 6625 EXPECT_FALSE(holder->object()); | 6627 EXPECT_FALSE(holder->object()); |
| 6626 } | 6628 } |
| 6627 | 6629 |
| 6628 namespace { | 6630 namespace { |
| 6629 | 6631 |
| 6630 void workerThreadMainForCrossThreadWeakPersistentTest(DestructorLockingObject**
object) | 6632 void workerThreadMainForCrossThreadWeakPersistentTest(DestructorLockingObject**
object) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6651 TEST(HeapTest, CrossThreadWeakPersistent) | 6653 TEST(HeapTest, CrossThreadWeakPersistent) |
| 6652 { | 6654 { |
| 6653 // Create an object in the worker thread, have a CrossThreadWeakPersistent p
ointing to it on the main thread, | 6655 // Create an object in the worker thread, have a CrossThreadWeakPersistent p
ointing to it on the main thread, |
| 6654 // clear the reference in the worker thread, run a GC in the worker thread,
and see if the | 6656 // clear the reference in the worker thread, run a GC in the worker thread,
and see if the |
| 6655 // CrossThreadWeakPersistent is cleared. | 6657 // CrossThreadWeakPersistent is cleared. |
| 6656 | 6658 |
| 6657 DestructorLockingObject::s_destructorCalls = 0; | 6659 DestructorLockingObject::s_destructorCalls = 0; |
| 6658 | 6660 |
| 6659 // Step 1: Initiate a worker thread, and wait for |object| to get allocated
on the worker thread. | 6661 // Step 1: Initiate a worker thread, and wait for |object| to get allocated
on the worker thread. |
| 6660 MutexLocker mainThreadMutexLocker(mainThreadMutex()); | 6662 MutexLocker mainThreadMutexLocker(mainThreadMutex()); |
| 6661 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThread(
"Test Worker Thread")); | 6663 std::unique_ptr<WebThread> workerThread = wrapUnique(Platform::current()->cr
eateThread("Test Worker Thread")); |
| 6662 DestructorLockingObject* object = nullptr; | 6664 DestructorLockingObject* object = nullptr; |
| 6663 workerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(w
orkerThreadMainForCrossThreadWeakPersistentTest, AllowCrossThreadAccess(&object)
)); | 6665 workerThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(w
orkerThreadMainForCrossThreadWeakPersistentTest, AllowCrossThreadAccess(&object)
)); |
| 6664 parkMainThread(); | 6666 parkMainThread(); |
| 6665 | 6667 |
| 6666 // Step 3: Set up a CrossThreadWeakPersistent. | 6668 // Step 3: Set up a CrossThreadWeakPersistent. |
| 6667 ASSERT_TRUE(object); | 6669 ASSERT_TRUE(object); |
| 6668 CrossThreadWeakPersistent<DestructorLockingObject> crossThreadWeakPersistent
(object); | 6670 CrossThreadWeakPersistent<DestructorLockingObject> crossThreadWeakPersistent
(object); |
| 6669 object = nullptr; | 6671 object = nullptr; |
| 6670 { | 6672 { |
| 6671 SafePointAwareMutexLocker recursiveMutexLocker(recursiveMutex()); | 6673 SafePointAwareMutexLocker recursiveMutexLocker(recursiveMutex()); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6922 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe
r>>>::value, "HeapLinkedHashSet"); | 6924 static_assert(WTF::IsGarbageCollectedType<HeapLinkedHashSet<Member<IntWrappe
r>>>::value, "HeapLinkedHashSet"); |
| 6923 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper>
>>::value, "HeapListHashSet"); | 6925 static_assert(WTF::IsGarbageCollectedType<HeapListHashSet<Member<IntWrapper>
>>::value, "HeapListHashSet"); |
| 6924 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp
er>>>::value, "HeapHashCountedSet"); | 6926 static_assert(WTF::IsGarbageCollectedType<HeapHashCountedSet<Member<IntWrapp
er>>>::value, "HeapHashCountedSet"); |
| 6925 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper
>>>::value, "HeapHashMap"); | 6927 static_assert(WTF::IsGarbageCollectedType<HeapHashMap<int, Member<IntWrapper
>>>::value, "HeapHashMap"); |
| 6926 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v
alue, "HeapVector"); | 6928 static_assert(WTF::IsGarbageCollectedType<HeapVector<Member<IntWrapper>>>::v
alue, "HeapVector"); |
| 6927 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va
lue, "HeapDeque"); | 6929 static_assert(WTF::IsGarbageCollectedType<HeapDeque<Member<IntWrapper>>>::va
lue, "HeapDeque"); |
| 6928 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap
per>>>::value, "HeapTerminatedArray"); | 6930 static_assert(WTF::IsGarbageCollectedType<HeapTerminatedArray<Member<IntWrap
per>>>::value, "HeapTerminatedArray"); |
| 6929 } | 6931 } |
| 6930 | 6932 |
| 6931 } // namespace blink | 6933 } // namespace blink |
| OLD | NEW |