V8 Project
v8::internal::GCIdleTimeHandler Class Reference

#include <gc-idle-time-handler.h>

+ Collaboration diagram for v8::internal::GCIdleTimeHandler:

Classes

struct  HeapState
 

Public Member Functions

 GCIdleTimeHandler ()
 
GCIdleTimeAction Compute (size_t idle_time_in_ms, HeapState heap_state)
 
void NotifyIdleMarkCompact ()
 
void NotifyScavenge ()
 

Static Public Member Functions

static size_t EstimateMarkingStepSize (size_t idle_time_in_ms, size_t marking_speed_in_bytes_per_ms)
 
static size_t EstimateMarkCompactTime (size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms)
 
static size_t EstimateScavengeTime (size_t new_space_size, size_t scavenger_speed_in_bytes_per_ms)
 
static bool ScavangeMayHappenSoon (size_t available_new_space_memory, size_t new_space_allocation_throughput_in_bytes_per_ms)
 

Static Public Attributes

static const size_t kInitialConservativeMarkingSpeed = 100 * KB
 
static const size_t kMaximumMarkingStepSize = 700 * MB
 
static const double kConservativeTimeRatio = 0.9
 
static const size_t kInitialConservativeMarkCompactSpeed = 2 * MB
 
static const size_t kMaxMarkCompactTimeInMs = 1000
 
static const size_t kMinTimeForFinalizeSweeping = 100
 
static const int kMaxMarkCompactsInIdleRound = 7
 
static const int kIdleScavengeThreshold = 5
 
static const size_t kSmallHeapSize = 4 * kPointerSize * MB
 
static const size_t kMaxFrameRenderingIdleTime = 16
 
static const size_t kNewSpaceAlmostFullTreshold = 100 * KB
 
static const size_t kInitialConservativeScavengeSpeed = 100 * KB
 

Private Member Functions

void StartIdleRound ()
 
bool IsMarkCompactIdleRoundFinished ()
 
bool EnoughGarbageSinceLastIdleRound ()
 
 DISALLOW_COPY_AND_ASSIGN (GCIdleTimeHandler)
 

Private Attributes

int mark_compacts_since_idle_round_started_
 
int scavenges_since_last_idle_round_
 

Detailed Description

Definition at line 78 of file gc-idle-time-handler.h.

Constructor & Destructor Documentation

◆ GCIdleTimeHandler()

v8::internal::GCIdleTimeHandler::GCIdleTimeHandler ( )
inline

Member Function Documentation

◆ Compute()

GCIdleTimeAction v8::internal::GCIdleTimeHandler::Compute ( size_t  idle_time_in_ms,
HeapState  heap_state 
)

Definition at line 111 of file gc-idle-time-handler.cc.

112  {
113  if (idle_time_in_ms <= kMaxFrameRenderingIdleTime &&
115  heap_state.available_new_space_memory,
116  heap_state.new_space_allocation_throughput_in_bytes_per_ms) &&
117  idle_time_in_ms >=
118  EstimateScavengeTime(heap_state.new_space_capacity,
119  heap_state.scavenge_speed_in_bytes_per_ms)) {
121  }
123  if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) {
124  StartIdleRound();
125  } else {
126  return GCIdleTimeAction::Done();
127  }
128  }
129 
130  if (idle_time_in_ms == 0) {
131  return GCIdleTimeAction::Nothing();
132  }
133 
134  if (heap_state.incremental_marking_stopped) {
135  size_t estimated_time_in_ms =
136  EstimateMarkCompactTime(heap_state.size_of_objects,
137  heap_state.mark_compact_speed_in_bytes_per_ms);
138  if (idle_time_in_ms >= estimated_time_in_ms ||
139  (heap_state.size_of_objects < kSmallHeapSize &&
140  heap_state.contexts_disposed > 0)) {
141  // If there are no more than two GCs left in this idle round and we are
142  // allowed to do a full GC, then make those GCs full in order to compact
143  // the code space.
144  // TODO(ulan): Once we enable code compaction for incremental marking, we
145  // can get rid of this special case and always start incremental marking.
146  int remaining_mark_sweeps =
148  if (heap_state.contexts_disposed > 0 ||
149  (idle_time_in_ms > kMaxFrameRenderingIdleTime &&
150  (remaining_mark_sweeps <= 2 ||
151  !heap_state.can_start_incremental_marking))) {
152  return GCIdleTimeAction::FullGC();
153  }
154  }
155  if (!heap_state.can_start_incremental_marking) {
156  return GCIdleTimeAction::Nothing();
157  }
158  }
159  // TODO(hpayer): Estimate finalize sweeping time.
160  if (heap_state.sweeping_in_progress &&
161  idle_time_in_ms >= kMinTimeForFinalizeSweeping) {
163  }
164 
165  if (heap_state.incremental_marking_stopped &&
166  !heap_state.can_start_incremental_marking) {
167  return GCIdleTimeAction::Nothing();
168  }
169  size_t step_size = EstimateMarkingStepSize(
170  idle_time_in_ms, heap_state.incremental_marking_speed_in_bytes_per_ms);
171  return GCIdleTimeAction::IncrementalMarking(step_size);
172 }
static GCIdleTimeAction Done()
static GCIdleTimeAction Scavenge()
static GCIdleTimeAction FinalizeSweeping()
static GCIdleTimeAction FullGC()
static GCIdleTimeAction Nothing()
static GCIdleTimeAction IncrementalMarking(intptr_t step_size)
static size_t EstimateScavengeTime(size_t new_space_size, size_t scavenger_speed_in_bytes_per_ms)
static const size_t kMinTimeForFinalizeSweeping
static const size_t kMaxFrameRenderingIdleTime
static size_t EstimateMarkCompactTime(size_t size_of_objects, size_t mark_compact_speed_in_bytes_per_ms)
static bool ScavangeMayHappenSoon(size_t available_new_space_memory, size_t new_space_allocation_throughput_in_bytes_per_ms)
static size_t EstimateMarkingStepSize(size_t idle_time_in_ms, size_t marking_speed_in_bytes_per_ms)

References v8::internal::GCIdleTimeHandler::HeapState::available_new_space_memory, v8::internal::GCIdleTimeHandler::HeapState::can_start_incremental_marking, v8::internal::GCIdleTimeHandler::HeapState::contexts_disposed, v8::internal::GCIdleTimeAction::Done(), EnoughGarbageSinceLastIdleRound(), EstimateMarkCompactTime(), EstimateMarkingStepSize(), EstimateScavengeTime(), v8::internal::GCIdleTimeAction::FinalizeSweeping(), v8::internal::GCIdleTimeAction::FullGC(), v8::internal::GCIdleTimeHandler::HeapState::incremental_marking_speed_in_bytes_per_ms, v8::internal::GCIdleTimeHandler::HeapState::incremental_marking_stopped, v8::internal::GCIdleTimeAction::IncrementalMarking(), IsMarkCompactIdleRoundFinished(), kMaxFrameRenderingIdleTime, kMaxMarkCompactsInIdleRound, kMinTimeForFinalizeSweeping, kSmallHeapSize, v8::internal::GCIdleTimeHandler::HeapState::mark_compact_speed_in_bytes_per_ms, mark_compacts_since_idle_round_started_, v8::internal::GCIdleTimeHandler::HeapState::new_space_allocation_throughput_in_bytes_per_ms, v8::internal::GCIdleTimeHandler::HeapState::new_space_capacity, v8::internal::GCIdleTimeAction::Nothing(), ScavangeMayHappenSoon(), v8::internal::GCIdleTimeAction::Scavenge(), v8::internal::GCIdleTimeHandler::HeapState::scavenge_speed_in_bytes_per_ms, v8::internal::GCIdleTimeHandler::HeapState::size_of_objects, StartIdleRound(), and v8::internal::GCIdleTimeHandler::HeapState::sweeping_in_progress.

Referenced by v8::internal::Heap::IdleNotification().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DISALLOW_COPY_AND_ASSIGN()

v8::internal::GCIdleTimeHandler::DISALLOW_COPY_AND_ASSIGN ( GCIdleTimeHandler  )
private

◆ EnoughGarbageSinceLastIdleRound()

bool v8::internal::GCIdleTimeHandler::EnoughGarbageSinceLastIdleRound ( )
inlineprivate

Definition at line 175 of file gc-idle-time-handler.h.

References kIdleScavengeThreshold, and scavenges_since_last_idle_round_.

Referenced by Compute().

+ Here is the caller graph for this function:

◆ EstimateMarkCompactTime()

size_t v8::internal::GCIdleTimeHandler::EstimateMarkCompactTime ( size_t  size_of_objects,
size_t  mark_compact_speed_in_bytes_per_ms 
)
static

Definition at line 64 of file gc-idle-time-handler.cc.

65  {
66  if (mark_compact_speed_in_bytes_per_ms == 0) {
67  mark_compact_speed_in_bytes_per_ms = kInitialConservativeMarkCompactSpeed;
68  }
69  size_t result = size_of_objects / mark_compact_speed_in_bytes_per_ms;
70  return Min(result, kMaxMarkCompactTimeInMs);
71 }
static const size_t kInitialConservativeMarkCompactSpeed
static const size_t kMaxMarkCompactTimeInMs
static LifetimePosition Min(LifetimePosition a, LifetimePosition b)

References kInitialConservativeMarkCompactSpeed, kMaxMarkCompactTimeInMs, and v8::internal::Min().

Referenced by Compute(), and v8::internal::TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EstimateMarkingStepSize()

size_t v8::internal::GCIdleTimeHandler::EstimateMarkingStepSize ( size_t  idle_time_in_ms,
size_t  marking_speed_in_bytes_per_ms 
)
static

Definition at line 43 of file gc-idle-time-handler.cc.

44  {
45  DCHECK(idle_time_in_ms > 0);
46 
47  if (marking_speed_in_bytes_per_ms == 0) {
48  marking_speed_in_bytes_per_ms = kInitialConservativeMarkingSpeed;
49  }
50 
51  size_t marking_step_size = marking_speed_in_bytes_per_ms * idle_time_in_ms;
52  if (marking_step_size / marking_speed_in_bytes_per_ms != idle_time_in_ms) {
53  // In the case of an overflow we return maximum marking step size.
55  }
56 
57  if (marking_step_size > kMaximumMarkingStepSize)
59 
60  return static_cast<size_t>(marking_step_size * kConservativeTimeRatio);
61 }
static const double kConservativeTimeRatio
static const size_t kInitialConservativeMarkingSpeed
static const size_t kMaximumMarkingStepSize
#define DCHECK(condition)
Definition: logging.h:205

References DCHECK, kConservativeTimeRatio, kInitialConservativeMarkingSpeed, and kMaximumMarkingStepSize.

Referenced by Compute(), and v8::internal::TEST().

+ Here is the caller graph for this function:

◆ EstimateScavengeTime()

size_t v8::internal::GCIdleTimeHandler::EstimateScavengeTime ( size_t  new_space_size,
size_t  scavenger_speed_in_bytes_per_ms 
)
static

Definition at line 74 of file gc-idle-time-handler.cc.

75  {
76  if (scavenge_speed_in_bytes_per_ms == 0) {
77  scavenge_speed_in_bytes_per_ms = kInitialConservativeScavengeSpeed;
78  }
79  return new_space_size / scavenge_speed_in_bytes_per_ms;
80 }
static const size_t kInitialConservativeScavengeSpeed

References kInitialConservativeScavengeSpeed.

Referenced by Compute(), and v8::internal::TEST().

+ Here is the caller graph for this function:

◆ IsMarkCompactIdleRoundFinished()

bool v8::internal::GCIdleTimeHandler::IsMarkCompactIdleRoundFinished ( )
inlineprivate

Definition at line 171 of file gc-idle-time-handler.h.

References kMaxMarkCompactsInIdleRound, and mark_compacts_since_idle_round_started_.

Referenced by Compute().

+ Here is the caller graph for this function:

◆ NotifyIdleMarkCompact()

void v8::internal::GCIdleTimeHandler::NotifyIdleMarkCompact ( )
inline

Definition at line 144 of file gc-idle-time-handler.h.

References kMaxMarkCompactsInIdleRound, mark_compacts_since_idle_round_started_, and scavenges_since_last_idle_round_.

Referenced by v8::internal::Heap::AdvanceIdleIncrementalMarking(), and v8::internal::Heap::IdleNotification().

+ Here is the caller graph for this function:

◆ NotifyScavenge()

void v8::internal::GCIdleTimeHandler::NotifyScavenge ( )
inline

◆ ScavangeMayHappenSoon()

bool v8::internal::GCIdleTimeHandler::ScavangeMayHappenSoon ( size_t  available_new_space_memory,
size_t  new_space_allocation_throughput_in_bytes_per_ms 
)
static

Definition at line 83 of file gc-idle-time-handler.cc.

85  {
86  if (available_new_space_memory <=
87  new_space_allocation_throughput_in_bytes_per_ms *
89  return true;
90  }
91  return false;
92 }

References kMaxFrameRenderingIdleTime.

Referenced by Compute(), and v8::internal::TEST().

+ Here is the caller graph for this function:

◆ StartIdleRound()

void v8::internal::GCIdleTimeHandler::StartIdleRound ( )
inlineprivate

Definition at line 170 of file gc-idle-time-handler.h.

References mark_compacts_since_idle_round_started_.

Referenced by Compute().

+ Here is the caller graph for this function:

Member Data Documentation

◆ kConservativeTimeRatio

const double v8::internal::GCIdleTimeHandler::kConservativeTimeRatio = 0.9
static

Definition at line 89 of file gc-idle-time-handler.h.

Referenced by EstimateMarkingStepSize(), and v8::internal::TEST().

◆ kIdleScavengeThreshold

const int v8::internal::GCIdleTimeHandler::kIdleScavengeThreshold = 5
static

◆ kInitialConservativeMarkCompactSpeed

const size_t v8::internal::GCIdleTimeHandler::kInitialConservativeMarkCompactSpeed = 2 * MB
static

Definition at line 93 of file gc-idle-time-handler.h.

Referenced by EstimateMarkCompactTime(), and v8::internal::TEST().

◆ kInitialConservativeMarkingSpeed

const size_t v8::internal::GCIdleTimeHandler::kInitialConservativeMarkingSpeed = 100 * KB
static

Definition at line 82 of file gc-idle-time-handler.h.

Referenced by EstimateMarkingStepSize(), and v8::internal::TEST().

◆ kInitialConservativeScavengeSpeed

const size_t v8::internal::GCIdleTimeHandler::kInitialConservativeScavengeSpeed = 100 * KB
static

Definition at line 122 of file gc-idle-time-handler.h.

Referenced by EstimateScavengeTime(), and v8::internal::TEST().

◆ kMaxFrameRenderingIdleTime

const size_t v8::internal::GCIdleTimeHandler::kMaxFrameRenderingIdleTime = 16
static

Definition at line 114 of file gc-idle-time-handler.h.

Referenced by Compute(), ScavangeMayHappenSoon(), and v8::internal::TEST().

◆ kMaximumMarkingStepSize

const size_t v8::internal::GCIdleTimeHandler::kMaximumMarkingStepSize = 700 * MB
static

Definition at line 85 of file gc-idle-time-handler.h.

Referenced by EstimateMarkingStepSize(), and v8::internal::TEST().

◆ kMaxMarkCompactsInIdleRound

const int v8::internal::GCIdleTimeHandler::kMaxMarkCompactsInIdleRound = 7
static

◆ kMaxMarkCompactTimeInMs

const size_t v8::internal::GCIdleTimeHandler::kMaxMarkCompactTimeInMs = 1000
static

Definition at line 96 of file gc-idle-time-handler.h.

Referenced by EstimateMarkCompactTime(), and v8::internal::TEST().

◆ kMinTimeForFinalizeSweeping

const size_t v8::internal::GCIdleTimeHandler::kMinTimeForFinalizeSweeping = 100
static

Definition at line 100 of file gc-idle-time-handler.h.

Referenced by Compute().

◆ kNewSpaceAlmostFullTreshold

const size_t v8::internal::GCIdleTimeHandler::kNewSpaceAlmostFullTreshold = 100 * KB
static

Definition at line 118 of file gc-idle-time-handler.h.

◆ kSmallHeapSize

const size_t v8::internal::GCIdleTimeHandler::kSmallHeapSize = 4 * kPointerSize * MB
static

Definition at line 111 of file gc-idle-time-handler.h.

Referenced by Compute().

◆ mark_compacts_since_idle_round_started_

int v8::internal::GCIdleTimeHandler::mark_compacts_since_idle_round_started_
private

◆ scavenges_since_last_idle_round_

int v8::internal::GCIdleTimeHandler::scavenges_since_last_idle_round_
private

The documentation for this class was generated from the following files: