Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: third_party/WebKit/Source/wtf/Partitions.h

Issue 1436153002: Apply clang-format with Chromium-style without column limit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
32 #define Partitions_h 32 #define Partitions_h
33 33
34 #include "wtf/PartitionAlloc.h" 34 #include "wtf/PartitionAlloc.h"
35 #include "wtf/WTF.h" 35 #include "wtf/WTF.h"
36 #include "wtf/WTFExport.h" 36 #include "wtf/WTFExport.h"
37 #include <string.h> 37 #include <string.h>
38 38
39 namespace WTF { 39 namespace WTF {
40 40
41 class WTF_EXPORT Partitions { 41 class WTF_EXPORT Partitions {
42 public: 42 public:
43 // Name of allocator used by tracing for marking sub-allocations while take 43 // Name of allocator used by tracing for marking sub-allocations while take
44 // memory snapshots. 44 // memory snapshots.
45 static const char* const kAllocatedObjectPoolName; 45 static const char* const kAllocatedObjectPoolName;
46 46
47 static void initialize(HistogramEnumerationFunction); 47 static void initialize(HistogramEnumerationFunction);
48 static void shutdown(); 48 static void shutdown();
49 ALWAYS_INLINE static PartitionRootGeneric* bufferPartition() 49 ALWAYS_INLINE static PartitionRootGeneric* bufferPartition() {
50 { 50 ASSERT(s_initialized);
51 ASSERT(s_initialized); 51 return m_bufferAllocator.root();
52 return m_bufferAllocator.root(); 52 }
53 }
54 53
55 ALWAYS_INLINE static PartitionRootGeneric* fastMallocPartition() 54 ALWAYS_INLINE static PartitionRootGeneric* fastMallocPartition() {
56 { 55 ASSERT(s_initialized);
57 ASSERT(s_initialized); 56 return m_fastMallocAllocator.root();
58 return m_fastMallocAllocator.root(); 57 }
59 }
60 58
61 ALWAYS_INLINE static PartitionRoot* nodePartition() 59 ALWAYS_INLINE static PartitionRoot* nodePartition() {
62 { 60 ASSERT(s_initialized);
63 ASSERT(s_initialized); 61 return m_nodeAllocator.root();
64 return m_nodeAllocator.root(); 62 }
65 } 63 ALWAYS_INLINE static PartitionRoot* layoutPartition() {
66 ALWAYS_INLINE static PartitionRoot* layoutPartition() 64 ASSERT(s_initialized);
67 { 65 return m_layoutAllocator.root();
68 ASSERT(s_initialized); 66 }
69 return m_layoutAllocator.root();
70 }
71 67
72 static size_t currentDOMMemoryUsage() 68 static size_t currentDOMMemoryUsage() {
73 { 69 ASSERT(s_initialized);
74 ASSERT(s_initialized); 70 return m_nodeAllocator.root()->totalSizeOfCommittedPages;
75 return m_nodeAllocator.root()->totalSizeOfCommittedPages; 71 }
76 }
77 72
78 static size_t totalSizeOfCommittedPages() 73 static size_t totalSizeOfCommittedPages() {
79 { 74 size_t totalSize = 0;
80 size_t totalSize = 0; 75 totalSize += m_fastMallocAllocator.root()->totalSizeOfCommittedPages;
81 totalSize += m_fastMallocAllocator.root()->totalSizeOfCommittedPages; 76 totalSize += m_bufferAllocator.root()->totalSizeOfCommittedPages;
82 totalSize += m_bufferAllocator.root()->totalSizeOfCommittedPages; 77 totalSize += m_nodeAllocator.root()->totalSizeOfCommittedPages;
83 totalSize += m_nodeAllocator.root()->totalSizeOfCommittedPages; 78 totalSize += m_layoutAllocator.root()->totalSizeOfCommittedPages;
84 totalSize += m_layoutAllocator.root()->totalSizeOfCommittedPages; 79 return totalSize;
85 return totalSize; 80 }
86 }
87 81
88 static void decommitFreeableMemory(); 82 static void decommitFreeableMemory();
89 83
90 static void reportMemoryUsageHistogram(); 84 static void reportMemoryUsageHistogram();
91 85
92 static void dumpMemoryStats(bool isLightDump, PartitionStatsDumper*); 86 static void dumpMemoryStats(bool isLightDump, PartitionStatsDumper*);
93 87
94 ALWAYS_INLINE static void* bufferMalloc(size_t n) 88 ALWAYS_INLINE static void* bufferMalloc(size_t n) {
95 { 89 return partitionAllocGeneric(bufferPartition(), n);
96 return partitionAllocGeneric(bufferPartition(), n); 90 }
97 } 91 ALWAYS_INLINE static void bufferFree(void* p) {
98 ALWAYS_INLINE static void bufferFree(void* p) 92 partitionFreeGeneric(bufferPartition(), p);
99 { 93 }
100 partitionFreeGeneric(bufferPartition(), p); 94 ALWAYS_INLINE static size_t bufferActualSize(size_t n) {
101 } 95 return partitionAllocActualSize(bufferPartition(), n);
102 ALWAYS_INLINE static size_t bufferActualSize(size_t n) 96 }
103 { 97 static void* fastMalloc(size_t n) {
104 return partitionAllocActualSize(bufferPartition(), n); 98 return partitionAllocGeneric(Partitions::fastMallocPartition(), n);
105 } 99 }
106 static void* fastMalloc(size_t n) 100 static void* fastZeroedMalloc(size_t n) {
107 { 101 void* result = fastMalloc(n);
108 return partitionAllocGeneric(Partitions::fastMallocPartition(), n); 102 memset(result, 0, n);
109 } 103 return result;
110 static void* fastZeroedMalloc(size_t n) 104 }
111 { 105 static void* fastRealloc(void* p, size_t n) {
112 void* result = fastMalloc(n); 106 return partitionReallocGeneric(Partitions::fastMallocPartition(), p, n);
113 memset(result, 0, n); 107 }
114 return result; 108 static void fastFree(void* p) {
115 } 109 partitionFreeGeneric(Partitions::fastMallocPartition(), p);
116 static void* fastRealloc(void* p, size_t n) 110 }
117 {
118 return partitionReallocGeneric(Partitions::fastMallocPartition(), p, n);
119 }
120 static void fastFree(void* p)
121 {
122 partitionFreeGeneric(Partitions::fastMallocPartition(), p);
123 }
124 111
125 static void handleOutOfMemory(); 112 static void handleOutOfMemory();
126 113
127 private: 114 private:
128 static int s_initializationLock; 115 static int s_initializationLock;
129 static bool s_initialized; 116 static bool s_initialized;
130 117
131 // We have the following four partitions. 118 // We have the following four partitions.
132 // - Node partition: A partition to allocate Nodes. We prepare a 119 // - Node partition: A partition to allocate Nodes. We prepare a
133 // dedicated partition for Nodes because Nodes are likely to be 120 // dedicated partition for Nodes because Nodes are likely to be
134 // a source of use-after-frees. Another reason is for performance: 121 // a source of use-after-frees. Another reason is for performance:
135 // Since Nodes are guaranteed to be used only by the main 122 // Since Nodes are guaranteed to be used only by the main
136 // thread, we can bypass acquiring a lock. Also we can improve memory 123 // thread, we can bypass acquiring a lock. Also we can improve memory
137 // locality by putting Nodes together. 124 // locality by putting Nodes together.
138 // - Layout object partition: A partition to allocate LayoutObjects. 125 // - Layout object partition: A partition to allocate LayoutObjects.
139 // we prepare a dedicated partition for the same reason as Nodes. 126 // we prepare a dedicated partition for the same reason as Nodes.
140 // - Buffer partition: A partition to allocate objects that have a strong 127 // - Buffer partition: A partition to allocate objects that have a strong
141 // risk where the length and/or the contents are exploited from user 128 // risk where the length and/or the contents are exploited from user
142 // scripts. Vectors, HashTables, ArrayBufferContents and Strings are 129 // scripts. Vectors, HashTables, ArrayBufferContents and Strings are
143 // allocated in the buffer partition. 130 // allocated in the buffer partition.
144 // - Fast malloc partition: A partition to allocate all other objects. 131 // - Fast malloc partition: A partition to allocate all other objects.
145 static PartitionAllocatorGeneric m_fastMallocAllocator; 132 static PartitionAllocatorGeneric m_fastMallocAllocator;
146 static PartitionAllocatorGeneric m_bufferAllocator; 133 static PartitionAllocatorGeneric m_bufferAllocator;
147 static SizeSpecificPartitionAllocator<3328> m_nodeAllocator; 134 static SizeSpecificPartitionAllocator<3328> m_nodeAllocator;
148 static SizeSpecificPartitionAllocator<1024> m_layoutAllocator; 135 static SizeSpecificPartitionAllocator<1024> m_layoutAllocator;
149 static HistogramEnumerationFunction m_histogramEnumeration; 136 static HistogramEnumerationFunction m_histogramEnumeration;
150 }; 137 };
151 138
152 } // namespace WTF 139 } // namespace WTF
153 140
154 #endif // Partitions_h 141 #endif // Partitions_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/PartitionAllocator.cpp ('k') | third_party/WebKit/Source/wtf/Partitions.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698