Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: third_party/WebKit/Source/wtf/allocator/Partitions.h

Issue 2518253002: Move Partition Allocator into Chromium base. (Closed)
Patch Set: Rebase and resolve conflict. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef Partitions_h 31 #ifndef Partitions_h
32 #define Partitions_h 32 #define Partitions_h
33 33
34 #include "base/allocator/partition_allocator/partition_alloc.h"
35 #include "base/synchronization/spin_lock.h"
36 #include "wtf/Assertions.h"
34 #include "wtf/WTF.h" 37 #include "wtf/WTF.h"
35 #include "wtf/WTFExport.h" 38 #include "wtf/WTFExport.h"
36 #include "wtf/allocator/PartitionAlloc.h"
37 #include <string.h> 39 #include <string.h>
38 40
39 namespace WTF { 41 namespace WTF {
40 42
41 class WTF_EXPORT Partitions { 43 class WTF_EXPORT Partitions {
42 public: 44 public:
43 typedef void (*ReportPartitionAllocSizeFunction)(size_t); 45 typedef void (*ReportPartitionAllocSizeFunction)(size_t);
44 46
45 // Name of allocator used by tracing for marking sub-allocations while take 47 // Name of allocator used by tracing for marking sub-allocations while take
46 // memory snapshots. 48 // memory snapshots.
47 static const char* const kAllocatedObjectPoolName; 49 static const char* const kAllocatedObjectPoolName;
48 50
49 static void initialize(ReportPartitionAllocSizeFunction); 51 static void initialize(ReportPartitionAllocSizeFunction);
50 static void shutdown(); 52 static void shutdown();
51 ALWAYS_INLINE static PartitionRootGeneric* bufferPartition() { 53 ALWAYS_INLINE static base::PartitionRootGeneric* bufferPartition() {
52 ASSERT(s_initialized); 54 ASSERT(s_initialized);
53 return m_bufferAllocator.root(); 55 return m_bufferAllocator.root();
54 } 56 }
55 57
56 ALWAYS_INLINE static PartitionRootGeneric* fastMallocPartition() { 58 ALWAYS_INLINE static base::PartitionRootGeneric* fastMallocPartition() {
57 ASSERT(s_initialized); 59 ASSERT(s_initialized);
58 return m_fastMallocAllocator.root(); 60 return m_fastMallocAllocator.root();
59 } 61 }
60 62
61 ALWAYS_INLINE static PartitionRoot* nodePartition() { 63 ALWAYS_INLINE static base::PartitionRoot* nodePartition() {
62 ASSERT_NOT_REACHED(); 64 ASSERT_NOT_REACHED();
63 return nullptr; 65 return nullptr;
64 } 66 }
65 ALWAYS_INLINE static PartitionRoot* layoutPartition() { 67 ALWAYS_INLINE static base::PartitionRoot* layoutPartition() {
66 ASSERT(s_initialized); 68 ASSERT(s_initialized);
67 return m_layoutAllocator.root(); 69 return m_layoutAllocator.root();
68 } 70 }
69 71
70 static size_t currentDOMMemoryUsage() { 72 static size_t currentDOMMemoryUsage() {
71 ASSERT(s_initialized); 73 ASSERT(s_initialized);
72 ASSERT_NOT_REACHED(); 74 ASSERT_NOT_REACHED();
73 return 0; 75 return 0;
74 } 76 }
75 77
76 static size_t totalSizeOfCommittedPages() { 78 static size_t totalSizeOfCommittedPages() {
77 size_t totalSize = 0; 79 size_t totalSize = 0;
78 totalSize += m_fastMallocAllocator.root()->totalSizeOfCommittedPages; 80 totalSize += m_fastMallocAllocator.root()->totalSizeOfCommittedPages;
79 totalSize += m_bufferAllocator.root()->totalSizeOfCommittedPages; 81 totalSize += m_bufferAllocator.root()->totalSizeOfCommittedPages;
80 totalSize += m_layoutAllocator.root()->totalSizeOfCommittedPages; 82 totalSize += m_layoutAllocator.root()->totalSizeOfCommittedPages;
81 return totalSize; 83 return totalSize;
82 } 84 }
83 85
84 static void decommitFreeableMemory(); 86 static void decommitFreeableMemory();
85 87
86 static void reportMemoryUsageHistogram(); 88 static void reportMemoryUsageHistogram();
87 89
88 static void dumpMemoryStats(bool isLightDump, PartitionStatsDumper*); 90 static void dumpMemoryStats(bool isLightDump, base::PartitionStatsDumper*);
89 91
90 ALWAYS_INLINE static void* bufferMalloc(size_t n, const char* typeName) { 92 ALWAYS_INLINE static void* bufferMalloc(size_t n, const char* typeName) {
91 return partitionAllocGeneric(bufferPartition(), n, typeName); 93 return partitionAllocGeneric(bufferPartition(), n, typeName);
92 } 94 }
93 ALWAYS_INLINE static void* bufferRealloc(void* p, 95 ALWAYS_INLINE static void* bufferRealloc(void* p,
94 size_t n, 96 size_t n,
95 const char* typeName) { 97 const char* typeName) {
96 return partitionReallocGeneric(bufferPartition(), p, n, typeName); 98 return partitionReallocGeneric(bufferPartition(), p, n, typeName);
97 } 99 }
98 ALWAYS_INLINE static void bufferFree(void* p) { 100 ALWAYS_INLINE static void bufferFree(void* p) {
(...skipping 15 matching lines...) Expand all
114 return partitionReallocGeneric(Partitions::fastMallocPartition(), p, n, 116 return partitionReallocGeneric(Partitions::fastMallocPartition(), p, n,
115 typeName); 117 typeName);
116 } 118 }
117 static void fastFree(void* p) { 119 static void fastFree(void* p) {
118 partitionFreeGeneric(Partitions::fastMallocPartition(), p); 120 partitionFreeGeneric(Partitions::fastMallocPartition(), p);
119 } 121 }
120 122
121 static void handleOutOfMemory(); 123 static void handleOutOfMemory();
122 124
123 private: 125 private:
124 static SpinLock s_initializationLock; 126 static base::subtle::SpinLock s_initializationLock;
125 static bool s_initialized; 127 static bool s_initialized;
126 128
127 // We have the following four partitions. 129 // We have the following four partitions.
128 // - LayoutObject partition: A partition to allocate LayoutObjects. 130 // - LayoutObject partition: A partition to allocate LayoutObjects.
129 // We prepare a dedicated partition for LayoutObjects because they 131 // We prepare a dedicated partition for LayoutObjects because they
130 // are likely to be a source of use-after-frees. Another reason 132 // are likely to be a source of use-after-frees. Another reason
131 // is for performance: As LayoutObjects are guaranteed to only be used 133 // is for performance: As LayoutObjects are guaranteed to only be used
132 // by the main thread, we can bypass acquiring a lock. Also we can 134 // by the main thread, we can bypass acquiring a lock. Also we can
133 // improve memory locality by putting LayoutObjects together. 135 // improve memory locality by putting LayoutObjects together.
134 // - Buffer partition: A partition to allocate objects that have a strong 136 // - Buffer partition: A partition to allocate objects that have a strong
135 // risk where the length and/or the contents are exploited from user 137 // risk where the length and/or the contents are exploited from user
136 // scripts. Vectors, HashTables, ArrayBufferContents and Strings are 138 // scripts. Vectors, HashTables, ArrayBufferContents and Strings are
137 // allocated in the buffer partition. 139 // allocated in the buffer partition.
138 // - Fast malloc partition: A partition to allocate all other objects. 140 // - Fast malloc partition: A partition to allocate all other objects.
139 static PartitionAllocatorGeneric m_fastMallocAllocator; 141 static base::PartitionAllocatorGeneric m_fastMallocAllocator;
140 static PartitionAllocatorGeneric m_bufferAllocator; 142 static base::PartitionAllocatorGeneric m_bufferAllocator;
141 static SizeSpecificPartitionAllocator<1024> m_layoutAllocator; 143 static base::SizeSpecificPartitionAllocator<1024> m_layoutAllocator;
142 static ReportPartitionAllocSizeFunction m_reportSizeFunction; 144 static ReportPartitionAllocSizeFunction m_reportSizeFunction;
143 }; 145 };
144 146
147 using base::kGenericMaxDirectMapped;
haraken 2016/12/08 08:43:55 Hmm, these using statements look nasty. I'd prefer
palmer 2016/12/08 22:29:58 They are not good. :)
148 using base::kPageAllocationGranularity;
149 using base::kPageAllocationGranularityBaseMask;
150 using base::kPageAllocationGranularityOffsetMask;
151 using base::kSystemPageSize;
152
153 using base::allocPages;
154 using base::decommitSystemPages;
155 using base::discardSystemPages;
156 using base::partitionFree;
157 using base::freePages;
158 using base::getAllocPageErrorCode;
159 using base::recommitSystemPages;
160 using base::roundDownToSystemPage;
161 using base::roundUpToSystemPage;
162 using base::setSystemPagesAccessible;
163 using base::setSystemPagesInaccessible;
164
165 using base::PageAccessible;
166 using base::PageInaccessible;
167 using base::PartitionStatsDumper;
168 using base::PartitionMemoryStats;
169 using base::PartitionBucketMemoryStats;
170 using base::PartitionAllocHooks;
171
145 } // namespace WTF 172 } // namespace WTF
146 173
147 #endif // Partitions_h 174 #endif // Partitions_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698