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

Unified Diff: Source/platform/heap/ThreadState.cpp

Issue 556823003: Revert "Revert of [oilpan]: optimize the way we allocate persistent handles in wrappers. (patchset … (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: review feedback Created 6 years, 3 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
« no previous file with comments | « Source/platform/heap/ThreadState.h ('k') | Source/platform/heap/blink_heap.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/ThreadState.cpp
diff --git a/Source/platform/heap/ThreadState.cpp b/Source/platform/heap/ThreadState.cpp
index dc651aece9d6ba3995f62280db05427bb1200533..be6bedd19b9a1dbdc761ed7d5dc19462022220ea 100644
--- a/Source/platform/heap/ThreadState.cpp
+++ b/Source/platform/heap/ThreadState.cpp
@@ -95,6 +95,9 @@ static void* getStackStart()
#endif
}
+// The maximum number of WrapperPersistentRegions to keep around in the
+// m_pooledWrapperPersistentRegions pool.
+static const size_t MaxPooledWrapperPersistentRegionCount = 2;
WTF::ThreadSpecific<ThreadState*>* ThreadState::s_threadSpecific = 0;
uint8_t ThreadState::s_mainThreadStateStorage[sizeof(ThreadState)];
@@ -265,7 +268,6 @@ private:
ThreadCondition m_resume;
};
-
BaseHeapPage::BaseHeapPage(PageMemory* storage, const GCInfo* gcInfo, ThreadState* state)
: m_storage(storage)
, m_gcInfo(gcInfo)
@@ -292,6 +294,9 @@ template<> struct InitializeHeaps<0> {
ThreadState::ThreadState()
: m_thread(currentThread())
+ , m_liveWrapperPersistents(new WrapperPersistentRegion())
+ , m_pooledWrapperPersistents(0)
+ , m_pooledWrapperPersistentRegionCount(0)
, m_persistents(adoptPtr(new PersistentAnchor()))
, m_startOfStack(reinterpret_cast<intptr_t*>(getStackStart()))
, m_endOfStack(reinterpret_cast<intptr_t*>(getStackStart()))
@@ -330,6 +335,14 @@ ThreadState::~ThreadState()
for (int i = 0; i < NumberOfHeaps; i++)
delete m_heaps[i];
deleteAllValues(m_interruptors);
+ while (m_liveWrapperPersistents) {
+ WrapperPersistentRegion* region = WrapperPersistentRegion::removeHead(&m_liveWrapperPersistents);
+ delete region;
+ }
+ while (m_pooledWrapperPersistents) {
+ WrapperPersistentRegion* region = WrapperPersistentRegion::removeHead(&m_pooledWrapperPersistents);
+ delete region;
+ }
**s_threadSpecific = 0;
}
@@ -561,6 +574,7 @@ void ThreadState::visitStack(Visitor* visitor)
void ThreadState::visitPersistents(Visitor* visitor)
{
m_persistents->trace(visitor);
+ WrapperPersistentRegion::trace(m_liveWrapperPersistents, visitor);
}
bool ThreadState::checkAndMarkPointer(Visitor* visitor, Address address)
@@ -680,6 +694,34 @@ bool ThreadState::popAndInvokeWeakPointerCallback(Visitor* visitor)
return m_weakCallbackStack->popAndInvokeCallback<WeaknessProcessing>(&m_weakCallbackStack, visitor);
}
+WrapperPersistentRegion* ThreadState::takeWrapperPersistentRegion()
+{
+ WrapperPersistentRegion* region;
+ if (m_pooledWrapperPersistentRegionCount) {
+ region = WrapperPersistentRegion::removeHead(&m_pooledWrapperPersistents);
+ m_pooledWrapperPersistentRegionCount--;
+ } else {
+ region = new WrapperPersistentRegion();
+ }
+ ASSERT(region);
+ WrapperPersistentRegion::insertHead(&m_liveWrapperPersistents, region);
+ return region;
+}
+
+void ThreadState::freeWrapperPersistentRegion(WrapperPersistentRegion* region)
+{
+ if (!region->removeIfNotLast(&m_liveWrapperPersistents))
+ return;
+
+ // Region was removed, ie. it was not the last region in the list.
+ if (m_pooledWrapperPersistentRegionCount < MaxPooledWrapperPersistentRegionCount) {
+ WrapperPersistentRegion::insertHead(&m_pooledWrapperPersistents, region);
+ m_pooledWrapperPersistentRegionCount++;
+ } else {
+ delete region;
+ }
+}
+
PersistentNode* ThreadState::globalRoots()
{
AtomicallyInitializedStatic(PersistentNode*, anchor = new PersistentAnchor);
« no previous file with comments | « Source/platform/heap/ThreadState.h ('k') | Source/platform/heap/blink_heap.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698