OLD | NEW |
1 # Memory management in Blink | 1 # Memory management in Blink |
2 | 2 |
3 This document gives a high-level overview of the memory management in Blink. | 3 This document gives a high-level overview of the memory management in Blink. |
4 | 4 |
5 [TOC] | 5 [TOC] |
6 | 6 |
7 ## Memory allocators | 7 ## Memory allocators |
8 | 8 |
9 Blink objects are allocated by one of the following four memory allocators. | 9 Blink objects are allocated by one of the following four memory allocators. |
10 | 10 |
11 ### Oilpan | 11 ### Oilpan |
12 | 12 |
13 Oilpan is a garbage collection system in Blink. | 13 Oilpan is a garbage collection system in Blink. |
14 The lifetime of objects allocated by Oilpan is automatically managed. | 14 The lifetime of objects allocated by Oilpan is automatically managed. |
15 The following objects are allocated by Oilpan: | 15 The following objects are allocated by Oilpan: |
16 | 16 |
17 * Objects that inherit from GarbageCollected<T> or GarbageCollectedFinalized<T>. | 17 * Objects that inherit from GarbageCollected<T> or GarbageCollectedFinalized<T>. |
18 | 18 |
19 * HeapVector<T>, HeapHashSet<T>, HeapHashMap<T, U> etc | 19 * HeapVector<T>, HeapHashSet<T>, HeapHashMap<T, U> etc |
20 | 20 |
21 The implementation is in platform/heap/. | 21 The implementation is in platform/heap/. |
22 See [BlinkGCDesign.md](platform/heap/BlinkGCDesign.md) to learn the design. | 22 See [BlinkGCDesign.md](../platform/heap/BlinkGCDesign.md) to learn the design. |
23 | 23 |
24 ### PartitionAlloc | 24 ### PartitionAlloc |
25 | 25 |
26 PartitionAlloc is Blink's default memory allocator. | 26 PartitionAlloc is Blink's default memory allocator. |
27 PartitionAlloc is highly optimized for performance and security requirements | 27 PartitionAlloc is highly optimized for performance and security requirements |
28 in Blink. All Blink objects that don't need a GC or discardable memory should be | 28 in Blink. All Blink objects that don't need a GC or discardable memory should be |
29 allocated by PartitionAlloc (instead of malloc). | 29 allocated by PartitionAlloc (instead of malloc). |
30 The following objects are allocated by PartitionAlloc: | 30 The following objects are allocated by PartitionAlloc: |
31 | 31 |
32 * Objects that have a USING_FAST_MALLOC macro. | 32 * Objects that have a USING_FAST_MALLOC macro. |
33 | 33 |
34 * Nodes (which will be moved to Oilpan in the near future) | 34 * Nodes (which will be moved to Oilpan in the near future) |
35 | 35 |
36 * LayoutObjects | 36 * LayoutObjects |
37 | 37 |
38 * Strings, Vectors, HashTables, ArrayBuffers and other primitive containers. | 38 * Strings, Vectors, HashTables, ArrayBuffers and other primitive containers. |
39 | 39 |
40 The implementation is in wtf/Partition*. | 40 The implementation is in /base/allocator/partition_allocator. |
41 See [PartitionAlloc.md](wtf/PartitionAlloc.md) to learn the design. | 41 See [PartitionAlloc.md](/base/allocator/partition_allocator/PartitionAlloc.md) |
| 42 to learn the design. |
42 | 43 |
43 ### Discardable memory | 44 ### Discardable memory |
44 | 45 |
45 Discardable memory is a memory allocator that automatically discards | 46 Discardable memory is a memory allocator that automatically discards |
46 (not-locked) objects under memory pressure. Currently SharedBuffers | 47 (not-locked) objects under memory pressure. Currently SharedBuffers |
47 (which are mainly used as backing storage of Resource objects) are the only | 48 (which are mainly used as backing storage of Resource objects) are the only |
48 user of the discardable memory. | 49 user of the discardable memory. |
49 | 50 |
50 The implementation is in src/base/memory/discardable_memory.*. | 51 The implementation is in src/base/memory/discardable_memory.*. |
51 See [this document](https://docs.google.com/document/d/1aNdOF_72_eG2KUM_z9kHdbT_
fEupWhaDALaZs5D8IAg/edit) | 52 See [this document](https://docs.google.com/document/d/1aNdOF_72_eG2KUM_z9kHdbT_
fEupWhaDALaZs5D8IAg/edit) |
(...skipping 14 matching lines...) Expand all Loading... |
66 | 67 |
67 In summary, Blink objects (except several special objects) should be allocated | 68 In summary, Blink objects (except several special objects) should be allocated |
68 using Oilpan or PartitionAlloc. malloc is discouraged. | 69 using Oilpan or PartitionAlloc. malloc is discouraged. |
69 | 70 |
70 The following is a basic rule to determine which of Oilpan or PartitionAlloc | 71 The following is a basic rule to determine which of Oilpan or PartitionAlloc |
71 you should use when allocating a new object: | 72 you should use when allocating a new object: |
72 | 73 |
73 * Use Oilpan if you want a GC to manage the lifetime of the object. | 74 * Use Oilpan if you want a GC to manage the lifetime of the object. |
74 You need to make the object inherit from GarbageCollected<T> or | 75 You need to make the object inherit from GarbageCollected<T> or |
75 GarbageCollectedFinalized<T>. See | 76 GarbageCollectedFinalized<T>. See |
76 [BlinkGCAPIReference.md](platform/heap/BlinkGCAPIReference.md) to learn | 77 [BlinkGCAPIReference.md](../platform/heap/BlinkGCAPIReference.md) to learn |
77 programming with Oilpan. | 78 programming with Oilpan. |
78 | 79 |
79 ```c++ | 80 ```c++ |
80 class X : public GarbageCollected<X> { | 81 class X : public GarbageCollected<X> { |
81 ...; | 82 ...; |
82 }; | 83 }; |
83 | 84 |
84 void func() { | 85 void func() { |
85 X* x = new X; // This is allocated by Oilpan. | 86 X* x = new X; // This is allocated by Oilpan. |
86 } | 87 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 void func() { | 177 void func() { |
177 X x; // This is allowed. | 178 X x; // This is allowed. |
178 X* x = new X; // This is forbidden. | 179 X* x = new X; // This is forbidden. |
179 } | 180 } |
180 ``` | 181 ``` |
181 | 182 |
182 Note that these macros are inherited. See a comment in wtf/Allocator.h | 183 Note that these macros are inherited. See a comment in wtf/Allocator.h |
183 for more details about the relationship between the macros and Oilpan. | 184 for more details about the relationship between the macros and Oilpan. |
184 | 185 |
185 If you have any question, ask oilpan-reviews@chromium.org. | 186 If you have any question, ask oilpan-reviews@chromium.org. |
OLD | NEW |