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/Allocator.h" |
10 #include "wtf/Assertions.h" | 10 #include "wtf/Assertions.h" |
11 #include "wtf/Compiler.h" | 11 #include "wtf/Compiler.h" |
12 #include "wtf/allocator/Partitions.h" | 12 #include "wtf/allocator/Partitions.h" |
13 | 13 |
14 #if OS(POSIX) | 14 #if OS(POSIX) |
15 #include <sys/mman.h> | 15 #include <sys/mman.h> |
16 #include <unistd.h> | 16 #include <unistd.h> |
17 #endif | 17 #endif |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 | 20 |
21 class RegionTree; | 21 class RegionTree; |
22 class RegionTreeNode; | 22 class RegionTreeNode; |
23 | 23 |
24 class MemoryRegion { | 24 class MemoryRegion { |
25 USING_FAST_MALLOC(MemoryRegion); | 25 USING_FAST_MALLOC(MemoryRegion); |
26 | 26 |
27 public: | 27 public: |
28 MemoryRegion(Address base, size_t size) : m_base(base), m_size(size) { | 28 MemoryRegion(Address base, size_t size) : m_base(base), m_size(size) { |
29 ASSERT(size > 0); | 29 DCHECK_GT(size, 0UL); |
30 } | 30 } |
31 | 31 |
32 bool contains(Address addr) const { | 32 bool contains(Address addr) const { |
33 return m_base <= addr && addr < (m_base + m_size); | 33 return m_base <= addr && addr < (m_base + m_size); |
34 } | 34 } |
35 | 35 |
36 bool contains(const MemoryRegion& other) const { | 36 bool contains(const MemoryRegion& other) const { |
37 return contains(other.m_base) && contains(other.m_base + other.m_size - 1); | 37 return contains(other.m_base) && contains(other.m_base + other.m_size - 1); |
38 } | 38 } |
39 | 39 |
(...skipping 15 matching lines...) Expand all Loading... |
55 // whole. The PageMemoryRegion allows us to do that by keeping track | 55 // whole. The PageMemoryRegion allows us to do that by keeping track |
56 // of the number of pages using it in order to be able to release all | 56 // of the number of pages using it in order to be able to release all |
57 // of the virtual address space when there are no more pages using it. | 57 // of the virtual address space when there are no more pages using it. |
58 class PageMemoryRegion : public MemoryRegion { | 58 class PageMemoryRegion : public MemoryRegion { |
59 public: | 59 public: |
60 ~PageMemoryRegion(); | 60 ~PageMemoryRegion(); |
61 | 61 |
62 void pageDeleted(Address); | 62 void pageDeleted(Address); |
63 | 63 |
64 void markPageUsed(Address page) { | 64 void markPageUsed(Address page) { |
65 ASSERT(!m_inUse[index(page)]); | 65 DCHECK(!m_inUse[index(page)]); |
66 m_inUse[index(page)] = true; | 66 m_inUse[index(page)] = true; |
67 } | 67 } |
68 | 68 |
69 void markPageUnused(Address page) { m_inUse[index(page)] = false; } | 69 void markPageUnused(Address page) { m_inUse[index(page)] = false; } |
70 | 70 |
71 static PageMemoryRegion* allocateLargePage(size_t size, | 71 static PageMemoryRegion* allocateLargePage(size_t size, |
72 RegionTree* regionTree) { | 72 RegionTree* regionTree) { |
73 return allocate(size, 1, regionTree); | 73 return allocate(size, 1, regionTree); |
74 } | 74 } |
75 | 75 |
76 static PageMemoryRegion* allocateNormalPages(RegionTree* regionTree) { | 76 static PageMemoryRegion* allocateNormalPages(RegionTree* regionTree) { |
77 return allocate(blinkPageSize * blinkPagesPerRegion, blinkPagesPerRegion, | 77 return allocate(blinkPageSize * blinkPagesPerRegion, blinkPagesPerRegion, |
78 regionTree); | 78 regionTree); |
79 } | 79 } |
80 | 80 |
81 BasePage* pageFromAddress(Address address) { | 81 BasePage* pageFromAddress(Address address) { |
82 ASSERT(contains(address)); | 82 DCHECK(contains(address)); |
83 if (!m_inUse[index(address)]) | 83 if (!m_inUse[index(address)]) |
84 return nullptr; | 84 return nullptr; |
85 if (m_isLargePage) | 85 if (m_isLargePage) |
86 return pageFromObject(base()); | 86 return pageFromObject(base()); |
87 return pageFromObject(address); | 87 return pageFromObject(address); |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
91 PageMemoryRegion(Address base, size_t, unsigned numPages, RegionTree*); | 91 PageMemoryRegion(Address base, size_t, unsigned numPages, RegionTree*); |
92 | 92 |
93 unsigned index(Address address) const { | 93 unsigned index(Address address) const { |
94 ASSERT(contains(address)); | 94 DCHECK(contains(address)); |
95 if (m_isLargePage) | 95 if (m_isLargePage) |
96 return 0; | 96 return 0; |
97 size_t offset = blinkPageAddress(address) - base(); | 97 size_t offset = blinkPageAddress(address) - base(); |
98 ASSERT(offset % blinkPageSize == 0); | 98 DCHECK_EQ(offset % blinkPageSize, 0UL); |
99 return offset / blinkPageSize; | 99 return offset / blinkPageSize; |
100 } | 100 } |
101 | 101 |
102 static PageMemoryRegion* allocate(size_t, unsigned numPages, RegionTree*); | 102 static PageMemoryRegion* allocate(size_t, unsigned numPages, RegionTree*); |
103 | 103 |
104 const bool m_isLargePage; | 104 const bool m_isLargePage; |
105 // A thread owns a page, but not a region. Represent the in-use | 105 // A thread owns a page, but not a region. Represent the in-use |
106 // bitmap such that thread non-interference comes for free. | 106 // bitmap such that thread non-interference comes for free. |
107 bool m_inUse[blinkPagesPerRegion]; | 107 bool m_inUse[blinkPagesPerRegion]; |
108 int m_numPages; | 108 int m_numPages; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 private: | 205 private: |
206 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable); | 206 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable); |
207 | 207 |
208 PageMemoryRegion* m_reserved; | 208 PageMemoryRegion* m_reserved; |
209 MemoryRegion m_writable; | 209 MemoryRegion m_writable; |
210 }; | 210 }; |
211 | 211 |
212 } // namespace blink | 212 } // namespace blink |
213 | 213 |
214 #endif | 214 #endif |
OLD | NEW |