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

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

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months 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 29 matching lines...) Expand all
40 #include "wtf/PartitionAlloc.h" 40 #include "wtf/PartitionAlloc.h"
41 #include "wtf/Partitions.h" 41 #include "wtf/Partitions.h"
42 42
43 #include <string.h> 43 #include <string.h>
44 44
45 namespace WTF { 45 namespace WTF {
46 46
47 class PartitionAllocatorDummyVisitor; 47 class PartitionAllocatorDummyVisitor;
48 48
49 class WTF_EXPORT PartitionAllocator { 49 class WTF_EXPORT PartitionAllocator {
50 public: 50 public:
51 typedef PartitionAllocatorDummyVisitor Visitor; 51 typedef PartitionAllocatorDummyVisitor Visitor;
52 static const bool isGarbageCollected = false; 52 static const bool isGarbageCollected = false;
53 53
54 template<typename T> 54 template <typename T>
55 static size_t quantizedSize(size_t count) 55 static size_t quantizedSize(size_t count) {
56 { 56 RELEASE_ASSERT(count <= kGenericMaxDirectMapped / sizeof(T));
57 RELEASE_ASSERT(count <= kGenericMaxDirectMapped / sizeof(T)); 57 return partitionAllocActualSize(Partitions::bufferPartition(),
58 return partitionAllocActualSize(Partitions::bufferPartition(), count * s izeof(T)); 58 count * sizeof(T));
59 } 59 }
60 template <typename T> 60 template <typename T>
61 static T* allocateVectorBacking(size_t size) 61 static T* allocateVectorBacking(size_t size) {
62 { 62 return reinterpret_cast<T*>(
63 return reinterpret_cast<T*>(allocateBacking(size, WTF_HEAP_PROFILER_TYPE _NAME(T))); 63 allocateBacking(size, WTF_HEAP_PROFILER_TYPE_NAME(T)));
64 } 64 }
65 template <typename T> 65 template <typename T>
66 static T* allocateExpandedVectorBacking(size_t size) 66 static T* allocateExpandedVectorBacking(size_t size) {
67 { 67 return reinterpret_cast<T*>(
68 return reinterpret_cast<T*>(allocateBacking(size, WTF_HEAP_PROFILER_TYPE _NAME(T))); 68 allocateBacking(size, WTF_HEAP_PROFILER_TYPE_NAME(T)));
69 } 69 }
70 static void freeVectorBacking(void* address); 70 static void freeVectorBacking(void* address);
71 static inline bool expandVectorBacking(void*, size_t) 71 static inline bool expandVectorBacking(void*, size_t) { return false; }
72 { 72 static inline bool shrinkVectorBacking(void* address,
73 return false; 73 size_t quantizedCurrentSize,
74 } 74 size_t quantizedShrunkSize) {
75 static inline bool shrinkVectorBacking(void* address, size_t quantizedCurren tSize, size_t quantizedShrunkSize) 75 // Optimization: if we're downsizing inside the same allocator bucket,
76 { 76 // we can skip reallocation.
77 // Optimization: if we're downsizing inside the same allocator bucket, 77 return quantizedCurrentSize == quantizedShrunkSize;
78 // we can skip reallocation. 78 }
79 return quantizedCurrentSize == quantizedShrunkSize; 79 template <typename T>
80 } 80 static T* allocateInlineVectorBacking(size_t size) {
81 template <typename T> 81 return allocateVectorBacking<T>(size);
82 static T* allocateInlineVectorBacking(size_t size) { return allocateVectorBa cking<T>(size); } 82 }
83 static inline void freeInlineVectorBacking(void* address) { freeVectorBackin g(address); } 83 static inline void freeInlineVectorBacking(void* address) {
84 static inline bool expandInlineVectorBacking(void*, size_t) { return false; } 84 freeVectorBacking(address);
85 static inline bool shrinkInlineVectorBacking(void* address, size_t quantized CurrentSize, size_t quantizedShrunkSize) { return shrinkVectorBacking(address, q uantizedCurrentSize, quantizedShrunkSize); } 85 }
86 static inline bool expandInlineVectorBacking(void*, size_t) { return false; }
87 static inline bool shrinkInlineVectorBacking(void* address,
88 size_t quantizedCurrentSize,
89 size_t quantizedShrunkSize) {
90 return shrinkVectorBacking(address, quantizedCurrentSize,
91 quantizedShrunkSize);
92 }
86 93
87 template <typename T, typename HashTable> 94 template <typename T, typename HashTable>
88 static T* allocateHashTableBacking(size_t size) 95 static T* allocateHashTableBacking(size_t size) {
89 { 96 return reinterpret_cast<T*>(
90 return reinterpret_cast<T*>(allocateBacking(size, WTF_HEAP_PROFILER_TYPE _NAME(T))); 97 allocateBacking(size, WTF_HEAP_PROFILER_TYPE_NAME(T)));
91 } 98 }
92 template <typename T, typename HashTable> 99 template <typename T, typename HashTable>
93 static T* allocateZeroedHashTableBacking(size_t size) 100 static T* allocateZeroedHashTableBacking(size_t size) {
94 { 101 void* result = allocateBacking(size, WTF_HEAP_PROFILER_TYPE_NAME(T));
95 void* result = allocateBacking(size, WTF_HEAP_PROFILER_TYPE_NAME(T)); 102 memset(result, 0, size);
96 memset(result, 0, size); 103 return reinterpret_cast<T*>(result);
97 return reinterpret_cast<T*>(result); 104 }
98 } 105 static void freeHashTableBacking(void* address);
99 static void freeHashTableBacking(void* address);
100 106
101 template <typename Return, typename Metadata> 107 template <typename Return, typename Metadata>
102 static Return malloc(size_t size, const char* typeName) 108 static Return malloc(size_t size, const char* typeName) {
103 { 109 return reinterpret_cast<Return>(Partitions::fastMalloc(size, typeName));
104 return reinterpret_cast<Return>(Partitions::fastMalloc(size, typeName)); 110 }
105 }
106 111
107 static inline bool expandHashTableBacking(void*, size_t) 112 static inline bool expandHashTableBacking(void*, size_t) { return false; }
108 { 113 static void free(void* address) { Partitions::fastFree(address); }
109 return false; 114 template <typename T>
110 } 115 static void* newArray(size_t bytes) {
111 static void free(void* address) 116 return malloc<void*, void>(bytes, WTF_HEAP_PROFILER_TYPE_NAME(T));
112 { 117 }
113 Partitions::fastFree(address); 118 static void deleteArray(void* ptr) {
114 } 119 free(ptr); // Not the system free, the one from this class.
115 template<typename T> 120 }
116 static void* newArray(size_t bytes)
117 {
118 return malloc<void*, void>(bytes, WTF_HEAP_PROFILER_TYPE_NAME(T));
119 }
120 static void
121 deleteArray(void* ptr)
122 {
123 free(ptr); // Not the system free, the one from this class.
124 }
125 121
126 static bool isAllocationAllowed() { return true; } 122 static bool isAllocationAllowed() { return true; }
127 template<typename T> 123 template <typename T>
128 static bool isHeapObjectAlive(T* object) 124 static bool isHeapObjectAlive(T* object) {
129 { 125 ASSERT_NOT_REACHED();
130 ASSERT_NOT_REACHED(); 126 return false;
131 return false; 127 }
132 }
133 128
134 static void markNoTracing(...) 129 static void markNoTracing(...) { ASSERT_NOT_REACHED(); }
135 {
136 ASSERT_NOT_REACHED();
137 }
138 130
139 static void registerDelayedMarkNoTracing(...) 131 static void registerDelayedMarkNoTracing(...) { ASSERT_NOT_REACHED(); }
140 {
141 ASSERT_NOT_REACHED();
142 }
143 132
144 static void registerWeakMembers(...) 133 static void registerWeakMembers(...) { ASSERT_NOT_REACHED(); }
145 {
146 ASSERT_NOT_REACHED();
147 }
148 134
149 static void registerWeakTable(...) 135 static void registerWeakTable(...) { ASSERT_NOT_REACHED(); }
150 {
151 ASSERT_NOT_REACHED();
152 }
153 136
154 #if ENABLE(ASSERT) 137 #if ENABLE(ASSERT)
155 static bool weakTableRegistered(...) 138 static bool weakTableRegistered(...) {
156 { 139 ASSERT_NOT_REACHED();
157 ASSERT_NOT_REACHED(); 140 return false;
158 return false; 141 }
159 }
160 #endif 142 #endif
161 143
162 template<typename T, typename Traits> 144 template <typename T, typename Traits>
163 static void trace(...) 145 static void trace(...) {
164 { 146 ASSERT_NOT_REACHED();
165 ASSERT_NOT_REACHED(); 147 }
166 }
167 148
168 template<typename T> 149 template <typename T>
169 struct OtherType { 150 struct OtherType {
170 typedef T* Type; 151 typedef T* Type;
171 }; 152 };
172 153
173 template<typename T> 154 template <typename T>
174 static T& getOther(T* other) 155 static T& getOther(T* other) {
175 { 156 return *other;
176 return *other; 157 }
177 }
178 158
179 static void enterGCForbiddenScope() { } 159 static void enterGCForbiddenScope() {}
180 static void leaveGCForbiddenScope() { } 160 static void leaveGCForbiddenScope() {}
181 161
182 private: 162 private:
183 static void* allocateBacking(size_t, const char* typeName); 163 static void* allocateBacking(size_t, const char* typeName);
184 }; 164 };
185 165
186 // The Windows compiler seems to be very eager to instantiate things it won't 166 // The Windows compiler seems to be very eager to instantiate things it won't
187 // need, so unless we have this class we get compile errors. 167 // need, so unless we have this class we get compile errors.
188 class PartitionAllocatorDummyVisitor { 168 class PartitionAllocatorDummyVisitor {
189 DISALLOW_NEW(); 169 DISALLOW_NEW();
190 public: 170
191 template<typename T> inline bool isHeapObjectAlive(T obj) 171 public:
192 { 172 template <typename T>
193 ASSERT_NOT_REACHED(); 173 inline bool isHeapObjectAlive(T obj) {
194 return false; 174 ASSERT_NOT_REACHED();
195 } 175 return false;
176 }
196 }; 177 };
197 178
198 // Specializations for heap profiling, so type profiling of |char| is possible 179 // Specializations for heap profiling, so type profiling of |char| is possible
199 // even in official builds (because |char| makes up a large portion of the heap. ) 180 // even in official builds (because |char| makes up a large portion of the heap. )
200 template <> WTF_EXPORT char* PartitionAllocator::allocateVectorBacking<char>(siz e_t size); 181 template <>
201 template <> WTF_EXPORT char* PartitionAllocator::allocateExpandedVectorBacking<c har>(size_t size); 182 WTF_EXPORT char* PartitionAllocator::allocateVectorBacking<char>(size_t size);
183 template <>
184 WTF_EXPORT char* PartitionAllocator::allocateExpandedVectorBacking<char>(
185 size_t size);
202 186
203 } // namespace WTF 187 } // namespace WTF
204 188
205 #define WTF_USE_ALLOCATOR(ClassName, Allocator) \ 189 #define WTF_USE_ALLOCATOR(ClassName, Allocator) \
206 public: \ 190 public: \
207 void* operator new(size_t size) \ 191 void* operator new(size_t size) { \
208 { \ 192 return Allocator::template malloc<void*, ClassName>( \
209 return Allocator::template malloc<void*, ClassName>(size, WTF_HEAP_PROFI LER_TYPE_NAME(ClassName)); \ 193 size, WTF_HEAP_PROFILER_TYPE_NAME(ClassName)); \
210 } \ 194 } \
211 void operator delete(void* p) { Allocator::free(p); } \ 195 void operator delete(void* p) { Allocator::free(p); } \
212 void* operator new[](size_t size) { return Allocator::template newArray<Clas sName>(size); } \ 196 void* operator new[](size_t size) { \
213 void operator delete[](void* p) { Allocator::deleteArray(p); } \ 197 return Allocator::template newArray<ClassName>(size); \
214 void* operator new(size_t, NotNullTag, void* location) \ 198 } \
215 { \ 199 void operator delete[](void* p) { Allocator::deleteArray(p); } \
216 ASSERT(location); \ 200 void* operator new(size_t, NotNullTag, void* location) { \
217 return location; \ 201 ASSERT(location); \
218 } \ 202 return location; \
219 private: \ 203 } \
220 typedef int __thisIsHereToForceASemicolonAfterThisMacro 204 \
205 private: \
206 typedef int __thisIsHereToForceASemicolonAfterThisMacro
221 207
222 using WTF::PartitionAllocator; 208 using WTF::PartitionAllocator;
223 209
224 #endif // WTF_PartitionAllocator_h 210 #endif // WTF_PartitionAllocator_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/PartitionAllocTest.cpp ('k') | third_party/WebKit/Source/wtf/PartitionAllocator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698