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

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

Issue 2531973002: Simple BlinkGC heap compaction. (Closed)
Patch Set: add pointer alignment handling to SparseHeapBitmap Created 4 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 Derived::fromHelper(this)->registerWeakCellWithCallback( 236 Derived::fromHelper(this)->registerWeakCellWithCallback(
237 reinterpret_cast<void**>( 237 reinterpret_cast<void**>(
238 const_cast<typename std::remove_const<T>::type**>(cell)), 238 const_cast<typename std::remove_const<T>::type**>(cell)),
239 &handleWeakCell<T>); 239 &handleWeakCell<T>);
240 } 240 }
241 241
242 template <typename T, void (T::*method)(Visitor*)> 242 template <typename T, void (T::*method)(Visitor*)>
243 void registerWeakMembers(const T* obj) { 243 void registerWeakMembers(const T* obj) {
244 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); 244 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline);
245 } 245 }
246
246 void registerWeakMembers(const void* object, WeakCallback callback) { 247 void registerWeakMembers(const void* object, WeakCallback callback) {
247 Derived::fromHelper(this)->registerWeakMembers(object, object, callback); 248 Derived::fromHelper(this)->registerWeakMembers(object, object, callback);
248 } 249 }
249 250
251 template <typename T>
252 void registerBackingStoreReference(T** slot) {
253 Derived::fromHelper(this)->registerMovingObjectReference(
254 reinterpret_cast<MovableReference*>(slot));
255 }
256
257 template <typename T>
258 void registerBackingStoreCallback(T* backingStore,
259 MovingObjectCallback callback,
260 void* callbackData) {
261 Derived::fromHelper(this)->registerMovingObjectCallback(
262 reinterpret_cast<MovableReference>(backingStore), callback,
263 callbackData);
264 }
265
250 inline ThreadState* state() const { return m_state; } 266 inline ThreadState* state() const { return m_state; }
251 inline ThreadHeap& heap() const { return state()->heap(); } 267 inline ThreadHeap& heap() const { return state()->heap(); }
252 268
253 private: 269 private:
254 template <typename T> 270 template <typename T>
255 static void handleWeakCell(Visitor* self, void* object); 271 static void handleWeakCell(Visitor* self, void* object);
256 272
257 ThreadState* m_state; 273 ThreadState* const m_state;
258 }; 274 };
259 275
260 // Visitor is used to traverse the Blink object graph. Used for the 276 // Visitor is used to traverse the Blink object graph. Used for the
261 // marking phase of the mark-sweep garbage collector. 277 // marking phase of the mark-sweep garbage collector.
262 // 278 //
263 // Pointers are marked and pushed on the marking stack by calling the 279 // Pointers are marked and pushed on the marking stack by calling the
264 // |mark| method with the pointer as an argument. 280 // |mark| method with the pointer as an argument.
265 // 281 //
266 // Pointers within objects are traced by calling the |trace| methods 282 // Pointers within objects are traced by calling the |trace| methods
267 // with the object as an argument. Tracing objects will mark all of the 283 // with the object as an argument. Tracing objects will mark all of the
268 // contained pointers and push them on the marking stack. 284 // contained pointers and push them on the marking stack.
269 class PLATFORM_EXPORT Visitor : public VisitorHelper<Visitor> { 285 class PLATFORM_EXPORT Visitor : public VisitorHelper<Visitor> {
270 public: 286 public:
271 friend class VisitorHelper<Visitor>; 287 friend class VisitorHelper<Visitor>;
272 friend class InlinedGlobalMarkingVisitor; 288 friend class InlinedGlobalMarkingVisitor;
273 289
274 enum MarkingMode { 290 enum MarkingMode {
275 // This is a default visitor. This is used for GCType=GCWithSweep 291 // This is a default visitor. This is used for GCType=GCWithSweep
276 // and GCType=GCWithoutSweep. 292 // and GCType=GCWithoutSweep.
277 GlobalMarking, 293 GlobalMarking,
278 // This visitor does not trace objects outside the heap of the 294 // This visitor does not trace objects outside the heap of the
279 // GCing thread. This is used for GCType=ThreadTerminationGC. 295 // GCing thread. This is used for GCType=ThreadTerminationGC.
280 ThreadLocalMarking, 296 ThreadLocalMarking,
281 // This visitor just marks objects and ignores weak processing. 297 // This visitor just marks objects and ignores weak processing.
282 // This is used for GCType=TakeSnapshot. 298 // This is used for GCType=TakeSnapshot.
283 SnapshotMarking, 299 SnapshotMarking,
284 // This visitor is used to trace objects during weak processing. 300 // This visitor is used to trace objects during weak processing.
285 // This visitor is allowed to trace only already marked objects. 301 // This visitor is allowed to trace only already marked objects.
286 WeakProcessing, 302 WeakProcessing,
303 // Perform global marking along with preparing for additional sweep
304 // compaction of heap arenas afterwards. Compared to the GlobalMarking
305 // visitor, this visitor will also register references to objects
306 // that might be moved during arena compaction -- the compaction
307 // pass will then fix up those references when the object move goes
308 // ahead.
309 GlobalMarkCompacting,
haraken 2016/12/09 07:25:56 GlobalMarkingWithCompaction ?
sof 2016/12/09 21:44:05 Twiddles, done.
287 }; 310 };
288 311
289 static std::unique_ptr<Visitor> create(ThreadState*, BlinkGC::GCType); 312 static std::unique_ptr<Visitor> create(ThreadState*, BlinkGC::GCType);
290 313
291 virtual ~Visitor(); 314 virtual ~Visitor();
292 315
293 using VisitorHelper<Visitor>::mark; 316 using VisitorHelper<Visitor>::mark;
294 317
295 // This method marks an object and adds it to the set of objects 318 // This method marks an object and adds it to the set of objects
296 // that should have their trace method called. Since not all 319 // that should have their trace method called. Since not all
297 // objects have vtables we have to have the callback as an 320 // objects have vtables we have to have the callback as an
298 // explicit argument, but we can use the templated one-argument 321 // explicit argument, but we can use the templated one-argument
299 // mark method above to automatically provide the callback 322 // mark method above to automatically provide the callback
300 // function. 323 // function.
301 virtual void mark(const void*, TraceCallback) = 0; 324 virtual void mark(const void*, TraceCallback) = 0;
302 325
303 // Used to mark objects during conservative scanning. 326 // Used to mark objects during conservative scanning.
304 virtual void markHeader(HeapObjectHeader*, TraceCallback) = 0; 327 virtual void markHeader(HeapObjectHeader*, TraceCallback) = 0;
305 328
306 // Used to delay the marking of objects until the usual marking 329 // Used to delay the marking of objects until the usual marking
307 // including emphemeron iteration is done. This is used to delay 330 // including emphemeron iteration is done. This is used to delay
308 // the marking of collection backing stores until we know if they 331 // the marking of collection backing stores until we know if they
309 // are reachable from locations other than the collection front 332 // are reachable from locations other than the collection front
310 // object. If collection backings are reachable from other 333 // object. If collection backings are reachable from other
311 // locations we strongify them to avoid issues with iterators and 334 // locations we strongify them to avoid issues with iterators and
312 // weak processing. 335 // weak processing.
313 virtual void registerDelayedMarkNoTracing(const void*) = 0; 336 // A pointer to the location holding the backing store reference
337 // is passed in. This is done so as to potentially allow that
338 // location to be updated by the garbage collector.
339 virtual void registerDelayedMarkNoTracing(void**) = 0;
314 340
315 // If the object calls this during the regular trace callback, then the 341 // If the object calls this during the regular trace callback, then the
316 // WeakCallback argument may be called later, when the strong roots 342 // WeakCallback argument may be called later, when the strong roots
317 // have all been found. The WeakCallback will normally use isAlive 343 // have all been found. The WeakCallback will normally use isAlive
318 // to find out whether some pointers are pointing to dying objects. When 344 // to find out whether some pointers are pointing to dying objects. When
319 // the WeakCallback is done the object must have purged all pointers 345 // the WeakCallback is done the object must have purged all pointers
320 // to objects where isAlive returned false. In the weak callback it is not 346 // to objects where isAlive returned false. In the weak callback it is not
321 // allowed to do anything that adds or extends the object graph (e.g., 347 // allowed to do anything that adds or extends the object graph (e.g.,
322 // allocate a new object, add a new reference revive a dead object etc.) 348 // allocate a new object, add a new reference revive a dead object etc.)
323 // Clearing out pointers to other heap objects is allowed, however. Note 349 // Clearing out pointers to other heap objects is allowed, however. Note
(...skipping 13 matching lines...) Expand all
337 363
338 virtual void registerWeakTable(const void*, 364 virtual void registerWeakTable(const void*,
339 EphemeronCallback, 365 EphemeronCallback,
340 EphemeronCallback) = 0; 366 EphemeronCallback) = 0;
341 #if ENABLE(ASSERT) 367 #if ENABLE(ASSERT)
342 virtual bool weakTableRegistered(const void*) = 0; 368 virtual bool weakTableRegistered(const void*) = 0;
343 #endif 369 #endif
344 370
345 virtual bool ensureMarked(const void*) = 0; 371 virtual bool ensureMarked(const void*) = 0;
346 372
373 virtual void registerMovingObjectReference(MovableReference*) = 0;
374
375 virtual void registerMovingObjectCallback(MovableReference,
376 MovingObjectCallback,
377 void*) = 0;
378
347 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0; 379 virtual void registerWeakCellWithCallback(void**, WeakCallback) = 0;
348 380
349 inline MarkingMode getMarkingMode() const { return m_markingMode; } 381 inline MarkingMode getMarkingMode() const { return m_markingMode; }
350 382
383 inline bool isGlobalMarking() const {
384 return m_markingMode == GlobalMarking ||
385 m_markingMode == GlobalMarkCompacting;
386 }
387
351 protected: 388 protected:
352 Visitor(ThreadState*, MarkingMode); 389 Visitor(ThreadState*, MarkingMode);
353 390
354 private: 391 private:
355 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) { 392 static Visitor* fromHelper(VisitorHelper<Visitor>* helper) {
356 return static_cast<Visitor*>(helper); 393 return static_cast<Visitor*>(helper);
357 } 394 }
358 395
359 ThreadState* m_state;
360 const MarkingMode m_markingMode; 396 const MarkingMode m_markingMode;
361 }; 397 };
362 398
363 } // namespace blink 399 } // namespace blink
364 400
365 #endif // Visitor_h 401 #endif // Visitor_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698