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 SpinLock Partitions::s_initializationLock; | 42 int Partitions::s_initializationLock = 0; |
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 SpinLock::Guard guard(s_initializationLock); | 53 spinLockLock(&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); |
64 } | 66 } |
65 | 67 |
66 void Partitions::shutdown() | 68 void Partitions::shutdown() |
67 { | 69 { |
68 SpinLock::Guard guard(s_initializationLock); | 70 spinLockLock(&s_initializationLock); |
69 | 71 |
70 // We could ASSERT here for a memory leak within the partition, but it leads | 72 // We could ASSERT here for a memory leak within the partition, but it leads |
71 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for | 73 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for |
72 // the valgrind and heapcheck bots, which run without partitions. | 74 // the valgrind and heapcheck bots, which run without partitions. |
73 if (s_initialized) { | 75 if (s_initialized) { |
74 (void) m_layoutAllocator.shutdown(); | 76 (void) m_layoutAllocator.shutdown(); |
75 (void) m_nodeAllocator.shutdown(); | 77 (void) m_nodeAllocator.shutdown(); |
76 (void) m_bufferAllocator.shutdown(); | 78 (void) m_bufferAllocator.shutdown(); |
77 (void) m_fastMallocAllocator.shutdown(); | 79 (void) m_fastMallocAllocator.shutdown(); |
78 } | 80 } |
| 81 |
| 82 spinLockUnlock(&s_initializationLock); |
79 } | 83 } |
80 | 84 |
81 void Partitions::decommitFreeableMemory() | 85 void Partitions::decommitFreeableMemory() |
82 { | 86 { |
83 RELEASE_ASSERT(isMainThread()); | 87 RELEASE_ASSERT(isMainThread()); |
84 if (!s_initialized) | 88 if (!s_initialized) |
85 return; | 89 return; |
86 | 90 |
87 partitionPurgeMemoryGeneric(bufferPartition(), PartitionPurgeDecommitEmptyPa
ges); | 91 partitionPurgeMemoryGeneric(bufferPartition(), PartitionPurgeDecommitEmptyPa
ges); |
88 partitionPurgeMemoryGeneric(fastMallocPartition(), PartitionPurgeDecommitEmp
tyPages); | 92 partitionPurgeMemoryGeneric(fastMallocPartition(), PartitionPurgeDecommitEmp
tyPages); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 if (totalUsage >= 64 * 1024 * 1024) | 209 if (totalUsage >= 64 * 1024 * 1024) |
206 partitionsOutOfMemoryUsing64M(); | 210 partitionsOutOfMemoryUsing64M(); |
207 if (totalUsage >= 32 * 1024 * 1024) | 211 if (totalUsage >= 32 * 1024 * 1024) |
208 partitionsOutOfMemoryUsing32M(); | 212 partitionsOutOfMemoryUsing32M(); |
209 if (totalUsage >= 16 * 1024 * 1024) | 213 if (totalUsage >= 16 * 1024 * 1024) |
210 partitionsOutOfMemoryUsing16M(); | 214 partitionsOutOfMemoryUsing16M(); |
211 partitionsOutOfMemoryUsingLessThan16M(); | 215 partitionsOutOfMemoryUsingLessThan16M(); |
212 } | 216 } |
213 | 217 |
214 } // namespace WTF | 218 } // namespace WTF |
OLD | NEW |