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 PageMemory_h | 5 #ifndef PageMemory_h |
6 #define PageMemory_h | 6 #define PageMemory_h |
7 | 7 |
8 #include "platform/heap/HeapPage.h" | 8 #include "platform/heap/HeapPage.h" |
| 9 #include "wtf/Allocator.h" |
9 #include "wtf/Assertions.h" | 10 #include "wtf/Assertions.h" |
10 #include "wtf/PageAllocator.h" | 11 #include "wtf/PageAllocator.h" |
11 | 12 |
12 #if OS(POSIX) | 13 #if OS(POSIX) |
13 #include <sys/mman.h> | 14 #include <sys/mman.h> |
14 #include <unistd.h> | 15 #include <unistd.h> |
15 #endif | 16 #endif |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 class MemoryRegion { | 20 class MemoryRegion { |
| 21 USING_FAST_MALLOC(MemoryRegion); |
20 public: | 22 public: |
21 MemoryRegion(Address base, size_t size) | 23 MemoryRegion(Address base, size_t size) |
22 : m_base(base) | 24 : m_base(base) |
23 , m_size(size) | 25 , m_size(size) |
24 { | 26 { |
25 ASSERT(size > 0); | 27 ASSERT(size > 0); |
26 } | 28 } |
27 | 29 |
28 bool contains(Address addr) const | 30 bool contains(Address addr) const |
29 { | 31 { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 static PageMemoryRegion* allocate(size_t, unsigned numPages); | 113 static PageMemoryRegion* allocate(size_t, unsigned numPages); |
112 | 114 |
113 bool m_isLargePage; | 115 bool m_isLargePage; |
114 bool m_inUse[blinkPagesPerRegion]; | 116 bool m_inUse[blinkPagesPerRegion]; |
115 unsigned m_numPages; | 117 unsigned m_numPages; |
116 }; | 118 }; |
117 | 119 |
118 // A RegionTree is a simple binary search tree of PageMemoryRegions sorted | 120 // A RegionTree is a simple binary search tree of PageMemoryRegions sorted |
119 // by base addresses. | 121 // by base addresses. |
120 class RegionTree { | 122 class RegionTree { |
| 123 USING_FAST_MALLOC(RegionTree); |
121 public: | 124 public: |
122 explicit RegionTree(PageMemoryRegion* region) | 125 explicit RegionTree(PageMemoryRegion* region) |
123 : m_region(region) | 126 : m_region(region) |
124 , m_left(nullptr) | 127 , m_left(nullptr) |
125 , m_right(nullptr) | 128 , m_right(nullptr) |
126 { | 129 { |
127 } | 130 } |
128 | 131 |
129 ~RegionTree() | 132 ~RegionTree() |
130 { | 133 { |
(...skipping 22 matching lines...) Expand all Loading... |
153 // instances can share the same reserved memory region and | 156 // instances can share the same reserved memory region and |
154 // therefore notify the reserved memory region on destruction so | 157 // therefore notify the reserved memory region on destruction so |
155 // that the system memory can be given back when all PageMemory | 158 // that the system memory can be given back when all PageMemory |
156 // instances for that memory are gone. | 159 // instances for that memory are gone. |
157 // | 160 // |
158 // 2. The writable memory (a sub-region of the reserved virtual | 161 // 2. The writable memory (a sub-region of the reserved virtual |
159 // memory region) that is used for the actual heap page payload. | 162 // memory region) that is used for the actual heap page payload. |
160 // | 163 // |
161 // Guard pages are created before and after the writable memory. | 164 // Guard pages are created before and after the writable memory. |
162 class PageMemory { | 165 class PageMemory { |
| 166 USING_FAST_MALLOC(PageMemory); |
163 public: | 167 public: |
164 ~PageMemory() | 168 ~PageMemory() |
165 { | 169 { |
166 __lsan_unregister_root_region(m_writable.base(), m_writable.size()); | 170 __lsan_unregister_root_region(m_writable.base(), m_writable.size()); |
167 m_reserved->pageDeleted(writableStart()); | 171 m_reserved->pageDeleted(writableStart()); |
168 } | 172 } |
169 | 173 |
170 WARN_UNUSED_RETURN bool commit() | 174 WARN_UNUSED_RETURN bool commit() |
171 { | 175 { |
172 m_reserved->markPageUsed(writableStart()); | 176 m_reserved->markPageUsed(writableStart()); |
(...skipping 27 matching lines...) Expand all Loading... |
200 private: | 204 private: |
201 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable); | 205 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable); |
202 | 206 |
203 PageMemoryRegion* m_reserved; | 207 PageMemoryRegion* m_reserved; |
204 MemoryRegion m_writable; | 208 MemoryRegion m_writable; |
205 }; | 209 }; |
206 | 210 |
207 } // namespace blink | 211 } // namespace blink |
208 | 212 |
209 #endif | 213 #endif |
OLD | NEW |