Commit c71cd221 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

heap: Re-land trivial refactorings from change 1713626

- Minor ThreadHeapStatsCollector fixes
- Refactor sweeping finalization to reflect the two-step approach (Notify ->
  PostSweep) that already happened in practice.

Initially landed see https://crrev.com/c/1713626

Bug: 982754
Change-Id: I358e0cb43129fd631c31b626e64157e3ba57ce07
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724675
Auto-Submit: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682274}
parent d43ba51c
...@@ -134,7 +134,7 @@ void ThreadHeapStatsCollector::NotifySweepingCompleted() { ...@@ -134,7 +134,7 @@ void ThreadHeapStatsCollector::NotifySweepingCompleted() {
? static_cast<double>(current().marked_bytes) / ? static_cast<double>(current().marked_bytes) /
current_.object_size_in_bytes_before_sweeping current_.object_size_in_bytes_before_sweeping
: 0.0; : 0.0;
current_.gc_nested_in_v8_ = gc_nested_in_v8_; current_.gc_nested_in_v8 = gc_nested_in_v8_;
gc_nested_in_v8_ = base::TimeDelta(); gc_nested_in_v8_ = base::TimeDelta();
// Reset the current state. // Reset the current state.
static_assert(std::is_trivially_copyable<Event>::value, static_assert(std::is_trivially_copyable<Event>::value,
......
...@@ -278,7 +278,7 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector { ...@@ -278,7 +278,7 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
size_t partition_alloc_bytes_before_sweeping = 0; size_t partition_alloc_bytes_before_sweeping = 0;
double live_object_rate = 0; double live_object_rate = 0;
size_t wrapper_count_before_sweeping = 0; size_t wrapper_count_before_sweeping = 0;
base::TimeDelta gc_nested_in_v8_; base::TimeDelta gc_nested_in_v8;
}; };
// Indicates a new garbage collection cycle. // Indicates a new garbage collection cycle.
...@@ -348,7 +348,6 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector { ...@@ -348,7 +348,6 @@ class PLATFORM_EXPORT ThreadHeapStatsCollector {
// Statistics for the previously running garbage collection. // Statistics for the previously running garbage collection.
const Event& previous() const { return previous_; } const Event& previous() const { return previous_; }
void RegisterObserver(ThreadHeapStatsObserver* observer); void RegisterObserver(ThreadHeapStatsObserver* observer);
void UnregisterObserver(ThreadHeapStatsObserver* observer); void UnregisterObserver(ThreadHeapStatsObserver* observer);
......
...@@ -637,7 +637,7 @@ void ThreadState::PerformIdleLazySweep(base::TimeTicks deadline) { ...@@ -637,7 +637,7 @@ void ThreadState::PerformIdleLazySweep(base::TimeTicks deadline) {
} }
if (sweep_completed) { if (sweep_completed) {
PostSweep(); NotifySweepDone();
} }
} }
...@@ -884,7 +884,7 @@ void ThreadState::AtomicPauseEpilogue() { ...@@ -884,7 +884,7 @@ void ThreadState::AtomicPauseEpilogue() {
if (!IsSweepingInProgress()) { if (!IsSweepingInProgress()) {
// Sweeping was finished during the atomic pause. Update statistics needs to // Sweeping was finished during the atomic pause. Update statistics needs to
// run outside of the top-most stats scope. // run outside of the top-most stats scope.
UpdateStatisticsAfterSweeping(); PostSweep();
} }
} }
...@@ -918,7 +918,7 @@ void ThreadState::CompleteSweep() { ...@@ -918,7 +918,7 @@ void ThreadState::CompleteSweep() {
if (!was_in_atomic_pause) if (!was_in_atomic_pause)
LeaveAtomicPause(); LeaveAtomicPause();
} }
PostSweep(); NotifySweepDone();
} }
void ThreadState::SynchronizeAndFinishConcurrentSweeping() { void ThreadState::SynchronizeAndFinishConcurrentSweeping() {
...@@ -1011,7 +1011,7 @@ void UpdateHistograms(const ThreadHeapStatsCollector::Event& event) { ...@@ -1011,7 +1011,7 @@ void UpdateHistograms(const ThreadHeapStatsCollector::Event& event) {
UMA_HISTOGRAM_TIMES("BlinkGC.TimeForIncrementalMarking", UMA_HISTOGRAM_TIMES("BlinkGC.TimeForIncrementalMarking",
event.incremental_marking_time()); event.incremental_marking_time());
UMA_HISTOGRAM_TIMES("BlinkGC.TimeForMarking", event.marking_time()); UMA_HISTOGRAM_TIMES("BlinkGC.TimeForMarking", event.marking_time());
UMA_HISTOGRAM_TIMES("BlinkGC.TimeForNestedInV8", event.gc_nested_in_v8_); UMA_HISTOGRAM_TIMES("BlinkGC.TimeForNestedInV8", event.gc_nested_in_v8);
UMA_HISTOGRAM_TIMES("BlinkGC.TimeForSweepingForeground", UMA_HISTOGRAM_TIMES("BlinkGC.TimeForSweepingForeground",
event.foreground_sweeping_time()); event.foreground_sweeping_time());
UMA_HISTOGRAM_TIMES("BlinkGC.TimeForSweepingBackground", UMA_HISTOGRAM_TIMES("BlinkGC.TimeForSweepingBackground",
...@@ -1110,30 +1110,29 @@ void UpdateHistograms(const ThreadHeapStatsCollector::Event& event) { ...@@ -1110,30 +1110,29 @@ void UpdateHistograms(const ThreadHeapStatsCollector::Event& event) {
} // namespace } // namespace
void ThreadState::UpdateStatisticsAfterSweeping() { void ThreadState::NotifySweepDone() {
DCHECK(!IsSweepingInProgress()); DCHECK(CheckThread());
DCHECK(Heap().stats_collector()->is_started()); SetGCPhase(GCPhase::kNone);
Heap().stats_collector()->NotifySweepingCompleted(); if (!in_atomic_pause()) {
if (IsMainThread()) PostSweep();
UpdateHistograms(Heap().stats_collector()->previous()); }
// Emit trace counters for all threads.
UpdateTraceCounters(*Heap().stats_collector());
} }
void ThreadState::PostSweep() { void ThreadState::PostSweep() {
DCHECK(CheckThread()); DCHECK(!in_atomic_pause());
DCHECK(!IsSweepingInProgress());
SetGCPhase(GCPhase::kNone);
gc_age_++; gc_age_++;
for (auto* const observer : observers_) for (auto* const observer : observers_)
observer->OnCompleteSweepDone(); observer->OnCompleteSweepDone();
if (!in_atomic_pause()) { Heap().stats_collector()->NotifySweepingCompleted();
// Immediately update the statistics if running outside of the atomic pause.
UpdateStatisticsAfterSweeping(); if (IsMainThread())
} UpdateHistograms(Heap().stats_collector()->previous());
// Emit trace counters for all threads.
UpdateTraceCounters(*Heap().stats_collector());
} }
void ThreadState::SafePoint(BlinkGC::StackState stack_state) { void ThreadState::SafePoint(BlinkGC::StackState stack_state) {
......
...@@ -293,6 +293,7 @@ class PLATFORM_EXPORT ThreadState final : private RAILModeObserver { ...@@ -293,6 +293,7 @@ class PLATFORM_EXPORT ThreadState final : private RAILModeObserver {
void CompleteSweep(); void CompleteSweep();
void FinishSnapshot(); void FinishSnapshot();
void NotifySweepDone();
void PostSweep(); void PostSweep();
// Returns whether it is currently allowed to allocate an object. Mainly used // Returns whether it is currently allowed to allocate an object. Mainly used
...@@ -500,8 +501,6 @@ class PLATFORM_EXPORT ThreadState final : private RAILModeObserver { ...@@ -500,8 +501,6 @@ class PLATFORM_EXPORT ThreadState final : private RAILModeObserver {
BlinkGC::SweepingType, BlinkGC::SweepingType,
BlinkGC::GCReason); BlinkGC::GCReason);
void UpdateStatisticsAfterSweeping();
// The version is needed to be able to start incremental marking. // The version is needed to be able to start incremental marking.
void MarkPhasePrologue(BlinkGC::StackState, void MarkPhasePrologue(BlinkGC::StackState,
BlinkGC::MarkingType, BlinkGC::MarkingType,
......
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