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

Side by Side Diff: third_party/WebKit/Source/platform/heap/Heap.h

Issue 1477023003: Refactor the Heap into ThreadHeap to prepare for per thread heaps Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 allocationSize = (allocationSize + allocationMask) & ~allocationMask; 191 allocationSize = (allocationSize + allocationMask) & ~allocationMask;
192 return allocationSize; 192 return allocationSize;
193 } 193 }
194 static Address allocateOnHeapIndex(ThreadState*, size_t, int heapIndex, size _t gcInfoIndex); 194 static Address allocateOnHeapIndex(ThreadState*, size_t, int heapIndex, size _t gcInfoIndex);
195 template<typename T> static Address allocate(size_t, bool eagerlySweep = fal se); 195 template<typename T> static Address allocate(size_t, bool eagerlySweep = fal se);
196 template<typename T> static Address reallocate(void* previous, size_t); 196 template<typename T> static Address reallocate(void* previous, size_t);
197 197
198 static const char* gcReasonString(BlinkGC::GCReason); 198 static const char* gcReasonString(BlinkGC::GCReason);
199 static void collectGarbage(BlinkGC::StackState, BlinkGC::GCType, BlinkGC::GC Reason); 199 static void collectGarbage(BlinkGC::StackState, BlinkGC::GCType, BlinkGC::GC Reason);
200 static void collectGarbageForTerminatingThread(ThreadState*); 200 static void collectGarbageForTerminatingThread(ThreadState*);
201 static void collectGarbageForIsolatedThread(ThreadState*);
201 static void collectAllGarbage(); 202 static void collectAllGarbage();
202 203
203 static void processMarkingStack(Visitor*); 204 static void processMarkingStack(Visitor*);
204 static void postMarkingProcessing(Visitor*); 205 static void postMarkingProcessing(Visitor*);
205 static void globalWeakProcessing(Visitor*); 206 static void globalWeakProcessing(Visitor*);
206 static void setForcePreciseGCForTesting(); 207 static void setForcePreciseGCForTesting();
207 208
208 static void preGC(); 209 static void preGC();
209 static void postGC(BlinkGC::GCType); 210 static void postGC(BlinkGC::GCType);
210 211
211 // Conservatively checks whether an address is a pointer in any of the 212 // Conservatively checks whether an address is a pointer in any of the
212 // thread heaps. If so marks the object pointed to as live. 213 // thread heaps. If so marks the object pointed to as live.
213 static Address checkAndMarkPointer(Visitor*, Address); 214 static Address checkAndMarkPointer(Visitor*, Address);
214 215
215 static size_t objectPayloadSizeForTesting(); 216 static size_t objectPayloadSizeForTesting();
216 217
217 static void flushHeapDoesNotContainCache();
218
219 static FreePagePool* freePagePool() { return s_freePagePool; }
220 static OrphanedPagePool* orphanedPagePool() { return s_orphanedPagePool; }
221
222 // This look-up uses the region search tree and a negative contains cache to 218 // This look-up uses the region search tree and a negative contains cache to
223 // provide an efficient mapping from arbitrary addresses to the containing 219 // provide an efficient mapping from arbitrary addresses to the containing
224 // heap-page if one exists. 220 // heap-page if one exists.
225 static BasePage* lookup(Address); 221 static BasePage* lookup(Address);
226 static void addPageMemoryRegion(PageMemoryRegion*); 222 static void addPageMemoryRegion(PageMemoryRegion*);
227 static void removePageMemoryRegion(PageMemoryRegion*); 223 static void removePageMemoryRegion(PageMemoryRegion*);
228 224
229 static const GCInfo* gcInfo(size_t gcInfoIndex) 225 static const GCInfo* gcInfo(size_t gcInfoIndex)
230 { 226 {
231 ASSERT(gcInfoIndex >= 1); 227 ASSERT(gcInfoIndex >= 1);
232 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); 228 ASSERT(gcInfoIndex < GCInfoTable::maxIndex);
233 ASSERT(s_gcInfoTable); 229 ASSERT(s_gcInfoTable);
234 const GCInfo* info = s_gcInfoTable[gcInfoIndex]; 230 const GCInfo* info = s_gcInfoTable[gcInfoIndex];
235 ASSERT(info); 231 ASSERT(info);
236 return info; 232 return info;
237 } 233 }
238 234
239 static void setMarkedObjectSizeAtLastCompleteSweep(size_t size) { releaseSto re(&s_markedObjectSizeAtLastCompleteSweep, size); }
240 static size_t markedObjectSizeAtLastCompleteSweep() { return acquireLoad(&s_ markedObjectSizeAtLastCompleteSweep); }
241 static void increaseAllocatedObjectSize(size_t delta) { atomicAdd(&s_allocat edObjectSize, static_cast<long>(delta)); }
242 static void decreaseAllocatedObjectSize(size_t delta) { atomicSubtract(&s_al locatedObjectSize, static_cast<long>(delta)); }
243 static size_t allocatedObjectSize() { return acquireLoad(&s_allocatedObjectS ize); }
244 static void increaseMarkedObjectSize(size_t delta) { atomicAdd(&s_markedObje ctSize, static_cast<long>(delta)); }
245 static size_t markedObjectSize() { return acquireLoad(&s_markedObjectSize); }
246 static void increaseAllocatedSpace(size_t delta) { atomicAdd(&s_allocatedSpa ce, static_cast<long>(delta)); }
247 static void decreaseAllocatedSpace(size_t delta) { atomicSubtract(&s_allocat edSpace, static_cast<long>(delta)); }
248 static size_t allocatedSpace() { return acquireLoad(&s_allocatedSpace); }
249 static size_t objectSizeAtLastGC() { return acquireLoad(&s_objectSizeAtLastG C); }
250 static void increaseWrapperCount(size_t delta) { atomicAdd(&s_wrapperCount, static_cast<long>(delta)); }
251 static void decreaseWrapperCount(size_t delta) { atomicSubtract(&s_wrapperCo unt, static_cast<long>(delta)); }
252 static size_t wrapperCount() { return acquireLoad(&s_wrapperCount); }
253 static size_t wrapperCountAtLastGC() { return acquireLoad(&s_wrapperCountAtL astGC); }
254 static void increaseCollectedWrapperCount(size_t delta) { atomicAdd(&s_colle ctedWrapperCount, static_cast<long>(delta)); }
255 static size_t collectedWrapperCount() { return acquireLoad(&s_collectedWrapp erCount); }
256 static size_t partitionAllocSizeAtLastGC() { return acquireLoad(&s_partition AllocSizeAtLastGC); }
257
258 static double estimatedMarkingTime();
259 static void reportMemoryUsageHistogram();
260 static void reportMemoryUsageForTracing();
261
262 #if ENABLE(ASSERT)
263 static uint16_t gcGeneration() { return s_gcGeneration; }
264 #endif
265
266 private: 235 private:
267 // A RegionTree is a simple binary search tree of PageMemoryRegions sorted
268 // by base addresses.
269 class RegionTree {
270 public:
271 explicit RegionTree(PageMemoryRegion* region) : m_region(region), m_left (nullptr), m_right(nullptr) { }
272 ~RegionTree()
273 {
274 delete m_left;
275 delete m_right;
276 }
277 PageMemoryRegion* lookup(Address);
278 static void add(RegionTree*, RegionTree**);
279 static void remove(PageMemoryRegion*, RegionTree**);
280 private:
281 PageMemoryRegion* m_region;
282 RegionTree* m_left;
283 RegionTree* m_right;
284 };
285
286 // Reset counters that track live and allocated-since-last-GC sizes.
287 static void resetHeapCounters();
288
289 static int heapIndexForObjectSize(size_t); 236 static int heapIndexForObjectSize(size_t);
290 static bool isNormalHeapIndex(int); 237 static bool isNormalHeapIndex(int);
291 238
292 static CallbackStack* s_markingStack;
293 static CallbackStack* s_postMarkingCallbackStack;
294 static CallbackStack* s_globalWeakCallbackStack;
295 static CallbackStack* s_ephemeronStack;
296 static HeapDoesNotContainCache* s_heapDoesNotContainCache;
297 static bool s_shutdownCalled;
298 static FreePagePool* s_freePagePool;
299 static OrphanedPagePool* s_orphanedPagePool;
300 static RegionTree* s_regionTree;
301 static size_t s_allocatedSpace;
302 static size_t s_allocatedObjectSize;
303 static size_t s_objectSizeAtLastGC;
304 static size_t s_markedObjectSize;
305 static size_t s_markedObjectSizeAtLastCompleteSweep;
306 static size_t s_wrapperCount;
307 static size_t s_wrapperCountAtLastGC;
308 static size_t s_collectedWrapperCount;
309 static size_t s_partitionAllocSizeAtLastGC;
310 static double s_estimatedMarkingTimePerByte;
311 #if ENABLE(ASSERT)
312 static uint16_t s_gcGeneration;
313 #endif
314
315 friend class ThreadState; 239 friend class ThreadState;
316 }; 240 };
317 241
318 template<typename T> 242 template<typename T>
319 struct IsEagerlyFinalizedType { 243 struct IsEagerlyFinalizedType {
320 private: 244 private:
321 typedef char YesType; 245 typedef char YesType;
322 struct NoType { 246 struct NoType {
323 char padding[8]; 247 char padding[8];
324 }; 248 };
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object) 427 void VisitorHelper<Derived>::handleWeakCell(Visitor* self, void* object)
504 { 428 {
505 T** cell = reinterpret_cast<T**>(object); 429 T** cell = reinterpret_cast<T**>(object);
506 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell)) 430 if (*cell && !ObjectAliveTrait<T>::isHeapObjectAlive(*cell))
507 *cell = nullptr; 431 *cell = nullptr;
508 } 432 }
509 433
510 } // namespace blink 434 } // namespace blink
511 435
512 #endif // Heap_h 436 #endif // Heap_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698