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 #ifndef V8_HEAP_MARKING_WORKLIST_INL_H_ 5 #define V8_HEAP_MARKING_WORKLIST_INL_H_ 6 7 #include <unordered_map> 8 #include <vector> 9 10 #include "src/heap/marking-worklist.h" 11 12 namespace v8 { 13 namespace internal { 14 15 template <typename Callback> Update(Callback callback)16void MarkingWorklists::Update(Callback callback) { 17 shared_.Update(callback); 18 on_hold_.Update(callback); 19 embedder_.Update(callback); 20 other_.Update(callback); 21 for (auto cw : context_worklists_) { 22 if (cw.context == kSharedContext || cw.context == kOtherContext) { 23 // These contexts were updated above. 24 continue; 25 } 26 cw.worklist->Update(callback); 27 } 28 } 29 Push(HeapObject object)30void MarkingWorklists::Local::Push(HeapObject object) { active_.Push(object); } 31 Pop(HeapObject * object)32bool MarkingWorklists::Local::Pop(HeapObject* object) { 33 if (active_.Pop(object)) return true; 34 if (!is_per_context_mode_) return false; 35 // The active worklist is empty. Find any other non-empty worklist and 36 // switch the active worklist to it. 37 return PopContext(object); 38 } 39 PushOnHold(HeapObject object)40void MarkingWorklists::Local::PushOnHold(HeapObject object) { 41 on_hold_.Push(object); 42 } 43 PopOnHold(HeapObject * object)44bool MarkingWorklists::Local::PopOnHold(HeapObject* object) { 45 return on_hold_.Pop(object); 46 } 47 PushEmbedder(HeapObject object)48void MarkingWorklists::Local::PushEmbedder(HeapObject object) { 49 embedder_.Push(object); 50 } 51 PopEmbedder(HeapObject * object)52bool MarkingWorklists::Local::PopEmbedder(HeapObject* object) { 53 return embedder_.Pop(object); 54 } 55 SwitchToContext(Address context)56Address MarkingWorklists::Local::SwitchToContext(Address context) { 57 if (context == active_context_) return context; 58 return SwitchToContextSlow(context); 59 } 60 SwitchToShared()61Address MarkingWorklists::Local::SwitchToShared() { 62 return SwitchToContext(kSharedContext); 63 } 64 SwitchToContext(Address context,MarkingWorklist::Local * worklist)65void MarkingWorklists::Local::SwitchToContext( 66 Address context, MarkingWorklist::Local* worklist) { 67 // Save the current worklist. 68 *active_owner_ = std::move(active_); 69 // Switch to the new worklist. 70 active_owner_ = worklist; 71 active_ = std::move(*worklist); 72 active_context_ = context; 73 } 74 75 } // namespace internal 76 } // namespace v8 77 78 #endif // V8_HEAP_MARKING_WORKLIST_INL_H_ 79