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

Side by Side Diff: third_party/WebKit/Source/platform/heap/BlinkGCAPIReference.md

Issue 2547853002: Add section for heap collections to BlinkGC documentation (Closed)
Patch Set: added sample code 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Blink GC API reference 1 # Blink GC API reference
2 2
3 This is a through document for Oilpan API usage. 3 This is a through document for Oilpan API usage.
4 If you want to learn the API usage quickly, look at 4 If you want to learn the API usage quickly, look at
5 [this tutorial](https://docs.google.com/presentation/d/1XPu03ymz8W295mCftEC9KshH 9Icxfq81YwIJQzQrvxo/edit#slide=id.p). 5 [this tutorial](https://docs.google.com/presentation/d/1XPu03ymz8W295mCftEC9KshH 9Icxfq81YwIJQzQrvxo/edit#slide=id.p).
6 If you're just interested in wrapper tracing,
7 see [Wrapper Tracing Reference](../../bindings/core/v8/TraceWrapperReference.md) .
6 8
7 [TOC] 9 [TOC]
8 10
9 ## Header file 11 ## Header file
10 12
11 Unless otherwise noted, any of the primitives explained in this page requires th e following `#include` statement: 13 Unless otherwise noted, any of the primitives explained in this page requires th e following `#include` statement:
12 14
13 ```c++ 15 ```c++
14 #include "platform/heap/Handle.h" 16 #include "platform/heap/Handle.h"
15 ``` 17 ```
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 ``` 419 ```
418 420
419 Please notice that if the object (of type `C`) is also not reachable, its `trace ` method 421 Please notice that if the object (of type `C`) is also not reachable, its `trace ` method
420 will not be invoked and any follow-on weak processing will not be done. Hence, i f the 422 will not be invoked and any follow-on weak processing will not be done. Hence, i f the
421 object must always perform some operation when the weak reference is cleared, th at 423 object must always perform some operation when the weak reference is cleared, th at
422 needs to (also) happen during finalization. 424 needs to (also) happen during finalization.
423 425
424 Weak callbacks have so far seen little use in Blink, but a mechanism that's avai lable. 426 Weak callbacks have so far seen little use in Blink, but a mechanism that's avai lable.
425 427
426 ## Heap collections 428 ## Heap collections
429
430 Heap collections are WTF collection types that support `Member<T>`, `WeakMember< T>`(see [below](#Weak collections)), and garbage collected objects as its elemen ts.
431
432 Here is the complete list:
433
434 - WTF::Vector → blink::HeapVector
435 - WTF::Deque → blink::HeapDeque
436 - WTF::HashMap → blink::HeapHashMap
437 - WTF::HashSet → blink::HeapHashSet
438 - WTF::LinkedHashSet → blink::HeapLinkedHashSet
439 - WTF::ListHashSet → blink::HeapListHashSet
440 - WTF::HashCountedSet → blink::HeapHashCountedSet
441
442 These heap collections work mostly the same way as their WTF collection counterp arts but there are some things to keep in mind.
443
444 Heap collections are special in that the types themselves do not inherit from Ga rbageCollected (hence they are not allocated on the Oilpan heap) but they still *need to be traced* from the trace method (because we need to trace the backing store which is on the Oilpan heap).
445
446 ```c++
447 class MyGarbageCollectedClass : public GarbageCollected<MyGarbageCollectedClass> {
448 public:
449 DEFINE_INLINE_TRACE() { visitor->trace(m_list); }
450 private:
451 HeapVector<Member<AnotherGarbageCollectedClass>> m_list;
452 };
453 ```
454
455 When you want to add a heap collection as a member of a non-garbage-collected cl ass, please use the persistent variants (just prefix the type with Persistent e. g. PersistentHeapVector, PersistentHeapHashMap, etc.).
456
457 ```c++
458 class MyNotGarbageCollectedClass {
459 private:
460 PersistentHeapVector<Member<MyGarbageCollectedClass>> m_list;
461 };
462 ```
463
464 Please be very cautious if you want to use a heap collection from multiple threa ds. Reference to heap collections may be passed to another thread using CrossThr eadPersistents, but *you may not modify the collection from the non-owner thread *. This is because modifications to collections may trigger backing store reallo cations, and Oilpan's per thread heap requires that modifications to a heap happ en on its owner thread.
465
466 ### Weak collections
467
468 You can put `WeakMember<T>` in heap collections except for `HeapVector` and `Hea pDeque` which we do not support.
469
470 During an Oilpan GC, the weak members that refernce a collected object will be r emoved from its heap collection, meaning the size of the collection will shrink and you do not have to check for null weak members when iterating through the co llection.
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698