Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/Source/platform/heap/HeapTest.cpp

Issue 1713143002: Remove most of the blink::Task wrapping of WTF::Function outside WebTaskRunner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/Task.h"
32 #include "platform/ThreadSafeFunctional.h" 31 #include "platform/ThreadSafeFunctional.h"
33 #include "platform/heap/Handle.h" 32 #include "platform/heap/Handle.h"
34 #include "platform/heap/Heap.h" 33 #include "platform/heap/Heap.h"
35 #include "platform/heap/HeapLinkedStack.h" 34 #include "platform/heap/HeapLinkedStack.h"
36 #include "platform/heap/HeapTerminatedArrayBuilder.h" 35 #include "platform/heap/HeapTerminatedArrayBuilder.h"
37 #include "platform/heap/SafePoint.h" 36 #include "platform/heap/SafePoint.h"
38 #include "platform/heap/ThreadState.h" 37 #include "platform/heap/ThreadState.h"
39 #include "platform/heap/Visitor.h" 38 #include "platform/heap/Visitor.h"
40 #include "platform/testing/UnitTestHelpers.h" 39 #include "platform/testing/UnitTestHelpers.h"
41 #include "public/platform/Platform.h" 40 #include "public/platform/Platform.h"
41 #include "public/platform/WebTaskRunner.h"
42 #include "public/platform/WebTraceLocation.h" 42 #include "public/platform/WebTraceLocation.h"
43 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
44 #include "wtf/HashTraits.h" 44 #include "wtf/HashTraits.h"
45 #include "wtf/LinkedHashSet.h" 45 #include "wtf/LinkedHashSet.h"
46 46
47 namespace blink { 47 namespace blink {
48 48
49 static void preciselyCollectGarbage() 49 static void preciselyCollectGarbage()
50 { 50 {
51 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, B linkGC::ForcedGC); 51 Heap::collectGarbage(BlinkGC::NoHeapPointersOnStack, BlinkGC::GCWithSweep, B linkGC::ForcedGC);
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 int IntWrapper::s_destructorCalls = 0; 454 int IntWrapper::s_destructorCalls = 0;
455 int OffHeapInt::s_destructorCalls = 0; 455 int OffHeapInt::s_destructorCalls = 0;
456 456
457 class ThreadedTesterBase { 457 class ThreadedTesterBase {
458 protected: 458 protected:
459 static void test(ThreadedTesterBase* tester) 459 static void test(ThreadedTesterBase* tester)
460 { 460 {
461 Vector<OwnPtr<WebThread>, numberOfThreads> m_threads; 461 Vector<OwnPtr<WebThread>, numberOfThreads> m_threads;
462 for (int i = 0; i < numberOfThreads; i++) { 462 for (int i = 0; i < numberOfThreads; i++) {
463 m_threads.append(adoptPtr(Platform::current()->createThread("blink g c testing thread"))); 463 m_threads.append(adoptPtr(Platform::current()->createThread("blink g c testing thread")));
464 m_threads.last()->taskRunner()->postTask(BLINK_FROM_HERE, new Task(t hreadSafeBind(threadFunc, AllowCrossThreadAccess(tester)))); 464 m_threads.last()->taskRunner()->postTask(BLINK_FROM_HERE, threadSafe Bind(threadFunc, AllowCrossThreadAccess(tester)));
465 } 465 }
466 while (tester->m_threadsToFinish) { 466 while (tester->m_threadsToFinish) {
467 SafePointScope scope(BlinkGC::NoHeapPointersOnStack); 467 SafePointScope scope(BlinkGC::NoHeapPointersOnStack);
468 testing::yieldCurrentThread(); 468 testing::yieldCurrentThread();
469 } 469 }
470 delete tester; 470 delete tester;
471 } 471 }
472 472
473 virtual void runThread() = 0; 473 virtual void runThread() = 0;
474 474
(...skipping 4221 matching lines...) Expand 10 before | Expand all | Expand 10 after
4696 } 4696 }
4697 preciselyCollectGarbage(); 4697 preciselyCollectGarbage();
4698 EXPECT_EQ(2, MixinA::s_traceCount); 4698 EXPECT_EQ(2, MixinA::s_traceCount);
4699 } 4699 }
4700 4700
4701 class GCParkingThreadTester { 4701 class GCParkingThreadTester {
4702 public: 4702 public:
4703 static void test() 4703 static void test()
4704 { 4704 {
4705 OwnPtr<WebThread> sleepingThread = adoptPtr(Platform::current()->createT hread("SleepingThread")); 4705 OwnPtr<WebThread> sleepingThread = adoptPtr(Platform::current()->createT hread("SleepingThread"));
4706 sleepingThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadS afeBind(sleeperMainFunc))); 4706 sleepingThread->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(s leeperMainFunc));
4707 4707
4708 // Wait for the sleeper to run. 4708 // Wait for the sleeper to run.
4709 while (!s_sleeperRunning) { 4709 while (!s_sleeperRunning) {
4710 testing::yieldCurrentThread(); 4710 testing::yieldCurrentThread();
4711 } 4711 }
4712 4712
4713 { 4713 {
4714 // Expect the first attempt to park the sleeping thread to fail 4714 // Expect the first attempt to park the sleeping thread to fail
4715 TestGCScope scope(BlinkGC::NoHeapPointersOnStack); 4715 TestGCScope scope(BlinkGC::NoHeapPointersOnStack);
4716 EXPECT_FALSE(scope.allThreadsParked()); 4716 EXPECT_FALSE(scope.allThreadsParked());
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
5366 } 5366 }
5367 5367
5368 class DeadBitTester { 5368 class DeadBitTester {
5369 public: 5369 public:
5370 static void test() 5370 static void test()
5371 { 5371 {
5372 IntWrapper::s_destructorCalls = 0; 5372 IntWrapper::s_destructorCalls = 0;
5373 5373
5374 MutexLocker locker(mainThreadMutex()); 5374 MutexLocker locker(mainThreadMutex());
5375 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr ead("Test Worker Thread")); 5375 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr ead("Test Worker Thread"));
5376 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSaf eBind(workerThreadMain))); 5376 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(wor kerThreadMain));
5377 5377
5378 // Wait for the worker thread to have done its initialization, 5378 // Wait for the worker thread to have done its initialization,
5379 // IE. the worker allocates an object and then throw aways any 5379 // IE. the worker allocates an object and then throw aways any
5380 // pointers to it. 5380 // pointers to it.
5381 parkMainThread(); 5381 parkMainThread();
5382 5382
5383 // Now do a GC. This will not find the worker threads object since it 5383 // Now do a GC. This will not find the worker threads object since it
5384 // is not referred from any of the threads. Even a conservative 5384 // is not referred from any of the threads. Even a conservative
5385 // GC will not find it. 5385 // GC will not find it.
5386 // Also at this point the worker is waiting for the main thread 5386 // Also at this point the worker is waiting for the main thread
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
5469 } 5469 }
5470 5470
5471 class ThreadedStrongificationTester { 5471 class ThreadedStrongificationTester {
5472 public: 5472 public:
5473 static void test() 5473 static void test()
5474 { 5474 {
5475 IntWrapper::s_destructorCalls = 0; 5475 IntWrapper::s_destructorCalls = 0;
5476 5476
5477 MutexLocker locker(mainThreadMutex()); 5477 MutexLocker locker(mainThreadMutex());
5478 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr ead("Test Worker Thread")); 5478 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr ead("Test Worker Thread"));
5479 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSaf eBind(workerThreadMain))); 5479 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(wor kerThreadMain));
5480 5480
5481 // Wait for the worker thread initialization. The worker 5481 // Wait for the worker thread initialization. The worker
5482 // allocates a weak collection where both collection and 5482 // allocates a weak collection where both collection and
5483 // contents are kept alive via persistent pointers. 5483 // contents are kept alive via persistent pointers.
5484 parkMainThread(); 5484 parkMainThread();
5485 5485
5486 // Perform two garbage collections where the worker thread does 5486 // Perform two garbage collections where the worker thread does
5487 // not wake up in between. This will cause us to remove marks 5487 // not wake up in between. This will cause us to remove marks
5488 // and mark unmarked objects dead. The collection on the worker 5488 // and mark unmarked objects dead. The collection on the worker
5489 // heap is found through the persistent and the backing should 5489 // heap is found through the persistent and the backing should
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
5672 int DestructorLockingObject::s_destructorCalls = 0; 5672 int DestructorLockingObject::s_destructorCalls = 0;
5673 5673
5674 class RecursiveLockingTester { 5674 class RecursiveLockingTester {
5675 public: 5675 public:
5676 static void test() 5676 static void test()
5677 { 5677 {
5678 DestructorLockingObject::s_destructorCalls = 0; 5678 DestructorLockingObject::s_destructorCalls = 0;
5679 5679
5680 MutexLocker locker(mainThreadMutex()); 5680 MutexLocker locker(mainThreadMutex());
5681 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr ead("Test Worker Thread")); 5681 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr ead("Test Worker Thread"));
5682 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSaf eBind(workerThreadMain))); 5682 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(wor kerThreadMain));
5683 5683
5684 // Park the main thread until the worker thread has initialized. 5684 // Park the main thread until the worker thread has initialized.
5685 parkMainThread(); 5685 parkMainThread();
5686 5686
5687 { 5687 {
5688 SafePointAwareMutexLocker recursiveLocker(recursiveMutex()); 5688 SafePointAwareMutexLocker recursiveLocker(recursiveMutex());
5689 5689
5690 // Let the worker try to acquire the above mutex. It won't get it 5690 // Let the worker try to acquire the above mutex. It won't get it
5691 // until the main thread has done its GC. 5691 // until the main thread has done its GC.
5692 wakeWorkerThread(); 5692 wakeWorkerThread();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
5746 { 5746 {
5747 RecursiveLockingTester::test(); 5747 RecursiveLockingTester::test();
5748 } 5748 }
5749 5749
5750 class CrossThreadPersistentOnMainThreadTester { 5750 class CrossThreadPersistentOnMainThreadTester {
5751 public: 5751 public:
5752 static void test() 5752 static void test()
5753 { 5753 {
5754 MutexLocker locker(mainThreadMutex()); 5754 MutexLocker locker(mainThreadMutex());
5755 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr ead("Test Worker Thread")); 5755 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThr ead("Test Worker Thread"));
5756 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSaf eBind(workerThreadMain))); 5756 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(wor kerThreadMain));
5757 5757
5758 parkMainThread(); 5758 parkMainThread();
5759 5759
5760 // (Temporarily) detach main thread and wake the worker thread, so that it 5760 // (Temporarily) detach main thread and wake the worker thread, so that it
5761 // can do its detach(). 5761 // can do its detach().
5762 ThreadState::detachMainThread(); 5762 ThreadState::detachMainThread();
5763 wakeWorkerThread(); 5763 wakeWorkerThread();
5764 5764
5765 parkMainThread(); 5765 parkMainThread();
5766 ThreadState::attachMainThread(); 5766 ThreadState::attachMainThread();
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
6465 // Create an object in the worker thread, have a CrossThreadWeakPersistent p ointing to it on the main thread, 6465 // Create an object in the worker thread, have a CrossThreadWeakPersistent p ointing to it on the main thread,
6466 // clear the reference in the worker thread, run a GC in the worker thread, and see if the 6466 // clear the reference in the worker thread, run a GC in the worker thread, and see if the
6467 // CrossThreadWeakPersistent is cleared. 6467 // CrossThreadWeakPersistent is cleared.
6468 6468
6469 DestructorLockingObject::s_destructorCalls = 0; 6469 DestructorLockingObject::s_destructorCalls = 0;
6470 6470
6471 // Step 1: Initiate a worker thread, and wait for |object| to get allocated on the worker thread. 6471 // Step 1: Initiate a worker thread, and wait for |object| to get allocated on the worker thread.
6472 MutexLocker mainThreadMutexLocker(mainThreadMutex()); 6472 MutexLocker mainThreadMutexLocker(mainThreadMutex());
6473 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThread( "Test Worker Thread")); 6473 OwnPtr<WebThread> workerThread = adoptPtr(Platform::current()->createThread( "Test Worker Thread"));
6474 DestructorLockingObject* object = nullptr; 6474 DestructorLockingObject* object = nullptr;
6475 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBin d(workerThreadMainForCrossThreadWeakPersistentTest, AllowCrossThreadAccessWrappe r<DestructorLockingObject**>(&object)))); 6475 workerThread->taskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(workerT hreadMainForCrossThreadWeakPersistentTest, AllowCrossThreadAccessWrapper<Destruc torLockingObject**>(&object)));
6476 parkMainThread(); 6476 parkMainThread();
6477 6477
6478 // Step 3: Set up a CrossThreadWeakPersistent. 6478 // Step 3: Set up a CrossThreadWeakPersistent.
6479 ASSERT_TRUE(object); 6479 ASSERT_TRUE(object);
6480 CrossThreadWeakPersistent<DestructorLockingObject> crossThreadWeakPersistent (object); 6480 CrossThreadWeakPersistent<DestructorLockingObject> crossThreadWeakPersistent (object);
6481 object = nullptr; 6481 object = nullptr;
6482 { 6482 {
6483 SafePointAwareMutexLocker recursiveMutexLocker(recursiveMutex()); 6483 SafePointAwareMutexLocker recursiveMutexLocker(recursiveMutex());
6484 EXPECT_EQ(0, DestructorLockingObject::s_destructorCalls); 6484 EXPECT_EQ(0, DestructorLockingObject::s_destructorCalls);
6485 } 6485 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
6526 EXPECT_EQ(1u, vector2.size()); 6526 EXPECT_EQ(1u, vector2.size());
6527 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables 6527 // TODO(Oilpan): when Vector.h's contiguous container support no longer disables
6528 // Vector<>s with inline capacity, remove. 6528 // Vector<>s with inline capacity, remove.
6529 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) 6529 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER)
6530 EXPECT_EQ(16u, vector1.capacity()); 6530 EXPECT_EQ(16u, vector1.capacity());
6531 EXPECT_EQ(16u, vector2.capacity()); 6531 EXPECT_EQ(16u, vector2.capacity());
6532 #endif 6532 #endif
6533 } 6533 }
6534 6534
6535 } // namespace blink 6535 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/HeapPage.cpp ('k') | third_party/WebKit/Source/web/WebNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698