| 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 int IntWrapper::s_destructorCalls = 0; | 458 int IntWrapper::s_destructorCalls = 0; |
| 459 int OffHeapInt::s_destructorCalls = 0; | 459 int OffHeapInt::s_destructorCalls = 0; |
| 460 | 460 |
| 461 class ThreadedTesterBase { | 461 class ThreadedTesterBase { |
| 462 protected: | 462 protected: |
| 463 static void test(ThreadedTesterBase* tester) | 463 static void test(ThreadedTesterBase* tester) |
| 464 { | 464 { |
| 465 Vector<OwnPtr<WebThread>, numberOfThreads> m_threads; | 465 Vector<OwnPtr<WebThread>, numberOfThreads> m_threads; |
| 466 for (int i = 0; i < numberOfThreads; i++) { | 466 for (int i = 0; i < numberOfThreads; i++) { |
| 467 m_threads.append(adoptPtr(Platform::current()->createThread("blink g
c testing thread"))); | 467 m_threads.append(adoptPtr(Platform::current()->createThread("blink g
c testing thread"))); |
| 468 m_threads.last()->taskRunner()->postTask(FROM_HERE, new Task(threadS
afeBind(threadFunc, AllowCrossThreadAccess(tester)))); | 468 m_threads.last()->taskRunner()->postTask(BLINK_FROM_HERE, new Task(t
hreadSafeBind(threadFunc, AllowCrossThreadAccess(tester)))); |
| 469 } | 469 } |
| 470 while (tester->m_threadsToFinish) { | 470 while (tester->m_threadsToFinish) { |
| 471 SafePointScope scope(BlinkGC::NoHeapPointersOnStack); | 471 SafePointScope scope(BlinkGC::NoHeapPointersOnStack); |
| 472 Platform::current()->yieldCurrentThread(); | 472 Platform::current()->yieldCurrentThread(); |
| 473 } | 473 } |
| 474 delete tester; | 474 delete tester; |
| 475 } | 475 } |
| 476 | 476 |
| 477 virtual void runThread() = 0; | 477 virtual void runThread() = 0; |
| 478 | 478 |
| (...skipping 4150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4629 } | 4629 } |
| 4630 preciselyCollectGarbage(); | 4630 preciselyCollectGarbage(); |
| 4631 EXPECT_EQ(3, IntWrapper::s_destructorCalls); | 4631 EXPECT_EQ(3, IntWrapper::s_destructorCalls); |
| 4632 } | 4632 } |
| 4633 | 4633 |
| 4634 class GCParkingThreadTester { | 4634 class GCParkingThreadTester { |
| 4635 public: | 4635 public: |
| 4636 static void test() | 4636 static void test() |
| 4637 { | 4637 { |
| 4638 OwnPtr<WebThread> sleepingThread = adoptPtr(Platform::current()->createT
hread("SleepingThread")); | 4638 OwnPtr<WebThread> sleepingThread = adoptPtr(Platform::current()->createT
hread("SleepingThread")); |
| 4639 sleepingThread->taskRunner()->postTask(FROM_HERE, new Task(threadSafeBin
d(sleeperMainFunc))); | 4639 sleepingThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadS
afeBind(sleeperMainFunc))); |
| 4640 | 4640 |
| 4641 // Wait for the sleeper to run. | 4641 // Wait for the sleeper to run. |
| 4642 while (!s_sleeperRunning) { | 4642 while (!s_sleeperRunning) { |
| 4643 Platform::current()->yieldCurrentThread(); | 4643 Platform::current()->yieldCurrentThread(); |
| 4644 } | 4644 } |
| 4645 | 4645 |
| 4646 { | 4646 { |
| 4647 // Expect the first attempt to park the sleeping thread to fail | 4647 // Expect the first attempt to park the sleeping thread to fail |
| 4648 TestGCScope scope(BlinkGC::NoHeapPointersOnStack); | 4648 TestGCScope scope(BlinkGC::NoHeapPointersOnStack); |
| 4649 EXPECT_FALSE(scope.allThreadsParked()); | 4649 EXPECT_FALSE(scope.allThreadsParked()); |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5299 } | 5299 } |
| 5300 | 5300 |
| 5301 class DeadBitTester { | 5301 class DeadBitTester { |
| 5302 public: | 5302 public: |
| 5303 static void test() | 5303 static void test() |
| 5304 { | 5304 { |
| 5305 IntWrapper::s_destructorCalls = 0; | 5305 IntWrapper::s_destructorCalls = 0; |
| 5306 | 5306 |
| 5307 MutexLocker locker(mainThreadMutex()); | 5307 MutexLocker locker(mainThreadMutex()); |
| 5308 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); | 5308 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); |
| 5309 workerThread->taskRunner()->postTask(FROM_HERE, new Task(threadSafeBind(
workerThreadMain))); | 5309 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSaf
eBind(workerThreadMain))); |
| 5310 | 5310 |
| 5311 // Wait for the worker thread to have done its initialization, | 5311 // Wait for the worker thread to have done its initialization, |
| 5312 // IE. the worker allocates an object and then throw aways any | 5312 // IE. the worker allocates an object and then throw aways any |
| 5313 // pointers to it. | 5313 // pointers to it. |
| 5314 parkMainThread(); | 5314 parkMainThread(); |
| 5315 | 5315 |
| 5316 // Now do a GC. This will not find the worker threads object since it | 5316 // Now do a GC. This will not find the worker threads object since it |
| 5317 // is not referred from any of the threads. Even a conservative | 5317 // is not referred from any of the threads. Even a conservative |
| 5318 // GC will not find it. | 5318 // GC will not find it. |
| 5319 // Also at this point the worker is waiting for the main thread | 5319 // Also at this point the worker is waiting for the main thread |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5402 } | 5402 } |
| 5403 | 5403 |
| 5404 class ThreadedStrongificationTester { | 5404 class ThreadedStrongificationTester { |
| 5405 public: | 5405 public: |
| 5406 static void test() | 5406 static void test() |
| 5407 { | 5407 { |
| 5408 IntWrapper::s_destructorCalls = 0; | 5408 IntWrapper::s_destructorCalls = 0; |
| 5409 | 5409 |
| 5410 MutexLocker locker(mainThreadMutex()); | 5410 MutexLocker locker(mainThreadMutex()); |
| 5411 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); | 5411 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); |
| 5412 workerThread->taskRunner()->postTask(FROM_HERE, new Task(threadSafeBind(
workerThreadMain))); | 5412 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSaf
eBind(workerThreadMain))); |
| 5413 | 5413 |
| 5414 // Wait for the worker thread initialization. The worker | 5414 // Wait for the worker thread initialization. The worker |
| 5415 // allocates a weak collection where both collection and | 5415 // allocates a weak collection where both collection and |
| 5416 // contents are kept alive via persistent pointers. | 5416 // contents are kept alive via persistent pointers. |
| 5417 parkMainThread(); | 5417 parkMainThread(); |
| 5418 | 5418 |
| 5419 // Perform two garbage collections where the worker thread does | 5419 // Perform two garbage collections where the worker thread does |
| 5420 // not wake up in between. This will cause us to remove marks | 5420 // not wake up in between. This will cause us to remove marks |
| 5421 // and mark unmarked objects dead. The collection on the worker | 5421 // and mark unmarked objects dead. The collection on the worker |
| 5422 // heap is found through the persistent and the backing should | 5422 // heap is found through the persistent and the backing should |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5605 int DestructorLockingObject::s_destructorCalls = 0; | 5605 int DestructorLockingObject::s_destructorCalls = 0; |
| 5606 | 5606 |
| 5607 class RecursiveLockingTester { | 5607 class RecursiveLockingTester { |
| 5608 public: | 5608 public: |
| 5609 static void test() | 5609 static void test() |
| 5610 { | 5610 { |
| 5611 DestructorLockingObject::s_destructorCalls = 0; | 5611 DestructorLockingObject::s_destructorCalls = 0; |
| 5612 | 5612 |
| 5613 MutexLocker locker(mainThreadMutex()); | 5613 MutexLocker locker(mainThreadMutex()); |
| 5614 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); | 5614 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); |
| 5615 workerThread->taskRunner()->postTask(FROM_HERE, new Task(threadSafeBind(
workerThreadMain))); | 5615 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSaf
eBind(workerThreadMain))); |
| 5616 | 5616 |
| 5617 // Park the main thread until the worker thread has initialized. | 5617 // Park the main thread until the worker thread has initialized. |
| 5618 parkMainThread(); | 5618 parkMainThread(); |
| 5619 | 5619 |
| 5620 { | 5620 { |
| 5621 SafePointAwareMutexLocker recursiveLocker(recursiveMutex()); | 5621 SafePointAwareMutexLocker recursiveLocker(recursiveMutex()); |
| 5622 | 5622 |
| 5623 // Let the worker try to acquire the above mutex. It won't get it | 5623 // Let the worker try to acquire the above mutex. It won't get it |
| 5624 // until the main thread has done its GC. | 5624 // until the main thread has done its GC. |
| 5625 wakeWorkerThread(); | 5625 wakeWorkerThread(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5679 { | 5679 { |
| 5680 RecursiveLockingTester::test(); | 5680 RecursiveLockingTester::test(); |
| 5681 } | 5681 } |
| 5682 | 5682 |
| 5683 class CrossThreadPersistentOnMainThreadTester { | 5683 class CrossThreadPersistentOnMainThreadTester { |
| 5684 public: | 5684 public: |
| 5685 static void test() | 5685 static void test() |
| 5686 { | 5686 { |
| 5687 MutexLocker locker(mainThreadMutex()); | 5687 MutexLocker locker(mainThreadMutex()); |
| 5688 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); | 5688 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr
ead("Test Worker Thread")); |
| 5689 workerThread->taskRunner()->postTask(FROM_HERE, new Task(threadSafeBind(
workerThreadMain))); | 5689 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSaf
eBind(workerThreadMain))); |
| 5690 | 5690 |
| 5691 parkMainThread(); | 5691 parkMainThread(); |
| 5692 | 5692 |
| 5693 // (Temporarily) detach main thread and wake the worker thread, so that
it | 5693 // (Temporarily) detach main thread and wake the worker thread, so that
it |
| 5694 // can do its detach(). | 5694 // can do its detach(). |
| 5695 ThreadState::detachMainThread(); | 5695 ThreadState::detachMainThread(); |
| 5696 wakeWorkerThread(); | 5696 wakeWorkerThread(); |
| 5697 | 5697 |
| 5698 parkMainThread(); | 5698 parkMainThread(); |
| 5699 ThreadState::attachMainThread(); | 5699 ThreadState::attachMainThread(); |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6397 // Create an object in the worker thread, have a CrossThreadWeakPersistent p
ointing to it on the main thread, | 6397 // Create an object in the worker thread, have a CrossThreadWeakPersistent p
ointing to it on the main thread, |
| 6398 // clear the reference in the worker thread, run a GC in the worker thread,
and see if the | 6398 // clear the reference in the worker thread, run a GC in the worker thread,
and see if the |
| 6399 // CrossThreadWeakPersistent is cleared. | 6399 // CrossThreadWeakPersistent is cleared. |
| 6400 | 6400 |
| 6401 DestructorLockingObject::s_destructorCalls = 0; | 6401 DestructorLockingObject::s_destructorCalls = 0; |
| 6402 | 6402 |
| 6403 // Step 1: Initiate a worker thread, and wait for |object| to get allocated
on the worker thread. | 6403 // Step 1: Initiate a worker thread, and wait for |object| to get allocated
on the worker thread. |
| 6404 MutexLocker mainThreadMutexLocker(mainThreadMutex()); | 6404 MutexLocker mainThreadMutexLocker(mainThreadMutex()); |
| 6405 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThread(
"Test Worker Thread")); | 6405 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThread(
"Test Worker Thread")); |
| 6406 DestructorLockingObject* object = nullptr; | 6406 DestructorLockingObject* object = nullptr; |
| 6407 workerThread->taskRunner()->postTask(FROM_HERE, new Task(threadSafeBind(work
erThreadMainForCrossThreadWeakPersistentTest, AllowCrossThreadAccessWrapper<Dest
ructorLockingObject**>(&object)))); | 6407 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBin
d(workerThreadMainForCrossThreadWeakPersistentTest, AllowCrossThreadAccessWrappe
r<DestructorLockingObject**>(&object)))); |
| 6408 parkMainThread(); | 6408 parkMainThread(); |
| 6409 | 6409 |
| 6410 // Step 3: Set up a CrossThreadWeakPersistent. | 6410 // Step 3: Set up a CrossThreadWeakPersistent. |
| 6411 ASSERT_TRUE(object); | 6411 ASSERT_TRUE(object); |
| 6412 CrossThreadWeakPersistent<DestructorLockingObject> crossThreadWeakPersistent
(object); | 6412 CrossThreadWeakPersistent<DestructorLockingObject> crossThreadWeakPersistent
(object); |
| 6413 object = nullptr; | 6413 object = nullptr; |
| 6414 { | 6414 { |
| 6415 SafePointAwareMutexLocker recursiveMutexLocker(recursiveMutex()); | 6415 SafePointAwareMutexLocker recursiveMutexLocker(recursiveMutex()); |
| 6416 EXPECT_EQ(0, DestructorLockingObject::s_destructorCalls); | 6416 EXPECT_EQ(0, DestructorLockingObject::s_destructorCalls); |
| 6417 } | 6417 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6428 { | 6428 { |
| 6429 SafePointAwareMutexLocker recursiveMutexLocker(recursiveMutex()); | 6429 SafePointAwareMutexLocker recursiveMutexLocker(recursiveMutex()); |
| 6430 EXPECT_EQ(1, DestructorLockingObject::s_destructorCalls); | 6430 EXPECT_EQ(1, DestructorLockingObject::s_destructorCalls); |
| 6431 } | 6431 } |
| 6432 | 6432 |
| 6433 wakeWorkerThread(); | 6433 wakeWorkerThread(); |
| 6434 parkMainThread(); | 6434 parkMainThread(); |
| 6435 } | 6435 } |
| 6436 | 6436 |
| 6437 } // namespace blink | 6437 } // namespace blink |
| OLD | NEW |