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

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

Issue 2762943002: Move files in wtf/ to platform/wtf/ (Part 6). (Closed)
Patch Set: Rebase. Created 3 years, 9 months 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 // Copyright 2017 The Chromium Authors. All rights reserved.
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be
3 * 3 // found in the LICENSE file.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30 4
31 #ifndef Partitions_h 5 #include "platform/wtf/allocator/Partitions.h"
32 #define Partitions_h
33 6
34 #include <string.h> 7 // The contents of this header was moved to platform/wtf as part of
35 #include "base/allocator/partition_allocator/partition_alloc.h" 8 // WTF migration project. See the following post for details:
36 #include "base/allocator/partition_allocator/spin_lock.h" 9 // https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gY CAAJ
37 #include "wtf/Assertions.h"
38 #include "wtf/WTF.h"
39 #include "wtf/WTFExport.h"
40
41 namespace WTF {
42
43 class WTF_EXPORT Partitions {
44 public:
45 typedef void (*ReportPartitionAllocSizeFunction)(size_t);
46
47 // Name of allocator used by tracing for marking sub-allocations while take
48 // memory snapshots.
49 static const char* const kAllocatedObjectPoolName;
50
51 static void initialize(ReportPartitionAllocSizeFunction);
52 ALWAYS_INLINE static base::PartitionRootGeneric* arrayBufferPartition() {
53 DCHECK(s_initialized);
54 return m_arrayBufferAllocator.root();
55 }
56
57 ALWAYS_INLINE static base::PartitionRootGeneric* bufferPartition() {
58 DCHECK(s_initialized);
59 return m_bufferAllocator.root();
60 }
61
62 ALWAYS_INLINE static base::PartitionRootGeneric* fastMallocPartition() {
63 DCHECK(s_initialized);
64 return m_fastMallocAllocator.root();
65 }
66
67 ALWAYS_INLINE static base::PartitionRoot* nodePartition() {
68 NOTREACHED();
69 return nullptr;
70 }
71 ALWAYS_INLINE static base::PartitionRoot* layoutPartition() {
72 DCHECK(s_initialized);
73 return m_layoutAllocator.root();
74 }
75
76 static size_t currentDOMMemoryUsage() {
77 NOTREACHED();
78 return 0;
79 }
80
81 static size_t totalSizeOfCommittedPages() {
82 size_t totalSize = 0;
83 totalSize += m_fastMallocAllocator.root()->total_size_of_committed_pages;
84 totalSize += m_arrayBufferAllocator.root()->total_size_of_committed_pages;
85 totalSize += m_bufferAllocator.root()->total_size_of_committed_pages;
86 totalSize += m_layoutAllocator.root()->total_size_of_committed_pages;
87 return totalSize;
88 }
89
90 static void decommitFreeableMemory();
91
92 static void reportMemoryUsageHistogram();
93
94 static void dumpMemoryStats(bool isLightDump, base::PartitionStatsDumper*);
95
96 ALWAYS_INLINE static void* bufferMalloc(size_t n, const char* typeName) {
97 return PartitionAllocGeneric(bufferPartition(), n, typeName);
98 }
99 ALWAYS_INLINE static void* bufferRealloc(void* p,
100 size_t n,
101 const char* typeName) {
102 return PartitionReallocGeneric(bufferPartition(), p, n, typeName);
103 }
104 ALWAYS_INLINE static void bufferFree(void* p) {
105 PartitionFreeGeneric(bufferPartition(), p);
106 }
107 ALWAYS_INLINE static size_t bufferActualSize(size_t n) {
108 return PartitionAllocActualSize(bufferPartition(), n);
109 }
110 static void* fastMalloc(size_t n, const char* typeName) {
111 return PartitionAllocGeneric(Partitions::fastMallocPartition(), n,
112 typeName);
113 }
114 static void* fastZeroedMalloc(size_t n, const char* typeName) {
115 void* result = fastMalloc(n, typeName);
116 memset(result, 0, n);
117 return result;
118 }
119 static void* fastRealloc(void* p, size_t n, const char* typeName) {
120 return PartitionReallocGeneric(Partitions::fastMallocPartition(), p, n,
121 typeName);
122 }
123 static void fastFree(void* p) {
124 PartitionFreeGeneric(Partitions::fastMallocPartition(), p);
125 }
126
127 static void handleOutOfMemory();
128
129 private:
130 static base::subtle::SpinLock s_initializationLock;
131 static bool s_initialized;
132
133 // We have the following four partitions.
134 // - LayoutObject partition: A partition to allocate LayoutObjects.
135 // We prepare a dedicated partition for LayoutObjects because they
136 // are likely to be a source of use-after-frees. Another reason
137 // is for performance: As LayoutObjects are guaranteed to only be used
138 // by the main thread, we can bypass acquiring a lock. Also we can
139 // improve memory locality by putting LayoutObjects together.
140 // - ArrayBuffer partition: A partition to allocate array buffers.
141 // - Buffer partition: A partition to allocate other buffers that have
142 // a strong risk where the length and/or the contents are exploited from
143 // user scripts. Vectors, HashTables and Strings are allocated in the
144 // buffer partition.
145 // - Fast malloc partition: A partition to allocate all other objects.
146 static base::PartitionAllocatorGeneric m_fastMallocAllocator;
147 static base::PartitionAllocatorGeneric m_arrayBufferAllocator;
148 static base::PartitionAllocatorGeneric m_bufferAllocator;
149 static base::SizeSpecificPartitionAllocator<1024> m_layoutAllocator;
150 static ReportPartitionAllocSizeFunction m_reportSizeFunction;
151 };
152
153 using base::kGenericMaxDirectMapped;
154 using base::kPageAllocationGranularity;
155 using base::kPageAllocationGranularityBaseMask;
156 using base::kPageAllocationGranularityOffsetMask;
157 using base::kSystemPageSize;
158
159 using base::AllocPages;
160 using base::DecommitSystemPages;
161 using base::DiscardSystemPages;
162 using base::PartitionFree;
163 using base::FreePages;
164 using base::GetAllocPageErrorCode;
165 using base::RecommitSystemPages;
166 using base::RoundDownToSystemPage;
167 using base::RoundUpToSystemPage;
168 using base::SetSystemPagesAccessible;
169 using base::SetSystemPagesInaccessible;
170
171 using base::PageAccessible;
172 using base::PageInaccessible;
173 using base::PartitionStatsDumper;
174 using base::PartitionMemoryStats;
175 using base::PartitionBucketMemoryStats;
176 using base::PartitionAllocHooks;
177
178 } // namespace WTF
179
180 #endif // Partitions_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/allocator/PartitionAllocator.cpp ('k') | third_party/WebKit/Source/wtf/allocator/Partitions.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698