Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Side by Side Diff: src/heap.cc

Issue 423303006: Make sure that there is enough time left before finishing incremental marking in idle notification. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/once.h" 9 #include "src/base/once.h"
10 #include "src/base/utils/random-number-generator.h" 10 #include "src/base/utils/random-number-generator.h"
(...skipping 4212 matching lines...) Expand 10 before | Expand all | Expand 10 after
4223 if (mark_compact_collector()->sweeping_in_progress()) { 4223 if (mark_compact_collector()->sweeping_in_progress()) {
4224 mark_compact_collector()->EnsureSweepingCompleted(); 4224 mark_compact_collector()->EnsureSweepingCompleted();
4225 } 4225 }
4226 ASSERT(IsHeapIterable()); 4226 ASSERT(IsHeapIterable());
4227 } 4227 }
4228 4228
4229 4229
4230 void Heap::AdvanceIdleIncrementalMarking(intptr_t step_size) { 4230 void Heap::AdvanceIdleIncrementalMarking(intptr_t step_size) {
4231 incremental_marking()->Step(step_size, 4231 incremental_marking()->Step(step_size,
4232 IncrementalMarking::NO_GC_VIA_STACK_GUARD); 4232 IncrementalMarking::NO_GC_VIA_STACK_GUARD);
4233 }
4233 4234
4235
4236 void Heap::FinalizeIdleIncrementalMarking() {
4234 if (incremental_marking()->IsComplete()) { 4237 if (incremental_marking()->IsComplete()) {
4235 bool uncommit = false; 4238 bool uncommit = false;
4236 if (gc_count_at_last_idle_gc_ == gc_count_) { 4239 if (gc_count_at_last_idle_gc_ == gc_count_) {
4237 // No GC since the last full GC, the mutator is probably not active. 4240 // No GC since the last full GC, the mutator is probably not active.
4238 isolate_->compilation_cache()->Clear(); 4241 isolate_->compilation_cache()->Clear();
4239 uncommit = true; 4242 uncommit = true;
4240 } 4243 }
4241 CollectAllGarbage(kReduceMemoryFootprintMask, 4244 CollectAllGarbage(kReduceMemoryFootprintMask,
4242 "idle notification: finalize incremental"); 4245 "idle notification: finalize incremental");
4243 mark_sweeps_since_idle_round_started_++; 4246 mark_sweeps_since_idle_round_started_++;
4244 gc_count_at_last_idle_gc_ = gc_count_; 4247 gc_count_at_last_idle_gc_ = gc_count_;
4245 if (uncommit) { 4248 if (uncommit) {
4246 new_space_.Shrink(); 4249 new_space_.Shrink();
4247 UncommitFromSpace(); 4250 UncommitFromSpace();
4248 } 4251 }
4249 } 4252 }
4250 } 4253 }
4251 4254
4252 4255
4253 bool Heap::IdleNotification(int hint) { 4256 bool Heap::IdleNotification(int idle_time_in_ms) {
4254 // If incremental marking is off, we do not perform idle notification. 4257 // If incremental marking is off, we do not perform idle notification.
4255 if (!FLAG_incremental_marking) return true; 4258 if (!FLAG_incremental_marking) return true;
4256 4259
4257 // Hints greater than this value indicate that 4260 // Hints greater than this value indicate that
4258 // the embedder is requesting a lot of GC work. 4261 // the embedder is requesting a lot of GC work.
4259 const int kMaxHint = 1000; 4262 const int kMaxHint = 1000;
4263 // TODO(hpayer): remove min hint
4260 const int kMinHintForIncrementalMarking = 10; 4264 const int kMinHintForIncrementalMarking = 10;
4261 // Minimal hint that allows to do full GC. 4265 // Minimal hint that allows to do full GC.
4262 const int kMinHintForFullGC = 100; 4266 const int kMinHintForFullGC = 100;
4263 intptr_t size_factor = Min(Max(hint, 20), kMaxHint) / 4; 4267 // TODO(hpayer, ernstm): use previous time measurements to calculate
4268 // proper size_factor
4269 intptr_t size_factor = Min(Max(idle_time_in_ms, 20), kMaxHint) / 4;
4264 // The size factor is in range [5..250]. The numbers here are chosen from 4270 // The size factor is in range [5..250]. The numbers here are chosen from
4265 // experiments. If you changes them, make sure to test with 4271 // experiments. If you changes them, make sure to test with
4266 // chrome/performance_ui_tests --gtest_filter="GeneralMixMemoryTest.* 4272 // chrome/performance_ui_tests --gtest_filter="GeneralMixMemoryTest.*
4267 intptr_t step_size = 4273 intptr_t step_size =
4268 size_factor * IncrementalMarking::kAllocatedThreshold; 4274 size_factor * IncrementalMarking::kAllocatedThreshold;
4269 4275
4270 isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample(hint); 4276 isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample(
4277 idle_time_in_ms);
4271 HistogramTimerScope idle_notification_scope( 4278 HistogramTimerScope idle_notification_scope(
4272 isolate_->counters()->gc_idle_notification()); 4279 isolate_->counters()->gc_idle_notification());
4273 4280
4274 if (contexts_disposed_ > 0) { 4281 if (contexts_disposed_ > 0) {
4275 contexts_disposed_ = 0; 4282 contexts_disposed_ = 0;
4276 int mark_sweep_time = Min(TimeMarkSweepWouldTakeInMs(), 1000); 4283 int mark_sweep_time = Min(TimeMarkSweepWouldTakeInMs(), 1000);
4277 if (hint >= mark_sweep_time && !FLAG_expose_gc && 4284 if (idle_time_in_ms >= mark_sweep_time && !FLAG_expose_gc &&
4278 incremental_marking()->IsStopped()) { 4285 incremental_marking()->IsStopped()) {
4279 HistogramTimerScope scope(isolate_->counters()->gc_context()); 4286 HistogramTimerScope scope(isolate_->counters()->gc_context());
4280 CollectAllGarbage(kReduceMemoryFootprintMask, 4287 CollectAllGarbage(kReduceMemoryFootprintMask,
4281 "idle notification: contexts disposed"); 4288 "idle notification: contexts disposed");
4282 } else { 4289 } else {
4283 AdvanceIdleIncrementalMarking(step_size); 4290 AdvanceIdleIncrementalMarking(step_size);
Hannes Payer (out of office) 2014/07/30 12:52:08 AdvanceIdleIncrementalMarking does not necessarily
4291 int elapsed_time = tracer_.last_incremental_marking_step_duration();
4292 if (idle_time_in_ms - elapsed_time > kMinHintForIncrementalMarking) {
4293 FinalizeIdleIncrementalMarking();
4294 }
4284 } 4295 }
4285 4296
4286 // After context disposal there is likely a lot of garbage remaining, reset 4297 // After context disposal there is likely a lot of garbage remaining, reset
4287 // the idle notification counters in order to trigger more incremental GCs 4298 // the idle notification counters in order to trigger more incremental GCs
4288 // on subsequent idle notifications. 4299 // on subsequent idle notifications.
4289 StartIdleRound(); 4300 StartIdleRound();
4290 return false; 4301 return false;
4291 } 4302 }
4292 4303
4293 // By doing small chunks of GC work in each IdleNotification, 4304 // By doing small chunks of GC work in each IdleNotification,
(...skipping 14 matching lines...) Expand all
4308 4319
4309 int remaining_mark_sweeps = kMaxMarkSweepsInIdleRound - 4320 int remaining_mark_sweeps = kMaxMarkSweepsInIdleRound -
4310 mark_sweeps_since_idle_round_started_; 4321 mark_sweeps_since_idle_round_started_;
4311 4322
4312 if (incremental_marking()->IsStopped()) { 4323 if (incremental_marking()->IsStopped()) {
4313 // If there are no more than two GCs left in this idle round and we are 4324 // If there are no more than two GCs left in this idle round and we are
4314 // allowed to do a full GC, then make those GCs full in order to compact 4325 // allowed to do a full GC, then make those GCs full in order to compact
4315 // the code space. 4326 // the code space.
4316 // TODO(ulan): Once we enable code compaction for incremental marking, 4327 // TODO(ulan): Once we enable code compaction for incremental marking,
4317 // we can get rid of this special case and always start incremental marking. 4328 // we can get rid of this special case and always start incremental marking.
4318 if (remaining_mark_sweeps <= 2 && hint >= kMinHintForFullGC) { 4329 if (remaining_mark_sweeps <= 2 && idle_time_in_ms >= kMinHintForFullGC) {
4319 CollectAllGarbage(kReduceMemoryFootprintMask, 4330 CollectAllGarbage(kReduceMemoryFootprintMask,
4320 "idle notification: finalize idle round"); 4331 "idle notification: finalize idle round");
4321 mark_sweeps_since_idle_round_started_++; 4332 mark_sweeps_since_idle_round_started_++;
4322 } else if (hint > kMinHintForIncrementalMarking) { 4333 } else if (idle_time_in_ms > kMinHintForIncrementalMarking) {
4323 incremental_marking()->Start(); 4334 incremental_marking()->Start();
4324 } 4335 }
4325 } 4336 }
4326 if (!incremental_marking()->IsStopped() && 4337 if (!incremental_marking()->IsStopped() &&
4327 hint > kMinHintForIncrementalMarking) { 4338 idle_time_in_ms > kMinHintForIncrementalMarking) {
4328 AdvanceIdleIncrementalMarking(step_size); 4339 AdvanceIdleIncrementalMarking(step_size);
4340 int elapsed_time = tracer_.last_incremental_marking_step_duration();
4341 if (idle_time_in_ms - elapsed_time > kMinHintForIncrementalMarking) {
4342 FinalizeIdleIncrementalMarking();
4343 }
4329 } 4344 }
4330 4345
4331 if (mark_sweeps_since_idle_round_started_ >= kMaxMarkSweepsInIdleRound) { 4346 if (mark_sweeps_since_idle_round_started_ >= kMaxMarkSweepsInIdleRound) {
4332 FinishIdleRound(); 4347 FinishIdleRound();
4333 return true; 4348 return true;
4334 } 4349 }
4335 4350
4336 // If the IdleNotifcation is called with a large hint we will wait for 4351 // If the IdleNotifcation is called with a large idle_time_in_ms we will wait
4337 // the sweepter threads here. 4352 // for the sweepter threads here.
4338 if (hint >= kMinHintForFullGC && 4353 if (idle_time_in_ms >= kMinHintForFullGC &&
4339 mark_compact_collector()->sweeping_in_progress()) { 4354 mark_compact_collector()->sweeping_in_progress()) {
4340 mark_compact_collector()->EnsureSweepingCompleted(); 4355 mark_compact_collector()->EnsureSweepingCompleted();
4341 } 4356 }
4342 4357
4343 return false; 4358 return false;
4344 } 4359 }
4345 4360
4346 4361
4347 #ifdef DEBUG 4362 #ifdef DEBUG
4348 4363
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after
6166 static_cast<int>(object_sizes_last_time_[index])); 6181 static_cast<int>(object_sizes_last_time_[index]));
6167 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 6182 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
6168 #undef ADJUST_LAST_TIME_OBJECT_COUNT 6183 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6169 6184
6170 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 6185 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
6171 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 6186 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
6172 ClearObjectStats(); 6187 ClearObjectStats();
6173 } 6188 }
6174 6189
6175 } } // namespace v8::internal 6190 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698