OLD | NEW |
---|---|
1 /* | 1 // Copyright (c) 2013 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 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITIONS_H |
32 #define Partitions_h | 6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITIONS_H |
33 | 7 |
34 #include "wtf/WTF.h" | |
35 #include "wtf/WTFExport.h" | |
36 #include "wtf/allocator/PartitionAlloc.h" | |
37 #include <string.h> | 8 #include <string.h> |
38 | 9 |
39 namespace WTF { | 10 #include "base/allocator/partition_allocator/partition_alloc.h" |
11 #include "base/base_export.h" | |
40 | 12 |
41 class WTF_EXPORT Partitions { | 13 namespace base { |
14 | |
15 class BASE_EXPORT Partitions { | |
42 public: | 16 public: |
43 typedef void (*ReportPartitionAllocSizeFunction)(size_t); | 17 typedef void (*ReportPartitionAllocSizeFunction)(size_t); |
44 | 18 |
45 // Name of allocator used by tracing for marking sub-allocations while take | 19 // Name of allocator used by tracing for marking sub-allocations while take |
46 // memory snapshots. | 20 // memory snapshots. |
47 static const char* const kAllocatedObjectPoolName; | 21 static const char* const kAllocatedObjectPoolName; |
48 | 22 |
49 static void initialize(ReportPartitionAllocSizeFunction); | 23 static void initialize(ReportPartitionAllocSizeFunction); |
50 static void shutdown(); | 24 static void shutdown(); |
51 ALWAYS_INLINE static PartitionRootGeneric* bufferPartition() { | 25 ALWAYS_INLINE static PartitionRootGeneric* bufferPartition() { |
haraken
2016/11/22 03:55:11
These methods are Blink-specific things, so I'd ke
palmer
2016/11/24 01:05:56
Done.
| |
52 ASSERT(s_initialized); | 26 DCHECK(s_initialized); |
53 return m_bufferAllocator.root(); | 27 return m_bufferAllocator.root(); |
54 } | 28 } |
55 | 29 |
56 ALWAYS_INLINE static PartitionRootGeneric* fastMallocPartition() { | 30 ALWAYS_INLINE static PartitionRootGeneric* fastMallocPartition() { |
57 ASSERT(s_initialized); | 31 DCHECK(s_initialized); |
58 return m_fastMallocAllocator.root(); | 32 return m_fastMallocAllocator.root(); |
59 } | 33 } |
60 | 34 |
61 ALWAYS_INLINE static PartitionRoot* nodePartition() { | 35 ALWAYS_INLINE static PartitionRoot* nodePartition() { |
62 ASSERT_NOT_REACHED(); | 36 NOTREACHED(); |
63 return nullptr; | 37 return nullptr; |
64 } | 38 } |
65 ALWAYS_INLINE static PartitionRoot* layoutPartition() { | 39 ALWAYS_INLINE static PartitionRoot* layoutPartition() { |
66 ASSERT(s_initialized); | 40 DCHECK(s_initialized); |
67 return m_layoutAllocator.root(); | 41 return m_layoutAllocator.root(); |
68 } | 42 } |
69 | 43 |
70 static size_t currentDOMMemoryUsage() { | 44 static size_t currentDOMMemoryUsage() { |
71 ASSERT(s_initialized); | 45 DCHECK(s_initialized); |
72 ASSERT_NOT_REACHED(); | 46 NOTREACHED(); |
73 return 0; | 47 return 0; |
74 } | 48 } |
75 | 49 |
76 static size_t totalSizeOfCommittedPages() { | 50 static size_t totalSizeOfCommittedPages() { |
77 size_t totalSize = 0; | 51 size_t totalSize = 0; |
78 totalSize += m_fastMallocAllocator.root()->totalSizeOfCommittedPages; | 52 totalSize += m_fastMallocAllocator.root()->totalSizeOfCommittedPages; |
79 totalSize += m_bufferAllocator.root()->totalSizeOfCommittedPages; | 53 totalSize += m_bufferAllocator.root()->totalSizeOfCommittedPages; |
80 totalSize += m_layoutAllocator.root()->totalSizeOfCommittedPages; | 54 totalSize += m_layoutAllocator.root()->totalSizeOfCommittedPages; |
81 return totalSize; | 55 return totalSize; |
82 } | 56 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 return partitionReallocGeneric(Partitions::fastMallocPartition(), p, n, | 88 return partitionReallocGeneric(Partitions::fastMallocPartition(), p, n, |
115 typeName); | 89 typeName); |
116 } | 90 } |
117 static void fastFree(void* p) { | 91 static void fastFree(void* p) { |
118 partitionFreeGeneric(Partitions::fastMallocPartition(), p); | 92 partitionFreeGeneric(Partitions::fastMallocPartition(), p); |
119 } | 93 } |
120 | 94 |
121 static void handleOutOfMemory(); | 95 static void handleOutOfMemory(); |
122 | 96 |
123 private: | 97 private: |
124 static SpinLock s_initializationLock; | 98 static subtle::SpinLock s_initializationLock; |
125 static bool s_initialized; | 99 static bool s_initialized; |
126 | 100 |
127 // We have the following four partitions. | 101 // We have the following four partitions. |
128 // - LayoutObject partition: A partition to allocate LayoutObjects. | 102 // - LayoutObject partition: A partition to allocate LayoutObjects. |
129 // We prepare a dedicated partition for LayoutObjects because they | 103 // We prepare a dedicated partition for LayoutObjects because they |
130 // are likely to be a source of use-after-frees. Another reason | 104 // are likely to be a source of use-after-frees. Another reason |
131 // is for performance: As LayoutObjects are guaranteed to only be used | 105 // 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 | 106 // by the main thread, we can bypass acquiring a lock. Also we can |
133 // improve memory locality by putting LayoutObjects together. | 107 // improve memory locality by putting LayoutObjects together. |
134 // - Buffer partition: A partition to allocate objects that have a strong | 108 // - Buffer partition: A partition to allocate objects that have a strong |
135 // risk where the length and/or the contents are exploited from user | 109 // risk where the length and/or the contents are exploited from user |
136 // scripts. Vectors, HashTables, ArrayBufferContents and Strings are | 110 // scripts. Vectors, HashTables, ArrayBufferContents and Strings are |
137 // allocated in the buffer partition. | 111 // allocated in the buffer partition. |
138 // - Fast malloc partition: A partition to allocate all other objects. | 112 // - Fast malloc partition: A partition to allocate all other objects. |
139 static PartitionAllocatorGeneric m_fastMallocAllocator; | 113 static PartitionAllocatorGeneric m_fastMallocAllocator; |
140 static PartitionAllocatorGeneric m_bufferAllocator; | 114 static PartitionAllocatorGeneric m_bufferAllocator; |
141 static SizeSpecificPartitionAllocator<1024> m_layoutAllocator; | 115 static SizeSpecificPartitionAllocator<1024> m_layoutAllocator; |
142 static ReportPartitionAllocSizeFunction m_reportSizeFunction; | 116 static ReportPartitionAllocSizeFunction m_reportSizeFunction; |
143 }; | 117 }; |
144 | 118 |
145 } // namespace WTF | 119 } // namespace base |
146 | 120 |
147 #endif // Partitions_h | 121 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITIONS_H |
OLD | NEW |