blob: f2213b8a363c5d41976859a221a63bcdddd67ba3 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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"
Ben Murdoch61f157c2016-09-16 13:49:30 +01009#include "src/heap/slot-set.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010
11namespace v8 {
12namespace internal {
13
14typedef void (*ScavengingCallback)(Map* map, HeapObject** slot,
15 HeapObject* object);
16
17class Scavenger {
18 public:
19 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);
Ben Murdoch61f157c2016-09-16 13:49:30 +010029 static inline SlotCallbackResult CheckAndScavengeObject(Heap* heap,
30 Address slot_address);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000031
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
48// Helper class for turning the scavenger into an object visitor that is also
49// filtering out non-HeapObjects and objects which do not reside in new space.
50class ScavengeVisitor : public ObjectVisitor {
51 public:
52 explicit ScavengeVisitor(Heap* heap) : heap_(heap) {}
53
54 void VisitPointer(Object** p) override;
55 void VisitPointers(Object** start, Object** end) override;
56
57 private:
58 inline void ScavengePointer(Object** p);
59
60 Heap* heap_;
61};
62
63
64// Helper class for turning the scavenger into an object visitor that is also
65// filtering out non-HeapObjects and objects which do not reside in new space.
Ben Murdoch61f157c2016-09-16 13:49:30 +010066template <PromotionMode promotion_mode>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000067class StaticScavengeVisitor
Ben Murdoch61f157c2016-09-16 13:49:30 +010068 : public StaticNewSpaceVisitor<StaticScavengeVisitor<promotion_mode>> {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000069 public:
70 static inline void VisitPointer(Heap* heap, HeapObject* object, Object** p);
71};
72
73} // namespace internal
74} // namespace v8
75
76#endif // V8_HEAP_SCAVENGER_H_