| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 namespace WTF { | 36 namespace WTF { |
| 37 | 37 |
| 38 const char* const Partitions::kAllocatedObjectPoolName = "partition_alloc/alloca
ted_objects"; | 38 const char* const Partitions::kAllocatedObjectPoolName = "partition_alloc/alloca
ted_objects"; |
| 39 | 39 |
| 40 SpinLock Partitions::s_initializationLock; | 40 SpinLock Partitions::s_initializationLock; |
| 41 bool Partitions::s_initialized = false; | 41 bool Partitions::s_initialized = false; |
| 42 | 42 |
| 43 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; | 43 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; |
| 44 PartitionAllocatorGeneric Partitions::m_bufferAllocator; | 44 PartitionAllocatorGeneric Partitions::m_bufferAllocator; |
| 45 #if !ENABLE(OILPAN) | |
| 46 SizeSpecificPartitionAllocator<3328> Partitions::m_nodeAllocator; | |
| 47 #endif | |
| 48 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; | 45 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; |
| 49 Partitions::ReportPartitionAllocSizeFunction Partitions::m_reportSizeFunction =
nullptr; | 46 Partitions::ReportPartitionAllocSizeFunction Partitions::m_reportSizeFunction =
nullptr; |
| 50 | 47 |
| 51 void Partitions::initialize(ReportPartitionAllocSizeFunction reportSizeFunction) | 48 void Partitions::initialize(ReportPartitionAllocSizeFunction reportSizeFunction) |
| 52 { | 49 { |
| 53 SpinLock::Guard guard(s_initializationLock); | 50 SpinLock::Guard guard(s_initializationLock); |
| 54 | 51 |
| 55 if (!s_initialized) { | 52 if (!s_initialized) { |
| 56 partitionAllocGlobalInit(&Partitions::handleOutOfMemory); | 53 partitionAllocGlobalInit(&Partitions::handleOutOfMemory); |
| 57 m_fastMallocAllocator.init(); | 54 m_fastMallocAllocator.init(); |
| 58 m_bufferAllocator.init(); | 55 m_bufferAllocator.init(); |
| 59 #if !ENABLE(OILPAN) | |
| 60 m_nodeAllocator.init(); | |
| 61 #endif | |
| 62 m_layoutAllocator.init(); | 56 m_layoutAllocator.init(); |
| 63 m_reportSizeFunction = reportSizeFunction; | 57 m_reportSizeFunction = reportSizeFunction; |
| 64 s_initialized = true; | 58 s_initialized = true; |
| 65 } | 59 } |
| 66 } | 60 } |
| 67 | 61 |
| 68 void Partitions::shutdown() | 62 void Partitions::shutdown() |
| 69 { | 63 { |
| 70 SpinLock::Guard guard(s_initializationLock); | 64 SpinLock::Guard guard(s_initializationLock); |
| 71 | 65 |
| 72 // We could ASSERT here for a memory leak within the partition, but it leads | 66 // We could ASSERT here for a memory leak within the partition, but it leads |
| 73 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for | 67 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for |
| 74 // the valgrind and heapcheck bots, which run without partitions. | 68 // the valgrind and heapcheck bots, which run without partitions. |
| 75 if (s_initialized) { | 69 if (s_initialized) { |
| 76 (void) m_layoutAllocator.shutdown(); | 70 (void) m_layoutAllocator.shutdown(); |
| 77 #if !ENABLE(OILPAN) | |
| 78 (void) m_nodeAllocator.shutdown(); | |
| 79 #endif | |
| 80 (void) m_bufferAllocator.shutdown(); | 71 (void) m_bufferAllocator.shutdown(); |
| 81 (void) m_fastMallocAllocator.shutdown(); | 72 (void) m_fastMallocAllocator.shutdown(); |
| 82 } | 73 } |
| 83 } | 74 } |
| 84 | 75 |
| 85 void Partitions::decommitFreeableMemory() | 76 void Partitions::decommitFreeableMemory() |
| 86 { | 77 { |
| 87 RELEASE_ASSERT(isMainThread()); | 78 RELEASE_ASSERT(isMainThread()); |
| 88 if (!s_initialized) | 79 if (!s_initialized) |
| 89 return; | 80 return; |
| 90 | 81 |
| 91 partitionPurgeMemoryGeneric(bufferPartition(), PartitionPurgeDecommitEmptyPa
ges); | 82 partitionPurgeMemoryGeneric(bufferPartition(), PartitionPurgeDecommitEmptyPa
ges); |
| 92 partitionPurgeMemoryGeneric(fastMallocPartition(), PartitionPurgeDecommitEmp
tyPages); | 83 partitionPurgeMemoryGeneric(fastMallocPartition(), PartitionPurgeDecommitEmp
tyPages); |
| 93 #if !ENABLE(OILPAN) | |
| 94 partitionPurgeMemory(nodePartition(), PartitionPurgeDecommitEmptyPages); | |
| 95 #endif | |
| 96 partitionPurgeMemory(layoutPartition(), PartitionPurgeDecommitEmptyPages); | 84 partitionPurgeMemory(layoutPartition(), PartitionPurgeDecommitEmptyPages); |
| 97 } | 85 } |
| 98 | 86 |
| 99 void Partitions::reportMemoryUsageHistogram() | 87 void Partitions::reportMemoryUsageHistogram() |
| 100 { | 88 { |
| 101 static size_t observedMaxSizeInMB = 0; | 89 static size_t observedMaxSizeInMB = 0; |
| 102 | 90 |
| 103 if (!m_reportSizeFunction) | 91 if (!m_reportSizeFunction) |
| 104 return; | 92 return; |
| 105 // We only report the memory in the main thread. | 93 // We only report the memory in the main thread. |
| 106 if (!isMainThread()) | 94 if (!isMainThread()) |
| 107 return; | 95 return; |
| 108 // +1 is for rounding up the sizeInMB. | 96 // +1 is for rounding up the sizeInMB. |
| 109 size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024 + 1; | 97 size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024 + 1; |
| 110 if (sizeInMB > observedMaxSizeInMB) { | 98 if (sizeInMB > observedMaxSizeInMB) { |
| 111 m_reportSizeFunction(sizeInMB); | 99 m_reportSizeFunction(sizeInMB); |
| 112 observedMaxSizeInMB = sizeInMB; | 100 observedMaxSizeInMB = sizeInMB; |
| 113 } | 101 } |
| 114 } | 102 } |
| 115 | 103 |
| 116 void Partitions::dumpMemoryStats(bool isLightDump, PartitionStatsDumper* partiti
onStatsDumper) | 104 void Partitions::dumpMemoryStats(bool isLightDump, PartitionStatsDumper* partiti
onStatsDumper) |
| 117 { | 105 { |
| 118 // Object model and rendering partitions are not thread safe and can be | 106 // Object model and rendering partitions are not thread safe and can be |
| 119 // accessed only on the main thread. | 107 // accessed only on the main thread. |
| 120 ASSERT(isMainThread()); | 108 ASSERT(isMainThread()); |
| 121 | 109 |
| 122 decommitFreeableMemory(); | 110 decommitFreeableMemory(); |
| 123 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump,
partitionStatsDumper); | 111 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc", isLightDump,
partitionStatsDumper); |
| 124 partitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump, partitio
nStatsDumper); | 112 partitionDumpStatsGeneric(bufferPartition(), "buffer", isLightDump, partitio
nStatsDumper); |
| 125 #if !ENABLE(OILPAN) | |
| 126 partitionDumpStats(nodePartition(), "node", isLightDump, partitionStatsDumpe
r); | |
| 127 #endif | |
| 128 partitionDumpStats(layoutPartition(), "layout", isLightDump, partitionStatsD
umper); | 113 partitionDumpStats(layoutPartition(), "layout", isLightDump, partitionStatsD
umper); |
| 129 } | 114 } |
| 130 | 115 |
| 131 static NEVER_INLINE void partitionsOutOfMemoryUsing2G() | 116 static NEVER_INLINE void partitionsOutOfMemoryUsing2G() |
| 132 { | 117 { |
| 133 size_t signature = 2UL * 1024 * 1024 * 1024; | 118 size_t signature = 2UL * 1024 * 1024 * 1024; |
| 134 base::debug::Alias(&signature); | 119 base::debug::Alias(&signature); |
| 135 IMMEDIATE_CRASH(); | 120 IMMEDIATE_CRASH(); |
| 136 } | 121 } |
| 137 | 122 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 if (totalUsage >= 64 * 1024 * 1024) | 195 if (totalUsage >= 64 * 1024 * 1024) |
| 211 partitionsOutOfMemoryUsing64M(); | 196 partitionsOutOfMemoryUsing64M(); |
| 212 if (totalUsage >= 32 * 1024 * 1024) | 197 if (totalUsage >= 32 * 1024 * 1024) |
| 213 partitionsOutOfMemoryUsing32M(); | 198 partitionsOutOfMemoryUsing32M(); |
| 214 if (totalUsage >= 16 * 1024 * 1024) | 199 if (totalUsage >= 16 * 1024 * 1024) |
| 215 partitionsOutOfMemoryUsing16M(); | 200 partitionsOutOfMemoryUsing16M(); |
| 216 partitionsOutOfMemoryUsingLessThan16M(); | 201 partitionsOutOfMemoryUsingLessThan16M(); |
| 217 } | 202 } |
| 218 | 203 |
| 219 } // namespace WTF | 204 } // namespace WTF |
| OLD | NEW |