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. |
217 if (new_space_->HadPromotionFailure() || old_space_->NeedExternalGC()) { | 219 if (new_space_->HadPromotionFailure() || old_space_->NeedExternalGC()) { |
218 // Old collections should call the API callbacks. | 220 // Old collections should call the API callbacks. |
219 CollectGarbage(kOld, kInvokeApiCallbacks); | 221 CollectGarbage(kOld, kInvokeApiCallbacks); |
220 } | 222 } |
221 break; | 223 break; |
222 } | 224 } |
223 case kOld: | 225 case kOld: |
224 case kCode: { | 226 case kCode: { |
225 VMTagScope tagScope(isolate, VMTag::kGCOldSpaceTagId); | 227 VMTagScope tagScope(isolate, VMTag::kGCOldSpaceTagId); |
226 bool promotion_failure = new_space_->HadPromotionFailure(); | 228 bool promotion_failure = new_space_->HadPromotionFailure(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 462 } |
461 | 463 |
462 | 464 |
463 void Heap::RecordBeforeGC(Space space, GCReason reason) { | 465 void Heap::RecordBeforeGC(Space space, GCReason reason) { |
464 ASSERT(!gc_in_progress_); | 466 ASSERT(!gc_in_progress_); |
465 gc_in_progress_ = true; | 467 gc_in_progress_ = true; |
466 stats_.num_++; | 468 stats_.num_++; |
467 stats_.space_ = space; | 469 stats_.space_ = space; |
468 stats_.reason_ = reason; | 470 stats_.reason_ = reason; |
469 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); | 471 stats_.before_.micros_ = OS::GetCurrentTimeMicros(); |
470 stats_.before_.new_used_in_words_ = new_space_->UsedInWords(); | 472 stats_.before_.new_ = new_space_->GetCurrentUsage(); |
471 stats_.before_.new_capacity_in_words_ = new_space_->CapacityInWords(); | 473 stats_.before_.old_ = old_space_->GetCurrentUsage(); |
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(); | |
476 stats_.times_[0] = 0; | 474 stats_.times_[0] = 0; |
477 stats_.times_[1] = 0; | 475 stats_.times_[1] = 0; |
478 stats_.times_[2] = 0; | 476 stats_.times_[2] = 0; |
479 stats_.times_[3] = 0; | 477 stats_.times_[3] = 0; |
480 stats_.data_[0] = 0; | 478 stats_.data_[0] = 0; |
481 stats_.data_[1] = 0; | 479 stats_.data_[1] = 0; |
482 stats_.data_[2] = 0; | 480 stats_.data_[2] = 0; |
483 stats_.data_[3] = 0; | 481 stats_.data_[3] = 0; |
484 } | 482 } |
485 | 483 |
486 | 484 |
487 void Heap::RecordAfterGC() { | 485 void Heap::RecordAfterGC() { |
488 stats_.after_.micros_ = OS::GetCurrentTimeMicros(); | 486 stats_.after_.micros_ = OS::GetCurrentTimeMicros(); |
489 int64_t delta = stats_.after_.micros_ - stats_.before_.micros_; | 487 int64_t delta = stats_.after_.micros_ - stats_.before_.micros_; |
490 if (stats_.space_ == kNew) { | 488 if (stats_.space_ == kNew) { |
491 new_space_->AddGCTime(delta); | 489 new_space_->AddGCTime(delta); |
492 new_space_->IncrementCollections(); | 490 new_space_->IncrementCollections(); |
493 } else { | 491 } else { |
494 old_space_->AddGCTime(delta); | 492 old_space_->AddGCTime(delta); |
495 old_space_->IncrementCollections(); | 493 old_space_->IncrementCollections(); |
496 } | 494 } |
497 stats_.after_.new_used_in_words_ = new_space_->UsedInWords(); | 495 stats_.after_.new_ = new_space_->GetCurrentUsage(); |
498 stats_.after_.new_capacity_in_words_ = new_space_->CapacityInWords(); | 496 stats_.after_.old_ = old_space_->GetCurrentUsage(); |
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(); | |
503 ASSERT(gc_in_progress_); | 497 ASSERT(gc_in_progress_); |
504 gc_in_progress_ = false; | 498 gc_in_progress_ = false; |
505 } | 499 } |
506 | 500 |
507 | 501 |
508 void Heap::PrintStats() { | 502 void Heap::PrintStats() { |
509 if (!FLAG_verbose_gc) return; | 503 if (!FLAG_verbose_gc) return; |
510 Isolate* isolate = Isolate::Current(); | 504 Isolate* isolate = Isolate::Current(); |
511 | 505 |
512 if ((FLAG_verbose_gc_hdr != 0) && | 506 if ((FLAG_verbose_gc_hdr != 0) && |
(...skipping 17 matching lines...) Expand all Loading... |
530 "%" Pd ", %" Pd ", " // old gen: capacity before/after | 524 "%" Pd ", %" Pd ", " // old gen: capacity before/after |
531 "%" Pd ", %" Pd ", " // old gen: external before/after | 525 "%" Pd ", %" Pd ", " // old gen: external before/after |
532 "%.3f, %.3f, %.3f, %.3f, " // times | 526 "%.3f, %.3f, %.3f, %.3f, " // times |
533 "%" Pd ", %" Pd ", %" Pd ", %" Pd ", " // data | 527 "%" Pd ", %" Pd ", %" Pd ", %" Pd ", " // data |
534 "]\n", // End with a comma to make it easier to import in spreadsheets. | 528 "]\n", // End with a comma to make it easier to import in spreadsheets. |
535 isolate->main_port(), space_str, GCReasonToString(stats_.reason_), | 529 isolate->main_port(), space_str, GCReasonToString(stats_.reason_), |
536 stats_.num_, | 530 stats_.num_, |
537 MicrosecondsToSeconds(stats_.before_.micros_ - isolate->start_time()), | 531 MicrosecondsToSeconds(stats_.before_.micros_ - isolate->start_time()), |
538 MicrosecondsToMilliseconds(stats_.after_.micros_ - | 532 MicrosecondsToMilliseconds(stats_.after_.micros_ - |
539 stats_.before_.micros_), | 533 stats_.before_.micros_), |
540 RoundWordsToKB(stats_.before_.new_used_in_words_), | 534 RoundWordsToKB(stats_.before_.new_.used_in_words), |
541 RoundWordsToKB(stats_.after_.new_used_in_words_), | 535 RoundWordsToKB(stats_.after_.new_.used_in_words), |
542 RoundWordsToKB(stats_.before_.new_capacity_in_words_), | 536 RoundWordsToKB(stats_.before_.new_.capacity_in_words), |
543 RoundWordsToKB(stats_.after_.new_capacity_in_words_), | 537 RoundWordsToKB(stats_.after_.new_.capacity_in_words), |
544 RoundWordsToKB(stats_.before_.new_external_in_words_), | 538 RoundWordsToKB(stats_.before_.new_.external_in_words), |
545 RoundWordsToKB(stats_.after_.new_external_in_words_), | 539 RoundWordsToKB(stats_.after_.new_.external_in_words), |
546 RoundWordsToKB(stats_.before_.old_used_in_words_), | 540 RoundWordsToKB(stats_.before_.old_.used_in_words), |
547 RoundWordsToKB(stats_.after_.old_used_in_words_), | 541 RoundWordsToKB(stats_.after_.old_.used_in_words), |
548 RoundWordsToKB(stats_.before_.old_capacity_in_words_), | 542 RoundWordsToKB(stats_.before_.old_.capacity_in_words), |
549 RoundWordsToKB(stats_.after_.old_capacity_in_words_), | 543 RoundWordsToKB(stats_.after_.old_.capacity_in_words), |
550 RoundWordsToKB(stats_.before_.old_external_in_words_), | 544 RoundWordsToKB(stats_.before_.old_.external_in_words), |
551 RoundWordsToKB(stats_.after_.old_external_in_words_), | 545 RoundWordsToKB(stats_.after_.old_.external_in_words), |
552 MicrosecondsToMilliseconds(stats_.times_[0]), | 546 MicrosecondsToMilliseconds(stats_.times_[0]), |
553 MicrosecondsToMilliseconds(stats_.times_[1]), | 547 MicrosecondsToMilliseconds(stats_.times_[1]), |
554 MicrosecondsToMilliseconds(stats_.times_[2]), | 548 MicrosecondsToMilliseconds(stats_.times_[2]), |
555 MicrosecondsToMilliseconds(stats_.times_[3]), | 549 MicrosecondsToMilliseconds(stats_.times_[3]), |
556 stats_.data_[0], | 550 stats_.data_[0], |
557 stats_.data_[1], | 551 stats_.data_[1], |
558 stats_.data_[2], | 552 stats_.data_[2], |
559 stats_.data_[3]); | 553 stats_.data_[3]); |
560 } | 554 } |
561 | 555 |
(...skipping 17 matching lines...) Expand all Loading... |
579 heap->DisableGrowthControl(); | 573 heap->DisableGrowthControl(); |
580 } | 574 } |
581 | 575 |
582 | 576 |
583 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 577 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
584 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 578 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
585 heap->SetGrowthControlState(current_growth_controller_state_); | 579 heap->SetGrowthControlState(current_growth_controller_state_); |
586 } | 580 } |
587 | 581 |
588 } // namespace dart | 582 } // namespace dart |
OLD | NEW |