Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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). | |
|
haraken
2016/12/02 12:50:46
Shall we add some code example?
keishi
2016/12/05 01:51:28
Done.
| |
| 445 | |
| 446 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.). | |
|
haraken
2016/12/02 12:50:46
Ditto.
keishi
2016/12/05 01:51:29
Done.
| |
| 447 | |
| 448 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. | |
|
haraken
2016/12/02 12:50:46
I'm just curious but do we have a runtime verifica
keishi
2016/12/05 01:51:29
We don't check for every modification (i.e. the ve
| |
| 449 | |
| 450 ### Weak collections | |
| 451 | |
| 452 You can use `WeakMember<T>` in heap collections except for `HeapVector` and `Hea pDeque` which we do not support. | |
| 453 | |
| 454 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. | |
| OLD | NEW |