summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/scavenger.h
blob: 5d0abf49d38502ce752c25a330c5c66fbf0fb693 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_HEAP_SCAVENGER_H_
#define V8_HEAP_SCAVENGER_H_

#include "src/heap/objects-visiting.h"

namespace v8 {
namespace internal {

typedef void (*ScavengingCallback)(Map* map, HeapObject** slot,
                                   HeapObject* object);

class Scavenger {
 public:
  explicit Scavenger(Heap* heap) : heap_(heap) {}

  // Initializes static visitor dispatch tables.
  static void Initialize();

  // Callback function passed to Heap::Iterate etc.  Copies an object if
  // necessary, the object might be promoted to an old space.  The caller must
  // ensure the precondition that the object is (a) a heap object and (b) in
  // the heap's from space.
  static inline void ScavengeObject(HeapObject** p, HeapObject* object);

  // Slow part of {ScavengeObject} above.
  static void ScavengeObjectSlow(HeapObject** p, HeapObject* object);

  // Chooses an appropriate static visitor table depending on the current state
  // of the heap (i.e. incremental marking, logging and profiling).
  void SelectScavengingVisitorsTable();

  Isolate* isolate();
  Heap* heap() { return heap_; }

 private:
  Heap* heap_;
  VisitorDispatchTable<ScavengingCallback> scavenging_visitors_table_;
};


// Helper class for turning the scavenger into an object visitor that is also
// filtering out non-HeapObjects and objects which do not reside in new space.
class ScavengeVisitor : public ObjectVisitor {
 public:
  explicit ScavengeVisitor(Heap* heap) : heap_(heap) {}

  void VisitPointer(Object** p) override;
  void VisitPointers(Object** start, Object** end) override;

 private:
  inline void ScavengePointer(Object** p);

  Heap* heap_;
};


// Helper class for turning the scavenger into an object visitor that is also
// filtering out non-HeapObjects and objects which do not reside in new space.
class StaticScavengeVisitor
    : public StaticNewSpaceVisitor<StaticScavengeVisitor> {
 public:
  static inline void VisitPointer(Heap* heap, HeapObject* object, Object** p);
};

}  // namespace internal
}  // namespace v8

#endif  // V8_HEAP_SCAVENGER_H_