OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_HEAP_ARRAY_BUFFER_TRACKER_H_ | |
6 #define V8_HEAP_ARRAY_BUFFER_TRACKER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "src/globals.h" | |
11 | |
12 namespace v8 { | |
13 namespace internal { | |
14 | |
15 // Forward declarations. | |
16 class Heap; | |
17 class JSArrayBuffer; | |
18 | |
19 class ArrayBufferTracker { | |
20 public: | |
21 explicit ArrayBufferTracker(Heap* heap) : heap_(heap) {} | |
22 | |
23 inline Heap* heap() { return heap_; } | |
24 | |
25 // The following methods are used to track raw C++ pointers to externally | |
26 // allocated memory used as backing store in live array buffers. | |
27 | |
28 // A new ArrayBuffer was created with |data| as backing store. | |
29 void RegisterNew(bool in_new_space, void* data, size_t length); | |
30 | |
31 // The backing store |data| is no longer owned by V8. | |
32 void Unregister(JSArrayBuffer* buffer); | |
33 | |
34 // A live ArrayBuffer was discovered during marking/scavenge. | |
35 void MarkLive(JSArrayBuffer* buffer); | |
36 | |
37 // Frees all backing store pointers that weren't discovered in the previous | |
38 // marking or scavenge phase. | |
39 void FreeDead(bool from_scavenge); | |
40 | |
41 // Prepare for a new scavenge phase. A new marking phase is implicitly | |
42 // prepared by finishing the previous one. | |
43 void PrepareDiscoveryInNewSpace(); | |
44 | |
45 // An ArrayBuffer moved from new space to old space. | |
46 void Promote(JSArrayBuffer* buffer); | |
47 | |
48 // Called on heap tear-down. Frees all remaining ArrayBuffer backing stores. | |
49 void TearDown(); | |
50 | |
51 private: | |
52 Heap* heap_; | |
53 | |
54 // |live_array_buffers_| maps externally allocated memory used as backing | |
55 // store for ArrayBuffers to the length of the respective memory blocks. | |
56 // | |
57 // At the beginning of mark/compact, |not_yet_discovered_array_buffers_| is | |
58 // a copy of |live_array_buffers_| and we remove pointers as we discover live | |
59 // ArrayBuffer objects during marking. At the end of mark/compact, the | |
60 // remaining memory blocks can be freed. | |
61 std::map<void*, size_t> live_array_buffers_; | |
62 std::map<void*, size_t> not_yet_discovered_array_buffers_; | |
63 | |
64 // To be able to free memory held by ArrayBuffers during scavenge as well, we | |
65 // have a separate list of allocated memory held by ArrayBuffers in new space. | |
66 // | |
67 // Since mark/compact also evacuates the new space, all pointers in the | |
68 // |live_array_buffers_for_scavenge_| list are also in the | |
69 // |live_array_buffers_| list. | |
70 std::map<void*, size_t> live_array_buffers_for_scavenge_; | |
71 std::map<void*, size_t> not_yet_discovered_array_buffers_for_scavenge_; | |
72 }; | |
73 } | |
Michael Lippautz
2015/09/04 09:09:57
nit:
};
} // namespace internal
} // namespace
| |
74 } // namespace v8::internal | |
75 #endif // V8_HEAP_ARRAY_BUFFER_TRACKER_H_ | |
OLD | NEW |