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 21 matching lines...) Expand all Loading... | |
32 #include "wtf/Partitions.h" | 32 #include "wtf/Partitions.h" |
33 | 33 |
34 #include "wtf/Alias.h" | 34 #include "wtf/Alias.h" |
35 #include "wtf/MainThread.h" | 35 #include "wtf/MainThread.h" |
36 #include "wtf/PartitionAllocator.h" | 36 #include "wtf/PartitionAllocator.h" |
37 | 37 |
38 namespace WTF { | 38 namespace WTF { |
39 | 39 |
40 const char* const Partitions::kAllocatedObjectPoolName = "partition_alloc/alloca ted_objects"; | 40 const char* const Partitions::kAllocatedObjectPoolName = "partition_alloc/alloca ted_objects"; |
41 | 41 |
42 int Partitions::s_initializationLock = 0; | 42 SpinLock Partitions::s_initializationLock; |
Primiano Tucci (use gerrit)
2015/12/07 10:11:57
This is now a static initializer, some bots are un
| |
43 bool Partitions::s_initialized = false; | 43 bool Partitions::s_initialized = false; |
44 | 44 |
45 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; | 45 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; |
46 PartitionAllocatorGeneric Partitions::m_bufferAllocator; | 46 PartitionAllocatorGeneric Partitions::m_bufferAllocator; |
47 SizeSpecificPartitionAllocator<3328> Partitions::m_nodeAllocator; | 47 SizeSpecificPartitionAllocator<3328> Partitions::m_nodeAllocator; |
48 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; | 48 SizeSpecificPartitionAllocator<1024> Partitions::m_layoutAllocator; |
49 HistogramEnumerationFunction Partitions::m_histogramEnumeration = nullptr; | 49 HistogramEnumerationFunction Partitions::m_histogramEnumeration = nullptr; |
50 | 50 |
51 void Partitions::initialize(HistogramEnumerationFunction histogramEnumeration) | 51 void Partitions::initialize(HistogramEnumerationFunction histogramEnumeration) |
52 { | 52 { |
53 spinLockLock(&s_initializationLock); | 53 SpinLock::Guard guard(s_initializationLock); |
54 | 54 |
55 if (!s_initialized) { | 55 if (!s_initialized) { |
56 partitionAllocGlobalInit(&Partitions::handleOutOfMemory); | 56 partitionAllocGlobalInit(&Partitions::handleOutOfMemory); |
57 m_fastMallocAllocator.init(); | 57 m_fastMallocAllocator.init(); |
58 m_bufferAllocator.init(); | 58 m_bufferAllocator.init(); |
59 m_nodeAllocator.init(); | 59 m_nodeAllocator.init(); |
60 m_layoutAllocator.init(); | 60 m_layoutAllocator.init(); |
61 m_histogramEnumeration = histogramEnumeration; | 61 m_histogramEnumeration = histogramEnumeration; |
62 s_initialized = true; | 62 s_initialized = true; |
63 } | 63 } |
64 | |
65 spinLockUnlock(&s_initializationLock); | |
66 } | 64 } |
67 | 65 |
68 void Partitions::shutdown() | 66 void Partitions::shutdown() |
69 { | 67 { |
70 spinLockLock(&s_initializationLock); | 68 SpinLock::Guard guard(s_initializationLock); |
71 | 69 |
72 // We could ASSERT here for a memory leak within the partition, but it leads | 70 // 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 | 71 // 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. | 72 // the valgrind and heapcheck bots, which run without partitions. |
75 if (s_initialized) { | 73 if (s_initialized) { |
76 (void) m_layoutAllocator.shutdown(); | 74 (void) m_layoutAllocator.shutdown(); |
77 (void) m_nodeAllocator.shutdown(); | 75 (void) m_nodeAllocator.shutdown(); |
78 (void) m_bufferAllocator.shutdown(); | 76 (void) m_bufferAllocator.shutdown(); |
79 (void) m_fastMallocAllocator.shutdown(); | 77 (void) m_fastMallocAllocator.shutdown(); |
80 } | 78 } |
81 | |
82 spinLockUnlock(&s_initializationLock); | |
83 } | 79 } |
84 | 80 |
85 void Partitions::decommitFreeableMemory() | 81 void Partitions::decommitFreeableMemory() |
86 { | 82 { |
87 RELEASE_ASSERT(isMainThread()); | 83 RELEASE_ASSERT(isMainThread()); |
88 if (!s_initialized) | 84 if (!s_initialized) |
89 return; | 85 return; |
90 | 86 |
91 partitionPurgeMemoryGeneric(bufferPartition(), PartitionPurgeDecommitEmptyPa ges); | 87 partitionPurgeMemoryGeneric(bufferPartition(), PartitionPurgeDecommitEmptyPa ges); |
92 partitionPurgeMemoryGeneric(fastMallocPartition(), PartitionPurgeDecommitEmp tyPages); | 88 partitionPurgeMemoryGeneric(fastMallocPartition(), PartitionPurgeDecommitEmp tyPages); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 if (totalUsage >= 64 * 1024 * 1024) | 205 if (totalUsage >= 64 * 1024 * 1024) |
210 partitionsOutOfMemoryUsing64M(); | 206 partitionsOutOfMemoryUsing64M(); |
211 if (totalUsage >= 32 * 1024 * 1024) | 207 if (totalUsage >= 32 * 1024 * 1024) |
212 partitionsOutOfMemoryUsing32M(); | 208 partitionsOutOfMemoryUsing32M(); |
213 if (totalUsage >= 16 * 1024 * 1024) | 209 if (totalUsage >= 16 * 1024 * 1024) |
214 partitionsOutOfMemoryUsing16M(); | 210 partitionsOutOfMemoryUsing16M(); |
215 partitionsOutOfMemoryUsingLessThan16M(); | 211 partitionsOutOfMemoryUsingLessThan16M(); |
216 } | 212 } |
217 | 213 |
218 } // namespace WTF | 214 } // namespace WTF |
OLD | NEW |