Commit 62d9188d authored by ulan@chromium.org's avatar ulan@chromium.org

Reland part of r23285 "Start incremental marking in idle time handler only if it is worthwhile.""

R=hpayer@chromium.org

Review URL: https://codereview.chromium.org/496873004

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23298 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2fd20234
...@@ -46,22 +46,20 @@ size_t GCIdleTimeHandler::EstimateMarkCompactTime( ...@@ -46,22 +46,20 @@ size_t GCIdleTimeHandler::EstimateMarkCompactTime(
GCIdleTimeAction GCIdleTimeHandler::Compute(int idle_time_in_ms, GCIdleTimeAction GCIdleTimeHandler::Compute(int idle_time_in_ms,
int contexts_disposed, HeapState heap_state,
size_t size_of_objects,
bool incremental_marking_stopped,
GCTracer* gc_tracer) { GCTracer* gc_tracer) {
if (IsIdleRoundFinished()) { if (IsIdleRoundFinished()) {
if (EnoughGarbageSinceLastIdleRound() || contexts_disposed > 0) { if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed > 0) {
StartIdleRound(); StartIdleRound();
} else { } else {
return GCIdleTimeAction::Nothing(); return GCIdleTimeAction::Nothing();
} }
} }
if (incremental_marking_stopped) { if (heap_state.incremental_marking_stopped) {
size_t speed = size_t speed =
static_cast<size_t>(gc_tracer->MarkCompactSpeedInBytesPerMillisecond()); static_cast<size_t>(gc_tracer->MarkCompactSpeedInBytesPerMillisecond());
if (idle_time_in_ms >= if (idle_time_in_ms >= static_cast<int>(EstimateMarkCompactTime(
static_cast<int>(EstimateMarkCompactTime(size_of_objects, speed))) { heap_state.size_of_objects, speed))) {
// If there are no more than two GCs left in this idle round and we are // If there are no more than two GCs left in this idle round and we are
// allowed to do a full GC, then make those GCs full in order to compact // allowed to do a full GC, then make those GCs full in order to compact
// the code space. // the code space.
...@@ -69,10 +67,14 @@ GCIdleTimeAction GCIdleTimeHandler::Compute(int idle_time_in_ms, ...@@ -69,10 +67,14 @@ GCIdleTimeAction GCIdleTimeHandler::Compute(int idle_time_in_ms,
// can get rid of this special case and always start incremental marking. // can get rid of this special case and always start incremental marking.
int remaining_mark_sweeps = int remaining_mark_sweeps =
kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_; kMaxMarkCompactsInIdleRound - mark_compacts_since_idle_round_started_;
if (contexts_disposed > 0 || remaining_mark_sweeps <= 2) { if (heap_state.contexts_disposed > 0 || remaining_mark_sweeps <= 2 ||
!heap_state.can_start_incremental_marking) {
return GCIdleTimeAction::FullGC(); return GCIdleTimeAction::FullGC();
} }
} }
if (!heap_state.can_start_incremental_marking) {
return GCIdleTimeAction::Nothing();
}
} }
intptr_t speed = gc_tracer->IncrementalMarkingSpeedInBytesPerMillisecond(); intptr_t speed = gc_tracer->IncrementalMarkingSpeedInBytesPerMillisecond();
size_t step_size = size_t step_size =
......
...@@ -49,6 +49,7 @@ class GCIdleTimeAction { ...@@ -49,6 +49,7 @@ class GCIdleTimeAction {
intptr_t parameter; intptr_t parameter;
}; };
class GCTracer; class GCTracer;
// The idle time handler makes decisions about which garbage collection // The idle time handler makes decisions about which garbage collection
...@@ -73,13 +74,18 @@ class GCIdleTimeHandler { ...@@ -73,13 +74,18 @@ class GCIdleTimeHandler {
// Maximum mark-compact time returned by EstimateMarkCompactTime. // Maximum mark-compact time returned by EstimateMarkCompactTime.
static const size_t kMaxMarkCompactTimeInMs; static const size_t kMaxMarkCompactTimeInMs;
struct HeapState {
int contexts_disposed;
size_t size_of_objects;
bool incremental_marking_stopped;
bool can_start_incremental_marking;
};
GCIdleTimeHandler() GCIdleTimeHandler()
: mark_compacts_since_idle_round_started_(0), : mark_compacts_since_idle_round_started_(0),
scavenges_since_last_idle_round_(0) {} scavenges_since_last_idle_round_(0) {}
GCIdleTimeAction Compute(int idle_time_in_ms, int contexts_disposed, GCIdleTimeAction Compute(int idle_time_in_ms, HeapState heap_state,
size_t size_of_objects,
bool incremental_marking_stopped,
GCTracer* gc_tracer); GCTracer* gc_tracer);
void NotifyIdleMarkCompact() { void NotifyIdleMarkCompact() {
......
...@@ -845,8 +845,7 @@ bool Heap::CollectGarbage(GarbageCollector collector, const char* gc_reason, ...@@ -845,8 +845,7 @@ bool Heap::CollectGarbage(GarbageCollector collector, const char* gc_reason,
// Start incremental marking for the next cycle. The heap snapshot // Start incremental marking for the next cycle. The heap snapshot
// generator needs incremental marking to stay off after it aborted. // generator needs incremental marking to stay off after it aborted.
if (!mark_compact_collector()->abort_incremental_marking() && if (!mark_compact_collector()->abort_incremental_marking() &&
incremental_marking()->IsStopped() && WorthActivatingIncrementalMarking()) {
incremental_marking()->WorthActivating() && NextGCIsLikelyToBeFull()) {
incremental_marking()->Start(); incremental_marking()->Start();
} }
...@@ -4277,6 +4276,12 @@ void Heap::AdvanceIdleIncrementalMarking(intptr_t step_size) { ...@@ -4277,6 +4276,12 @@ void Heap::AdvanceIdleIncrementalMarking(intptr_t step_size) {
} }
bool Heap::WorthActivatingIncrementalMarking() {
return incremental_marking()->IsStopped() &&
incremental_marking()->WorthActivating() && NextGCIsLikelyToBeFull();
}
bool Heap::IdleNotification(int idle_time_in_ms) { bool Heap::IdleNotification(int idle_time_in_ms) {
// If incremental marking is off, we do not perform idle notification. // If incremental marking is off, we do not perform idle notification.
if (!FLAG_incremental_marking) return true; if (!FLAG_incremental_marking) return true;
...@@ -4285,9 +4290,16 @@ bool Heap::IdleNotification(int idle_time_in_ms) { ...@@ -4285,9 +4290,16 @@ bool Heap::IdleNotification(int idle_time_in_ms) {
HistogramTimerScope idle_notification_scope( HistogramTimerScope idle_notification_scope(
isolate_->counters()->gc_idle_notification()); isolate_->counters()->gc_idle_notification());
GCIdleTimeAction action = gc_idle_time_handler_.Compute( GCIdleTimeHandler::HeapState heap_state;
idle_time_in_ms, contexts_disposed_, static_cast<size_t>(SizeOfObjects()), heap_state.contexts_disposed = contexts_disposed_;
incremental_marking()->IsStopped(), tracer()); heap_state.size_of_objects = static_cast<size_t>(SizeOfObjects());
heap_state.incremental_marking_stopped = incremental_marking()->IsStopped();
// TODO(ulan): Start incremental marking only for large heaps.
heap_state.can_start_incremental_marking = true;
GCIdleTimeAction action =
gc_idle_time_handler_.Compute(idle_time_in_ms, heap_state, tracer());
contexts_disposed_ = 0; contexts_disposed_ = 0;
bool result = false; bool result = false;
switch (action.type) { switch (action.type) {
......
...@@ -1929,6 +1929,8 @@ class Heap { ...@@ -1929,6 +1929,8 @@ class Heap {
void AdvanceIdleIncrementalMarking(intptr_t step_size); void AdvanceIdleIncrementalMarking(intptr_t step_size);
bool WorthActivatingIncrementalMarking();
void ClearObjectStats(bool clear_last_time_stats = false); void ClearObjectStats(bool clear_last_time_stats = false);
void set_weak_object_to_code_table(Object* value) { void set_weak_object_to_code_table(Object* value) {
......
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