| 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" |
| 11 #include "vm/object.h" | 11 #include "vm/object.h" |
| 12 #include "vm/object_set.h" | 12 #include "vm/object_set.h" |
| 13 #include "vm/os.h" | 13 #include "vm/os.h" |
| 14 #include "vm/pages.h" | 14 #include "vm/pages.h" |
| 15 #include "vm/raw_object.h" | 15 #include "vm/raw_object.h" |
| 16 #include "vm/scavenger.h" | 16 #include "vm/scavenger.h" |
| 17 #include "vm/service.h" |
| 17 #include "vm/stack_frame.h" | 18 #include "vm/stack_frame.h" |
| 18 #include "vm/tags.h" | 19 #include "vm/tags.h" |
| 19 #include "vm/verifier.h" | 20 #include "vm/verifier.h" |
| 20 #include "vm/virtual_memory.h" | 21 #include "vm/virtual_memory.h" |
| 21 #include "vm/weak_table.h" | 22 #include "vm/weak_table.h" |
| 22 | 23 |
| 23 namespace dart { | 24 namespace dart { |
| 24 | 25 |
| 25 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); | 26 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); |
| 26 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); | 27 DEFINE_FLAG(int, verbose_gc_hdr, 40, "Print verbose GC header interval."); |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 new_space_->AddGCTime(delta); | 497 new_space_->AddGCTime(delta); |
| 497 new_space_->IncrementCollections(); | 498 new_space_->IncrementCollections(); |
| 498 } else { | 499 } else { |
| 499 old_space_->AddGCTime(delta); | 500 old_space_->AddGCTime(delta); |
| 500 old_space_->IncrementCollections(); | 501 old_space_->IncrementCollections(); |
| 501 } | 502 } |
| 502 stats_.after_.new_ = new_space_->GetCurrentUsage(); | 503 stats_.after_.new_ = new_space_->GetCurrentUsage(); |
| 503 stats_.after_.old_ = old_space_->GetCurrentUsage(); | 504 stats_.after_.old_ = old_space_->GetCurrentUsage(); |
| 504 ASSERT(gc_in_progress_); | 505 ASSERT(gc_in_progress_); |
| 505 gc_in_progress_ = false; | 506 gc_in_progress_ = false; |
| 507 if (Service::NeedsGCEvents()) { |
| 508 GCEvent event(stats_); |
| 509 Service::HandleGCEvent(&event); |
| 510 } |
| 506 } | 511 } |
| 507 | 512 |
| 508 | 513 |
| 509 void Heap::PrintStats() { | 514 void Heap::PrintStats() { |
| 510 if (!FLAG_verbose_gc) return; | 515 if (!FLAG_verbose_gc) return; |
| 511 | 516 |
| 512 if ((FLAG_verbose_gc_hdr != 0) && | 517 if ((FLAG_verbose_gc_hdr != 0) && |
| 513 (((stats_.num_ - 1) % FLAG_verbose_gc_hdr) == 0)) { | 518 (((stats_.num_ - 1) % FLAG_verbose_gc_hdr) == 0)) { |
| 514 OS::PrintErr("[ GC | space | count | start | gc time | " | 519 OS::PrintErr("[ GC | space | count | start | gc time | " |
| 515 "new gen (KB) | old gen (KB) | timers | data ]\n" | 520 "new gen (KB) | old gen (KB) | timers | data ]\n" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 MicrosecondsToMilliseconds(stats_.times_[1]), | 558 MicrosecondsToMilliseconds(stats_.times_[1]), |
| 554 MicrosecondsToMilliseconds(stats_.times_[2]), | 559 MicrosecondsToMilliseconds(stats_.times_[2]), |
| 555 MicrosecondsToMilliseconds(stats_.times_[3]), | 560 MicrosecondsToMilliseconds(stats_.times_[3]), |
| 556 stats_.data_[0], | 561 stats_.data_[0], |
| 557 stats_.data_[1], | 562 stats_.data_[1], |
| 558 stats_.data_[2], | 563 stats_.data_[2], |
| 559 stats_.data_[3]); | 564 stats_.data_[3]); |
| 560 } | 565 } |
| 561 | 566 |
| 562 | 567 |
| 568 void GCEvent::PrintJSON(JSONStream* js) const { |
| 569 Isolate* isolate = Isolate::Current(); |
| 570 { |
| 571 JSONObject jsobj(js); |
| 572 jsobj.AddProperty("type", "ServiceEvent"); |
| 573 jsobj.AddPropertyF("id", "gc/%" Pd, stats_.num_); |
| 574 jsobj.AddProperty("eventType", "GC"); // TODO(koda): "GarbageCollected" |
| 575 jsobj.AddProperty("isolate", isolate); |
| 576 jsobj.AddProperty("reason", Heap::GCReasonToString(stats_.reason_)); |
| 577 isolate->heap()->PrintToJSONObject(Heap::kNew, &jsobj); |
| 578 isolate->heap()->PrintToJSONObject(Heap::kOld, &jsobj); |
| 579 } |
| 580 } |
| 581 |
| 582 |
| 563 #if defined(DEBUG) | 583 #if defined(DEBUG) |
| 564 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { | 584 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { |
| 565 isolate()->IncrementNoGCScopeDepth(); | 585 isolate()->IncrementNoGCScopeDepth(); |
| 566 } | 586 } |
| 567 | 587 |
| 568 | 588 |
| 569 NoGCScope::~NoGCScope() { | 589 NoGCScope::~NoGCScope() { |
| 570 isolate()->DecrementNoGCScopeDepth(); | 590 isolate()->DecrementNoGCScopeDepth(); |
| 571 } | 591 } |
| 572 #endif // defined(DEBUG) | 592 #endif // defined(DEBUG) |
| 573 | 593 |
| 574 | 594 |
| 575 NoHeapGrowthControlScope::NoHeapGrowthControlScope() | 595 NoHeapGrowthControlScope::NoHeapGrowthControlScope() |
| 576 : StackResource(Isolate::Current()) { | 596 : StackResource(Isolate::Current()) { |
| 577 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 597 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 578 current_growth_controller_state_ = heap->GrowthControlState(); | 598 current_growth_controller_state_ = heap->GrowthControlState(); |
| 579 heap->DisableGrowthControl(); | 599 heap->DisableGrowthControl(); |
| 580 } | 600 } |
| 581 | 601 |
| 582 | 602 |
| 583 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 603 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 584 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 604 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 585 heap->SetGrowthControlState(current_growth_controller_state_); | 605 heap->SetGrowthControlState(current_growth_controller_state_); |
| 586 } | 606 } |
| 587 | 607 |
| 588 } // namespace dart | 608 } // namespace dart |
| OLD | NEW |