diff --git a/src/heap/heap.cc b/src/heap/heap.cc index b00ee0da4b..995ee61f42 100644 --- a/src/heap/heap.cc +++ b/src/heap/heap.cc @@ -202,7 +202,7 @@ Heap::Heap() : isolate_(isolate()), memory_pressure_level_(MemoryPressureLevel::kNone), global_pretenuring_feedback_(kInitialFeedbackCapacity), - safepoint_(new Safepoint(this)), + safepoint_(new GlobalSafepoint(this)), external_string_table_(this) { // Ensure old_generation_size_ is a multiple of kPageSize. DCHECK_EQ(0, max_old_generation_size_ & (Page::kPageSize - 1)); diff --git a/src/heap/heap.h b/src/heap/heap.h index 6d6eddf61a..3dfd36321a 100644 --- a/src/heap/heap.h +++ b/src/heap/heap.h @@ -66,6 +66,7 @@ class ConcurrentMarking; class GCIdleTimeHandler; class GCIdleTimeHeapState; class GCTracer; +class GlobalSafepoint; class HeapObjectAllocationTracker; class HeapObjectsFilter; class HeapStats; @@ -83,7 +84,6 @@ class Page; class PagedSpace; class ReadOnlyHeap; class RootVisitor; -class Safepoint; class ScavengeJob; class Scavenger; class ScavengerCollector; @@ -620,7 +620,7 @@ class Heap { void AppendArrayBufferExtension(JSArrayBuffer object, ArrayBufferExtension* extension); - Safepoint* safepoint() { return safepoint_.get(); } + GlobalSafepoint* safepoint() { return safepoint_.get(); } V8_EXPORT_PRIVATE double MonotonicallyIncreasingTimeInMs(); @@ -2166,7 +2166,7 @@ class Heap { GCCallbackFlags current_gc_callback_flags_ = GCCallbackFlags::kNoGCCallbackFlags; - std::unique_ptr safepoint_; + std::unique_ptr safepoint_; bool is_current_gc_forced_ = false; diff --git a/src/heap/local-heap.h b/src/heap/local-heap.h index 8255eeb325..615fc4600c 100644 --- a/src/heap/local-heap.h +++ b/src/heap/local-heap.h @@ -11,6 +11,7 @@ #include "src/base/platform/condition-variable.h" #include "src/base/platform/mutex.h" #include "src/execution/isolate.h" +#include "src/heap/safepoint.h" namespace v8 { namespace internal { @@ -78,7 +79,7 @@ class LocalHeap { std::unique_ptr persistent_handles_; friend class Heap; - friend class Safepoint; + friend class GlobalSafepoint; friend class ParkedScope; }; diff --git a/src/heap/safepoint.cc b/src/heap/safepoint.cc index a37eb36491..44210b6512 100644 --- a/src/heap/safepoint.cc +++ b/src/heap/safepoint.cc @@ -12,14 +12,14 @@ namespace v8 { namespace internal { -Safepoint::Safepoint(Heap* heap) +GlobalSafepoint::GlobalSafepoint(Heap* heap) : heap_(heap), local_heaps_head_(nullptr), is_active_(false) {} -void Safepoint::Start() { StopThreads(); } +void GlobalSafepoint::Start() { StopThreads(); } -void Safepoint::End() { ResumeThreads(); } +void GlobalSafepoint::End() { ResumeThreads(); } -void Safepoint::StopThreads() { +void GlobalSafepoint::StopThreads() { local_heaps_mutex_.Lock(); barrier_.Arm(); @@ -41,7 +41,7 @@ void Safepoint::StopThreads() { is_active_ = true; } -void Safepoint::ResumeThreads() { +void GlobalSafepoint::ResumeThreads() { is_active_ = false; for (LocalHeap* current = local_heaps_head_; current; @@ -54,7 +54,7 @@ void Safepoint::ResumeThreads() { local_heaps_mutex_.Unlock(); } -void Safepoint::EnterFromThread(LocalHeap* local_heap) { +void GlobalSafepoint::EnterFromThread(LocalHeap* local_heap) { { base::MutexGuard guard(&local_heap->state_mutex_); local_heap->state_ = LocalHeap::ThreadState::Safepoint; @@ -69,20 +69,20 @@ void Safepoint::EnterFromThread(LocalHeap* local_heap) { } } -void Safepoint::Barrier::Arm() { +void GlobalSafepoint::Barrier::Arm() { base::MutexGuard guard(&mutex_); CHECK(!armed_); armed_ = true; } -void Safepoint::Barrier::Disarm() { +void GlobalSafepoint::Barrier::Disarm() { base::MutexGuard guard(&mutex_); CHECK(armed_); armed_ = false; cond_.NotifyAll(); } -void Safepoint::Barrier::Wait() { +void GlobalSafepoint::Barrier::Wait() { base::MutexGuard guard(&mutex_); while (armed_) { cond_.Wait(&mutex_); @@ -95,7 +95,7 @@ SafepointScope::SafepointScope(Heap* heap) : safepoint_(heap->safepoint()) { SafepointScope::~SafepointScope() { safepoint_->ResumeThreads(); } -void Safepoint::AddLocalHeap(LocalHeap* local_heap) { +void GlobalSafepoint::AddLocalHeap(LocalHeap* local_heap) { base::MutexGuard guard(&local_heaps_mutex_); if (local_heaps_head_) local_heaps_head_->prev_ = local_heap; local_heap->prev_ = nullptr; @@ -103,7 +103,7 @@ void Safepoint::AddLocalHeap(LocalHeap* local_heap) { local_heaps_head_ = local_heap; } -void Safepoint::RemoveLocalHeap(LocalHeap* local_heap) { +void GlobalSafepoint::RemoveLocalHeap(LocalHeap* local_heap) { base::MutexGuard guard(&local_heaps_mutex_); if (local_heap->next_) local_heap->next_->prev_ = local_heap->prev_; if (local_heap->prev_) @@ -112,7 +112,7 @@ void Safepoint::RemoveLocalHeap(LocalHeap* local_heap) { local_heaps_head_ = local_heap->next_; } -bool Safepoint::ContainsLocalHeap(LocalHeap* local_heap) { +bool GlobalSafepoint::ContainsLocalHeap(LocalHeap* local_heap) { base::MutexGuard guard(&local_heaps_mutex_); LocalHeap* current = local_heaps_head_; @@ -124,12 +124,12 @@ bool Safepoint::ContainsLocalHeap(LocalHeap* local_heap) { return false; } -bool Safepoint::ContainsAnyLocalHeap() { +bool GlobalSafepoint::ContainsAnyLocalHeap() { base::MutexGuard guard(&local_heaps_mutex_); return local_heaps_head_ != nullptr; } -void Safepoint::Iterate(RootVisitor* visitor) { +void GlobalSafepoint::Iterate(RootVisitor* visitor) { DCHECK(IsActive()); for (LocalHeap* current = local_heaps_head_; current; current = current->next_) { diff --git a/src/heap/safepoint.h b/src/heap/safepoint.h index 06f9c75044..2ab3f0ac43 100644 --- a/src/heap/safepoint.h +++ b/src/heap/safepoint.h @@ -17,9 +17,11 @@ class Heap; class LocalHeap; class RootVisitor; -class Safepoint { +// Used to bring all background threads with heap access to a safepoint such +// that e.g. a garabge collection can be performed. +class GlobalSafepoint { public: - explicit Safepoint(Heap* heap); + explicit GlobalSafepoint(Heap* heap); // Enter the safepoint from a thread void EnterFromThread(LocalHeap* local_heap); @@ -75,7 +77,7 @@ class SafepointScope { V8_EXPORT_PRIVATE ~SafepointScope(); private: - Safepoint* safepoint_; + GlobalSafepoint* safepoint_; }; } // namespace internal