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 // Returns whether the job has been joined. 28 bool Join(); 29 // Returns whether the job has been cancelled. 30 bool Cancel(); 31 32 void NotifyIncrementalMutatorStepCompleted(); 33 34 bool IsActive() const; 35 heap()36 HeapBase& heap() const { return heap_; } marking_worklists()37 MarkingWorklists& marking_worklists() const { return marking_worklists_; } incremental_marking_schedule()38 IncrementalMarkingSchedule& incremental_marking_schedule() const { 39 return incremental_marking_schedule_; 40 } 41 42 virtual std::unique_ptr<Visitor> CreateConcurrentMarkingVisitor( 43 ConcurrentMarkingState&) const = 0; 44 45 protected: 46 void IncreaseMarkingPriorityIfNeeded(); 47 48 private: 49 HeapBase& heap_; 50 MarkingWorklists& marking_worklists_; 51 IncrementalMarkingSchedule& incremental_marking_schedule_; 52 cppgc::Platform* const platform_; 53 54 // The job handle doubles as flag to denote concurrent marking was started. 55 std::unique_ptr<JobHandle> concurrent_marking_handle_{nullptr}; 56 57 size_t last_concurrently_marked_bytes_ = 0; 58 v8::base::TimeTicks last_concurrently_marked_bytes_update_; 59 bool concurrent_marking_priority_increased_{false}; 60 }; 61 62 class V8_EXPORT_PRIVATE ConcurrentMarker : public ConcurrentMarkerBase { 63 public: ConcurrentMarker(HeapBase & heap,MarkingWorklists & marking_worklists,IncrementalMarkingSchedule & incremental_marking_schedule,cppgc::Platform * platform)64 ConcurrentMarker(HeapBase& heap, MarkingWorklists& marking_worklists, 65 IncrementalMarkingSchedule& incremental_marking_schedule, 66 cppgc::Platform* platform) 67 : ConcurrentMarkerBase(heap, marking_worklists, 68 incremental_marking_schedule, platform) {} 69 70 std::unique_ptr<Visitor> CreateConcurrentMarkingVisitor( 71 ConcurrentMarkingState&) const final; 72 }; 73 74 } // namespace internal 75 } // namespace cppgc 76 77 #endif // V8_HEAP_CPPGC_CONCURRENT_MARKER_H_ 78