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, | 6 If you're just interested in wrapper tracing, |
7 see [Wrapper Tracing Reference](../../bindings/core/v8/TraceWrapperReference.md)
. | 7 see [Wrapper Tracing Reference](../../bindings/core/v8/TraceWrapperReference.md)
. |
8 | 8 |
9 [TOC] | 9 [TOC] |
10 | 10 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 Member<OtherClass> m_other; | 195 Member<OtherClass> m_other; |
196 }; | 196 }; |
197 ``` | 197 ``` |
198 | 198 |
199 Pre-finalizers have some implications on the garbage collector's performance: th
e garbage-collector needs to iterate | 199 Pre-finalizers have some implications on the garbage collector's performance: th
e garbage-collector needs to iterate |
200 all registered pre-finalizers at every GC. Therefore, a pre-finalizer should be
avoided unless it is really necessary. | 200 all registered pre-finalizers at every GC. Therefore, a pre-finalizer should be
avoided unless it is really necessary. |
201 Especially, avoid defining a pre-finalizer in a class that can be allocated a lo
t. | 201 Especially, avoid defining a pre-finalizer in a class that can be allocated a lo
t. |
202 | 202 |
203 ### EAGERLY_FINALIZE | 203 ### EAGERLY_FINALIZE |
204 | 204 |
| 205 A class-level annotation to indicate that class instances that the GC have deter
mined as unreachable, should be eagerly |
| 206 swept and finalized by the garbage collector, before the Blink thread (the mutat
or) resumes after a garbage |
| 207 collection. The C++ destructor runs as part of this step. The default sweeping b
ehavior is incremental, sweeping |
| 208 pages as demanded by later heap allocations. |
| 209 |
| 210 Like for the pre-finalizer mechanism, an `EAGERLY_FINALIZE()`d class is allowed
to touch other heap objects, which |
| 211 is sometimes required, but the main use case for eager finalization is to prompt
ly let go of off-heap resources |
| 212 and associations, by unregistering and destructing those eagerly. If not done, t
hese external references would |
| 213 otherwise attempt to unsafely access an effectively-dead object (pending lazy sw
eeping of its heap page.) |
| 214 |
| 215 `EAGERLY_FINALIZE()` solves the same problem as pre-finalizers, but it arguably
fits more naturally with the host |
| 216 language's mechanism for finalization (C++ destructors.) One `EAGERLY_FINALIZE()
` caveat is that the destructor |
| 217 is not allowed to touch another eagerly finalized object (their finalization ord
ering isn't deterministic) nor |
| 218 any pre-finalized objects. Choose the one you think best fits your need for prom
pt finalization. |
| 219 |
| 220 ### STACK_ALLOCATED |
| 221 |
| 222 Class level annotation that should be used if the object is only stack allocated
; it disallows use |
| 223 of `operator new`. Any garbage-collected objects should be kept as `Member<T>` r
eferences, but you do not |
| 224 need to define a `trace()` method as they are on the stack, and automatically tr
aced and kept alive should |
| 225 a conservative GC be required. |
| 226 |
| 227 ### DISALLOW_NEW() |
| 228 |
| 229 Class-level annotation declaring the class a part object that cannot be separate
ly allocated using `operator new`. |
| 230 If the class has `Member<T>` references, you need a `trace()` method which the o
bject containing the `DISALLOW_NEW()` |
| 231 part object must call upon. The clang Blink GC plugin checks and enforces this. |
| 232 |
205 ### DISALLOW_NEW_EXCEPT_PLACEMENT_NEW | 233 ### DISALLOW_NEW_EXCEPT_PLACEMENT_NEW |
206 | 234 |
207 ### STACK_ALLOCATED | 235 Class-level annotation allowing only the use of the placement `new` operator. Th
is disallows general allocation of the |
| 236 object but allows putting the object as a value object in collections. If the c
lass has `Member<T>` references, |
| 237 you need to declare a `trace()` method. That trace method will be called automat
ically by the on-heap collections. |
208 | 238 |
209 ## Handles | 239 ## Handles |
210 | 240 |
211 Class templates in this section are smart pointers, each carrying a pointer to a
n on-heap object (think of `RefPtr<T>` | 241 Class templates in this section are smart pointers, each carrying a pointer to a
n on-heap object (think of `RefPtr<T>` |
212 for `RefCounted<T>`). Collectively, they are called *handles*. | 242 for `RefCounted<T>`). Collectively, they are called *handles*. |
213 | 243 |
214 On-heap objects must be retained by any of these, depending on the situation. | 244 On-heap objects must be retained by any of these, depending on the situation. |
215 | 245 |
216 ### Raw pointers | 246 ### Raw pointers |
217 | 247 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 }; | 484 }; |
455 ``` | 485 ``` |
456 | 486 |
457 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. | 487 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. |
458 | 488 |
459 ### Weak collections | 489 ### Weak collections |
460 | 490 |
461 You can put `WeakMember<T>` in heap collections except for `HeapVector` and `Hea
pDeque` which we do not support. | 491 You can put `WeakMember<T>` in heap collections except for `HeapVector` and `Hea
pDeque` which we do not support. |
462 | 492 |
463 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. | 493 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 |