Commit cdf548da authored by Nikolaos Papaspyrou's avatar Nikolaos Papaspyrou Committed by V8 LUCI CQ

[heap] Bug fix and zeros in metrics for incremental mark/sweep

This CL fixes a bug in the units of the reported metrics for
V8.GC.Cycle.MainThread.Full.Incremental.Mark (ms instead of us).

It also reports incremental marking/sweeping metrics (both for the
unified heap and the C++ managed heap) only when incremental
marking/sweeping were used; otherwise, no zero values are reported.

Bug: chromium:1154636
Bug: chromium:1343507
Change-Id: Ibc0103ea62fa0eeb5f7184280c8514e99a5c21a3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3768502Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Nikolaos Papaspyrou <nikolaos@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81803}
parent b47a76c3
...@@ -252,6 +252,7 @@ void HeapBase::Terminate() { ...@@ -252,6 +252,7 @@ void HeapBase::Terminate() {
in_atomic_pause_ = true; in_atomic_pause_ = true;
stats_collector()->NotifyMarkingStarted( stats_collector()->NotifyMarkingStarted(
GarbageCollector::Config::CollectionType::kMajor, GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kForced); GarbageCollector::Config::IsForcedGC::kForced);
object_allocator().ResetLinearAllocationBuffers(); object_allocator().ResetLinearAllocationBuffers();
stats_collector()->NotifyMarkingCompleted(0); stats_collector()->NotifyMarkingCompleted(0);
......
...@@ -218,8 +218,8 @@ void MarkerBase::StartMarking() { ...@@ -218,8 +218,8 @@ void MarkerBase::StartMarking() {
? StatsCollector::kAtomicMark ? StatsCollector::kAtomicMark
: StatsCollector::kIncrementalMark); : StatsCollector::kIncrementalMark);
heap().stats_collector()->NotifyMarkingStarted(config_.collection_type, heap().stats_collector()->NotifyMarkingStarted(
config_.is_forced_gc); config_.collection_type, config_.marking_type, config_.is_forced_gc);
is_marking_ = true; is_marking_ = true;
if (EnterIncrementalMarkingIfNeeded(config_, heap())) { if (EnterIncrementalMarkingIfNeeded(config_, heap())) {
......
...@@ -108,10 +108,12 @@ StatsCollector::Event::Event() { ...@@ -108,10 +108,12 @@ StatsCollector::Event::Event() {
} }
void StatsCollector::NotifyMarkingStarted(CollectionType collection_type, void StatsCollector::NotifyMarkingStarted(CollectionType collection_type,
MarkingType marking_type,
IsForcedGC is_forced_gc) { IsForcedGC is_forced_gc) {
DCHECK_EQ(GarbageCollectionState::kNotRunning, gc_state_); DCHECK_EQ(GarbageCollectionState::kNotRunning, gc_state_);
current_.collection_type = collection_type; current_.collection_type = collection_type;
current_.is_forced_gc = is_forced_gc; current_.is_forced_gc = is_forced_gc;
current_.marking_type = marking_type;
gc_state_ = GarbageCollectionState::kMarking; gc_state_ = GarbageCollectionState::kMarking;
} }
...@@ -169,7 +171,9 @@ int64_t SumPhases(const MetricRecorder::GCCycle::Phases& phases) { ...@@ -169,7 +171,9 @@ int64_t SumPhases(const MetricRecorder::GCCycle::Phases& phases) {
} }
MetricRecorder::GCCycle GetCycleEventForMetricRecorder( MetricRecorder::GCCycle GetCycleEventForMetricRecorder(
StatsCollector::CollectionType type, int64_t atomic_mark_us, StatsCollector::CollectionType type,
StatsCollector::MarkingType marking_type,
StatsCollector::SweepingType sweeping_type, int64_t atomic_mark_us,
int64_t atomic_weak_us, int64_t atomic_compact_us, int64_t atomic_sweep_us, int64_t atomic_weak_us, int64_t atomic_compact_us, int64_t atomic_sweep_us,
int64_t incremental_mark_us, int64_t incremental_sweep_us, int64_t incremental_mark_us, int64_t incremental_sweep_us,
int64_t concurrent_mark_us, int64_t concurrent_sweep_us, int64_t concurrent_mark_us, int64_t concurrent_sweep_us,
...@@ -181,8 +185,13 @@ MetricRecorder::GCCycle GetCycleEventForMetricRecorder( ...@@ -181,8 +185,13 @@ MetricRecorder::GCCycle GetCycleEventForMetricRecorder(
? MetricRecorder::GCCycle::Type::kMajor ? MetricRecorder::GCCycle::Type::kMajor
: MetricRecorder::GCCycle::Type::kMinor; : MetricRecorder::GCCycle::Type::kMinor;
// MainThread.Incremental: // MainThread.Incremental:
event.main_thread_incremental.mark_duration_us = incremental_mark_us; event.main_thread_incremental.mark_duration_us =
event.main_thread_incremental.sweep_duration_us = incremental_sweep_us; marking_type != StatsCollector::MarkingType::kAtomic ? incremental_mark_us
: -1;
event.main_thread_incremental.sweep_duration_us =
sweeping_type != StatsCollector::SweepingType::kAtomic
? incremental_sweep_us
: -1;
// MainThread.Atomic: // MainThread.Atomic:
event.main_thread_atomic.mark_duration_us = atomic_mark_us; event.main_thread_atomic.mark_duration_us = atomic_mark_us;
event.main_thread_atomic.weak_duration_us = atomic_weak_us; event.main_thread_atomic.weak_duration_us = atomic_weak_us;
...@@ -190,15 +199,13 @@ MetricRecorder::GCCycle GetCycleEventForMetricRecorder( ...@@ -190,15 +199,13 @@ MetricRecorder::GCCycle GetCycleEventForMetricRecorder(
event.main_thread_atomic.sweep_duration_us = atomic_sweep_us; event.main_thread_atomic.sweep_duration_us = atomic_sweep_us;
// MainThread: // MainThread:
event.main_thread.mark_duration_us = event.main_thread.mark_duration_us =
event.main_thread_atomic.mark_duration_us + event.main_thread_atomic.mark_duration_us + incremental_mark_us;
event.main_thread_incremental.mark_duration_us;
event.main_thread.weak_duration_us = event.main_thread.weak_duration_us =
event.main_thread_atomic.weak_duration_us; event.main_thread_atomic.weak_duration_us;
event.main_thread.compact_duration_us = event.main_thread.compact_duration_us =
event.main_thread_atomic.compact_duration_us; event.main_thread_atomic.compact_duration_us;
event.main_thread.sweep_duration_us = event.main_thread.sweep_duration_us =
event.main_thread_atomic.sweep_duration_us + event.main_thread_atomic.sweep_duration_us + incremental_sweep_us;
event.main_thread_incremental.sweep_duration_us;
// Total: // Total:
event.total.mark_duration_us = event.total.mark_duration_us =
event.main_thread.mark_duration_us + concurrent_mark_us; event.main_thread.mark_duration_us + concurrent_mark_us;
...@@ -240,14 +247,21 @@ MetricRecorder::GCCycle GetCycleEventForMetricRecorder( ...@@ -240,14 +247,21 @@ MetricRecorder::GCCycle GetCycleEventForMetricRecorder(
} // namespace } // namespace
void StatsCollector::NotifySweepingCompleted() { void StatsCollector::NotifySweepingCompleted(SweepingType sweeping_type) {
DCHECK_EQ(GarbageCollectionState::kSweeping, gc_state_); DCHECK_EQ(GarbageCollectionState::kSweeping, gc_state_);
gc_state_ = GarbageCollectionState::kNotRunning; gc_state_ = GarbageCollectionState::kNotRunning;
current_.sweeping_type = sweeping_type;
previous_ = std::move(current_); previous_ = std::move(current_);
current_ = Event(); current_ = Event();
DCHECK_IMPLIES(previous_.marking_type == StatsCollector::MarkingType::kAtomic,
previous_.scope_data[kIncrementalMark].IsZero());
DCHECK_IMPLIES(
previous_.sweeping_type == StatsCollector::SweepingType::kAtomic,
previous_.scope_data[kIncrementalSweep].IsZero());
if (metric_recorder_) { if (metric_recorder_) {
MetricRecorder::GCCycle event = GetCycleEventForMetricRecorder( MetricRecorder::GCCycle event = GetCycleEventForMetricRecorder(
previous_.collection_type, previous_.collection_type, previous_.marking_type,
previous_.sweeping_type,
previous_.scope_data[kAtomicMark].InMicroseconds(), previous_.scope_data[kAtomicMark].InMicroseconds(),
previous_.scope_data[kAtomicWeak].InMicroseconds(), previous_.scope_data[kAtomicWeak].InMicroseconds(),
previous_.scope_data[kAtomicCompact].InMicroseconds(), previous_.scope_data[kAtomicCompact].InMicroseconds(),
......
...@@ -71,6 +71,8 @@ class V8_EXPORT_PRIVATE StatsCollector final { ...@@ -71,6 +71,8 @@ class V8_EXPORT_PRIVATE StatsCollector final {
public: public:
using CollectionType = GarbageCollector::Config::CollectionType; using CollectionType = GarbageCollector::Config::CollectionType;
using MarkingType = GarbageCollector::Config::MarkingType;
using SweepingType = GarbageCollector::Config::SweepingType;
#if defined(CPPGC_DECLARE_ENUM) #if defined(CPPGC_DECLARE_ENUM)
static_assert(false, "CPPGC_DECLARE_ENUM macro is already defined"); static_assert(false, "CPPGC_DECLARE_ENUM macro is already defined");
...@@ -107,6 +109,8 @@ class V8_EXPORT_PRIVATE StatsCollector final { ...@@ -107,6 +109,8 @@ class V8_EXPORT_PRIVATE StatsCollector final {
size_t epoch = -1; size_t epoch = -1;
CollectionType collection_type = CollectionType::kMajor; CollectionType collection_type = CollectionType::kMajor;
MarkingType marking_type = MarkingType::kAtomic;
SweepingType sweeping_type = SweepingType::kAtomic;
IsForcedGC is_forced_gc = IsForcedGC::kNotForced; IsForcedGC is_forced_gc = IsForcedGC::kNotForced;
// Marked bytes collected during marking. // Marked bytes collected during marking.
size_t marked_bytes = 0; size_t marked_bytes = 0;
...@@ -270,13 +274,13 @@ class V8_EXPORT_PRIVATE StatsCollector final { ...@@ -270,13 +274,13 @@ class V8_EXPORT_PRIVATE StatsCollector final {
void NotifySafePointForTesting(); void NotifySafePointForTesting();
// Indicates a new garbage collection cycle. // Indicates a new garbage collection cycle.
void NotifyMarkingStarted(CollectionType, IsForcedGC); void NotifyMarkingStarted(CollectionType, MarkingType, IsForcedGC);
// Indicates that marking of the current garbage collection cycle is // Indicates that marking of the current garbage collection cycle is
// completed. // completed.
void NotifyMarkingCompleted(size_t marked_bytes); void NotifyMarkingCompleted(size_t marked_bytes);
// Indicates the end of a garbage collection cycle. This means that sweeping // Indicates the end of a garbage collection cycle. This means that sweeping
// is finished at this point. // is finished at this point.
void NotifySweepingCompleted(); void NotifySweepingCompleted(SweepingType);
size_t allocated_memory_size() const; size_t allocated_memory_size() const;
// Size of live objects in bytes on the heap. Based on the most recent marked // Size of live objects in bytes on the heap. Based on the most recent marked
......
...@@ -902,7 +902,7 @@ class Sweeper::SweeperImpl final { ...@@ -902,7 +902,7 @@ class Sweeper::SweeperImpl final {
DCHECK(!is_in_progress_); DCHECK(!is_in_progress_);
DCHECK(notify_done_pending_); DCHECK(notify_done_pending_);
notify_done_pending_ = false; notify_done_pending_ = false;
stats_collector_->NotifySweepingCompleted(); stats_collector_->NotifySweepingCompleted(config_.sweeping_type);
} }
void NotifyDoneIfNeeded() { void NotifyDoneIfNeeded() {
......
...@@ -1392,13 +1392,17 @@ void CopyTimeMetrics( ...@@ -1392,13 +1392,17 @@ void CopyTimeMetrics(
::v8::metrics::GarbageCollectionPhases& metrics, ::v8::metrics::GarbageCollectionPhases& metrics,
const cppgc::internal::MetricRecorder::GCCycle::IncrementalPhases& const cppgc::internal::MetricRecorder::GCCycle::IncrementalPhases&
cppgc_metrics) { cppgc_metrics) {
DCHECK_NE(-1, cppgc_metrics.mark_duration_us); // Allow for uninitialized values (-1), in case incremental marking/sweeping
// were not used.
DCHECK_LE(-1, cppgc_metrics.mark_duration_us);
metrics.mark_wall_clock_duration_in_us = cppgc_metrics.mark_duration_us; metrics.mark_wall_clock_duration_in_us = cppgc_metrics.mark_duration_us;
DCHECK_NE(-1, cppgc_metrics.sweep_duration_us); DCHECK_LE(-1, cppgc_metrics.sweep_duration_us);
metrics.sweep_wall_clock_duration_in_us = cppgc_metrics.sweep_duration_us; metrics.sweep_wall_clock_duration_in_us = cppgc_metrics.sweep_duration_us;
// The total duration is initialized, even if both incremental
// marking and sweeping were not used.
metrics.total_wall_clock_duration_in_us = metrics.total_wall_clock_duration_in_us =
metrics.mark_wall_clock_duration_in_us + std::max(INT64_C(0), metrics.mark_wall_clock_duration_in_us) +
metrics.sweep_wall_clock_duration_in_us; std::max(INT64_C(0), metrics.sweep_wall_clock_duration_in_us);
} }
void CopyTimeMetrics( void CopyTimeMetrics(
...@@ -1578,10 +1582,19 @@ void GCTracer::ReportFullCycleToRecorder() { ...@@ -1578,10 +1582,19 @@ void GCTracer::ReportFullCycleToRecorder() {
event.total.sweep_wall_clock_duration_in_us = event.total.sweep_wall_clock_duration_in_us =
static_cast<int64_t>((sweeping_duration + sweeping_background_duration) * static_cast<int64_t>((sweeping_duration + sweeping_background_duration) *
base::Time::kMicrosecondsPerMillisecond); base::Time::kMicrosecondsPerMillisecond);
event.main_thread_incremental.mark_wall_clock_duration_in_us = if (current_.type == Event::INCREMENTAL_MARK_COMPACTOR) {
incremental_marking; event.main_thread_incremental.mark_wall_clock_duration_in_us =
static_cast<int64_t>(incremental_marking *
base::Time::kMicrosecondsPerMillisecond);
} else {
DCHECK_EQ(0, incremental_marking);
event.main_thread_incremental.mark_wall_clock_duration_in_us = -1;
}
// TODO(chromium:1154636): We always report the value of incremental sweeping,
// even if it is zero.
event.main_thread_incremental.sweep_wall_clock_duration_in_us = event.main_thread_incremental.sweep_wall_clock_duration_in_us =
incremental_sweeping; static_cast<int64_t>(incremental_sweeping *
base::Time::kMicrosecondsPerMillisecond);
// TODO(chromium:1154636): Populate the following: // TODO(chromium:1154636): Populate the following:
// - event.objects // - event.objects
......
...@@ -124,10 +124,12 @@ TEST_F(CompactorTest, NothingToCompact) { ...@@ -124,10 +124,12 @@ TEST_F(CompactorTest, NothingToCompact) {
StartCompaction(); StartCompaction();
heap()->stats_collector()->NotifyMarkingStarted( heap()->stats_collector()->NotifyMarkingStarted(
GarbageCollector::Config::CollectionType::kMajor, GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
heap()->stats_collector()->NotifyMarkingCompleted(0); heap()->stats_collector()->NotifyMarkingCompleted(0);
FinishCompaction(); FinishCompaction();
heap()->stats_collector()->NotifySweepingCompleted(); heap()->stats_collector()->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
} }
TEST_F(CompactorTest, NonEmptySpaceAllLive) { TEST_F(CompactorTest, NonEmptySpaceAllLive) {
......
...@@ -74,6 +74,7 @@ class ConcurrentSweeperTest : public testing::TestWithHeap { ...@@ -74,6 +74,7 @@ class ConcurrentSweeperTest : public testing::TestWithHeap {
// methods are called in the right order. // methods are called in the right order.
heap->stats_collector()->NotifyMarkingStarted( heap->stats_collector()->NotifyMarkingStarted(
GarbageCollector::Config::CollectionType::kMajor, GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
heap->stats_collector()->NotifyMarkingCompleted(0); heap->stats_collector()->NotifyMarkingCompleted(0);
Sweeper& sweeper = heap->sweeper(); Sweeper& sweeper = heap->sweeper();
......
...@@ -66,7 +66,8 @@ class EphemeronPairTest : public testing::TestWithHeap { ...@@ -66,7 +66,8 @@ class EphemeronPairTest : public testing::TestWithHeap {
marker_->FinishMarking(MarkingConfig::StackState::kNoHeapPointers); marker_->FinishMarking(MarkingConfig::StackState::kNoHeapPointers);
// Pretend do finish sweeping as StatsCollector verifies that Notify* // Pretend do finish sweeping as StatsCollector verifies that Notify*
// methods are called in the right order. // methods are called in the right order.
Heap::From(GetHeap())->stats_collector()->NotifySweepingCompleted(); Heap::From(GetHeap())->stats_collector()->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kIncremental);
} }
void InitializeMarker(HeapBase& heap, cppgc::Platform* platform) { void InitializeMarker(HeapBase& heap, cppgc::Platform* platform) {
......
...@@ -25,9 +25,11 @@ class FakeGarbageCollector : public GarbageCollector { ...@@ -25,9 +25,11 @@ class FakeGarbageCollector : public GarbageCollector {
void CollectGarbage(GarbageCollector::Config config) override { void CollectGarbage(GarbageCollector::Config config) override {
stats_collector_->NotifyMarkingStarted( stats_collector_->NotifyMarkingStarted(
GarbageCollector::Config::CollectionType::kMajor, GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
stats_collector_->NotifyMarkingCompleted(live_bytes_); stats_collector_->NotifyMarkingCompleted(live_bytes_);
stats_collector_->NotifySweepingCompleted(); stats_collector_->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
callcount_++; callcount_++;
} }
......
...@@ -35,7 +35,8 @@ class MarkerTest : public testing::TestWithHeap { ...@@ -35,7 +35,8 @@ class MarkerTest : public testing::TestWithHeap {
marker_->FinishMarking(stack_state); marker_->FinishMarking(stack_state);
// Pretend do finish sweeping as StatsCollector verifies that Notify* // Pretend do finish sweeping as StatsCollector verifies that Notify*
// methods are called in the right order. // methods are called in the right order.
heap->stats_collector()->NotifySweepingCompleted(); heap->stats_collector()->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
} }
void InitializeMarker(HeapBase& heap, cppgc::Platform* platform, void InitializeMarker(HeapBase& heap, cppgc::Platform* platform,
...@@ -416,7 +417,8 @@ class IncrementalMarkingTest : public testing::TestWithHeap { ...@@ -416,7 +417,8 @@ class IncrementalMarkingTest : public testing::TestWithHeap {
// Pretend do finish sweeping as StatsCollector verifies that Notify* // Pretend do finish sweeping as StatsCollector verifies that Notify*
// methods are called in the right order. // methods are called in the right order.
GetMarkerRef().reset(); GetMarkerRef().reset();
Heap::From(GetHeap())->stats_collector()->NotifySweepingCompleted(); Heap::From(GetHeap())->stats_collector()->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kIncremental);
} }
void InitializeMarker(HeapBase& heap, cppgc::Platform* platform, void InitializeMarker(HeapBase& heap, cppgc::Platform* platform,
......
...@@ -53,11 +53,13 @@ class MetricRecorderTest : public testing::TestWithHeap { ...@@ -53,11 +53,13 @@ class MetricRecorderTest : public testing::TestWithHeap {
void StartGC() { void StartGC() {
stats->NotifyMarkingStarted( stats->NotifyMarkingStarted(
GarbageCollector::Config::CollectionType::kMajor, GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kIncremental,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
} }
void EndGC(size_t marked_bytes) { void EndGC(size_t marked_bytes) {
stats->NotifyMarkingCompleted(marked_bytes); stats->NotifyMarkingCompleted(marked_bytes);
stats->NotifySweepingCompleted(); stats->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kIncremental);
} }
StatsCollector* stats; StatsCollector* stats;
...@@ -99,7 +101,7 @@ TEST_F(MetricRecorderTest, IncrementalScopesReportedImmediately) { ...@@ -99,7 +101,7 @@ TEST_F(MetricRecorderTest, IncrementalScopesReportedImmediately) {
EndGC(0); EndGC(0);
} }
TEST_F(MetricRecorderTest, NonIncrementlaScopesNotReportedImmediately) { TEST_F(MetricRecorderTest, NonIncrementalScopesNotReportedImmediately) {
MetricRecorderImpl::GCCycle_callcount = 0u; MetricRecorderImpl::GCCycle_callcount = 0u;
MetricRecorderImpl::MainThreadIncrementalMark_callcount = 0u; MetricRecorderImpl::MainThreadIncrementalMark_callcount = 0u;
MetricRecorderImpl::MainThreadIncrementalSweep_callcount = 0u; MetricRecorderImpl::MainThreadIncrementalSweep_callcount = 0u;
...@@ -306,7 +308,8 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) { ...@@ -306,7 +308,8 @@ TEST_F(MetricRecorderTest, ObjectSizeMetricsWithAllocations) {
stats->NotifyAllocation(150); stats->NotifyAllocation(150);
stats->NotifyAllocatedMemory(1000); stats->NotifyAllocatedMemory(1000);
stats->NotifyFreedMemory(400); stats->NotifyFreedMemory(400);
stats->NotifySweepingCompleted(); stats->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
EXPECT_EQ(1300u, MetricRecorderImpl::GCCycle_event.objects.before_bytes); EXPECT_EQ(1300u, MetricRecorderImpl::GCCycle_event.objects.before_bytes);
EXPECT_EQ(800, MetricRecorderImpl::GCCycle_event.objects.after_bytes); EXPECT_EQ(800, MetricRecorderImpl::GCCycle_event.objects.after_bytes);
EXPECT_EQ(500u, MetricRecorderImpl::GCCycle_event.objects.freed_bytes); EXPECT_EQ(500u, MetricRecorderImpl::GCCycle_event.objects.freed_bytes);
......
...@@ -78,7 +78,8 @@ class V8_NODISCARD CppgcTracingScopesTest : public testing::TestWithHeap { ...@@ -78,7 +78,8 @@ class V8_NODISCARD CppgcTracingScopesTest : public testing::TestWithHeap {
DelegatingTracingControllerImpl::check_expectations = false; DelegatingTracingControllerImpl::check_expectations = false;
GetMarkerRef()->FinishMarking(Config::StackState::kNoHeapPointers); GetMarkerRef()->FinishMarking(Config::StackState::kNoHeapPointers);
GetMarkerRef().reset(); GetMarkerRef().reset();
Heap::From(GetHeap())->stats_collector()->NotifySweepingCompleted(); Heap::From(GetHeap())->stats_collector()->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
} }
void ResetDelegatingTracingController(const char* expected_name = nullptr) { void ResetDelegatingTracingController(const char* expected_name = nullptr) {
...@@ -229,9 +230,11 @@ TEST_F(CppgcTracingScopesTest, InitalScopesAreZero) { ...@@ -229,9 +230,11 @@ TEST_F(CppgcTracingScopesTest, InitalScopesAreZero) {
StatsCollector* stats_collector = Heap::From(GetHeap())->stats_collector(); StatsCollector* stats_collector = Heap::From(GetHeap())->stats_collector();
stats_collector->NotifyMarkingStarted( stats_collector->NotifyMarkingStarted(
GarbageCollector::Config::CollectionType::kMajor, GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
stats_collector->NotifyMarkingCompleted(0); stats_collector->NotifyMarkingCompleted(0);
stats_collector->NotifySweepingCompleted(); stats_collector->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
const StatsCollector::Event& event = const StatsCollector::Event& event =
stats_collector->GetPreviousEventForTesting(); stats_collector->GetPreviousEventForTesting();
for (int i = 0; i < StatsCollector::kNumHistogramScopeIds; ++i) { for (int i = 0; i < StatsCollector::kNumHistogramScopeIds; ++i) {
...@@ -248,6 +251,7 @@ TEST_F(CppgcTracingScopesTest, TestIndividualScopes) { ...@@ -248,6 +251,7 @@ TEST_F(CppgcTracingScopesTest, TestIndividualScopes) {
StatsCollector* stats_collector = Heap::From(GetHeap())->stats_collector(); StatsCollector* stats_collector = Heap::From(GetHeap())->stats_collector();
stats_collector->NotifyMarkingStarted( stats_collector->NotifyMarkingStarted(
GarbageCollector::Config::CollectionType::kMajor, GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kIncremental,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
DelegatingTracingControllerImpl::check_expectations = false; DelegatingTracingControllerImpl::check_expectations = false;
{ {
...@@ -260,7 +264,8 @@ TEST_F(CppgcTracingScopesTest, TestIndividualScopes) { ...@@ -260,7 +264,8 @@ TEST_F(CppgcTracingScopesTest, TestIndividualScopes) {
} }
} }
stats_collector->NotifyMarkingCompleted(0); stats_collector->NotifyMarkingCompleted(0);
stats_collector->NotifySweepingCompleted(); stats_collector->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kIncremental);
const StatsCollector::Event& event = const StatsCollector::Event& event =
stats_collector->GetPreviousEventForTesting(); stats_collector->GetPreviousEventForTesting();
for (int i = 0; i < StatsCollector::kNumHistogramScopeIds; ++i) { for (int i = 0; i < StatsCollector::kNumHistogramScopeIds; ++i) {
...@@ -281,6 +286,7 @@ TEST_F(CppgcTracingScopesTest, TestIndividualConcurrentScopes) { ...@@ -281,6 +286,7 @@ TEST_F(CppgcTracingScopesTest, TestIndividualConcurrentScopes) {
StatsCollector* stats_collector = Heap::From(GetHeap())->stats_collector(); StatsCollector* stats_collector = Heap::From(GetHeap())->stats_collector();
stats_collector->NotifyMarkingStarted( stats_collector->NotifyMarkingStarted(
GarbageCollector::Config::CollectionType::kMajor, GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
DelegatingTracingControllerImpl::check_expectations = false; DelegatingTracingControllerImpl::check_expectations = false;
{ {
...@@ -293,7 +299,8 @@ TEST_F(CppgcTracingScopesTest, TestIndividualConcurrentScopes) { ...@@ -293,7 +299,8 @@ TEST_F(CppgcTracingScopesTest, TestIndividualConcurrentScopes) {
} }
} }
stats_collector->NotifyMarkingCompleted(0); stats_collector->NotifyMarkingCompleted(0);
stats_collector->NotifySweepingCompleted(); stats_collector->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
const StatsCollector::Event& event = const StatsCollector::Event& event =
stats_collector->GetPreviousEventForTesting(); stats_collector->GetPreviousEventForTesting();
for (int i = 0; i < StatsCollector::kNumHistogramScopeIds; ++i) { for (int i = 0; i < StatsCollector::kNumHistogramScopeIds; ++i) {
......
...@@ -39,18 +39,22 @@ class StatsCollectorTest : public ::testing::Test { ...@@ -39,18 +39,22 @@ class StatsCollectorTest : public ::testing::Test {
TEST_F(StatsCollectorTest, NoMarkedBytes) { TEST_F(StatsCollectorTest, NoMarkedBytes) {
stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor, stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
stats.NotifyMarkingCompleted(kNoMarkedBytes); stats.NotifyMarkingCompleted(kNoMarkedBytes);
stats.NotifySweepingCompleted(); stats.NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
auto event = stats.GetPreviousEventForTesting(); auto event = stats.GetPreviousEventForTesting();
EXPECT_EQ(0u, event.marked_bytes); EXPECT_EQ(0u, event.marked_bytes);
} }
TEST_F(StatsCollectorTest, EventPrevGCMarkedObjectSize) { TEST_F(StatsCollectorTest, EventPrevGCMarkedObjectSize) {
stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor, stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
stats.NotifyMarkingCompleted(1024); stats.NotifyMarkingCompleted(1024);
stats.NotifySweepingCompleted(); stats.NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
auto event = stats.GetPreviousEventForTesting(); auto event = stats.GetPreviousEventForTesting();
EXPECT_EQ(1024u, event.marked_bytes); EXPECT_EQ(1024u, event.marked_bytes);
} }
...@@ -71,45 +75,53 @@ TEST_F(StatsCollectorTest, AlllocationReportAboveAllocationThresholdBytes) { ...@@ -71,45 +75,53 @@ TEST_F(StatsCollectorTest, AlllocationReportAboveAllocationThresholdBytes) {
TEST_F(StatsCollectorTest, InitialAllocatedObjectSize) { TEST_F(StatsCollectorTest, InitialAllocatedObjectSize) {
stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor, stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
EXPECT_EQ(0u, stats.allocated_object_size()); EXPECT_EQ(0u, stats.allocated_object_size());
stats.NotifyMarkingCompleted(kNoMarkedBytes); stats.NotifyMarkingCompleted(kNoMarkedBytes);
EXPECT_EQ(0u, stats.allocated_object_size()); EXPECT_EQ(0u, stats.allocated_object_size());
stats.NotifySweepingCompleted(); stats.NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
EXPECT_EQ(0u, stats.allocated_object_size()); EXPECT_EQ(0u, stats.allocated_object_size());
} }
TEST_F(StatsCollectorTest, AllocatedObjectSize) { TEST_F(StatsCollectorTest, AllocatedObjectSize) {
stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor, stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
FakeAllocate(kMinReportedSize); FakeAllocate(kMinReportedSize);
EXPECT_EQ(kMinReportedSize, stats.allocated_object_size()); EXPECT_EQ(kMinReportedSize, stats.allocated_object_size());
stats.NotifyMarkingCompleted(kMinReportedSize); stats.NotifyMarkingCompleted(kMinReportedSize);
EXPECT_EQ(kMinReportedSize, stats.allocated_object_size()); EXPECT_EQ(kMinReportedSize, stats.allocated_object_size());
stats.NotifySweepingCompleted(); stats.NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
EXPECT_EQ(kMinReportedSize, stats.allocated_object_size()); EXPECT_EQ(kMinReportedSize, stats.allocated_object_size());
} }
TEST_F(StatsCollectorTest, AllocatedObjectSizeNoMarkedBytes) { TEST_F(StatsCollectorTest, AllocatedObjectSizeNoMarkedBytes) {
stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor, stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
FakeAllocate(kMinReportedSize); FakeAllocate(kMinReportedSize);
EXPECT_EQ(kMinReportedSize, stats.allocated_object_size()); EXPECT_EQ(kMinReportedSize, stats.allocated_object_size());
stats.NotifyMarkingCompleted(kNoMarkedBytes); stats.NotifyMarkingCompleted(kNoMarkedBytes);
EXPECT_EQ(0u, stats.allocated_object_size()); EXPECT_EQ(0u, stats.allocated_object_size());
stats.NotifySweepingCompleted(); stats.NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
EXPECT_EQ(0u, stats.allocated_object_size()); EXPECT_EQ(0u, stats.allocated_object_size());
} }
TEST_F(StatsCollectorTest, AllocatedObjectSizeAllocateAfterMarking) { TEST_F(StatsCollectorTest, AllocatedObjectSizeAllocateAfterMarking) {
stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor, stats.NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
FakeAllocate(kMinReportedSize); FakeAllocate(kMinReportedSize);
EXPECT_EQ(kMinReportedSize, stats.allocated_object_size()); EXPECT_EQ(kMinReportedSize, stats.allocated_object_size());
stats.NotifyMarkingCompleted(kMinReportedSize); stats.NotifyMarkingCompleted(kMinReportedSize);
FakeAllocate(kMinReportedSize); FakeAllocate(kMinReportedSize);
EXPECT_EQ(2 * kMinReportedSize, stats.allocated_object_size()); EXPECT_EQ(2 * kMinReportedSize, stats.allocated_object_size());
stats.NotifySweepingCompleted(); stats.NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
EXPECT_EQ(2 * kMinReportedSize, stats.allocated_object_size()); EXPECT_EQ(2 * kMinReportedSize, stats.allocated_object_size());
} }
...@@ -142,9 +154,11 @@ namespace { ...@@ -142,9 +154,11 @@ namespace {
void FakeGC(StatsCollector* stats, size_t marked_bytes) { void FakeGC(StatsCollector* stats, size_t marked_bytes) {
stats->NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor, stats->NotifyMarkingStarted(GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
stats->NotifyMarkingCompleted(marked_bytes); stats->NotifyMarkingCompleted(marked_bytes);
stats->NotifySweepingCompleted(); stats->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
} }
} // namespace } // namespace
......
...@@ -49,6 +49,7 @@ class SweeperTest : public testing::TestWithHeap { ...@@ -49,6 +49,7 @@ class SweeperTest : public testing::TestWithHeap {
// methods are called in the right order. // methods are called in the right order.
heap->stats_collector()->NotifyMarkingStarted( heap->stats_collector()->NotifyMarkingStarted(
GarbageCollector::Config::CollectionType::kMajor, GarbageCollector::Config::CollectionType::kMajor,
GarbageCollector::Config::MarkingType::kAtomic,
GarbageCollector::Config::IsForcedGC::kNotForced); GarbageCollector::Config::IsForcedGC::kNotForced);
heap->stats_collector()->NotifyMarkingCompleted(0); heap->stats_collector()->NotifyMarkingCompleted(0);
const Sweeper::SweepingConfig sweeping_config{ const Sweeper::SweepingConfig sweeping_config{
......
...@@ -36,7 +36,8 @@ class WeakContainerTest : public testing::TestWithHeap { ...@@ -36,7 +36,8 @@ class WeakContainerTest : public testing::TestWithHeap {
marked_bytes_ = marked_bytes_ =
Heap::From(GetHeap())->AsBase().stats_collector()->marked_bytes(); Heap::From(GetHeap())->AsBase().stats_collector()->marked_bytes();
GetMarkerRef().reset(); GetMarkerRef().reset();
Heap::From(GetHeap())->stats_collector()->NotifySweepingCompleted(); Heap::From(GetHeap())->stats_collector()->NotifySweepingCompleted(
GarbageCollector::Config::SweepingType::kAtomic);
} }
size_t GetMarkedBytes() const { return marked_bytes_; } size_t GetMarkedBytes() const { return marked_bytes_; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment