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

Side by Side Diff: src/heap/heap.cc

Issue 750813003: Use deadline in IdleNotification. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « src/heap/heap.h ('k') | test/unittests/heap/gc-idle-time-handler-unittest.cc » ('j') | 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/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 4374 matching lines...) Expand 10 before | Expand all | Expand 10 after
4385 } 4385 }
4386 4386
4387 4387
4388 bool Heap::WorthActivatingIncrementalMarking() { 4388 bool Heap::WorthActivatingIncrementalMarking() {
4389 return incremental_marking()->IsStopped() && 4389 return incremental_marking()->IsStopped() &&
4390 incremental_marking()->WorthActivating() && NextGCIsLikelyToBeFull(); 4390 incremental_marking()->WorthActivating() && NextGCIsLikelyToBeFull();
4391 } 4391 }
4392 4392
4393 4393
4394 bool Heap::IdleNotification(int idle_time_in_ms) { 4394 bool Heap::IdleNotification(int idle_time_in_ms) {
4395 base::ElapsedTimer timer; 4395 return IdleNotification(
4396 timer.Start(); 4396 V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() +
4397 isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample( 4397 static_cast<double>(idle_time_in_ms));
4398 idle_time_in_ms); 4398 }
4399
4400
4401 bool Heap::IdleNotification(double deadline) {
4399 HistogramTimerScope idle_notification_scope( 4402 HistogramTimerScope idle_notification_scope(
4400 isolate_->counters()->gc_idle_notification()); 4403 isolate_->counters()->gc_idle_notification());
4401 4404
4402 GCIdleTimeHandler::HeapState heap_state; 4405 GCIdleTimeHandler::HeapState heap_state;
4403 heap_state.contexts_disposed = contexts_disposed_; 4406 heap_state.contexts_disposed = contexts_disposed_;
4404 heap_state.contexts_disposal_rate = 4407 heap_state.contexts_disposal_rate =
4405 tracer()->ContextDisposalRateInMilliseconds(); 4408 tracer()->ContextDisposalRateInMilliseconds();
4406 heap_state.size_of_objects = static_cast<size_t>(SizeOfObjects()); 4409 heap_state.size_of_objects = static_cast<size_t>(SizeOfObjects());
4407 heap_state.incremental_marking_stopped = incremental_marking()->IsStopped(); 4410 heap_state.incremental_marking_stopped = incremental_marking()->IsStopped();
4408 // TODO(ulan): Start incremental marking only for large heaps. 4411 // TODO(ulan): Start incremental marking only for large heaps.
4409 heap_state.can_start_incremental_marking = 4412 heap_state.can_start_incremental_marking =
4410 incremental_marking()->ShouldActivate() && FLAG_incremental_marking; 4413 incremental_marking()->ShouldActivate() && FLAG_incremental_marking;
4411 heap_state.sweeping_in_progress = 4414 heap_state.sweeping_in_progress =
4412 mark_compact_collector()->sweeping_in_progress(); 4415 mark_compact_collector()->sweeping_in_progress();
4413 heap_state.mark_compact_speed_in_bytes_per_ms = 4416 heap_state.mark_compact_speed_in_bytes_per_ms =
4414 static_cast<size_t>(tracer()->MarkCompactSpeedInBytesPerMillisecond()); 4417 static_cast<size_t>(tracer()->MarkCompactSpeedInBytesPerMillisecond());
4415 heap_state.incremental_marking_speed_in_bytes_per_ms = static_cast<size_t>( 4418 heap_state.incremental_marking_speed_in_bytes_per_ms = static_cast<size_t>(
4416 tracer()->IncrementalMarkingSpeedInBytesPerMillisecond()); 4419 tracer()->IncrementalMarkingSpeedInBytesPerMillisecond());
4417 heap_state.scavenge_speed_in_bytes_per_ms = 4420 heap_state.scavenge_speed_in_bytes_per_ms =
4418 static_cast<size_t>(tracer()->ScavengeSpeedInBytesPerMillisecond()); 4421 static_cast<size_t>(tracer()->ScavengeSpeedInBytesPerMillisecond());
4419 heap_state.used_new_space_size = new_space_.Size(); 4422 heap_state.used_new_space_size = new_space_.Size();
4420 heap_state.new_space_capacity = new_space_.Capacity(); 4423 heap_state.new_space_capacity = new_space_.Capacity();
4421 heap_state.new_space_allocation_throughput_in_bytes_per_ms = 4424 heap_state.new_space_allocation_throughput_in_bytes_per_ms =
4422 static_cast<size_t>( 4425 static_cast<size_t>(
4423 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond()); 4426 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond());
4424 4427
4428 double idle_time =
4429 deadline - V8::GetCurrentPlatform()->MonotonicallyIncreasingTime();
rmcilroy 2014/11/25 10:35:41 Both deadline and MonotonicallyIncreasingTime() re
Hannes Payer (out of office) 2014/11/25 12:28:59 I am using now seconds granularity on the api leve
4425 GCIdleTimeAction action = 4430 GCIdleTimeAction action =
4426 gc_idle_time_handler_.Compute(idle_time_in_ms, heap_state); 4431 gc_idle_time_handler_.Compute(idle_time, heap_state);
4432 isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample(
4433 static_cast<int>(idle_time));
4427 4434
4428 bool result = false; 4435 bool result = false;
4429 int actual_time_in_ms = 0;
4430 switch (action.type) { 4436 switch (action.type) {
4431 case DONE: 4437 case DONE:
4432 result = true; 4438 result = true;
4433 break; 4439 break;
4434 case DO_INCREMENTAL_MARKING: { 4440 case DO_INCREMENTAL_MARKING: {
4435 if (incremental_marking()->IsStopped()) { 4441 if (incremental_marking()->IsStopped()) {
4436 incremental_marking()->Start(); 4442 incremental_marking()->Start();
4437 } 4443 }
4438 incremental_marking()->Step(action.parameter, 4444 incremental_marking()->Step(action.parameter,
4439 IncrementalMarking::NO_GC_VIA_STACK_GUARD, 4445 IncrementalMarking::NO_GC_VIA_STACK_GUARD,
4440 IncrementalMarking::FORCE_MARKING, 4446 IncrementalMarking::FORCE_MARKING,
4441 IncrementalMarking::DO_NOT_FORCE_COMPLETION); 4447 IncrementalMarking::DO_NOT_FORCE_COMPLETION);
4442 actual_time_in_ms = static_cast<int>(timer.Elapsed().InMilliseconds()); 4448 double remaining_idle_time_in_ms =
4443 int remaining_idle_time_in_ms = idle_time_in_ms - actual_time_in_ms; 4449 deadline - V8::GetCurrentPlatform()->MonotonicallyIncreasingTime();
4444 if (remaining_idle_time_in_ms > 0) { 4450 if (remaining_idle_time_in_ms > 0.0) {
4445 TryFinalizeIdleIncrementalMarking( 4451 TryFinalizeIdleIncrementalMarking(
4446 remaining_idle_time_in_ms, heap_state.size_of_objects, 4452 static_cast<size_t>(remaining_idle_time_in_ms),
4453 heap_state.size_of_objects,
4447 heap_state.mark_compact_speed_in_bytes_per_ms); 4454 heap_state.mark_compact_speed_in_bytes_per_ms);
4448 } 4455 }
4449 break; 4456 break;
4450 } 4457 }
4451 case DO_FULL_GC: { 4458 case DO_FULL_GC: {
4452 HistogramTimerScope scope(isolate_->counters()->gc_context()); 4459 HistogramTimerScope scope(isolate_->counters()->gc_context());
4453 if (contexts_disposed_) { 4460 if (contexts_disposed_) {
4454 CollectAllGarbage(kNoGCFlags, "idle notification: contexts disposed"); 4461 CollectAllGarbage(kNoGCFlags, "idle notification: contexts disposed");
4455 gc_idle_time_handler_.NotifyIdleMarkCompact(); 4462 gc_idle_time_handler_.NotifyIdleMarkCompact();
4456 gc_count_at_last_idle_gc_ = gc_count_; 4463 gc_count_at_last_idle_gc_ = gc_count_;
4457 } else { 4464 } else {
4458 IdleMarkCompact("idle notification: finalize idle round"); 4465 IdleMarkCompact("idle notification: finalize idle round");
4459 } 4466 }
4460 break; 4467 break;
4461 } 4468 }
4462 case DO_SCAVENGE: 4469 case DO_SCAVENGE:
4463 CollectGarbage(NEW_SPACE, "idle notification: scavenge"); 4470 CollectGarbage(NEW_SPACE, "idle notification: scavenge");
4464 break; 4471 break;
4465 case DO_FINALIZE_SWEEPING: 4472 case DO_FINALIZE_SWEEPING:
4466 mark_compact_collector()->EnsureSweepingCompleted(); 4473 mark_compact_collector()->EnsureSweepingCompleted();
4467 break; 4474 break;
4468 case DO_NOTHING: 4475 case DO_NOTHING:
4469 break; 4476 break;
4470 } 4477 }
4471 4478
4472 actual_time_in_ms = static_cast<int>(timer.Elapsed().InMilliseconds()); 4479
4473 if (actual_time_in_ms <= idle_time_in_ms) { 4480 double deadline_difference =
4481 deadline - V8::GetCurrentPlatform()->MonotonicallyIncreasingTime();
4482 if (deadline_difference >= 0) {
4474 if (action.type != DONE && action.type != DO_NOTHING) { 4483 if (action.type != DONE && action.type != DO_NOTHING) {
4475 isolate()->counters()->gc_idle_time_limit_undershot()->AddSample( 4484 isolate()->counters()->gc_idle_time_limit_undershot()->AddSample(
4476 idle_time_in_ms - actual_time_in_ms); 4485 static_cast<int>(deadline_difference));
4477 } 4486 }
4478 } else { 4487 } else {
4479 isolate()->counters()->gc_idle_time_limit_overshot()->AddSample( 4488 isolate()->counters()->gc_idle_time_limit_overshot()->AddSample(
4480 actual_time_in_ms - idle_time_in_ms); 4489 static_cast<int>(-deadline_difference));
4481 } 4490 }
4482 4491
4483 if (FLAG_trace_idle_notification) { 4492 if (FLAG_trace_idle_notification) {
4484 PrintF("Idle notification: requested idle time %d ms, actual time %d ms [", 4493 PrintF(
4485 idle_time_in_ms, actual_time_in_ms); 4494 "Idle notification: requested idle time %.2f ms, deadline difference "
4495 "%.2f ms [",
4496 idle_time, deadline_difference);
4486 action.Print(); 4497 action.Print();
4487 PrintF("]"); 4498 PrintF("]");
4488 if (FLAG_trace_idle_notification_verbose) { 4499 if (FLAG_trace_idle_notification_verbose) {
4489 PrintF("["); 4500 PrintF("[");
4490 heap_state.Print(); 4501 heap_state.Print();
4491 PrintF("]"); 4502 PrintF("]");
4492 } 4503 }
4493 PrintF("\n"); 4504 PrintF("\n");
4494 } 4505 }
4495 4506
(...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after
6311 static_cast<int>(object_sizes_last_time_[index])); 6322 static_cast<int>(object_sizes_last_time_[index]));
6312 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 6323 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
6313 #undef ADJUST_LAST_TIME_OBJECT_COUNT 6324 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6314 6325
6315 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 6326 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
6316 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 6327 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
6317 ClearObjectStats(); 6328 ClearObjectStats();
6318 } 6329 }
6319 } 6330 }
6320 } // namespace v8::internal 6331 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | test/unittests/heap/gc-idle-time-handler-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698