OLD | NEW |
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 Loading... |
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 #include "config.h" | 31 #include "config.h" |
32 #include "wtf/Partitions.h" | 32 #include "wtf/Partitions.h" |
33 | 33 |
| 34 #include "wtf/Alias.h" |
34 #include "wtf/DefaultAllocator.h" | 35 #include "wtf/DefaultAllocator.h" |
35 #include "wtf/FastMalloc.h" | 36 #include "wtf/FastMalloc.h" |
36 #include "wtf/MainThread.h" | 37 #include "wtf/MainThread.h" |
37 | 38 |
38 namespace WTF { | 39 namespace WTF { |
39 | 40 |
40 int Partitions::s_initializationLock = 0; | 41 int Partitions::s_initializationLock = 0; |
41 bool Partitions::s_initialized = false; | 42 bool Partitions::s_initialized = false; |
42 | 43 |
43 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; | 44 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; |
44 PartitionAllocatorGeneric Partitions::m_bufferAllocator; | 45 PartitionAllocatorGeneric Partitions::m_bufferAllocator; |
45 SizeSpecificPartitionAllocator<3328> Partitions::m_nodeAllocator; | 46 SizeSpecificPartitionAllocator<3328> Partitions::m_nodeAllocator; |
46 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; | 47 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; |
47 HistogramEnumerationFunction Partitions::m_histogramEnumeration = nullptr; | 48 HistogramEnumerationFunction Partitions::m_histogramEnumeration = nullptr; |
48 | 49 |
49 void Partitions::initialize() | 50 void Partitions::initialize() |
50 { | 51 { |
51 spinLockLock(&s_initializationLock); | 52 spinLockLock(&s_initializationLock); |
52 | 53 |
53 if (!s_initialized) { | 54 if (!s_initialized) { |
| 55 partitionAllocGlobalInit(&Partitions::handleOutOfMemory); |
54 m_fastMallocAllocator.init(); | 56 m_fastMallocAllocator.init(); |
55 m_bufferAllocator.init(); | 57 m_bufferAllocator.init(); |
56 m_nodeAllocator.init(); | 58 m_nodeAllocator.init(); |
57 m_layoutAllocator.init(); | 59 m_layoutAllocator.init(); |
58 s_initialized = true; | 60 s_initialized = true; |
59 } | 61 } |
60 | 62 |
61 spinLockUnlock(&s_initializationLock); | 63 spinLockUnlock(&s_initializationLock); |
62 } | 64 } |
63 | 65 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // Object model and rendering partitions are not thread safe and can be | 117 // Object model and rendering partitions are not thread safe and can be |
116 // accessed only on the main thread. | 118 // accessed only on the main thread. |
117 ASSERT(isMainThread()); | 119 ASSERT(isMainThread()); |
118 | 120 |
119 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc_partition", is
LightDump, partitionStatsDumper); | 121 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc_partition", is
LightDump, partitionStatsDumper); |
120 partitionDumpStatsGeneric(bufferPartition(), "buffer_partition", isLightDump
, partitionStatsDumper); | 122 partitionDumpStatsGeneric(bufferPartition(), "buffer_partition", isLightDump
, partitionStatsDumper); |
121 partitionDumpStats(nodePartition(), "node_partition", isLightDump, partition
StatsDumper); | 123 partitionDumpStats(nodePartition(), "node_partition", isLightDump, partition
StatsDumper); |
122 partitionDumpStats(layoutPartition(), "layout_partition", isLightDump, parti
tionStatsDumper); | 124 partitionDumpStats(layoutPartition(), "layout_partition", isLightDump, parti
tionStatsDumper); |
123 } | 125 } |
124 | 126 |
| 127 static NEVER_INLINE void partitionsOutOfMemoryUsing2G() |
| 128 { |
| 129 size_t signature = 2UL * 1024 * 1024 * 1024; |
| 130 alias(&signature); |
| 131 IMMEDIATE_CRASH(); |
| 132 } |
| 133 |
| 134 static NEVER_INLINE void partitionsOutOfMemoryUsing1G() |
| 135 { |
| 136 size_t signature = 1UL * 1024 * 1024 * 1024; |
| 137 alias(&signature); |
| 138 IMMEDIATE_CRASH(); |
| 139 } |
| 140 |
| 141 static NEVER_INLINE void partitionsOutOfMemoryUsing512M() |
| 142 { |
| 143 size_t signature = 512 * 1024 * 1024; |
| 144 alias(&signature); |
| 145 IMMEDIATE_CRASH(); |
| 146 } |
| 147 |
| 148 static NEVER_INLINE void partitionsOutOfMemoryUsing256M() |
| 149 { |
| 150 size_t signature = 256 * 1024 * 1024; |
| 151 alias(&signature); |
| 152 IMMEDIATE_CRASH(); |
| 153 } |
| 154 |
| 155 static NEVER_INLINE void partitionsOutOfMemoryUsing128M() |
| 156 { |
| 157 size_t signature = 128 * 1024 * 1024; |
| 158 alias(&signature); |
| 159 IMMEDIATE_CRASH(); |
| 160 } |
| 161 |
| 162 static NEVER_INLINE void partitionsOutOfMemoryUsing64M() |
| 163 { |
| 164 size_t signature = 64 * 1024 * 1024; |
| 165 alias(&signature); |
| 166 IMMEDIATE_CRASH(); |
| 167 } |
| 168 |
| 169 static NEVER_INLINE void partitionsOutOfMemoryUsing32M() |
| 170 { |
| 171 size_t signature = 32 * 1024 * 1024; |
| 172 alias(&signature); |
| 173 IMMEDIATE_CRASH(); |
| 174 } |
| 175 |
| 176 static NEVER_INLINE void partitionsOutOfMemoryUsing16M() |
| 177 { |
| 178 size_t signature = 16 * 1024 * 1024; |
| 179 alias(&signature); |
| 180 IMMEDIATE_CRASH(); |
| 181 } |
| 182 |
| 183 static NEVER_INLINE void partitionsOutOfMemoryUsingLessThan16M() |
| 184 { |
| 185 size_t signature = 16 * 1024 * 1024 - 1; |
| 186 alias(&signature); |
| 187 IMMEDIATE_CRASH(); |
| 188 } |
| 189 |
| 190 void Partitions::handleOutOfMemory() |
| 191 { |
| 192 volatile size_t totalUsage = totalSizeOfCommittedPages(); |
| 193 |
| 194 if (totalUsage >= 2UL * 1024 * 1024 * 1024) |
| 195 partitionsOutOfMemoryUsing2G(); |
| 196 if (totalUsage >= 1UL * 1024 * 1024 * 1024) |
| 197 partitionsOutOfMemoryUsing1G(); |
| 198 if (totalUsage >= 512 * 1024 * 1024) |
| 199 partitionsOutOfMemoryUsing512M(); |
| 200 if (totalUsage >= 256 * 1024 * 1024) |
| 201 partitionsOutOfMemoryUsing256M(); |
| 202 if (totalUsage >= 128 * 1024 * 1024) |
| 203 partitionsOutOfMemoryUsing128M(); |
| 204 if (totalUsage >= 64 * 1024 * 1024) |
| 205 partitionsOutOfMemoryUsing64M(); |
| 206 if (totalUsage >= 32 * 1024 * 1024) |
| 207 partitionsOutOfMemoryUsing32M(); |
| 208 if (totalUsage >= 16 * 1024 * 1024) |
| 209 partitionsOutOfMemoryUsing16M(); |
| 210 partitionsOutOfMemoryUsingLessThan16M(); |
| 211 } |
| 212 |
125 } // namespace WTF | 213 } // namespace WTF |
OLD | NEW |