1 // Copyright 2022 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_REMEMBERED_SET_H_ 6 #define V8_HEAP_CPPGC_REMEMBERED_SET_H_ 7 8 #include <set> 9 10 #include "src/base/macros.h" 11 #include "src/heap/cppgc/marking-worklists.h" 12 13 namespace cppgc { 14 15 class Visitor; 16 class LivenessBroker; 17 18 namespace internal { 19 20 class HeapBase; 21 class HeapObjectHeader; 22 class MutatorMarkingState; 23 24 class V8_EXPORT_PRIVATE OldToNewRememberedSet final { 25 public: 26 using WeakCallbackItem = MarkingWorklists::WeakCallbackItem; 27 OldToNewRememberedSet(const HeapBase & heap)28 explicit OldToNewRememberedSet(const HeapBase& heap) 29 : heap_(heap), remembered_weak_callbacks_(compare_parameter) {} 30 31 OldToNewRememberedSet(const OldToNewRememberedSet&) = delete; 32 OldToNewRememberedSet& operator=(const OldToNewRememberedSet&) = delete; 33 34 void AddSlot(void* slot); 35 void AddSourceObject(HeapObjectHeader& source_hoh); 36 void AddWeakCallback(WeakCallbackItem); 37 38 void InvalidateRememberedSlotsInRange(void* begin, void* end); 39 void InvalidateRememberedSourceObject(HeapObjectHeader& source_hoh); 40 41 void Visit(Visitor&, MutatorMarkingState&); 42 43 void ExecuteCustomCallbacks(LivenessBroker); 44 void ReleaseCustomCallbacks(); 45 46 void Reset(); 47 48 private: 49 friend class MinorGCTest; 50 51 static constexpr struct { operator__anon307178b7010852 bool operator()(const WeakCallbackItem& lhs, 53 const WeakCallbackItem& rhs) const { 54 return lhs.parameter < rhs.parameter; 55 } 56 } compare_parameter{}; 57 58 const HeapBase& heap_; 59 std::set<void*> remembered_slots_; 60 std::set<HeapObjectHeader*> remembered_source_objects_; 61 std::set<WeakCallbackItem, decltype(compare_parameter)> 62 remembered_weak_callbacks_; 63 }; 64 65 } // namespace internal 66 } // namespace cppgc 67 68 #endif // V8_HEAP_CPPGC_REMEMBERED_SET_H_ 69