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

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
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 static_cast<double>(base::Time::kMillisecondsPerSecond)));
4399 }
4400
4401
4402 bool Heap::IdleNotification(double deadline_in_seconds) {
4403 double deadline_in_ms =
4404 deadline_in_seconds *
4405 static_cast<double>(base::Time::kMillisecondsPerSecond);
4399 HistogramTimerScope idle_notification_scope( 4406 HistogramTimerScope idle_notification_scope(
4400 isolate_->counters()->gc_idle_notification()); 4407 isolate_->counters()->gc_idle_notification());
4401 4408
4402 GCIdleTimeHandler::HeapState heap_state; 4409 GCIdleTimeHandler::HeapState heap_state;
4403 heap_state.contexts_disposed = contexts_disposed_; 4410 heap_state.contexts_disposed = contexts_disposed_;
4404 heap_state.contexts_disposal_rate = 4411 heap_state.contexts_disposal_rate =
4405 tracer()->ContextDisposalRateInMilliseconds(); 4412 tracer()->ContextDisposalRateInMilliseconds();
4406 heap_state.size_of_objects = static_cast<size_t>(SizeOfObjects()); 4413 heap_state.size_of_objects = static_cast<size_t>(SizeOfObjects());
4407 heap_state.incremental_marking_stopped = incremental_marking()->IsStopped(); 4414 heap_state.incremental_marking_stopped = incremental_marking()->IsStopped();
4408 // TODO(ulan): Start incremental marking only for large heaps. 4415 // TODO(ulan): Start incremental marking only for large heaps.
4409 heap_state.can_start_incremental_marking = 4416 heap_state.can_start_incremental_marking =
4410 incremental_marking()->ShouldActivate() && FLAG_incremental_marking; 4417 incremental_marking()->ShouldActivate() && FLAG_incremental_marking;
4411 heap_state.sweeping_in_progress = 4418 heap_state.sweeping_in_progress =
4412 mark_compact_collector()->sweeping_in_progress(); 4419 mark_compact_collector()->sweeping_in_progress();
4413 heap_state.mark_compact_speed_in_bytes_per_ms = 4420 heap_state.mark_compact_speed_in_bytes_per_ms =
4414 static_cast<size_t>(tracer()->MarkCompactSpeedInBytesPerMillisecond()); 4421 static_cast<size_t>(tracer()->MarkCompactSpeedInBytesPerMillisecond());
4415 heap_state.incremental_marking_speed_in_bytes_per_ms = static_cast<size_t>( 4422 heap_state.incremental_marking_speed_in_bytes_per_ms = static_cast<size_t>(
4416 tracer()->IncrementalMarkingSpeedInBytesPerMillisecond()); 4423 tracer()->IncrementalMarkingSpeedInBytesPerMillisecond());
4417 heap_state.final_incremental_mark_compact_speed_in_bytes_per_ms = 4424 heap_state.final_incremental_mark_compact_speed_in_bytes_per_ms =
4418 static_cast<size_t>( 4425 static_cast<size_t>(
4419 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); 4426 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond());
4420 heap_state.scavenge_speed_in_bytes_per_ms = 4427 heap_state.scavenge_speed_in_bytes_per_ms =
4421 static_cast<size_t>(tracer()->ScavengeSpeedInBytesPerMillisecond()); 4428 static_cast<size_t>(tracer()->ScavengeSpeedInBytesPerMillisecond());
4422 heap_state.used_new_space_size = new_space_.Size(); 4429 heap_state.used_new_space_size = new_space_.Size();
4423 heap_state.new_space_capacity = new_space_.Capacity(); 4430 heap_state.new_space_capacity = new_space_.Capacity();
4424 heap_state.new_space_allocation_throughput_in_bytes_per_ms = 4431 heap_state.new_space_allocation_throughput_in_bytes_per_ms =
4425 static_cast<size_t>( 4432 static_cast<size_t>(
4426 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond()); 4433 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond());
4427 4434
4435 double idle_time_in_ms =
4436 deadline_in_ms -
4437 (V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() *
4438 static_cast<double>(base::Time::kMillisecondsPerSecond));
4428 GCIdleTimeAction action = 4439 GCIdleTimeAction action =
4429 gc_idle_time_handler_.Compute(idle_time_in_ms, heap_state); 4440 gc_idle_time_handler_.Compute(idle_time_in_ms, heap_state);
4441 isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample(
4442 static_cast<int>(idle_time_in_ms));
4430 4443
4431 bool result = false; 4444 bool result = false;
4432 int actual_time_in_ms = 0;
4433 switch (action.type) { 4445 switch (action.type) {
4434 case DONE: 4446 case DONE:
4435 result = true; 4447 result = true;
4436 break; 4448 break;
4437 case DO_INCREMENTAL_MARKING: { 4449 case DO_INCREMENTAL_MARKING: {
4438 if (incremental_marking()->IsStopped()) { 4450 if (incremental_marking()->IsStopped()) {
4439 incremental_marking()->Start(); 4451 incremental_marking()->Start();
4440 } 4452 }
4441 incremental_marking()->Step(action.parameter, 4453 incremental_marking()->Step(action.parameter,
4442 IncrementalMarking::NO_GC_VIA_STACK_GUARD, 4454 IncrementalMarking::NO_GC_VIA_STACK_GUARD,
4443 IncrementalMarking::FORCE_MARKING, 4455 IncrementalMarking::FORCE_MARKING,
4444 IncrementalMarking::DO_NOT_FORCE_COMPLETION); 4456 IncrementalMarking::DO_NOT_FORCE_COMPLETION);
4445 actual_time_in_ms = static_cast<int>(timer.Elapsed().InMilliseconds()); 4457 double remaining_idle_time_in_ms =
4446 int remaining_idle_time_in_ms = idle_time_in_ms - actual_time_in_ms; 4458 deadline_in_ms -
4447 if (remaining_idle_time_in_ms > 0) { 4459 (V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() *
4460 static_cast<double>(base::Time::kMillisecondsPerSecond));
rmcilroy 2014/11/26 11:35:41 nit - would be good to have a helper for Monotonic
Hannes Payer (out of office) 2014/11/27 12:19:15 Done.
4461 if (remaining_idle_time_in_ms > 0.0) {
4448 TryFinalizeIdleIncrementalMarking( 4462 TryFinalizeIdleIncrementalMarking(
4449 remaining_idle_time_in_ms, heap_state.size_of_objects, 4463 static_cast<size_t>(remaining_idle_time_in_ms),
4464 heap_state.size_of_objects,
4450 heap_state.final_incremental_mark_compact_speed_in_bytes_per_ms); 4465 heap_state.final_incremental_mark_compact_speed_in_bytes_per_ms);
4451 } 4466 }
4452 break; 4467 break;
4453 } 4468 }
4454 case DO_FULL_GC: { 4469 case DO_FULL_GC: {
4455 HistogramTimerScope scope(isolate_->counters()->gc_context()); 4470 HistogramTimerScope scope(isolate_->counters()->gc_context());
4456 if (contexts_disposed_) { 4471 if (contexts_disposed_) {
4457 CollectAllGarbage(kNoGCFlags, "idle notification: contexts disposed"); 4472 CollectAllGarbage(kNoGCFlags, "idle notification: contexts disposed");
4458 gc_idle_time_handler_.NotifyIdleMarkCompact(); 4473 gc_idle_time_handler_.NotifyIdleMarkCompact();
4459 gc_count_at_last_idle_gc_ = gc_count_; 4474 gc_count_at_last_idle_gc_ = gc_count_;
4460 } else { 4475 } else {
4461 IdleMarkCompact("idle notification: finalize idle round"); 4476 IdleMarkCompact("idle notification: finalize idle round");
4462 } 4477 }
4463 break; 4478 break;
4464 } 4479 }
4465 case DO_SCAVENGE: 4480 case DO_SCAVENGE:
4466 CollectGarbage(NEW_SPACE, "idle notification: scavenge"); 4481 CollectGarbage(NEW_SPACE, "idle notification: scavenge");
4467 break; 4482 break;
4468 case DO_FINALIZE_SWEEPING: 4483 case DO_FINALIZE_SWEEPING:
4469 mark_compact_collector()->EnsureSweepingCompleted(); 4484 mark_compact_collector()->EnsureSweepingCompleted();
4470 break; 4485 break;
4471 case DO_NOTHING: 4486 case DO_NOTHING:
4472 break; 4487 break;
4473 } 4488 }
4474 4489
4475 actual_time_in_ms = static_cast<int>(timer.Elapsed().InMilliseconds()); 4490
4476 if (actual_time_in_ms <= idle_time_in_ms) { 4491 double deadline_difference =
4492 deadline_in_ms -
4493 (V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() *
4494 static_cast<double>(base::Time::kMillisecondsPerSecond));
4495 if (deadline_difference >= 0) {
4477 if (action.type != DONE && action.type != DO_NOTHING) { 4496 if (action.type != DONE && action.type != DO_NOTHING) {
4478 isolate()->counters()->gc_idle_time_limit_undershot()->AddSample( 4497 isolate()->counters()->gc_idle_time_limit_undershot()->AddSample(
4479 idle_time_in_ms - actual_time_in_ms); 4498 static_cast<int>(deadline_difference));
4480 } 4499 }
4481 } else { 4500 } else {
4482 isolate()->counters()->gc_idle_time_limit_overshot()->AddSample( 4501 isolate()->counters()->gc_idle_time_limit_overshot()->AddSample(
4483 actual_time_in_ms - idle_time_in_ms); 4502 static_cast<int>(-deadline_difference));
4484 } 4503 }
4485 4504
4486 if (FLAG_trace_idle_notification) { 4505 if (FLAG_trace_idle_notification) {
4487 PrintF("Idle notification: requested idle time %d ms, actual time %d ms [", 4506 PrintF(
4488 idle_time_in_ms, actual_time_in_ms); 4507 "Idle notification: requested idle time %.2f ms, deadline difference "
4508 "%.2f ms [",
4509 idle_time_in_ms, deadline_difference);
4489 action.Print(); 4510 action.Print();
4490 PrintF("]"); 4511 PrintF("]");
4491 if (FLAG_trace_idle_notification_verbose) { 4512 if (FLAG_trace_idle_notification_verbose) {
4492 PrintF("["); 4513 PrintF("[");
4493 heap_state.Print(); 4514 heap_state.Print();
4494 PrintF("]"); 4515 PrintF("]");
4495 } 4516 }
4496 PrintF("\n"); 4517 PrintF("\n");
4497 } 4518 }
4498 4519
(...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after
6314 static_cast<int>(object_sizes_last_time_[index])); 6335 static_cast<int>(object_sizes_last_time_[index]));
6315 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 6336 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
6316 #undef ADJUST_LAST_TIME_OBJECT_COUNT 6337 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6317 6338
6318 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 6339 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
6319 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 6340 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
6320 ClearObjectStats(); 6341 ClearObjectStats();
6321 } 6342 }
6322 } 6343 }
6323 } // namespace v8::internal 6344 } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698