5 #ifndef V8_HEAP_SCAVENGER_H_ 6 #define V8_HEAP_SCAVENGER_H_ 8 #include "src/base/platform/condition-variable.h" 9 #include "src/heap/local-allocator.h" 10 #include "src/heap/objects-visiting.h" 11 #include "src/heap/slot-set.h" 12 #include "src/heap/worklist.h" 19 enum class CopyAndForwardResult {
20 SUCCESS_YOUNG_GENERATION,
21 SUCCESS_OLD_GENERATION,
25 using ObjectAndSize = std::pair<HeapObject*, int>;
26 using SurvivingNewLargeObjectsMap = std::unordered_map<HeapObject*, Map>;
27 using SurvivingNewLargeObjectMapEntry = std::pair<HeapObject*, Map>;
31 static const int kMaxScavengerTasks = 8;
32 static const int kMaxWaitTimeMs = 2;
36 void CollectGarbage();
39 void MergeSurvivingNewLargeObjects(
40 const SurvivingNewLargeObjectsMap& objects);
42 int NumberOfScavengeTasks();
44 void HandleSurvivingNewLargeObjects();
49 SurvivingNewLargeObjectsMap surviving_new_large_objects_;
67 : promotion_list_(promotion_list), task_id_(task_id) {}
69 inline void PushRegularObject(
HeapObject*
object,
int size);
70 inline void PushLargeObject(
HeapObject*
object,
Map map,
int size);
71 inline bool IsEmpty();
72 inline size_t LocalPushSegmentSize();
74 inline bool IsGlobalPoolEmpty();
75 inline bool ShouldEagerlyProcessPromotionList();
83 : regular_object_promotion_list_(num_tasks),
84 large_object_promotion_list_(num_tasks) {}
86 inline void PushRegularObject(
int task_id,
HeapObject*
object,
int size);
87 inline void PushLargeObject(
int task_id,
HeapObject*
object,
Map map,
89 inline bool IsEmpty();
90 inline size_t LocalPushSegmentSize(
int task_id);
92 inline bool IsGlobalPoolEmpty();
93 inline bool ShouldEagerlyProcessPromotionList(
int task_id);
96 static const int kRegularObjectPromotionListSegmentSize = 256;
97 static const int kLargeObjectPromotionListSegmentSize = 4;
99 using RegularObjectPromotionList =
101 using LargeObjectPromotionList =
104 RegularObjectPromotionList regular_object_promotion_list_;
105 LargeObjectPromotionList large_object_promotion_list_;
108 static const int kCopiedListSegmentSize = 256;
113 CopiedList* copied_list, PromotionList* promotion_list,
127 size_t bytes_copied()
const {
return copied_size_; }
128 size_t bytes_promoted()
const {
return promoted_size_; }
133 static const int kInterruptThreshold = 128;
134 static const int kInitialLocalPretenuringFeedbackCapacity = 256;
136 inline Heap* heap() {
return heap_; }
138 inline void PageMemoryFence(MaybeObject
object);
140 void AddPageToSweeperIfNecessary(MemoryChunk* page);
144 inline SlotCallbackResult CheckAndScavengeObject(Heap* heap,
145 MaybeObjectSlot slot);
149 inline SlotCallbackResult ScavengeObject(HeapObjectSlot p,
153 V8_INLINE
bool MigrateObject(Map map, HeapObject* source, HeapObject* target,
156 V8_INLINE SlotCallbackResult
157 RememberedSetEntryNeeded(CopyAndForwardResult result);
159 V8_INLINE CopyAndForwardResult SemiSpaceCopyObject(Map map,
164 V8_INLINE CopyAndForwardResult PromoteObject(Map map, HeapObjectSlot slot,
168 V8_INLINE SlotCallbackResult EvacuateObject(HeapObjectSlot slot, Map map,
171 V8_INLINE
bool HandleLargeObject(Map map, HeapObject*
object,
175 V8_INLINE SlotCallbackResult EvacuateObjectDefault(Map map,
180 inline SlotCallbackResult EvacuateThinString(Map map, HeapObjectSlot slot,
184 inline SlotCallbackResult EvacuateShortcutCandidate(Map map,
189 void IterateAndScavengePromotedObject(HeapObject* target, Map map,
int size);
191 static inline bool ContainsOnlyData(VisitorId visitor_id);
193 ScavengerCollector*
const collector_;
195 PromotionList::View promotion_list_;
196 CopiedList::View copied_list_;
197 Heap::PretenuringFeedbackMap local_pretenuring_feedback_;
199 size_t promoted_size_;
200 LocalAllocator allocator_;
201 SurvivingNewLargeObjectsMap surviving_new_large_objects_;
202 const bool is_logging_;
203 const bool is_incremental_marking_;
204 const bool is_compacting_;
206 friend class IterateAndScavengePromotedObjectsVisitor;
207 friend class RootScavengeVisitor;
208 friend class ScavengeVisitor;
217 void VisitRootPointer(Root root,
const char* description,
ObjectSlot p)
final;
218 void VisitRootPointers(Root root,
const char* description,
ObjectSlot start,
243 #endif // V8_HEAP_SCAVENGER_H_