Line data Source code
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_SCAVENGER_H_
6 : #define V8_HEAP_SCAVENGER_H_
7 :
8 : #include "src/heap/objects-visiting.h"
9 : #include "src/heap/slot-set.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 : typedef void (*ScavengingCallback)(Map* map, HeapObject** slot,
15 : HeapObject* object);
16 :
17 : class Scavenger {
18 : public:
19 60782 : explicit Scavenger(Heap* heap) : heap_(heap) {}
20 :
21 : // Initializes static visitor dispatch tables.
22 : static void Initialize();
23 :
24 : // Callback function passed to Heap::Iterate etc. Copies an object if
25 : // necessary, the object might be promoted to an old space. The caller must
26 : // ensure the precondition that the object is (a) a heap object and (b) in
27 : // the heap's from space.
28 : static inline void ScavengeObject(HeapObject** p, HeapObject* object);
29 : static inline SlotCallbackResult CheckAndScavengeObject(Heap* heap,
30 : Address slot_address);
31 :
32 : // Slow part of {ScavengeObject} above.
33 : static void ScavengeObjectSlow(HeapObject** p, HeapObject* object);
34 :
35 : // Chooses an appropriate static visitor table depending on the current state
36 : // of the heap (i.e. incremental marking, logging and profiling).
37 : void SelectScavengingVisitorsTable();
38 :
39 : Isolate* isolate();
40 : Heap* heap() { return heap_; }
41 :
42 : private:
43 : Heap* heap_;
44 : VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_;
45 : };
46 :
47 : // Helper class for turning the scavenger into an object visitor that is also
48 : // filtering out non-HeapObjects and objects which do not reside in new space.
49 69189 : class RootScavengeVisitor : public RootVisitor {
50 : public:
51 69189 : explicit RootScavengeVisitor(Heap* heap) : heap_(heap) {}
52 :
53 : void VisitRootPointer(Root root, Object** p) override;
54 : void VisitRootPointers(Root root, Object** start, Object** end) override;
55 :
56 : private:
57 : inline void ScavengePointer(Object** p);
58 :
59 : Heap* heap_;
60 : };
61 :
62 :
63 : // Helper class for turning the scavenger into an object visitor that is also
64 : // filtering out non-HeapObjects and objects which do not reside in new space.
65 : class StaticScavengeVisitor
66 : : public StaticNewSpaceVisitor<StaticScavengeVisitor> {
67 : public:
68 : static inline void VisitPointer(Heap* heap, HeapObject* object, Object** p);
69 : };
70 :
71 : } // namespace internal
72 : } // namespace v8
73 :
74 : #endif // V8_HEAP_SCAVENGER_H_
|