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

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

Issue 1138663002: Oilpan: support eager finalization/sweeping. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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
« no previous file with comments | « no previous file | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/Heap.h
diff --git a/Source/platform/heap/Heap.h b/Source/platform/heap/Heap.h
index d4ebf651d764e4f85b3a8ddff28bc1a8617ee1c5..b066d13f748fb1407eba8ed9010d806003e9452b 100644
--- a/Source/platform/heap/Heap.h
+++ b/Source/platform/heap/Heap.h
@@ -1122,23 +1122,47 @@ protected:
}
};
-// We use sized heaps for normal pages to improve memory locality.
+// Assigning class types to their heaps.
+//
+// We use sized heaps for most 'normal' objcts to improve memory locality.
haraken 2015/05/11 01:20:27 objects
// It seems that the same type of objects are likely to be accessed together,
-// which means that we want to group objects by type. That's why we provide
-// dedicated heaps for popular types (e.g., Node, CSSValue), but it's not
-// practical to prepare dedicated heaps for all types. Thus we group objects
-// by their sizes, hoping that it will approximately group objects
-// by their types.
-static int heapIndexForNormalHeap(size_t size)
-{
- if (size < 64) {
- if (size < 32)
+// which means that we want to group objects by type. That's one reason
+// why we provide dedicated heaps for popular types (e.g., Node, CSSValue),
+// but it's not practical to prepare dedicated heaps for all types.
+// Thus we group objects by their sizes, hoping that this will approximately
+// group objects by their types.
+//
+// An exception to the use of sized heaps is made for class types that
+// require prompt finalization after a garbage collection. That is, their
+// instances have to be finalized early and cannot be delayed until lazy
+// sweeping kicks in for their heap and page. The WILL_BE_EAGERLY_SWEPT()
+// macro is used to declare a class (and its derived classes) as being
+// in need of 'eager sweeping'.
+//
+template<typename T, typename Enabled = void>
+class HeapIndexTrait {
+public:
+ static int heapIndexForObject(size_t size)
+ {
+ if (size < 64) {
+ if (size < 32)
return NormalPage1HeapIndex;
haraken 2015/05/11 01:20:27 Indent
- return NormalPage2HeapIndex;
- }
- if (size < 128)
+ return NormalPage2HeapIndex;
+ }
+ if (size < 128)
return NormalPage3HeapIndex;
haraken 2015/05/11 01:20:27 Indent
- return NormalPage4HeapIndex;
+ return NormalPage4HeapIndex;
+ }
+};
+
+#define WILL_BE_EAGERLY_SWEPT(TYPE) \
haraken 2015/05/11 01:20:27 WILL_BE_EAGERLY_SWEPT => EAGERLY_SWEPT ?
sof 2015/05/11 05:20:22 That doesn't give enough context about what this i
haraken 2015/05/11 06:44:07 XWillBeY means that it is X on non-oilpan and it i
sof 2015/05/19 15:00:15 Naming. I've now prefixed OILPAN_ to give some ha
+template<typename T> \
+class HeapIndexTrait<T, typename WTF::EnableIf<WTF::IsSubclass<T, TYPE>::value>::Type> { \
+public: \
+ static int heapIndexForObject(size_t) \
+ { \
+ return EagerSweepHeapIndex; \
+ } \
}
NO_SANITIZE_ADDRESS inline
@@ -1259,7 +1283,7 @@ template<typename T>
Address Heap::allocate(size_t size)
{
ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state();
- return Heap::allocateOnHeapIndex(state, size, heapIndexForNormalHeap(size), GCInfoTrait<T>::index());
+ return Heap::allocateOnHeapIndex(state, size, HeapIndexTrait<T>::heapIndexForObject(size), GCInfoTrait<T>::index());
}
template<typename T>
@@ -1273,7 +1297,7 @@ Address Heap::reallocate(void* previous, size_t size)
ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state();
// TODO(haraken): reallocate() should use the heap that the original object
// is using. This won't be a big deal since reallocate() is rarely used.
- Address address = Heap::allocateOnHeapIndex(state, size, heapIndexForNormalHeap(size), GCInfoTrait<T>::index());
+ Address address = Heap::allocateOnHeapIndex(state, size, HeapIndexTrait<T>::heapIndexForObject(size), GCInfoTrait<T>::index());
if (!previous) {
// This is equivalent to malloc(size).
return address;
« no previous file with comments | « no previous file | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698