| OLD | NEW |
| 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 4368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4379 gc_idle_time_handler_.NotifyIdleMarkCompact(); | 4379 gc_idle_time_handler_.NotifyIdleMarkCompact(); |
| 4380 gc_count_at_last_idle_gc_ = gc_count_; | 4380 gc_count_at_last_idle_gc_ = gc_count_; |
| 4381 if (uncommit) { | 4381 if (uncommit) { |
| 4382 new_space_.Shrink(); | 4382 new_space_.Shrink(); |
| 4383 UncommitFromSpace(); | 4383 UncommitFromSpace(); |
| 4384 } | 4384 } |
| 4385 } | 4385 } |
| 4386 | 4386 |
| 4387 | 4387 |
| 4388 void Heap::TryFinalizeIdleIncrementalMarking( | 4388 void Heap::TryFinalizeIdleIncrementalMarking( |
| 4389 size_t idle_time_in_ms, size_t size_of_objects, | 4389 double idle_time_in_ms, size_t size_of_objects, |
| 4390 size_t final_incremental_mark_compact_speed_in_bytes_per_ms) { | 4390 size_t final_incremental_mark_compact_speed_in_bytes_per_ms) { |
| 4391 if (incremental_marking()->IsComplete() || | 4391 if (incremental_marking()->IsComplete() || |
| 4392 (mark_compact_collector()->IsMarkingDequeEmpty() && | 4392 (mark_compact_collector()->IsMarkingDequeEmpty() && |
| 4393 gc_idle_time_handler_.ShouldDoFinalIncrementalMarkCompact( | 4393 gc_idle_time_handler_.ShouldDoFinalIncrementalMarkCompact( |
| 4394 idle_time_in_ms, size_of_objects, | 4394 static_cast<size_t>(idle_time_in_ms), size_of_objects, |
| 4395 final_incremental_mark_compact_speed_in_bytes_per_ms))) { | 4395 final_incremental_mark_compact_speed_in_bytes_per_ms))) { |
| 4396 CollectAllGarbage(kNoGCFlags, "idle notification: finalize incremental"); | 4396 CollectAllGarbage(kNoGCFlags, "idle notification: finalize incremental"); |
| 4397 } | 4397 } |
| 4398 } | 4398 } |
| 4399 | 4399 |
| 4400 | 4400 |
| 4401 bool Heap::WorthActivatingIncrementalMarking() { | 4401 bool Heap::WorthActivatingIncrementalMarking() { |
| 4402 return incremental_marking()->IsStopped() && | 4402 return incremental_marking()->IsStopped() && |
| 4403 incremental_marking()->WorthActivating() && NextGCIsLikelyToBeFull(); | 4403 incremental_marking()->WorthActivating() && NextGCIsLikelyToBeFull(); |
| 4404 } | 4404 } |
| 4405 | 4405 |
| 4406 | 4406 |
| 4407 static double MonotonicallyIncreasingTimeInMs() { |
| 4408 return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() * |
| 4409 static_cast<double>(base::Time::kMillisecondsPerSecond); |
| 4410 } |
| 4411 |
| 4412 |
| 4407 bool Heap::IdleNotification(int idle_time_in_ms) { | 4413 bool Heap::IdleNotification(int idle_time_in_ms) { |
| 4408 base::ElapsedTimer timer; | 4414 return IdleNotification( |
| 4409 timer.Start(); | 4415 V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() + |
| 4410 isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample( | 4416 (static_cast<double>(idle_time_in_ms) / |
| 4411 idle_time_in_ms); | 4417 static_cast<double>(base::Time::kMillisecondsPerSecond))); |
| 4418 } |
| 4419 |
| 4420 |
| 4421 bool Heap::IdleNotification(double deadline_in_seconds) { |
| 4422 double deadline_in_ms = |
| 4423 deadline_in_seconds * |
| 4424 static_cast<double>(base::Time::kMillisecondsPerSecond); |
| 4412 HistogramTimerScope idle_notification_scope( | 4425 HistogramTimerScope idle_notification_scope( |
| 4413 isolate_->counters()->gc_idle_notification()); | 4426 isolate_->counters()->gc_idle_notification()); |
| 4414 | 4427 |
| 4415 GCIdleTimeHandler::HeapState heap_state; | 4428 GCIdleTimeHandler::HeapState heap_state; |
| 4416 heap_state.contexts_disposed = contexts_disposed_; | 4429 heap_state.contexts_disposed = contexts_disposed_; |
| 4417 heap_state.contexts_disposal_rate = | 4430 heap_state.contexts_disposal_rate = |
| 4418 tracer()->ContextDisposalRateInMilliseconds(); | 4431 tracer()->ContextDisposalRateInMilliseconds(); |
| 4419 heap_state.size_of_objects = static_cast<size_t>(SizeOfObjects()); | 4432 heap_state.size_of_objects = static_cast<size_t>(SizeOfObjects()); |
| 4420 heap_state.incremental_marking_stopped = incremental_marking()->IsStopped(); | 4433 heap_state.incremental_marking_stopped = incremental_marking()->IsStopped(); |
| 4421 // TODO(ulan): Start incremental marking only for large heaps. | 4434 // TODO(ulan): Start incremental marking only for large heaps. |
| 4422 heap_state.can_start_incremental_marking = | 4435 heap_state.can_start_incremental_marking = |
| 4423 incremental_marking()->ShouldActivate() && FLAG_incremental_marking; | 4436 incremental_marking()->ShouldActivate() && FLAG_incremental_marking; |
| 4424 heap_state.sweeping_in_progress = | 4437 heap_state.sweeping_in_progress = |
| 4425 mark_compact_collector()->sweeping_in_progress(); | 4438 mark_compact_collector()->sweeping_in_progress(); |
| 4426 heap_state.mark_compact_speed_in_bytes_per_ms = | 4439 heap_state.mark_compact_speed_in_bytes_per_ms = |
| 4427 static_cast<size_t>(tracer()->MarkCompactSpeedInBytesPerMillisecond()); | 4440 static_cast<size_t>(tracer()->MarkCompactSpeedInBytesPerMillisecond()); |
| 4428 heap_state.incremental_marking_speed_in_bytes_per_ms = static_cast<size_t>( | 4441 heap_state.incremental_marking_speed_in_bytes_per_ms = static_cast<size_t>( |
| 4429 tracer()->IncrementalMarkingSpeedInBytesPerMillisecond()); | 4442 tracer()->IncrementalMarkingSpeedInBytesPerMillisecond()); |
| 4430 heap_state.final_incremental_mark_compact_speed_in_bytes_per_ms = | 4443 heap_state.final_incremental_mark_compact_speed_in_bytes_per_ms = |
| 4431 static_cast<size_t>( | 4444 static_cast<size_t>( |
| 4432 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); | 4445 tracer()->FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); |
| 4433 heap_state.scavenge_speed_in_bytes_per_ms = | 4446 heap_state.scavenge_speed_in_bytes_per_ms = |
| 4434 static_cast<size_t>(tracer()->ScavengeSpeedInBytesPerMillisecond()); | 4447 static_cast<size_t>(tracer()->ScavengeSpeedInBytesPerMillisecond()); |
| 4435 heap_state.used_new_space_size = new_space_.Size(); | 4448 heap_state.used_new_space_size = new_space_.Size(); |
| 4436 heap_state.new_space_capacity = new_space_.Capacity(); | 4449 heap_state.new_space_capacity = new_space_.Capacity(); |
| 4437 heap_state.new_space_allocation_throughput_in_bytes_per_ms = | 4450 heap_state.new_space_allocation_throughput_in_bytes_per_ms = |
| 4438 static_cast<size_t>( | 4451 static_cast<size_t>( |
| 4439 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond()); | 4452 tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond()); |
| 4440 | 4453 |
| 4454 double idle_time_in_ms = deadline_in_ms - MonotonicallyIncreasingTimeInMs(); |
| 4441 GCIdleTimeAction action = | 4455 GCIdleTimeAction action = |
| 4442 gc_idle_time_handler_.Compute(idle_time_in_ms, heap_state); | 4456 gc_idle_time_handler_.Compute(idle_time_in_ms, heap_state); |
| 4457 isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample( |
| 4458 static_cast<int>(idle_time_in_ms)); |
| 4443 | 4459 |
| 4444 bool result = false; | 4460 bool result = false; |
| 4445 int actual_time_in_ms = 0; | |
| 4446 switch (action.type) { | 4461 switch (action.type) { |
| 4447 case DONE: | 4462 case DONE: |
| 4448 result = true; | 4463 result = true; |
| 4449 break; | 4464 break; |
| 4450 case DO_INCREMENTAL_MARKING: { | 4465 case DO_INCREMENTAL_MARKING: { |
| 4451 if (incremental_marking()->IsStopped()) { | 4466 if (incremental_marking()->IsStopped()) { |
| 4452 incremental_marking()->Start(); | 4467 incremental_marking()->Start(); |
| 4453 } | 4468 } |
| 4454 incremental_marking()->Step(action.parameter, | 4469 incremental_marking()->Step(action.parameter, |
| 4455 IncrementalMarking::NO_GC_VIA_STACK_GUARD, | 4470 IncrementalMarking::NO_GC_VIA_STACK_GUARD, |
| 4456 IncrementalMarking::FORCE_MARKING, | 4471 IncrementalMarking::FORCE_MARKING, |
| 4457 IncrementalMarking::DO_NOT_FORCE_COMPLETION); | 4472 IncrementalMarking::DO_NOT_FORCE_COMPLETION); |
| 4458 actual_time_in_ms = static_cast<int>(timer.Elapsed().InMilliseconds()); | 4473 double remaining_idle_time_in_ms = |
| 4459 int remaining_idle_time_in_ms = idle_time_in_ms - actual_time_in_ms; | 4474 deadline_in_ms - MonotonicallyIncreasingTimeInMs(); |
| 4460 if (remaining_idle_time_in_ms > 0) { | 4475 if (remaining_idle_time_in_ms > 0.0) { |
| 4461 TryFinalizeIdleIncrementalMarking( | 4476 TryFinalizeIdleIncrementalMarking( |
| 4462 remaining_idle_time_in_ms, heap_state.size_of_objects, | 4477 remaining_idle_time_in_ms, heap_state.size_of_objects, |
| 4463 heap_state.final_incremental_mark_compact_speed_in_bytes_per_ms); | 4478 heap_state.final_incremental_mark_compact_speed_in_bytes_per_ms); |
| 4464 } | 4479 } |
| 4465 break; | 4480 break; |
| 4466 } | 4481 } |
| 4467 case DO_FULL_GC: { | 4482 case DO_FULL_GC: { |
| 4468 if (contexts_disposed_) { | 4483 if (contexts_disposed_) { |
| 4469 HistogramTimerScope scope(isolate_->counters()->gc_context()); | 4484 HistogramTimerScope scope(isolate_->counters()->gc_context()); |
| 4470 CollectAllGarbage(kNoGCFlags, "idle notification: contexts disposed"); | 4485 CollectAllGarbage(kNoGCFlags, "idle notification: contexts disposed"); |
| 4471 gc_idle_time_handler_.NotifyIdleMarkCompact(); | 4486 gc_idle_time_handler_.NotifyIdleMarkCompact(); |
| 4472 gc_count_at_last_idle_gc_ = gc_count_; | 4487 gc_count_at_last_idle_gc_ = gc_count_; |
| 4473 } else { | 4488 } else { |
| 4474 IdleMarkCompact("idle notification: finalize idle round"); | 4489 IdleMarkCompact("idle notification: finalize idle round"); |
| 4475 } | 4490 } |
| 4476 break; | 4491 break; |
| 4477 } | 4492 } |
| 4478 case DO_SCAVENGE: | 4493 case DO_SCAVENGE: |
| 4479 CollectGarbage(NEW_SPACE, "idle notification: scavenge"); | 4494 CollectGarbage(NEW_SPACE, "idle notification: scavenge"); |
| 4480 break; | 4495 break; |
| 4481 case DO_FINALIZE_SWEEPING: | 4496 case DO_FINALIZE_SWEEPING: |
| 4482 mark_compact_collector()->EnsureSweepingCompleted(); | 4497 mark_compact_collector()->EnsureSweepingCompleted(); |
| 4483 break; | 4498 break; |
| 4484 case DO_NOTHING: | 4499 case DO_NOTHING: |
| 4485 break; | 4500 break; |
| 4486 } | 4501 } |
| 4487 | 4502 |
| 4488 actual_time_in_ms = static_cast<int>(timer.Elapsed().InMilliseconds()); | 4503 double current_time = MonotonicallyIncreasingTimeInMs(); |
| 4489 if (actual_time_in_ms <= idle_time_in_ms) { | 4504 double deadline_difference = deadline_in_ms - current_time; |
| 4505 |
| 4506 if (deadline_difference >= 0) { |
| 4490 if (action.type != DONE && action.type != DO_NOTHING) { | 4507 if (action.type != DONE && action.type != DO_NOTHING) { |
| 4491 isolate()->counters()->gc_idle_time_limit_undershot()->AddSample( | 4508 isolate()->counters()->gc_idle_time_limit_undershot()->AddSample( |
| 4492 idle_time_in_ms - actual_time_in_ms); | 4509 static_cast<int>(deadline_difference)); |
| 4493 } | 4510 } |
| 4494 } else { | 4511 } else { |
| 4495 isolate()->counters()->gc_idle_time_limit_overshot()->AddSample( | 4512 isolate()->counters()->gc_idle_time_limit_overshot()->AddSample( |
| 4496 actual_time_in_ms - idle_time_in_ms); | 4513 static_cast<int>(-deadline_difference)); |
| 4497 } | 4514 } |
| 4498 | 4515 |
| 4499 if ((FLAG_trace_idle_notification && action.type > DO_NOTHING) || | 4516 if ((FLAG_trace_idle_notification && action.type > DO_NOTHING) || |
| 4500 FLAG_trace_idle_notification_verbose) { | 4517 FLAG_trace_idle_notification_verbose) { |
| 4501 PrintF("Idle notification: requested idle time %d ms, actual time %d ms [", | 4518 PrintF( |
| 4502 idle_time_in_ms, actual_time_in_ms); | 4519 "Idle notification: requested idle time %.2f ms, used idle time %.2f " |
| 4520 "ms, deadline usage %.2f ms [", |
| 4521 idle_time_in_ms, current_time, deadline_difference); |
| 4503 action.Print(); | 4522 action.Print(); |
| 4504 PrintF("]"); | 4523 PrintF("]"); |
| 4505 if (FLAG_trace_idle_notification_verbose) { | 4524 if (FLAG_trace_idle_notification_verbose) { |
| 4506 PrintF("["); | 4525 PrintF("["); |
| 4507 heap_state.Print(); | 4526 heap_state.Print(); |
| 4508 PrintF("]"); | 4527 PrintF("]"); |
| 4509 } | 4528 } |
| 4510 PrintF("\n"); | 4529 PrintF("\n"); |
| 4511 } | 4530 } |
| 4512 | 4531 |
| (...skipping 1815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6328 static_cast<int>(object_sizes_last_time_[index])); | 6347 static_cast<int>(object_sizes_last_time_[index])); |
| 6329 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 6348 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 6330 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 6349 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 6331 | 6350 |
| 6332 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 6351 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 6333 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 6352 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 6334 ClearObjectStats(); | 6353 ClearObjectStats(); |
| 6335 } | 6354 } |
| 6336 } | 6355 } |
| 6337 } // namespace v8::internal | 6356 } // namespace v8::internal |
| OLD | NEW |