| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 const char* GCTracer::Event::TypeName(bool short_name) const { | 62 const char* GCTracer::Event::TypeName(bool short_name) const { |
| 63 switch (type) { | 63 switch (type) { |
| 64 case SCAVENGER: | 64 case SCAVENGER: |
| 65 if (short_name) { | 65 if (short_name) { |
| 66 return "s"; | 66 return "s"; |
| 67 } else { | 67 } else { |
| 68 return "Scavenge"; | 68 return "Scavenge"; |
| 69 } | 69 } |
| 70 case MARK_COMPACTOR: | 70 case MARK_COMPACTOR: |
| 71 case INCREMENTAL_MARK_COMPACTOR: |
| 71 if (short_name) { | 72 if (short_name) { |
| 72 return "ms"; | 73 return "ms"; |
| 73 } else { | 74 } else { |
| 74 return "Mark-sweep"; | 75 return "Mark-sweep"; |
| 75 } | 76 } |
| 76 case START: | 77 case START: |
| 77 if (short_name) { | 78 if (short_name) { |
| 78 return "st"; | 79 return "st"; |
| 79 } else { | 80 } else { |
| 80 return "Start"; | 81 return "Start"; |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 return "Unknown Event Type"; | 84 return "Unknown Event Type"; |
| 84 } | 85 } |
| 85 | 86 |
| 86 | 87 |
| 87 GCTracer::GCTracer(Heap* heap) | 88 GCTracer::GCTracer(Heap* heap) |
| 88 : heap_(heap), | 89 : heap_(heap), |
| 89 cumulative_incremental_marking_steps_(0), | 90 cumulative_incremental_marking_steps_(0), |
| 90 cumulative_incremental_marking_bytes_(0), | 91 cumulative_incremental_marking_bytes_(0), |
| 91 cumulative_incremental_marking_duration_(0.0), | 92 cumulative_incremental_marking_duration_(0.0), |
| 92 cumulative_pure_incremental_marking_duration_(0.0), | 93 cumulative_pure_incremental_marking_duration_(0.0), |
| 93 longest_incremental_marking_step_(0.0), | 94 longest_incremental_marking_step_(0.0), |
| 94 cumulative_marking_duration_(0.0), | 95 cumulative_marking_duration_(0.0), |
| 95 cumulative_sweeping_duration_(0.0), | 96 cumulative_sweeping_duration_(0.0), |
| 96 new_space_top_after_gc_(0) { | 97 new_space_top_after_gc_(0) { |
| 97 current_ = Event(Event::START, NULL, NULL); | 98 current_ = Event(Event::START, NULL, NULL); |
| 98 current_.end_time = base::OS::TimeCurrentMillis(); | 99 current_.end_time = base::OS::TimeCurrentMillis(); |
| 99 previous_ = previous_mark_compactor_event_ = current_; | 100 previous_ = previous_incremental_mark_compactor_event_ = current_; |
| 100 } | 101 } |
| 101 | 102 |
| 102 | 103 |
| 103 void GCTracer::Start(GarbageCollector collector, const char* gc_reason, | 104 void GCTracer::Start(GarbageCollector collector, const char* gc_reason, |
| 104 const char* collector_reason) { | 105 const char* collector_reason) { |
| 105 previous_ = current_; | 106 previous_ = current_; |
| 106 double start_time = base::OS::TimeCurrentMillis(); | 107 double start_time = base::OS::TimeCurrentMillis(); |
| 107 if (new_space_top_after_gc_ != 0) { | 108 if (new_space_top_after_gc_ != 0) { |
| 108 AddNewSpaceAllocationTime( | 109 AddNewSpaceAllocationTime( |
| 109 start_time - previous_.end_time, | 110 start_time - previous_.end_time, |
| 110 reinterpret_cast<intptr_t>((heap_->new_space()->top()) - | 111 reinterpret_cast<intptr_t>((heap_->new_space()->top()) - |
| 111 new_space_top_after_gc_)); | 112 new_space_top_after_gc_)); |
| 112 } | 113 } |
| 113 if (current_.type == Event::MARK_COMPACTOR) | 114 if (current_.type == Event::INCREMENTAL_MARK_COMPACTOR) |
| 114 previous_mark_compactor_event_ = current_; | 115 previous_incremental_mark_compactor_event_ = current_; |
| 115 | 116 |
| 116 if (collector == SCAVENGER) { | 117 if (collector == SCAVENGER) { |
| 117 current_ = Event(Event::SCAVENGER, gc_reason, collector_reason); | 118 current_ = Event(Event::SCAVENGER, gc_reason, collector_reason); |
| 118 } else { | 119 } else if (collector == MARK_COMPACTOR) { |
| 119 current_ = Event(Event::MARK_COMPACTOR, gc_reason, collector_reason); | 120 if (heap_->incremental_marking()->IsMarking()) { |
| 121 current_ = |
| 122 Event(Event::INCREMENTAL_MARK_COMPACTOR, gc_reason, collector_reason); |
| 123 } else { |
| 124 current_ = Event(Event::MARK_COMPACTOR, gc_reason, collector_reason); |
| 125 } |
| 120 } | 126 } |
| 121 | 127 |
| 122 current_.start_time = start_time; | 128 current_.start_time = start_time; |
| 123 current_.start_object_size = heap_->SizeOfObjects(); | 129 current_.start_object_size = heap_->SizeOfObjects(); |
| 124 current_.start_memory_size = heap_->isolate()->memory_allocator()->Size(); | 130 current_.start_memory_size = heap_->isolate()->memory_allocator()->Size(); |
| 125 current_.start_holes_size = CountTotalHolesSize(heap_); | 131 current_.start_holes_size = CountTotalHolesSize(heap_); |
| 126 current_.new_space_object_size = | 132 current_.new_space_object_size = |
| 127 heap_->new_space()->top() - heap_->new_space()->bottom(); | 133 heap_->new_space()->top() - heap_->new_space()->bottom(); |
| 128 | 134 |
| 129 current_.cumulative_incremental_marking_steps = | 135 current_.cumulative_incremental_marking_steps = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 157 current_.incremental_marking_bytes = | 163 current_.incremental_marking_bytes = |
| 158 current_.cumulative_incremental_marking_bytes - | 164 current_.cumulative_incremental_marking_bytes - |
| 159 previous_.cumulative_incremental_marking_bytes; | 165 previous_.cumulative_incremental_marking_bytes; |
| 160 current_.incremental_marking_duration = | 166 current_.incremental_marking_duration = |
| 161 current_.cumulative_incremental_marking_duration - | 167 current_.cumulative_incremental_marking_duration - |
| 162 previous_.cumulative_incremental_marking_duration; | 168 previous_.cumulative_incremental_marking_duration; |
| 163 current_.pure_incremental_marking_duration = | 169 current_.pure_incremental_marking_duration = |
| 164 current_.cumulative_pure_incremental_marking_duration - | 170 current_.cumulative_pure_incremental_marking_duration - |
| 165 previous_.cumulative_pure_incremental_marking_duration; | 171 previous_.cumulative_pure_incremental_marking_duration; |
| 166 scavenger_events_.push_front(current_); | 172 scavenger_events_.push_front(current_); |
| 167 } else { | 173 } else if (current_.type == Event::INCREMENTAL_MARK_COMPACTOR) { |
| 168 current_.incremental_marking_steps = | 174 current_.incremental_marking_steps = |
| 169 current_.cumulative_incremental_marking_steps - | 175 current_.cumulative_incremental_marking_steps - |
| 170 previous_mark_compactor_event_.cumulative_incremental_marking_steps; | 176 previous_incremental_mark_compactor_event_ |
| 177 .cumulative_incremental_marking_steps; |
| 171 current_.incremental_marking_bytes = | 178 current_.incremental_marking_bytes = |
| 172 current_.cumulative_incremental_marking_bytes - | 179 current_.cumulative_incremental_marking_bytes - |
| 173 previous_mark_compactor_event_.cumulative_incremental_marking_bytes; | 180 previous_incremental_mark_compactor_event_ |
| 181 .cumulative_incremental_marking_bytes; |
| 174 current_.incremental_marking_duration = | 182 current_.incremental_marking_duration = |
| 175 current_.cumulative_incremental_marking_duration - | 183 current_.cumulative_incremental_marking_duration - |
| 176 previous_mark_compactor_event_.cumulative_incremental_marking_duration; | 184 previous_incremental_mark_compactor_event_ |
| 185 .cumulative_incremental_marking_duration; |
| 177 current_.pure_incremental_marking_duration = | 186 current_.pure_incremental_marking_duration = |
| 178 current_.cumulative_pure_incremental_marking_duration - | 187 current_.cumulative_pure_incremental_marking_duration - |
| 179 previous_mark_compactor_event_ | 188 previous_incremental_mark_compactor_event_ |
| 180 .cumulative_pure_incremental_marking_duration; | 189 .cumulative_pure_incremental_marking_duration; |
| 181 longest_incremental_marking_step_ = 0.0; | 190 longest_incremental_marking_step_ = 0.0; |
| 191 incremental_mark_compactor_events_.push_front(current_); |
| 192 } else { |
| 193 DCHECK(current_.incremental_marking_bytes == 0); |
| 194 DCHECK(current_.incremental_marking_duration == 0); |
| 195 DCHECK(current_.pure_incremental_marking_duration == 0); |
| 196 DCHECK(longest_incremental_marking_step_ == 0.0); |
| 182 mark_compactor_events_.push_front(current_); | 197 mark_compactor_events_.push_front(current_); |
| 183 } | 198 } |
| 184 | 199 |
| 185 // TODO(ernstm): move the code below out of GCTracer. | 200 // TODO(ernstm): move the code below out of GCTracer. |
| 186 | 201 |
| 187 if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; | 202 if (!FLAG_trace_gc && !FLAG_print_cumulative_gc_stat) return; |
| 188 | 203 |
| 189 double duration = current_.end_time - current_.start_time; | 204 double duration = current_.end_time - current_.start_time; |
| 190 double spent_in_mutator = Max(current_.start_time - previous_.end_time, 0.0); | 205 double spent_in_mutator = Max(current_.start_time - previous_.end_time, 0.0); |
| 191 | 206 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 389 |
| 375 return maximum; | 390 return maximum; |
| 376 } | 391 } |
| 377 | 392 |
| 378 | 393 |
| 379 double GCTracer::MeanIncrementalMarkingDuration() const { | 394 double GCTracer::MeanIncrementalMarkingDuration() const { |
| 380 if (cumulative_incremental_marking_steps_ == 0) return 0.0; | 395 if (cumulative_incremental_marking_steps_ == 0) return 0.0; |
| 381 | 396 |
| 382 // We haven't completed an entire round of incremental marking, yet. | 397 // We haven't completed an entire round of incremental marking, yet. |
| 383 // Use data from GCTracer instead of data from event buffers. | 398 // Use data from GCTracer instead of data from event buffers. |
| 384 if (mark_compactor_events_.empty()) { | 399 if (incremental_mark_compactor_events_.empty()) { |
| 385 return cumulative_incremental_marking_duration_ / | 400 return cumulative_incremental_marking_duration_ / |
| 386 cumulative_incremental_marking_steps_; | 401 cumulative_incremental_marking_steps_; |
| 387 } | 402 } |
| 388 | 403 |
| 389 int steps = 0; | 404 int steps = 0; |
| 390 double durations = 0.0; | 405 double durations = 0.0; |
| 391 EventBuffer::const_iterator iter = mark_compactor_events_.begin(); | 406 EventBuffer::const_iterator iter = incremental_mark_compactor_events_.begin(); |
| 392 while (iter != mark_compactor_events_.end()) { | 407 while (iter != incremental_mark_compactor_events_.end()) { |
| 393 steps += iter->incremental_marking_steps; | 408 steps += iter->incremental_marking_steps; |
| 394 durations += iter->incremental_marking_duration; | 409 durations += iter->incremental_marking_duration; |
| 395 ++iter; | 410 ++iter; |
| 396 } | 411 } |
| 397 | 412 |
| 398 if (steps == 0) return 0.0; | 413 if (steps == 0) return 0.0; |
| 399 | 414 |
| 400 return durations / steps; | 415 return durations / steps; |
| 401 } | 416 } |
| 402 | 417 |
| 403 | 418 |
| 404 double GCTracer::MaxIncrementalMarkingDuration() const { | 419 double GCTracer::MaxIncrementalMarkingDuration() const { |
| 405 // We haven't completed an entire round of incremental marking, yet. | 420 // We haven't completed an entire round of incremental marking, yet. |
| 406 // Use data from GCTracer instead of data from event buffers. | 421 // Use data from GCTracer instead of data from event buffers. |
| 407 if (mark_compactor_events_.empty()) return longest_incremental_marking_step_; | 422 if (incremental_mark_compactor_events_.empty()) |
| 423 return longest_incremental_marking_step_; |
| 408 | 424 |
| 409 double max_duration = 0.0; | 425 double max_duration = 0.0; |
| 410 EventBuffer::const_iterator iter = mark_compactor_events_.begin(); | 426 EventBuffer::const_iterator iter = incremental_mark_compactor_events_.begin(); |
| 411 while (iter != mark_compactor_events_.end()) | 427 while (iter != incremental_mark_compactor_events_.end()) |
| 412 max_duration = Max(iter->longest_incremental_marking_step, max_duration); | 428 max_duration = Max(iter->longest_incremental_marking_step, max_duration); |
| 413 | 429 |
| 414 return max_duration; | 430 return max_duration; |
| 415 } | 431 } |
| 416 | 432 |
| 417 | 433 |
| 418 intptr_t GCTracer::IncrementalMarkingSpeedInBytesPerMillisecond() const { | 434 intptr_t GCTracer::IncrementalMarkingSpeedInBytesPerMillisecond() const { |
| 419 if (cumulative_incremental_marking_duration_ == 0.0) return 0; | 435 if (cumulative_incremental_marking_duration_ == 0.0) return 0; |
| 420 | 436 |
| 421 // We haven't completed an entire round of incremental marking, yet. | 437 // We haven't completed an entire round of incremental marking, yet. |
| 422 // Use data from GCTracer instead of data from event buffers. | 438 // Use data from GCTracer instead of data from event buffers. |
| 423 if (mark_compactor_events_.empty()) { | 439 if (incremental_mark_compactor_events_.empty()) { |
| 424 return static_cast<intptr_t>(cumulative_incremental_marking_bytes_ / | 440 return static_cast<intptr_t>(cumulative_incremental_marking_bytes_ / |
| 425 cumulative_pure_incremental_marking_duration_); | 441 cumulative_pure_incremental_marking_duration_); |
| 426 } | 442 } |
| 427 | 443 |
| 428 intptr_t bytes = 0; | 444 intptr_t bytes = 0; |
| 429 double durations = 0.0; | 445 double durations = 0.0; |
| 430 EventBuffer::const_iterator iter = mark_compactor_events_.begin(); | 446 EventBuffer::const_iterator iter = incremental_mark_compactor_events_.begin(); |
| 431 while (iter != mark_compactor_events_.end()) { | 447 while (iter != incremental_mark_compactor_events_.end()) { |
| 432 bytes += iter->incremental_marking_bytes; | 448 bytes += iter->incremental_marking_bytes; |
| 433 durations += iter->pure_incremental_marking_duration; | 449 durations += iter->pure_incremental_marking_duration; |
| 434 ++iter; | 450 ++iter; |
| 435 } | 451 } |
| 436 | 452 |
| 437 if (durations == 0.0) return 0; | 453 if (durations == 0.0) return 0; |
| 438 | 454 |
| 439 return static_cast<intptr_t>(bytes / durations); | 455 return static_cast<intptr_t>(bytes / durations); |
| 440 } | 456 } |
| 441 | 457 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 455 return static_cast<intptr_t>(bytes / durations); | 471 return static_cast<intptr_t>(bytes / durations); |
| 456 } | 472 } |
| 457 | 473 |
| 458 | 474 |
| 459 intptr_t GCTracer::MarkCompactSpeedInBytesPerMillisecond() const { | 475 intptr_t GCTracer::MarkCompactSpeedInBytesPerMillisecond() const { |
| 460 intptr_t bytes = 0; | 476 intptr_t bytes = 0; |
| 461 double durations = 0.0; | 477 double durations = 0.0; |
| 462 EventBuffer::const_iterator iter = mark_compactor_events_.begin(); | 478 EventBuffer::const_iterator iter = mark_compactor_events_.begin(); |
| 463 while (iter != mark_compactor_events_.end()) { | 479 while (iter != mark_compactor_events_.end()) { |
| 464 bytes += iter->start_object_size; | 480 bytes += iter->start_object_size; |
| 465 durations += iter->end_time - iter->start_time + | 481 durations += iter->end_time - iter->start_time; |
| 466 iter->pure_incremental_marking_duration; | |
| 467 ++iter; | 482 ++iter; |
| 468 } | 483 } |
| 469 | 484 |
| 485 if (durations == 0.0) return 0; |
| 486 |
| 487 return static_cast<intptr_t>(bytes / durations); |
| 488 } |
| 489 |
| 490 |
| 491 intptr_t GCTracer::FinalIncrementalMarkCompactSpeedInBytesPerMillisecond() |
| 492 const { |
| 493 intptr_t bytes = 0; |
| 494 double durations = 0.0; |
| 495 EventBuffer::const_iterator iter = incremental_mark_compactor_events_.begin(); |
| 496 while (iter != incremental_mark_compactor_events_.end()) { |
| 497 bytes += iter->start_object_size; |
| 498 durations += iter->end_time - iter->start_time; |
| 499 ++iter; |
| 500 } |
| 501 |
| 470 if (durations == 0.0) return 0; | 502 if (durations == 0.0) return 0; |
| 471 | 503 |
| 472 return static_cast<intptr_t>(bytes / durations); | 504 return static_cast<intptr_t>(bytes / durations); |
| 473 } | 505 } |
| 474 | 506 |
| 475 | 507 |
| 476 intptr_t GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond() const { | 508 intptr_t GCTracer::NewSpaceAllocationThroughputInBytesPerMillisecond() const { |
| 477 intptr_t bytes = 0; | 509 intptr_t bytes = 0; |
| 478 double durations = 0.0; | 510 double durations = 0.0; |
| 479 AllocationEventBuffer::const_iterator iter = allocation_events_.begin(); | 511 AllocationEventBuffer::const_iterator iter = allocation_events_.begin(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 498 context_disposal_events_.begin(); | 530 context_disposal_events_.begin(); |
| 499 while (iter != context_disposal_events_.end()) { | 531 while (iter != context_disposal_events_.end()) { |
| 500 end = iter->time_; | 532 end = iter->time_; |
| 501 ++iter; | 533 ++iter; |
| 502 } | 534 } |
| 503 | 535 |
| 504 return (begin - end) / context_disposal_events_.size(); | 536 return (begin - end) / context_disposal_events_.size(); |
| 505 } | 537 } |
| 506 } | 538 } |
| 507 } // namespace v8::internal | 539 } // namespace v8::internal |
| OLD | NEW |