OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/heap/gc-tracer.h" | 7 #include "src/heap/gc-tracer.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 cumulative_pure_incremental_marking_duration_(0.0), | 98 cumulative_pure_incremental_marking_duration_(0.0), |
99 longest_incremental_marking_step_(0.0), | 99 longest_incremental_marking_step_(0.0), |
100 cumulative_marking_duration_(0.0), | 100 cumulative_marking_duration_(0.0), |
101 cumulative_sweeping_duration_(0.0), | 101 cumulative_sweeping_duration_(0.0), |
102 allocation_time_ms_(0.0), | 102 allocation_time_ms_(0.0), |
103 new_space_allocation_counter_bytes_(0), | 103 new_space_allocation_counter_bytes_(0), |
104 old_generation_allocation_counter_bytes_(0), | 104 old_generation_allocation_counter_bytes_(0), |
105 allocation_duration_since_gc_(0.0), | 105 allocation_duration_since_gc_(0.0), |
106 new_space_allocation_in_bytes_since_gc_(0), | 106 new_space_allocation_in_bytes_since_gc_(0), |
107 old_generation_allocation_in_bytes_since_gc_(0), | 107 old_generation_allocation_in_bytes_since_gc_(0), |
| 108 combined_mark_compact_speed_cache_(0.0), |
108 start_counter_(0) { | 109 start_counter_(0) { |
109 current_ = Event(Event::START, NULL, NULL); | 110 current_ = Event(Event::START, NULL, NULL); |
110 current_.end_time = base::OS::TimeCurrentMillis(); | 111 current_.end_time = base::OS::TimeCurrentMillis(); |
111 previous_ = previous_incremental_mark_compactor_event_ = current_; | 112 previous_ = previous_incremental_mark_compactor_event_ = current_; |
112 } | 113 } |
113 | 114 |
114 | 115 |
115 void GCTracer::Start(GarbageCollector collector, const char* gc_reason, | 116 void GCTracer::Start(GarbageCollector collector, const char* gc_reason, |
116 const char* collector_reason) { | 117 const char* collector_reason) { |
117 start_counter_++; | 118 start_counter_++; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 current_.incremental_marking_duration = | 220 current_.incremental_marking_duration = |
220 current_.cumulative_incremental_marking_duration - | 221 current_.cumulative_incremental_marking_duration - |
221 previous_incremental_mark_compactor_event_ | 222 previous_incremental_mark_compactor_event_ |
222 .cumulative_incremental_marking_duration; | 223 .cumulative_incremental_marking_duration; |
223 current_.pure_incremental_marking_duration = | 224 current_.pure_incremental_marking_duration = |
224 current_.cumulative_pure_incremental_marking_duration - | 225 current_.cumulative_pure_incremental_marking_duration - |
225 previous_incremental_mark_compactor_event_ | 226 previous_incremental_mark_compactor_event_ |
226 .cumulative_pure_incremental_marking_duration; | 227 .cumulative_pure_incremental_marking_duration; |
227 longest_incremental_marking_step_ = 0.0; | 228 longest_incremental_marking_step_ = 0.0; |
228 incremental_mark_compactor_events_.push_front(current_); | 229 incremental_mark_compactor_events_.push_front(current_); |
| 230 combined_mark_compact_speed_cache_ = 0.0; |
229 } else { | 231 } else { |
230 DCHECK(current_.incremental_marking_bytes == 0); | 232 DCHECK(current_.incremental_marking_bytes == 0); |
231 DCHECK(current_.incremental_marking_duration == 0); | 233 DCHECK(current_.incremental_marking_duration == 0); |
232 DCHECK(current_.pure_incremental_marking_duration == 0); | 234 DCHECK(current_.pure_incremental_marking_duration == 0); |
233 longest_incremental_marking_step_ = 0.0; | 235 longest_incremental_marking_step_ = 0.0; |
234 mark_compactor_events_.push_front(current_); | 236 mark_compactor_events_.push_front(current_); |
| 237 combined_mark_compact_speed_cache_ = 0.0; |
235 } | 238 } |
236 | 239 |
237 // TODO(ernstm): move the code below out of GCTracer. | 240 // TODO(ernstm): move the code below out of GCTracer. |
238 | 241 |
239 double duration = current_.end_time - current_.start_time; | 242 double duration = current_.end_time - current_.start_time; |
240 double spent_in_mutator = Max(current_.start_time - previous_.end_time, 0.0); | 243 double spent_in_mutator = Max(current_.start_time - previous_.end_time, 0.0); |
241 | 244 |
242 heap_->UpdateCumulativeGCStatistics(duration, spent_in_mutator, | 245 heap_->UpdateCumulativeGCStatistics(duration, spent_in_mutator, |
243 current_.scopes[Scope::MC_MARK]); | 246 current_.scopes[Scope::MC_MARK]); |
244 | 247 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 new_space_allocation_in_bytes_since_gc_ += new_space_allocated_bytes; | 288 new_space_allocation_in_bytes_since_gc_ += new_space_allocated_bytes; |
286 old_generation_allocation_in_bytes_since_gc_ += | 289 old_generation_allocation_in_bytes_since_gc_ += |
287 old_generation_allocated_bytes; | 290 old_generation_allocated_bytes; |
288 } | 291 } |
289 | 292 |
290 | 293 |
291 void GCTracer::AddAllocation(double current_ms) { | 294 void GCTracer::AddAllocation(double current_ms) { |
292 allocation_time_ms_ = current_ms; | 295 allocation_time_ms_ = current_ms; |
293 new_space_allocation_events_.push_front(AllocationEvent( | 296 new_space_allocation_events_.push_front(AllocationEvent( |
294 allocation_duration_since_gc_, new_space_allocation_in_bytes_since_gc_)); | 297 allocation_duration_since_gc_, new_space_allocation_in_bytes_since_gc_)); |
295 allocation_events_.push_front( | 298 old_generation_allocation_events_.push_front( |
296 AllocationEvent(allocation_duration_since_gc_, | 299 AllocationEvent(allocation_duration_since_gc_, |
297 new_space_allocation_in_bytes_since_gc_ + | 300 old_generation_allocation_in_bytes_since_gc_)); |
298 old_generation_allocation_in_bytes_since_gc_)); | |
299 allocation_duration_since_gc_ = 0; | 301 allocation_duration_since_gc_ = 0; |
300 new_space_allocation_in_bytes_since_gc_ = 0; | 302 new_space_allocation_in_bytes_since_gc_ = 0; |
301 old_generation_allocation_in_bytes_since_gc_ = 0; | 303 old_generation_allocation_in_bytes_since_gc_ = 0; |
302 } | 304 } |
303 | 305 |
304 | 306 |
305 void GCTracer::AddContextDisposalTime(double time) { | 307 void GCTracer::AddContextDisposalTime(double time) { |
306 context_disposal_events_.push_front(ContextDisposalEvent(time)); | 308 context_disposal_events_.push_front(ContextDisposalEvent(time)); |
307 } | 309 } |
308 | 310 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 intptr_t bytes = 0; | 555 intptr_t bytes = 0; |
554 double durations = 0.0; | 556 double durations = 0.0; |
555 EventBuffer::const_iterator iter = incremental_mark_compactor_events_.begin(); | 557 EventBuffer::const_iterator iter = incremental_mark_compactor_events_.begin(); |
556 while (iter != incremental_mark_compactor_events_.end()) { | 558 while (iter != incremental_mark_compactor_events_.end()) { |
557 bytes += iter->incremental_marking_bytes; | 559 bytes += iter->incremental_marking_bytes; |
558 durations += iter->pure_incremental_marking_duration; | 560 durations += iter->pure_incremental_marking_duration; |
559 ++iter; | 561 ++iter; |
560 } | 562 } |
561 | 563 |
562 if (durations == 0.0) return 0; | 564 if (durations == 0.0) return 0; |
563 | 565 // Make sure the result is at least 1. |
564 return static_cast<intptr_t>(bytes / durations); | 566 return Max<size_t>(static_cast<size_t>(bytes / durations + 0.5), 1); |
565 } | 567 } |
566 | 568 |
567 | 569 |
568 intptr_t GCTracer::ScavengeSpeedInBytesPerMillisecond() const { | 570 intptr_t GCTracer::ScavengeSpeedInBytesPerMillisecond() const { |
569 intptr_t bytes = 0; | 571 intptr_t bytes = 0; |
570 double durations = 0.0; | 572 double durations = 0.0; |
571 EventBuffer::const_iterator iter = scavenger_events_.begin(); | 573 EventBuffer::const_iterator iter = scavenger_events_.begin(); |
572 while (iter != scavenger_events_.end()) { | 574 while (iter != scavenger_events_.end()) { |
573 bytes += iter->new_space_object_size; | 575 bytes += iter->new_space_object_size; |
574 durations += iter->end_time - iter->start_time; | 576 durations += iter->end_time - iter->start_time; |
575 ++iter; | 577 ++iter; |
576 } | 578 } |
577 | 579 |
578 if (durations == 0.0) return 0; | 580 if (durations == 0.0) return 0; |
579 | 581 // Make sure the result is at least 1. |
580 return static_cast<intptr_t>(bytes / durations); | 582 return Max<size_t>(static_cast<size_t>(bytes / durations + 0.5), 1); |
581 } | 583 } |
582 | 584 |
583 | 585 |
584 intptr_t GCTracer::MarkCompactSpeedInBytesPerMillisecond() const { | 586 intptr_t GCTracer::MarkCompactSpeedInBytesPerMillisecond() const { |
585 intptr_t bytes = 0; | 587 intptr_t bytes = 0; |
586 double durations = 0.0; | 588 double durations = 0.0; |
587 EventBuffer::const_iterator iter = mark_compactor_events_.begin(); | 589 EventBuffer::const_iterator iter = mark_compactor_events_.begin(); |
588 while (iter != mark_compactor_events_.end()) { | 590 while (iter != mark_compactor_events_.end()) { |
589 bytes += iter->start_object_size; | 591 bytes += iter->start_object_size; |
590 durations += iter->end_time - iter->start_time; | 592 durations += iter->end_time - iter->start_time; |
591 ++iter; | 593 ++iter; |
592 } | 594 } |
593 | 595 |
594 if (durations == 0.0) return 0; | 596 if (durations == 0.0) return 0; |
595 | 597 // Make sure the result is at least 1. |
596 return static_cast<intptr_t>(bytes / durations); | 598 return Max<size_t>(static_cast<size_t>(bytes / durations + 0.5), 1); |
597 } | 599 } |
598 | 600 |
599 | 601 |
600 intptr_t GCTracer::FinalIncrementalMarkCompactSpeedInBytesPerMillisecond() | 602 intptr_t GCTracer::FinalIncrementalMarkCompactSpeedInBytesPerMillisecond() |
601 const { | 603 const { |
602 intptr_t bytes = 0; | 604 intptr_t bytes = 0; |
603 double durations = 0.0; | 605 double durations = 0.0; |
604 EventBuffer::const_iterator iter = incremental_mark_compactor_events_.begin(); | 606 EventBuffer::const_iterator iter = incremental_mark_compactor_events_.begin(); |
605 while (iter != incremental_mark_compactor_events_.end()) { | 607 while (iter != incremental_mark_compactor_events_.end()) { |
606 bytes += iter->start_object_size; | 608 bytes += iter->start_object_size; |
607 durations += iter->end_time - iter->start_time; | 609 durations += iter->end_time - iter->start_time; |
608 ++iter; | 610 ++iter; |
609 } | 611 } |
610 | 612 |
611 if (durations == 0.0) return 0; | 613 if (durations == 0.0) return 0; |
612 | 614 // Make sure the result is at least 1. |
613 return static_cast<intptr_t>(bytes / durations); | 615 return Max<size_t>(static_cast<size_t>(bytes / durations + 0.5), 1); |
614 } | 616 } |
615 | 617 |
616 | 618 |
617 size_t GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond() const { | 619 double GCTracer::CombinedMarkCompactSpeedInBytesPerMillisecond() { |
| 620 if (combined_mark_compact_speed_cache_ > 0) |
| 621 return combined_mark_compact_speed_cache_; |
| 622 const double kEpsilon = 1; |
| 623 double speed1 = |
| 624 static_cast<double>(IncrementalMarkingSpeedInBytesPerMillisecond()); |
| 625 double speed2 = static_cast<double>( |
| 626 FinalIncrementalMarkCompactSpeedInBytesPerMillisecond()); |
| 627 if (speed1 + speed2 < kEpsilon) { |
| 628 // No data for the incremental marking speed. |
| 629 // Return the non-incremental mark-compact speed. |
| 630 combined_mark_compact_speed_cache_ = |
| 631 static_cast<double>(MarkCompactSpeedInBytesPerMillisecond()); |
| 632 } else { |
| 633 // Combine the speed of incremental step and the speed of the final step. |
| 634 // 1 / (1 / speed1 + 1 / speed2) = speed1 * speed2 / (speed1 + speed2). |
| 635 combined_mark_compact_speed_cache_ = speed1 * speed2 / (speed1 + speed2); |
| 636 } |
| 637 return combined_mark_compact_speed_cache_; |
| 638 } |
| 639 |
| 640 |
| 641 size_t GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond( |
| 642 double time_ms) const { |
618 size_t bytes = new_space_allocation_in_bytes_since_gc_; | 643 size_t bytes = new_space_allocation_in_bytes_since_gc_; |
619 double durations = allocation_duration_since_gc_; | 644 double durations = allocation_duration_since_gc_; |
620 AllocationEventBuffer::const_iterator iter = | 645 AllocationEventBuffer::const_iterator iter = |
621 new_space_allocation_events_.begin(); | 646 new_space_allocation_events_.begin(); |
622 const size_t max_bytes = static_cast<size_t>(-1); | 647 const size_t max_bytes = static_cast<size_t>(-1); |
623 while (iter != new_space_allocation_events_.end() && | 648 while (iter != new_space_allocation_events_.end() && |
624 bytes < max_bytes - bytes) { | 649 bytes < max_bytes - bytes && (time_ms == 0 || durations < time_ms)) { |
625 bytes += iter->allocation_in_bytes_; | 650 bytes += iter->allocation_in_bytes_; |
626 durations += iter->duration_; | 651 durations += iter->duration_; |
627 ++iter; | 652 ++iter; |
628 } | 653 } |
629 | 654 |
630 if (durations == 0.0) return 0; | 655 if (durations == 0.0) return 0; |
631 | 656 // Make sure the result is at least 1. |
632 return static_cast<size_t>(bytes / durations + 0.5); | 657 return Max<size_t>(static_cast<size_t>(bytes / durations + 0.5), 1); |
633 } | 658 } |
634 | 659 |
635 | 660 |
636 size_t GCTracer::AllocationThroughputInBytesPerMillisecond( | 661 size_t GCTracer::OldGenerationAllocationThroughputInBytesPerMillisecond( |
637 double time_ms) const { | 662 double time_ms) const { |
638 size_t bytes = new_space_allocation_in_bytes_since_gc_ + | 663 size_t bytes = old_generation_allocation_in_bytes_since_gc_; |
639 old_generation_allocation_in_bytes_since_gc_; | |
640 double durations = allocation_duration_since_gc_; | 664 double durations = allocation_duration_since_gc_; |
641 AllocationEventBuffer::const_iterator iter = allocation_events_.begin(); | 665 AllocationEventBuffer::const_iterator iter = |
| 666 old_generation_allocation_events_.begin(); |
642 const size_t max_bytes = static_cast<size_t>(-1); | 667 const size_t max_bytes = static_cast<size_t>(-1); |
643 while (iter != allocation_events_.end() && bytes < max_bytes - bytes && | 668 while (iter != old_generation_allocation_events_.end() && |
644 durations < time_ms) { | 669 bytes < max_bytes - bytes && (time_ms == 0 || durations < time_ms)) { |
645 bytes += iter->allocation_in_bytes_; | 670 bytes += iter->allocation_in_bytes_; |
646 durations += iter->duration_; | 671 durations += iter->duration_; |
647 ++iter; | 672 ++iter; |
648 } | 673 } |
649 | 674 |
650 if (durations == 0.0) return 0; | 675 if (durations == 0.0) return 0; |
651 | 676 // Make sure the result is at least 1. |
652 return static_cast<size_t>(bytes / durations + 0.5); | 677 return Max<size_t>(static_cast<size_t>(bytes / durations + 0.5), 1); |
653 } | 678 } |
654 | 679 |
655 | 680 |
| 681 size_t GCTracer::AllocationThroughputInBytesPerMillisecond( |
| 682 double time_ms) const { |
| 683 return NewSpaceAllocationThroughputInBytesPerMillisecond(time_ms) + |
| 684 OldGenerationAllocationThroughputInBytesPerMillisecond(time_ms); |
| 685 } |
| 686 |
| 687 |
656 size_t GCTracer::CurrentAllocationThroughputInBytesPerMillisecond() const { | 688 size_t GCTracer::CurrentAllocationThroughputInBytesPerMillisecond() const { |
657 static const double kThroughputTimeFrame = 5000; | 689 static const double kThroughputTimeFrame = 5000; |
658 return AllocationThroughputInBytesPerMillisecond(kThroughputTimeFrame); | 690 return AllocationThroughputInBytesPerMillisecond(kThroughputTimeFrame); |
659 } | 691 } |
660 | 692 |
661 | 693 |
662 double GCTracer::ContextDisposalRateInMilliseconds() const { | 694 double GCTracer::ContextDisposalRateInMilliseconds() const { |
663 if (context_disposal_events_.size() < kRingBufferMaxSize) return 0.0; | 695 if (context_disposal_events_.size() < kRingBufferMaxSize) return 0.0; |
664 | 696 |
665 double begin = base::OS::TimeCurrentMillis(); | 697 double begin = base::OS::TimeCurrentMillis(); |
(...skipping 24 matching lines...) Expand all Loading... |
690 | 722 |
691 | 723 |
692 bool GCTracer::SurvivalEventsRecorded() const { | 724 bool GCTracer::SurvivalEventsRecorded() const { |
693 return survival_events_.size() > 0; | 725 return survival_events_.size() > 0; |
694 } | 726 } |
695 | 727 |
696 | 728 |
697 void GCTracer::ResetSurvivalEvents() { survival_events_.reset(); } | 729 void GCTracer::ResetSurvivalEvents() { survival_events_.reset(); } |
698 } // namespace internal | 730 } // namespace internal |
699 } // namespace v8 | 731 } // namespace v8 |
OLD | NEW |