1 // Copyright 2020 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_CPPGC_CONCURRENT_MARKER_H_ 6 #define V8_HEAP_CPPGC_CONCURRENT_MARKER_H_ 7 8 #include "include/cppgc/platform.h" 9 #include "src/heap/cppgc/incremental-marking-schedule.h" 10 #include "src/heap/cppgc/marking-state.h" 11 #include "src/heap/cppgc/marking-visitor.h" 12 #include "src/heap/cppgc/marking-worklists.h" 13 14 namespace cppgc { 15 namespace internal { 16 17 class V8_EXPORT_PRIVATE ConcurrentMarkerBase { 18 public: 19 ConcurrentMarkerBase(HeapBase&, MarkingWorklists&, 20 IncrementalMarkingSchedule&, cppgc::Platform*); 21 virtual ~ConcurrentMarkerBase(); 22 23 ConcurrentMarkerBase(const ConcurrentMarkerBase&) = delete; 24 ConcurrentMarkerBase& operator=(const ConcurrentMarkerBase&) = delete; 25 26 void Start(); 27 void Cancel(); 28 29 void JoinForTesting(); 30 31 bool NotifyIncrementalMutatorStepCompleted(); 32 33 bool IsActive() const; 34 heap()35 HeapBase& heap() const { return heap_; } marking_worklists()36 MarkingWorklists& marking_worklists() const { return marking_worklists_; } incremental_marking_schedule()37 IncrementalMarkingSchedule& incremental_marking_schedule() const { 38 return incremental_marking_schedule_; 39 } 40 41 virtual std::unique_ptr<Visitor> CreateConcurrentMarkingVisitor( 42 ConcurrentMarkingState&) const = 0; 43 44 protected: 45 void IncreaseMarkingPriorityIfNeeded(); 46 47 private: 48 HeapBase& heap_; 49 MarkingWorklists& marking_worklists_; 50 IncrementalMarkingSchedule& incremental_marking_schedule_; 51 cppgc::Platform* const platform_; 52 53 // The job handle doubles as flag to denote concurrent marking was started. 54 std::unique_ptr<JobHandle> concurrent_marking_handle_{nullptr}; 55 56 size_t last_concurrently_marked_bytes_ = 0; 57 v8::base::TimeTicks last_concurrently_marked_bytes_update_; 58 bool concurrent_marking_priority_increased_{false}; 59 }; 60 61 class V8_EXPORT_PRIVATE ConcurrentMarker : public ConcurrentMarkerBase { 62 public: ConcurrentMarker(HeapBase & heap,MarkingWorklists & marking_worklists,IncrementalMarkingSchedule & incremental_marking_schedule,cppgc::Platform * platform)63 ConcurrentMarker(HeapBase& heap, MarkingWorklists& marking_worklists, 64 IncrementalMarkingSchedule& incremental_marking_schedule, 65 cppgc::Platform* platform) 66 : ConcurrentMarkerBase(heap, marking_worklists, 67 incremental_marking_schedule, platform) {} 68 69 std::unique_ptr<Visitor> CreateConcurrentMarkingVisitor( 70 ConcurrentMarkingState&) const final; 71 }; 72 73 } // namespace internal 74 } // namespace cppgc 75 76 #endif // V8_HEAP_CPPGC_CONCURRENT_MARKER_H_ 77