Chromium Code Reviews| 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; |