Home | History | Annotate | Download | only in heap
      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   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 
     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.
     50 class 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.
     66 class StaticScavengeVisitor
     67     : public StaticNewSpaceVisitor<StaticScavengeVisitor> {
     68  public:
     69   static inline void VisitPointer(Heap* heap, HeapObject* object, Object** p);
     70 };
     71 
     72 }  // namespace internal
     73 }  // namespace v8
     74 
     75 #endif  // V8_HEAP_SCAVENGER_H_
     76