| Index: Source/platform/heap/HeapTest.cpp
|
| diff --git a/Source/platform/heap/HeapTest.cpp b/Source/platform/heap/HeapTest.cpp
|
| index efca31223ec1f2b0360c5a01208a1f138ceeb71d..11fe61874253ef740bdb263c6ddfe278ae5a591e 100644
|
| --- a/Source/platform/heap/HeapTest.cpp
|
| +++ b/Source/platform/heap/HeapTest.cpp
|
| @@ -36,6 +36,7 @@
|
| #include "platform/heap/HeapTerminatedArrayBuilder.h"
|
| #include "platform/heap/ThreadState.h"
|
| #include "platform/heap/Visitor.h"
|
| +#include "public/platform/Platform.h"
|
| #include "wtf/HashTraits.h"
|
| #include "wtf/LinkedHashSet.h"
|
|
|
| @@ -99,28 +100,39 @@ public:
|
| explicit TestGCScope(ThreadState::StackState state)
|
| : m_state(ThreadState::current())
|
| , m_safePointScope(state)
|
| + , m_parkedAllThreads(false)
|
| {
|
| m_state->checkThread();
|
| ASSERT(!m_state->isInGC());
|
| - ThreadState::stopThreads();
|
| - m_state->enterGC();
|
| + if (LIKELY(ThreadState::stopThreads())) {
|
| + m_state->enterGC();
|
| + m_parkedAllThreads = true;
|
| + }
|
| }
|
|
|
| + bool allThreadsParked() { return m_parkedAllThreads; }
|
| +
|
| ~TestGCScope()
|
| {
|
| - m_state->leaveGC();
|
| - ASSERT(!m_state->isInGC());
|
| - ThreadState::resumeThreads();
|
| + // Only cleanup if we parked all threads in which case the GC happened
|
| + // and we need to resume the other threads.
|
| + if (LIKELY(m_parkedAllThreads)) {
|
| + m_state->leaveGC();
|
| + ASSERT(!m_state->isInGC());
|
| + ThreadState::resumeThreads();
|
| + }
|
| }
|
|
|
| private:
|
| ThreadState* m_state;
|
| ThreadState::SafePointScope m_safePointScope;
|
| + bool m_parkedAllThreads; // False if we fail to park all threads
|
| };
|
|
|
| static void getHeapStats(HeapStats* stats)
|
| {
|
| TestGCScope scope(ThreadState::NoHeapPointersOnStack);
|
| + EXPECT_TRUE(scope.allThreadsParked());
|
| Heap::getStats(stats);
|
| }
|
|
|
| @@ -3170,6 +3182,7 @@ TEST(HeapTest, CheckAndMarkPointer)
|
| // checkAndMarkPointer tests.
|
| {
|
| TestGCScope scope(ThreadState::HeapPointersOnStack);
|
| + EXPECT_TRUE(scope.allThreadsParked()); // Fail the test if we could not park all threads.
|
| Heap::makeConsistentForGC();
|
| for (size_t i = 0; i < objectAddresses.size(); i++) {
|
| EXPECT_TRUE(Heap::checkAndMarkPointer(&visitor, objectAddresses[i]));
|
| @@ -3188,6 +3201,7 @@ TEST(HeapTest, CheckAndMarkPointer)
|
| clearOutOldGarbage(&initialHeapStats);
|
| {
|
| TestGCScope scope(ThreadState::HeapPointersOnStack);
|
| + EXPECT_TRUE(scope.allThreadsParked());
|
| Heap::makeConsistentForGC();
|
| for (size_t i = 0; i < objectAddresses.size(); i++) {
|
| EXPECT_FALSE(Heap::checkAndMarkPointer(&visitor, objectAddresses[i]));
|
| @@ -3623,4 +3637,62 @@ TEST(HeapTest, DestructorsCalledOnMapClear)
|
| ASSERT(SimpleClassWithDestructor::s_wasDestructed);
|
| }
|
|
|
| +
|
| +class GCParkingThreadTester {
|
| +public:
|
| + static void test()
|
| + {
|
| + createThread(&sleeperMainFunc, 0, "SleepingThread");
|
| +
|
| + // Wait for the sleeper to run.
|
| + while (!s_sleeperRunning) {
|
| + yield();
|
| + }
|
| +
|
| + {
|
| + // Expect the first attempt to park the sleeping thread to fail
|
| + TestGCScope scope(ThreadState::NoHeapPointersOnStack);
|
| + EXPECT_FALSE(scope.allThreadsParked());
|
| + }
|
| +
|
| + s_sleeperDone = true;
|
| +
|
| + // Wait for the sleeper to finish.
|
| + while (s_sleeperRunning) {
|
| + yield();
|
| + }
|
| + {
|
| + // Since the sleeper thread has detached this is the only thread.
|
| + TestGCScope scope(ThreadState::NoHeapPointersOnStack);
|
| + EXPECT_TRUE(scope.allThreadsParked());
|
| + }
|
| + }
|
| +
|
| +private:
|
| + static void sleeperMainFunc(void* data)
|
| + {
|
| + ThreadState::attach();
|
| + s_sleeperRunning = true;
|
| +
|
| + // Simulate a long running op that is not entering a safepoint.
|
| + while (!s_sleeperDone) {
|
| + yield();
|
| + }
|
| +
|
| + ThreadState::detach();
|
| + s_sleeperRunning = false;
|
| + }
|
| +
|
| + static volatile bool s_sleeperRunning;
|
| + static volatile bool s_sleeperDone;
|
| +};
|
| +
|
| +volatile bool GCParkingThreadTester::s_sleeperRunning = false;
|
| +volatile bool GCParkingThreadTester::s_sleeperDone = false;
|
| +
|
| +TEST(HeapTest, GCParkingTimeout)
|
| +{
|
| + GCParkingThreadTester::test();
|
| +}
|
| +
|
| } // WebCore namespace
|
|
|