| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PagePool_h | 5 #ifndef PagePool_h |
| 6 #define PagePool_h | 6 #define PagePool_h |
| 7 | 7 |
| 8 #include "platform/heap/ThreadState.h" | 8 #include "platform/heap/ThreadState.h" |
| 9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
| 10 #include "wtf/ThreadingPrimitives.h" | 10 #include "wtf/ThreadingPrimitives.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class PageMemory; | 14 class PageMemory; |
| 15 | 15 |
| 16 template <typename DataType> | |
| 17 class PagePool { | |
| 18 USING_FAST_MALLOC(PagePool); | |
| 19 | |
| 20 protected: | |
| 21 PagePool() { | |
| 22 for (int i = 0; i < BlinkGC::NumberOfArenas; ++i) | |
| 23 m_pool[i] = nullptr; | |
| 24 } | |
| 25 | |
| 26 class PoolEntry { | |
| 27 USING_FAST_MALLOC(PoolEntry); | |
| 28 | |
| 29 public: | |
| 30 PoolEntry(DataType* data, PoolEntry* next) : data(data), next(next) {} | |
| 31 | |
| 32 DataType* data; | |
| 33 PoolEntry* next; | |
| 34 }; | |
| 35 | |
| 36 PoolEntry* m_pool[BlinkGC::NumberOfArenas]; | |
| 37 }; | |
| 38 | |
| 39 // Once pages have been used for one type of thread heap they will never be | 16 // Once pages have been used for one type of thread heap they will never be |
| 40 // reused for another type of thread heap. Instead of unmapping, we add the | 17 // reused for another type of thread heap. Instead of unmapping, we add the |
| 41 // pages to a pool of pages to be reused later by a thread heap of the same | 18 // pages to a pool of pages to be reused later by a thread heap of the same |
| 42 // type. This is done as a security feature to avoid type confusion. The | 19 // type. This is done as a security feature to avoid type confusion. The |
| 43 // heaps are type segregated by having separate thread arenas for different | 20 // heaps are type segregated by having separate thread arenas for different |
| 44 // types of objects. Holding on to pages ensures that the same virtual address | 21 // types of objects. Holding on to pages ensures that the same virtual address |
| 45 // space cannot be used for objects of another type than the type contained | 22 // space cannot be used for objects of another type than the type contained |
| 46 // in this page to begin with. | 23 // in this page to begin with. |
| 47 class FreePagePool : public PagePool<PageMemory> { | 24 class PagePool { |
| 25 USING_FAST_MALLOC(PagePool); |
| 26 |
| 48 public: | 27 public: |
| 49 ~FreePagePool(); | 28 PagePool(); |
| 50 void addFreePage(int, PageMemory*); | 29 ~PagePool(); |
| 51 PageMemory* takeFreePage(int); | 30 void add(int, PageMemory*); |
| 31 PageMemory* take(int); |
| 52 | 32 |
| 53 private: | 33 private: |
| 34 class PoolEntry { |
| 35 USING_FAST_MALLOC(PoolEntry); |
| 36 |
| 37 public: |
| 38 PoolEntry(PageMemory* data, PoolEntry* next) : data(data), next(next) {} |
| 39 |
| 40 PageMemory* data; |
| 41 PoolEntry* next; |
| 42 }; |
| 43 |
| 44 PoolEntry* m_pool[BlinkGC::NumberOfArenas]; |
| 54 Mutex m_mutex[BlinkGC::NumberOfArenas]; | 45 Mutex m_mutex[BlinkGC::NumberOfArenas]; |
| 55 }; | 46 }; |
| 56 | 47 |
| 57 } // namespace blink | 48 } // namespace blink |
| 58 | 49 |
| 59 #endif | 50 #endif |
| OLD | NEW |