Chromium Code Reviews| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 // it is pointing at is garbage, you can use this. This will register a | 213 // it is pointing at is garbage, you can use this. This will register a |
| 214 // callback for each cell that needs to be zeroed, so if you have a lot of | 214 // callback for each cell that needs to be zeroed, so if you have a lot of |
| 215 // weak cells in your object you should still consider using | 215 // weak cells in your object you should still consider using |
| 216 // registerWeakMembers above. | 216 // registerWeakMembers above. |
| 217 // | 217 // |
| 218 // In contrast to registerWeakMembers, the weak cell callbacks are | 218 // In contrast to registerWeakMembers, the weak cell callbacks are |
| 219 // run on the thread performing garbage collection. Therefore, all | 219 // run on the thread performing garbage collection. Therefore, all |
| 220 // threads are stopped during weak cell callbacks. | 220 // threads are stopped during weak cell callbacks. |
| 221 template <typename T> | 221 template <typename T> |
| 222 void registerWeakCell(T** cell) { | 222 void registerWeakCell(T** cell) { |
| 223 registerWeakCellWithCallback( | 223 registerWeakCallback( |
| 224 reinterpret_cast<void**>( | 224 reinterpret_cast<void**>( |
| 225 const_cast<typename std::remove_const<T>::type**>(cell)), | 225 const_cast<typename std::remove_const<T>::type**>(cell)), |
| 226 &handleWeakCell<T>); | 226 &handleWeakCell<T>); |
| 227 } | 227 } |
| 228 | 228 |
| 229 template <typename T, void (T::*method)(Visitor*)> | 229 template <typename T, void (T::*method)(Visitor*)> |
| 230 void registerWeakMembers(const T* obj) { | 230 void registerWeakMembers(const T* obj) { |
| 231 registerWeakMembers(obj, &TraceMethodDelegate<T, method>::trampoline); | 231 registerWeakCallback(const_cast<T*>(obj), |
| 232 &TraceMethodDelegate<T, method>::trampoline); | |
| 232 } | 233 } |
| 233 | 234 |
| 234 void registerWeakMembers(const void* object, WeakCallback callback) { | |
| 235 registerWeakMembers(object, object, callback); | |
| 236 } | |
| 237 | 235 |
| 238 inline void registerBackingStoreReference(void* slot); | 236 inline void registerBackingStoreReference(void* slot); |
| 239 | 237 |
| 240 inline void registerBackingStoreCallback(void* backingStore, | 238 inline void registerBackingStoreCallback(void* backingStore, |
| 241 MovingObjectCallback, | 239 MovingObjectCallback, |
| 242 void* callbackData); | 240 void* callbackData); |
| 243 | 241 |
| 244 // This method marks an object and adds it to the set of objects | 242 // This method marks an object and adds it to the set of objects |
| 245 // that should have their trace method called. Since not all | 243 // that should have their trace method called. Since not all |
| 246 // objects have vtables we have to have the callback as an | 244 // objects have vtables we have to have the callback as an |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 264 // to find out whether some pointers are pointing to dying objects. When | 262 // to find out whether some pointers are pointing to dying objects. When |
| 265 // the WeakCallback is done the object must have purged all pointers | 263 // the WeakCallback is done the object must have purged all pointers |
| 266 // to objects where isAlive returned false. In the weak callback it is not | 264 // to objects where isAlive returned false. In the weak callback it is not |
| 267 // allowed to do anything that adds or extends the object graph (e.g., | 265 // allowed to do anything that adds or extends the object graph (e.g., |
| 268 // allocate a new object, add a new reference revive a dead object etc.) | 266 // allocate a new object, add a new reference revive a dead object etc.) |
| 269 // Clearing out pointers to other heap objects is allowed, however. Note | 267 // Clearing out pointers to other heap objects is allowed, however. Note |
| 270 // that even removing things from HeapHashSet or HeapHashMap can cause | 268 // that even removing things from HeapHashSet or HeapHashMap can cause |
| 271 // an allocation if the backing store resizes, but these collections know | 269 // an allocation if the backing store resizes, but these collections know |
| 272 // how to remove WeakMember elements safely. | 270 // how to remove WeakMember elements safely. |
| 273 // | 271 // |
| 274 // The weak pointer callbacks are run on the thread that owns the | 272 // The weak pointer callbacks are run on the thread that owns the |
|
sof
2017/02/14 07:16:48
nit: refresh this paragraph a bit?
| |
| 275 // object and other threads are not stopped during the | 273 // object and other threads are not stopped during the |
| 276 // callbacks. Since isAlive is used in the callback to determine | 274 // callbacks. Since isAlive is used in the callback to determine |
| 277 // if objects pointed to are alive it is crucial that the object | 275 // if objects pointed to are alive it is crucial that the object |
| 278 // pointed to belong to the same thread as the object receiving | 276 // pointed to belong to the same thread as the object receiving |
| 279 // the weak callback. Since other threads have been resumed the | 277 // the weak callback. Since other threads have been resumed the |
| 280 // mark bits are not valid for objects from other threads. | 278 // mark bits are not valid for objects from other threads. |
| 281 inline void registerWeakMembers(const void* closure, | 279 inline void registerWeakCallback(void* closure, WeakCallback); |
| 282 const void* pointer, | |
| 283 WeakCallback); | |
| 284 | 280 |
| 285 inline void registerWeakTable(const void* closure, | 281 inline void registerWeakTable(const void* closure, |
| 286 EphemeronCallback iterationCallback, | 282 EphemeronCallback iterationCallback, |
| 287 EphemeronCallback iterationDoneCallback); | 283 EphemeronCallback iterationDoneCallback); |
| 288 | 284 |
| 289 #if DCHECK_IS_ON() | 285 #if DCHECK_IS_ON() |
| 290 inline bool weakTableRegistered(const void* closure); | 286 inline bool weakTableRegistered(const void* closure); |
| 291 #endif | 287 #endif |
| 292 | 288 |
| 293 inline bool ensureMarked(const void* pointer); | 289 inline bool ensureMarked(const void* pointer); |
| 294 | 290 |
| 295 inline void registerWeakCellWithCallback(void** cell, WeakCallback); | |
| 296 | |
| 297 inline void markNoTracing(const void* pointer) { | 291 inline void markNoTracing(const void* pointer) { |
| 298 mark(pointer, reinterpret_cast<TraceCallback>(0)); | 292 mark(pointer, reinterpret_cast<TraceCallback>(0)); |
| 299 } | 293 } |
| 300 | 294 |
| 301 inline void markHeaderNoTracing(HeapObjectHeader*); | 295 inline void markHeaderNoTracing(HeapObjectHeader*); |
| 302 | 296 |
| 303 // Used to mark objects during conservative scanning. | 297 // Used to mark objects during conservative scanning. |
| 304 inline void markHeader(HeapObjectHeader*, | 298 inline void markHeader(HeapObjectHeader*, |
| 305 const void* objectPointer, | 299 const void* objectPointer, |
| 306 TraceCallback); | 300 TraceCallback); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 318 | 312 |
| 319 static void markNoTracingCallback(Visitor*, void*); | 313 static void markNoTracingCallback(Visitor*, void*); |
| 320 | 314 |
| 321 ThreadState* const m_state; | 315 ThreadState* const m_state; |
| 322 const MarkingMode m_markingMode; | 316 const MarkingMode m_markingMode; |
| 323 }; | 317 }; |
| 324 | 318 |
| 325 } // namespace blink | 319 } // namespace blink |
| 326 | 320 |
| 327 #endif // Visitor_h | 321 #endif // Visitor_h |
| OLD | NEW |