diff --git a/src/handles/global-handles.cc b/src/handles/global-handles.cc index 46cab4c57b..8bc022e5af 100644 --- a/src/handles/global-handles.cc +++ b/src/handles/global-handles.cc @@ -880,6 +880,20 @@ void GlobalHandles::OnStackTracedNodeSpace::CleanupBelowCurrentStackPosition() { on_stack_nodes_.erase(on_stack_nodes_.begin(), it); } +// static +void GlobalHandles::EnableMarkingBarrier(Isolate* isolate) { + auto* global_handles = isolate->global_handles(); + DCHECK(!global_handles->is_marking_); + global_handles->is_marking_ = true; +} + +// static +void GlobalHandles::DisableMarkingBarrier(Isolate* isolate) { + auto* global_handles = isolate->global_handles(); + DCHECK(global_handles->is_marking_); + global_handles->is_marking_ = false; +} + // static void GlobalHandles::TracedNode::Verify(GlobalHandles* global_handles, const Address* const* slot) { @@ -1172,10 +1186,7 @@ void GlobalHandles::DestroyTraced(Address* location) { // When marking is off the handle may be freed immediately. Note that this // includes also the case when invoking the first pass callbacks during the // atomic pause which requires releasing a node fully. - if (!global_handles->isolate() - ->heap() - ->incremental_marking() - ->IsMarking()) { + if (!global_handles->is_marking_) { NodeSpace::Release(node); return; } diff --git a/src/handles/global-handles.h b/src/handles/global-handles.h index 86b276c2df..058af91069 100644 --- a/src/handles/global-handles.h +++ b/src/handles/global-handles.h @@ -45,6 +45,9 @@ enum WeaknessType { // callbacks and finalizers attached to them. class V8_EXPORT_PRIVATE GlobalHandles final { public: + static void EnableMarkingBarrier(Isolate*); + static void DisableMarkingBarrier(Isolate*); + GlobalHandles(const GlobalHandles&) = delete; GlobalHandles& operator=(const GlobalHandles&) = delete; @@ -236,6 +239,7 @@ class V8_EXPORT_PRIVATE GlobalHandles final { Node* node); Isolate* const isolate_; + bool is_marking_ = false; std::unique_ptr> regular_nodes_; // Contains all nodes holding young objects. Note: when the list diff --git a/src/heap/incremental-marking.cc b/src/heap/incremental-marking.cc index 130b1fdd1b..66d1556b28 100644 --- a/src/heap/incremental-marking.cc +++ b/src/heap/incremental-marking.cc @@ -6,6 +6,7 @@ #include "src/codegen/compilation-cache.h" #include "src/execution/vm-state-inl.h" +#include "src/handles/global-handles.h" #include "src/heap/concurrent-marking.h" #include "src/heap/embedder-tracing.h" #include "src/heap/gc-idle-time-handler.h" @@ -251,6 +252,7 @@ void IncrementalMarking::StartMarking() { SetState(MARKING); MarkingBarrier::ActivateAll(heap(), is_compacting_); + GlobalHandles::EnableMarkingBarrier(heap()->isolate()); heap_->isolate()->compilation_cache()->MarkCompactPrologue(); diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc index f1d6755161..96d36c1c65 100644 --- a/src/heap/mark-compact.cc +++ b/src/heap/mark-compact.cc @@ -2440,6 +2440,7 @@ void MarkCompactCollector::MarkLiveObjects() { } if (was_marked_incrementally_) { MarkingBarrier::DeactivateAll(heap()); + GlobalHandles::DisableMarkingBarrier(heap()->isolate()); } epoch_++;