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

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

Issue 1220253004: Implement a fast buffer allocator for Vector, HashTable and StringBuilder Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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/HeapAllocator.h ('k') | Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/ThreadState.h
diff --git a/Source/platform/heap/ThreadState.h b/Source/platform/heap/ThreadState.h
index c098f13abb01baaeb028f556f20bbfca355640a8..ad2aae20643a80f84d08696fa74d5b545b731525 100644
--- a/Source/platform/heap/ThreadState.h
+++ b/Source/platform/heap/ThreadState.h
@@ -204,7 +204,11 @@ public:
Vector3HeapIndex,
Vector4HeapIndex,
InlineVectorHeapIndex,
- HashTableHeapIndex,
+ HashTable1HeapIndex,
+ HashTable2HeapIndex,
+ HashTable3HeapIndex,
+ HashTable4HeapIndex,
+ BufferStringHeapIndex,
FOR_EACH_TYPED_HEAP(TypedHeapEnumName)
LargeObjectHeapIndex,
// Values used for iteration of heap segments.
@@ -285,10 +289,12 @@ public:
// call thread can start using the garbage collected heap infrastructure.
// It also has to periodically check for safepoints.
static void attach();
+ bool attached() const { return m_attached; }
// Disassociate attached ThreadState from the current thread. The thread
// can no longer use the garbage collected heap after this call.
static void detach();
+ void cleanupPages();
static ThreadState* current()
{
@@ -316,6 +322,9 @@ public:
return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage);
}
+ explicit ThreadState(bool shouldAttach = true);
+ ~ThreadState();
+
bool isMainThread() const { return this == mainThreadState(); }
#if ENABLE(ASSERT)
bool checkThread() const { return m_thread == currentThread(); }
@@ -631,7 +640,6 @@ public:
//
BaseHeap* vectorBackingHeap(size_t gcInfoIndex)
{
- ASSERT(checkThread());
size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask;
--m_likelyToBePromptlyFreed[entryIndex];
int heapIndex = m_vectorBackingHeapIndex;
@@ -640,9 +648,15 @@ public:
// since the last GC.
if (m_likelyToBePromptlyFreed[entryIndex] > 0) {
m_heapAges[heapIndex] = ++m_currentHeapAges;
- m_vectorBackingHeapIndex = heapIndexOfVectorHeapLeastRecentlyExpanded(Vector1HeapIndex, Vector4HeapIndex);
+ m_vectorBackingHeapIndex = heapIndexOfLeastRecentlyExpanded(Vector1HeapIndex, Vector4HeapIndex);
}
ASSERT(isVectorHeapIndex(heapIndex));
+#if BUFFER_ALLOCATOR_DEBUG
+ if (!attached() && heapIndex != m_vectorBackingHeapIndex)
+ fprintf(stderr, "heap index updated: %d => %d\n", heapIndex, m_vectorBackingHeapIndex);
+ if (!attached())
+ fprintf(stderr, "vectorBackingHeap: heapIndex=%d, likely=%d\n", heapIndex, m_likelyToBePromptlyFreed[entryIndex]);
+#endif
return m_heaps[heapIndex];
}
BaseHeap* expandedVectorBackingHeap(size_t gcInfoIndex);
@@ -650,8 +664,35 @@ public:
{
return Vector1HeapIndex <= heapIndex && heapIndex <= Vector4HeapIndex;
}
+ BaseHeap* hashTableBackingHeap(size_t gcInfoIndex)
+ {
+ size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask;
+ --m_likelyToBePromptlyFreed[entryIndex];
+ int heapIndex = m_hashTableBackingHeapIndex;
+ // If m_likelyToBePromptlyFreed[entryIndex] > 0, that means that
+ // more than 33% of hash tables of the type have been promptly freed
+ // since the last GC.
+ if (m_likelyToBePromptlyFreed[entryIndex] > 0) {
+ m_heapAges[heapIndex] = ++m_currentHeapAges;
+ m_hashTableBackingHeapIndex = heapIndexOfLeastRecentlyExpanded(HashTable1HeapIndex, HashTable4HeapIndex);
+ }
+ ASSERT(isHashTableHeapIndex(heapIndex));
+#if BUFFER_ALLOCATOR_DEBUG
+ if (!attached() && heapIndex != m_hashTableBackingHeapIndex)
+ fprintf(stderr, "heap index updated: %d => %d\n", heapIndex, m_hashTableBackingHeapIndex);
+ if (!attached())
+ fprintf(stderr, "hashTableBackingHeap: heapIndex=%d, likely=%d\n", heapIndex, m_likelyToBePromptlyFreed[entryIndex]);
+#endif
+ return m_heaps[heapIndex];
+ }
+ BaseHeap* expandedHashTableBackingHeap(size_t gcInfoIndex);
+ static bool isHashTableHeapIndex(int heapIndex)
+ {
+ return HashTable1HeapIndex <= heapIndex && heapIndex <= HashTable4HeapIndex;
+ }
void allocationPointAdjusted(int heapIndex);
void promptlyFreed(size_t gcInfoIndex);
+ void clearHeapAges();
private:
enum SnapshotType {
@@ -659,9 +700,6 @@ private:
FreelistSnapshot
};
- ThreadState();
- ~ThreadState();
-
NO_SANITIZE_ADDRESS void copyStackUntilSafePointScope();
void clearSafePointScopeMarker()
{
@@ -669,6 +707,15 @@ private:
m_safePointScopeMarker = nullptr;
}
+ // When ThreadState is detaching from non-main thread its
+ // heap is expected to be empty (because it is going away).
+ // Perform registered cleanup tasks and garbage collection
+ // to sweep away any objects that are left on this heap.
+ // We assert that nothing must remain after this cleanup.
+ // If assertion does not hold we crash as we are potentially
+ // in the dangling pointer situation.
+ void cleanup();
+
// shouldSchedule{Precise,Idle}GC and shouldForceConservativeGC
// implement the heuristics that are used to determine when to collect garbage.
// If shouldForceConservativeGC returns true, we force the garbage
@@ -695,24 +742,13 @@ private:
void poisonAllHeaps();
#endif
- // When ThreadState is detaching from non-main thread its
- // heap is expected to be empty (because it is going away).
- // Perform registered cleanup tasks and garbage collection
- // to sweep away any objects that are left on this heap.
- // We assert that nothing must remain after this cleanup.
- // If assertion does not hold we crash as we are potentially
- // in the dangling pointer situation.
- void cleanup();
- void cleanupPages();
-
void invokePreFinalizers();
void takeSnapshot(SnapshotType);
#if ENABLE(GC_PROFILING)
void snapshotFreeList();
#endif
- void clearHeapAges();
- int heapIndexOfVectorHeapLeastRecentlyExpanded(int beginHeapIndex, int endHeapIndex);
+ int heapIndexOfLeastRecentlyExpanded(int beginHeapIndex, int endHeapIndex);
using InterruptorVector = Vector<OwnPtr<Interruptor>>;
@@ -737,6 +773,7 @@ private:
// and lazily construct ThreadState in it using placement new.
static uint8_t s_mainThreadStateStorage[];
+ bool m_attached;
ThreadIdentifier m_thread;
OwnPtr<PersistentRegion> m_persistentRegion;
StackState m_stackState;
@@ -754,6 +791,7 @@ private:
BaseHeap* m_heaps[NumberOfHeaps];
int m_vectorBackingHeapIndex;
+ int m_hashTableBackingHeapIndex;
size_t m_heapAges[NumberOfHeaps];
size_t m_currentHeapAges;
« no previous file with comments | « Source/platform/heap/HeapAllocator.h ('k') | Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698