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

Unified Diff: third_party/WebKit/Source/platform/heap/HeapTest.cpp

Issue 1957523007: Cleanly release thread-local static persistents during termination GCs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/heap/HeapTest.cpp
diff --git a/third_party/WebKit/Source/platform/heap/HeapTest.cpp b/third_party/WebKit/Source/platform/heap/HeapTest.cpp
index 32afcf147f5b4b9682c3c759654daf21e0ac98c0..9810e94dc593b50d24f60b1a1341b44bae7693d1 100644
--- a/third_party/WebKit/Source/platform/heap/HeapTest.cpp
+++ b/third_party/WebKit/Source/platform/heap/HeapTest.cpp
@@ -6498,14 +6498,27 @@ public:
}
private:
+ void runWhileAttached();
+
void runThread() override
{
ThreadState::attachCurrentThread(false);
EXPECT_EQ(42, threadSpecificIntWrapper().value());
+ runWhileAttached();
ThreadState::detachCurrentThread();
atomicDecrement(&m_threadsToFinish);
}
+ class HeapObject;
+ friend class HeapObject;
+
+ using WeakHeapObjectSet = PersistentHeapHashSet<WeakMember<HeapObject>>;
+
+ static WeakHeapObjectSet& weakHeapObjectSet();
+
+ using HeapObjectSet = PersistentHeapHashSet<Member<HeapObject>>;
+ static HeapObjectSet& heapObjectSet();
+
static IntWrapper& threadSpecificIntWrapper()
{
DEFINE_THREAD_SAFE_STATIC_LOCAL(
@@ -6520,6 +6533,69 @@ private:
}
};
+class ThreadedClearOnShutdownTester::HeapObject final : public GarbageCollectedFinalized<ThreadedClearOnShutdownTester::HeapObject> {
+public:
+ static HeapObject* create(bool testDestructor)
+ {
+ return new HeapObject(testDestructor);
+ }
+
+ ~HeapObject()
+ {
+ if (!m_testDestructor)
+ return;
+
+ // Verify that the weak reference is gone.
+ EXPECT_FALSE(weakHeapObjectSet().contains(this));
+
+ // Add a new member to the static singleton; this will
+ // re-initializes the persistent node of the collection
+ // object. Done while terminating the test thread, so
+ // verify that this brings about the release of the
+ // persistent also.
+ heapObjectSet().add(create(false));
+ }
+
+ DEFINE_INLINE_TRACE() { }
+
+private:
+ explicit HeapObject(bool testDestructor)
+ : m_testDestructor(testDestructor)
+ {
+ }
+
+ bool m_testDestructor;
+};
+
+ThreadedClearOnShutdownTester::WeakHeapObjectSet& ThreadedClearOnShutdownTester::weakHeapObjectSet()
+{
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(
+ ThreadSpecific<WeakHeapObjectSet>, singleton,
+ new ThreadSpecific<WeakHeapObjectSet>);
+ if (!singleton.isSet())
+ singleton->registerAsStaticReference();
+
+ return *singleton;
+}
+
+ThreadedClearOnShutdownTester::HeapObjectSet& ThreadedClearOnShutdownTester::heapObjectSet()
+{
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(
+ ThreadSpecific<HeapObjectSet>, singleton,
+ new ThreadSpecific<HeapObjectSet>);
+ if (!singleton.isSet())
+ singleton->registerAsStaticReference();
+
+ return *singleton;
+}
+
+void ThreadedClearOnShutdownTester::runWhileAttached()
+{
+ EXPECT_EQ(42, threadSpecificIntWrapper().value());
+ // Creates a thread-specific singleton to a weakly held object.
+ weakHeapObjectSet().add(HeapObject::create(true));
+}
+
} // namespace
TEST(HeapTest, TestClearOnShutdown)
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Handle.h ('k') | third_party/WebKit/Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698