| 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 #include "wtf/FastMalloc.h" | 35 #include "wtf/FastMalloc.h" |
| 36 #include "wtf/MainThread.h" | 36 #include "wtf/MainThread.h" |
| 37 | 37 |
| 38 namespace WTF { | 38 namespace WTF { |
| 39 | 39 |
| 40 bool Partitions::s_initialized; | 40 bool Partitions::s_initialized; |
| 41 | 41 |
| 42 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; | 42 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; |
| 43 PartitionAllocatorGeneric Partitions::m_bufferAllocator; | 43 PartitionAllocatorGeneric Partitions::m_bufferAllocator; |
| 44 SizeSpecificPartitionAllocator<3328> Partitions::m_objectModelAllocator; | 44 SizeSpecificPartitionAllocator<3328> Partitions::m_objectModelAllocator; |
| 45 SizeSpecificPartitionAllocator<1024> Partitions::m_renderingAllocator; | 45 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; |
| 46 HistogramEnumerationFunction Partitions::m_histogramEnumeration = nullptr; | 46 HistogramEnumerationFunction Partitions::m_histogramEnumeration = nullptr; |
| 47 | 47 |
| 48 void Partitions::initialize(HistogramEnumerationFunction histogramEnumeration) | 48 void Partitions::initialize(HistogramEnumerationFunction histogramEnumeration) |
| 49 { | 49 { |
| 50 static int lock = 0; | 50 static int lock = 0; |
| 51 // Guard against two threads hitting here in parallel. | 51 // Guard against two threads hitting here in parallel. |
| 52 spinLockLock(&lock); | 52 spinLockLock(&lock); |
| 53 if (!s_initialized) { | 53 if (!s_initialized) { |
| 54 m_fastMallocAllocator.init(); | 54 m_fastMallocAllocator.init(); |
| 55 m_bufferAllocator.init(); | 55 m_bufferAllocator.init(); |
| 56 m_objectModelAllocator.init(); | 56 m_objectModelAllocator.init(); |
| 57 m_renderingAllocator.init(); | 57 m_layoutAllocator.init(); |
| 58 m_histogramEnumeration = histogramEnumeration; | 58 m_histogramEnumeration = histogramEnumeration; |
| 59 s_initialized = true; | 59 s_initialized = true; |
| 60 } | 60 } |
| 61 spinLockUnlock(&lock); | 61 spinLockUnlock(&lock); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void Partitions::shutdown() | 64 void Partitions::shutdown() |
| 65 { | 65 { |
| 66 // 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 |
| 67 // 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 |
| 68 // the valgrind and heapcheck bots, which run without partitions. | 68 // the valgrind and heapcheck bots, which run without partitions. |
| 69 (void) m_renderingAllocator.shutdown(); | 69 (void) m_layoutAllocator.shutdown(); |
| 70 (void) m_objectModelAllocator.shutdown(); | 70 (void) m_objectModelAllocator.shutdown(); |
| 71 (void) m_bufferAllocator.shutdown(); | 71 (void) m_bufferAllocator.shutdown(); |
| 72 (void) m_fastMallocAllocator.shutdown(); | 72 (void) m_fastMallocAllocator.shutdown(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void Partitions::decommitFreeableMemory() | 75 void Partitions::decommitFreeableMemory() |
| 76 { | 76 { |
| 77 ASSERT(isMainThread()); | 77 ASSERT(isMainThread()); |
| 78 | 78 |
| 79 partitionPurgeMemoryGeneric(getBufferPartition()); | 79 partitionPurgeMemoryGeneric(bufferPartition()); |
| 80 partitionPurgeMemoryGeneric(getFastMallocPartition()); | 80 partitionPurgeMemoryGeneric(fastMallocPartition()); |
| 81 partitionPurgeMemory(getObjectModelPartition()); | 81 partitionPurgeMemory(objectModelPartition()); |
| 82 partitionPurgeMemory(getRenderingPartition()); | 82 partitionPurgeMemory(layoutPartition()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void Partitions::reportMemoryUsageHistogram() | 85 void Partitions::reportMemoryUsageHistogram() |
| 86 { | 86 { |
| 87 static size_t supportedMaxSizeInMB = 4 * 1024; | 87 static size_t supportedMaxSizeInMB = 4 * 1024; |
| 88 static size_t observedMaxSizeInMB = 0; | 88 static size_t observedMaxSizeInMB = 0; |
| 89 | 89 |
| 90 if (!m_histogramEnumeration) | 90 if (!m_histogramEnumeration) |
| 91 return; | 91 return; |
| 92 // We only report the memory in the main thread. | 92 // We only report the memory in the main thread. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 103 observedMaxSizeInMB = sizeInMB; | 103 observedMaxSizeInMB = sizeInMB; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 void Partitions::dumpMemoryStats(PartitionStatsDumper* partitionStatsDumper) | 107 void Partitions::dumpMemoryStats(PartitionStatsDumper* partitionStatsDumper) |
| 108 { | 108 { |
| 109 // Object model and rendering partitions are not thread safe and can be | 109 // Object model and rendering partitions are not thread safe and can be |
| 110 // accessed only on the main thread. | 110 // accessed only on the main thread. |
| 111 ASSERT(isMainThread()); | 111 ASSERT(isMainThread()); |
| 112 | 112 |
| 113 partitionDumpStatsGeneric(getFastMallocPartition(), "fast_malloc_partition",
partitionStatsDumper); | 113 partitionDumpStatsGeneric(fastMallocPartition(), "fast_malloc_partition", pa
rtitionStatsDumper); |
| 114 partitionDumpStatsGeneric(getBufferPartition(), "buffer_partition", partitio
nStatsDumper); | 114 partitionDumpStatsGeneric(bufferPartition(), "buffer_partition", partitionSt
atsDumper); |
| 115 partitionDumpStats(getObjectModelPartition(), "object_model_partition", part
itionStatsDumper); | 115 partitionDumpStats(objectModelPartition(), "object_model_partition", partiti
onStatsDumper); |
| 116 partitionDumpStats(getRenderingPartition(), "rendering_partition", partition
StatsDumper); | 116 partitionDumpStats(layoutPartition(), "layout_partition", partitionStatsDump
er); |
| 117 } | 117 } |
| 118 | 118 |
| 119 } // namespace WTF | 119 } // namespace WTF |
| OLD | NEW |