OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/heap.h" | 5 #include "vm/heap.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 Isolate* isolate = Isolate::Current(); | 207 Isolate* isolate = Isolate::Current(); |
208 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 208 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
209 switch (space) { | 209 switch (space) { |
210 case kNew: { | 210 case kNew: { |
211 VMTagScope tagScope(isolate, VMTag::kGCNewSpaceTagId); | 211 VMTagScope tagScope(isolate, VMTag::kGCNewSpaceTagId); |
212 RecordBeforeGC(kNew, kNewSpace); | 212 RecordBeforeGC(kNew, kNewSpace); |
213 UpdateClassHeapStatsBeforeGC(kNew); | 213 UpdateClassHeapStatsBeforeGC(kNew); |
214 new_space_->Scavenge(invoke_api_callbacks); | 214 new_space_->Scavenge(invoke_api_callbacks); |
215 RecordAfterGC(); | 215 RecordAfterGC(); |
216 PrintStats(); | 216 PrintStats(); |
217 // TODO(koda): Replace promotion failure tracking with | |
218 // old_space_->NeedsGarbageCollection. | |
219 if (new_space_->HadPromotionFailure() || old_space_->NeedExternalGC()) { | 217 if (new_space_->HadPromotionFailure() || old_space_->NeedExternalGC()) { |
220 // Old collections should call the API callbacks. | 218 // Old collections should call the API callbacks. |
221 CollectGarbage(kOld, kInvokeApiCallbacks); | 219 CollectGarbage(kOld, kInvokeApiCallbacks); |
222 } | 220 } |
223 break; | 221 break; |
224 } | 222 } |
225 case kOld: | 223 case kOld: |
226 case kCode: { | 224 case kCode: { |
227 VMTagScope tagScope(isolate, VMTag::kGCOldSpaceTagId); | 225 VMTagScope tagScope(isolate, VMTag::kGCOldSpaceTagId); |
228 bool promotion_failure = new_space_->HadPromotionFailure(); | 226 bool promotion_failure = new_space_->HadPromotionFailure(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 } | 460 } |
463 | 461 |
464 | 462 |
465 void Heap::RecordBeforeGC(Space space, GCReason reason) { | 463 void Heap::RecordBeforeGC(Space space, GCReason reason) { |
466 ASSERT(!gc_in_progress_); | 464 ASSERT(!gc_in_progress_); |
467 gc_in_progress_ = true; | 465 gc_in_progress_ = true; |
468 stats_.num_++; | 466 stats_.num_++; |
469 stats_.space_ = space; | 467 stats_.space_ = space; |
470 stats_.reason_ = reason; | 468 stats_.reason_ = reason; |
471 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); | 469 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); |
472 stats_.before_.new_ = new_space_->GetCurrentUsage(); | 470 stats_.before_.new_used_in_words_ = new_space_->UsedInWords(); |
473 stats_.before_.old_ = old_space_->GetCurrentUsage(); | 471 stats_.before_.new_capacity_in_words_ = new_space_->CapacityInWords(); |
| 472 stats_.before_.new_external_in_words_ = new_space_->ExternalInWords(); |
| 473 stats_.before_.old_used_in_words_ = old_space_->UsedInWords(); |
| 474 stats_.before_.old_capacity_in_words_ = old_space_->CapacityInWords(); |
| 475 stats_.before_.old_external_in_words_ = old_space_->ExternalInWords(); |
474 stats_.times_[0] = 0; | 476 stats_.times_[0] = 0; |
475 stats_.times_[1] = 0; | 477 stats_.times_[1] = 0; |
476 stats_.times_[2] = 0; | 478 stats_.times_[2] = 0; |
477 stats_.times_[3] = 0; | 479 stats_.times_[3] = 0; |
478 stats_.data_[0] = 0; | 480 stats_.data_[0] = 0; |
479 stats_.data_[1] = 0; | 481 stats_.data_[1] = 0; |
480 stats_.data_[2] = 0; | 482 stats_.data_[2] = 0; |
481 stats_.data_[3] = 0; | 483 stats_.data_[3] = 0; |
482 } | 484 } |
483 | 485 |
484 | 486 |
485 void Heap::RecordAfterGC() { | 487 void Heap::RecordAfterGC() { |
486 stats_.after_.micros_ = OS::GetCurrentTimeMicros(); | 488 stats_.after_.micros_ = OS::GetCurrentTimeMicros(); |
487 int64_t delta = stats_.after_.micros_ - stats_.before_.micros_; | 489 int64_t delta = stats_.after_.micros_ - stats_.before_.micros_; |
488 if (stats_.space_ == kNew) { | 490 if (stats_.space_ == kNew) { |
489 new_space_->AddGCTime(delta); | 491 new_space_->AddGCTime(delta); |
490 new_space_->IncrementCollections(); | 492 new_space_->IncrementCollections(); |
491 } else { | 493 } else { |
492 old_space_->AddGCTime(delta); | 494 old_space_->AddGCTime(delta); |
493 old_space_->IncrementCollections(); | 495 old_space_->IncrementCollections(); |
494 } | 496 } |
495 stats_.after_.new_ = new_space_->GetCurrentUsage(); | 497 stats_.after_.new_used_in_words_ = new_space_->UsedInWords(); |
496 stats_.after_.old_ = old_space_->GetCurrentUsage(); | 498 stats_.after_.new_capacity_in_words_ = new_space_->CapacityInWords(); |
| 499 stats_.after_.new_external_in_words_ = new_space_->ExternalInWords(); |
| 500 stats_.after_.old_used_in_words_ = old_space_->UsedInWords(); |
| 501 stats_.after_.old_capacity_in_words_ = old_space_->CapacityInWords(); |
| 502 stats_.after_.old_external_in_words_ = old_space_->ExternalInWords(); |
497 ASSERT(gc_in_progress_); | 503 ASSERT(gc_in_progress_); |
498 gc_in_progress_ = false; | 504 gc_in_progress_ = false; |
499 } | 505 } |
500 | 506 |
501 | 507 |
502 void Heap::PrintStats() { | 508 void Heap::PrintStats() { |
503 if (!FLAG_verbose_gc) return; | 509 if (!FLAG_verbose_gc) return; |
504 Isolate* isolate = Isolate::Current(); | 510 Isolate* isolate = Isolate::Current(); |
505 | 511 |
506 if ((FLAG_verbose_gc_hdr != 0) && | 512 if ((FLAG_verbose_gc_hdr != 0) && |
(...skipping 17 matching lines...) Expand all Loading... |
524 "%" Pd ", %" Pd ", " // old gen: capacity before/after | 530 "%" Pd ", %" Pd ", " // old gen: capacity before/after |
525 "%" Pd ", %" Pd ", " // old gen: external before/after | 531 "%" Pd ", %" Pd ", " // old gen: external before/after |
526 "%.3f, %.3f, %.3f, %.3f, " // times | 532 "%.3f, %.3f, %.3f, %.3f, " // times |
527 "%" Pd ", %" Pd ", %" Pd ", %" Pd ", " // data | 533 "%" Pd ", %" Pd ", %" Pd ", %" Pd ", " // data |
528 "]\n", // End with a comma to make it easier to import in spreadsheets. | 534 "]\n", // End with a comma to make it easier to import in spreadsheets. |
529 isolate->main_port(), space_str, GCReasonToString(stats_.reason_), | 535 isolate->main_port(), space_str, GCReasonToString(stats_.reason_), |
530 stats_.num_, | 536 stats_.num_, |
531 MicrosecondsToSeconds(stats_.before_.micros_ - isolate->start_time()), | 537 MicrosecondsToSeconds(stats_.before_.micros_ - isolate->start_time()), |
532 MicrosecondsToMilliseconds(stats_.after_.micros_ - | 538 MicrosecondsToMilliseconds(stats_.after_.micros_ - |
533 stats_.before_.micros_), | 539 stats_.before_.micros_), |
534 RoundWordsToKB(stats_.before_.new_.used_in_words), | 540 RoundWordsToKB(stats_.before_.new_used_in_words_), |
535 RoundWordsToKB(stats_.after_.new_.used_in_words), | 541 RoundWordsToKB(stats_.after_.new_used_in_words_), |
536 RoundWordsToKB(stats_.before_.new_.capacity_in_words), | 542 RoundWordsToKB(stats_.before_.new_capacity_in_words_), |
537 RoundWordsToKB(stats_.after_.new_.capacity_in_words), | 543 RoundWordsToKB(stats_.after_.new_capacity_in_words_), |
538 RoundWordsToKB(stats_.before_.new_.external_in_words), | 544 RoundWordsToKB(stats_.before_.new_external_in_words_), |
539 RoundWordsToKB(stats_.after_.new_.external_in_words), | 545 RoundWordsToKB(stats_.after_.new_external_in_words_), |
540 RoundWordsToKB(stats_.before_.old_.used_in_words), | 546 RoundWordsToKB(stats_.before_.old_used_in_words_), |
541 RoundWordsToKB(stats_.after_.old_.used_in_words), | 547 RoundWordsToKB(stats_.after_.old_used_in_words_), |
542 RoundWordsToKB(stats_.before_.old_.capacity_in_words), | 548 RoundWordsToKB(stats_.before_.old_capacity_in_words_), |
543 RoundWordsToKB(stats_.after_.old_.capacity_in_words), | 549 RoundWordsToKB(stats_.after_.old_capacity_in_words_), |
544 RoundWordsToKB(stats_.before_.old_.external_in_words), | 550 RoundWordsToKB(stats_.before_.old_external_in_words_), |
545 RoundWordsToKB(stats_.after_.old_.external_in_words), | 551 RoundWordsToKB(stats_.after_.old_external_in_words_), |
546 MicrosecondsToMilliseconds(stats_.times_[0]), | 552 MicrosecondsToMilliseconds(stats_.times_[0]), |
547 MicrosecondsToMilliseconds(stats_.times_[1]), | 553 MicrosecondsToMilliseconds(stats_.times_[1]), |
548 MicrosecondsToMilliseconds(stats_.times_[2]), | 554 MicrosecondsToMilliseconds(stats_.times_[2]), |
549 MicrosecondsToMilliseconds(stats_.times_[3]), | 555 MicrosecondsToMilliseconds(stats_.times_[3]), |
550 stats_.data_[0], | 556 stats_.data_[0], |
551 stats_.data_[1], | 557 stats_.data_[1], |
552 stats_.data_[2], | 558 stats_.data_[2], |
553 stats_.data_[3]); | 559 stats_.data_[3]); |
554 } | 560 } |
555 | 561 |
(...skipping 17 matching lines...) Expand all Loading... |
573 heap->DisableGrowthControl(); | 579 heap->DisableGrowthControl(); |
574 } | 580 } |
575 | 581 |
576 | 582 |
577 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 583 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
578 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 584 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
579 heap->SetGrowthControlState(current_growth_controller_state_); | 585 heap->SetGrowthControlState(current_growth_controller_state_); |
580 } | 586 } |
581 | 587 |
582 } // namespace dart | 588 } // namespace dart |
OLD | NEW |