| 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/ThreadingPrimitives.h" | 9 #include "wtf/ThreadingPrimitives.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 class BasePage; | 13 class BasePage; |
| 14 class PageMemory; | 14 class PageMemory; |
| 15 | 15 |
| 16 template<typename DataType> | 16 template<typename DataType> |
| 17 class PagePool { | 17 class PagePool { |
| 18 protected: | 18 protected: |
| 19 PagePool() | 19 PagePool() |
| 20 { | 20 { |
| 21 for (int i = 0; i < ThreadState::NumberOfHeaps; ++i) | 21 for (int i = 0; i < BlinkGC::NumberOfHeaps; ++i) |
| 22 m_pool[i] = nullptr; | 22 m_pool[i] = nullptr; |
| 23 } | 23 } |
| 24 | 24 |
| 25 class PoolEntry { | 25 class PoolEntry { |
| 26 public: | 26 public: |
| 27 PoolEntry(DataType* data, PoolEntry* next) | 27 PoolEntry(DataType* data, PoolEntry* next) |
| 28 : data(data) | 28 : data(data) |
| 29 , next(next) | 29 , next(next) |
| 30 { } | 30 { } |
| 31 | 31 |
| 32 DataType* data; | 32 DataType* data; |
| 33 PoolEntry* next; | 33 PoolEntry* next; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 PoolEntry* m_pool[ThreadState::NumberOfHeaps]; | 36 PoolEntry* m_pool[BlinkGC::NumberOfHeaps]; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // Once pages have been used for one type of thread heap they will never be | 39 // 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 | 40 // 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 | 41 // 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 | 42 // type. This is done as a security feature to avoid type confusion. The |
| 43 // heaps are type segregated by having separate thread heaps for different | 43 // heaps are type segregated by having separate thread heaps for different |
| 44 // types of objects. Holding on to pages ensures that the same virtual address | 44 // 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 | 45 // space cannot be used for objects of another type than the type contained |
| 46 // in this page to begin with. | 46 // in this page to begin with. |
| 47 class FreePagePool : public PagePool<PageMemory> { | 47 class FreePagePool : public PagePool<PageMemory> { |
| 48 public: | 48 public: |
| 49 ~FreePagePool(); | 49 ~FreePagePool(); |
| 50 void addFreePage(int, PageMemory*); | 50 void addFreePage(int, PageMemory*); |
| 51 PageMemory* takeFreePage(int); | 51 PageMemory* takeFreePage(int); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 Mutex m_mutex[ThreadState::NumberOfHeaps]; | 54 Mutex m_mutex[BlinkGC::NumberOfHeaps]; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class OrphanedPagePool : public PagePool<BasePage> { | 57 class OrphanedPagePool : public PagePool<BasePage> { |
| 58 public: | 58 public: |
| 59 // The orphaned zap value must be zero in the lowest bits to allow for | 59 // The orphaned zap value must be zero in the lowest bits to allow for |
| 60 // using the mark bit when tracing. | 60 // using the mark bit when tracing. |
| 61 static const uint8_t orphanedZapValue = 0xdc; | 61 static const uint8_t orphanedZapValue = 0xdc; |
| 62 | 62 |
| 63 ~OrphanedPagePool(); | 63 ~OrphanedPagePool(); |
| 64 void addOrphanedPage(int, BasePage*); | 64 void addOrphanedPage(int, BasePage*); |
| 65 void decommitOrphanedPages(); | 65 void decommitOrphanedPages(); |
| 66 #if ENABLE(ASSERT) | 66 #if ENABLE(ASSERT) |
| 67 bool contains(void*); | 67 bool contains(void*); |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 // For orphaned pages, we need to memset with ASan disabled, because | 70 // For orphaned pages, we need to memset with ASan disabled, because |
| 71 // the orphaned pages can still contain poisoned memory or annotated | 71 // the orphaned pages can still contain poisoned memory or annotated |
| 72 // container but we want to forcibly clear the orphaned pages without | 72 // container but we want to forcibly clear the orphaned pages without |
| 73 // causing ASan errors. asanDisabledMemset must not be used for | 73 // causing ASan errors. asanDisabledMemset must not be used for |
| 74 // non-orphaned pages. | 74 // non-orphaned pages. |
| 75 static void asanDisabledMemset(Address, char, size_t); | 75 static void asanDisabledMemset(Address, char, size_t); |
| 76 private: | 76 private: |
| 77 void clearMemory(PageMemory*); | 77 void clearMemory(PageMemory*); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace blink | 80 } // namespace blink |
| 81 | 81 |
| 82 #endif | 82 #endif |
| OLD | NEW |