| 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/lockers.h" | 11 #include "vm/lockers.h" |
| 12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 #include "vm/object_set.h" | 13 #include "vm/object_set.h" |
| 14 #include "vm/os.h" | 14 #include "vm/os.h" |
| 15 #include "vm/pages.h" | 15 #include "vm/pages.h" |
| 16 #include "vm/raw_object.h" | 16 #include "vm/raw_object.h" |
| 17 #include "vm/scavenger.h" | 17 #include "vm/scavenger.h" |
| 18 #include "vm/service.h" | 18 #include "vm/service.h" |
| 19 #include "vm/service_event.h" |
| 19 #include "vm/stack_frame.h" | 20 #include "vm/stack_frame.h" |
| 20 #include "vm/tags.h" | 21 #include "vm/tags.h" |
| 21 #include "vm/verifier.h" | 22 #include "vm/verifier.h" |
| 22 #include "vm/virtual_memory.h" | 23 #include "vm/virtual_memory.h" |
| 23 #include "vm/weak_table.h" | 24 #include "vm/weak_table.h" |
| 24 | 25 |
| 25 namespace dart { | 26 namespace dart { |
| 26 | 27 |
| 27 DEFINE_FLAG(bool, disable_alloc_stubs_after_gc, false, "Stress testing flag."); | 28 DEFINE_FLAG(bool, disable_alloc_stubs_after_gc, false, "Stress testing flag."); |
| 28 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); | 29 DEFINE_FLAG(bool, gc_at_alloc, false, "GC at every allocation."); |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 new_space_->IncrementCollections(); | 614 new_space_->IncrementCollections(); |
| 614 } else { | 615 } else { |
| 615 old_space_->AddGCTime(delta); | 616 old_space_->AddGCTime(delta); |
| 616 old_space_->IncrementCollections(); | 617 old_space_->IncrementCollections(); |
| 617 } | 618 } |
| 618 stats_.after_.new_ = new_space_->GetCurrentUsage(); | 619 stats_.after_.new_ = new_space_->GetCurrentUsage(); |
| 619 stats_.after_.old_ = old_space_->GetCurrentUsage(); | 620 stats_.after_.old_ = old_space_->GetCurrentUsage(); |
| 620 ASSERT(gc_in_progress_); | 621 ASSERT(gc_in_progress_); |
| 621 gc_in_progress_ = false; | 622 gc_in_progress_ = false; |
| 622 if (Service::NeedsEvents()) { | 623 if (Service::NeedsEvents()) { |
| 623 GCEvent event(stats_); | 624 ServiceEvent event(Isolate::Current(), ServiceEvent::kGC); |
| 624 Service::HandleGCEvent(&event); | 625 event.set_gc_stats(&stats_); |
| 626 Service::HandleEvent(&event); |
| 625 } | 627 } |
| 626 } | 628 } |
| 627 | 629 |
| 628 | 630 |
| 629 void Heap::PrintStats() { | 631 void Heap::PrintStats() { |
| 630 if (!FLAG_verbose_gc) return; | 632 if (!FLAG_verbose_gc) return; |
| 631 | 633 |
| 632 if ((FLAG_verbose_gc_hdr != 0) && | 634 if ((FLAG_verbose_gc_hdr != 0) && |
| 633 (((stats_.num_ - 1) % FLAG_verbose_gc_hdr) == 0)) { | 635 (((stats_.num_ - 1) % FLAG_verbose_gc_hdr) == 0)) { |
| 634 OS::PrintErr("[ GC | space | count | start | gc time | " | 636 OS::PrintErr("[ GC | space | count | start | gc time | " |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 MicrosecondsToMilliseconds(stats_.times_[1]), | 675 MicrosecondsToMilliseconds(stats_.times_[1]), |
| 674 MicrosecondsToMilliseconds(stats_.times_[2]), | 676 MicrosecondsToMilliseconds(stats_.times_[2]), |
| 675 MicrosecondsToMilliseconds(stats_.times_[3]), | 677 MicrosecondsToMilliseconds(stats_.times_[3]), |
| 676 stats_.data_[0], | 678 stats_.data_[0], |
| 677 stats_.data_[1], | 679 stats_.data_[1], |
| 678 stats_.data_[2], | 680 stats_.data_[2], |
| 679 stats_.data_[3]); | 681 stats_.data_[3]); |
| 680 } | 682 } |
| 681 | 683 |
| 682 | 684 |
| 683 void GCEvent::PrintJSON(JSONStream* js) const { | |
| 684 Isolate* isolate = Isolate::Current(); | |
| 685 { | |
| 686 JSONObject jsobj(js); | |
| 687 jsobj.AddProperty("type", "ServiceEvent"); | |
| 688 jsobj.AddPropertyF("id", "gc/%" Pd, stats_.num_); | |
| 689 jsobj.AddProperty("eventType", "GC"); // TODO(koda): "GarbageCollected" | |
| 690 jsobj.AddProperty("isolate", isolate); | |
| 691 jsobj.AddProperty("reason", Heap::GCReasonToString(stats_.reason_)); | |
| 692 isolate->heap()->PrintToJSONObject(Heap::kNew, &jsobj); | |
| 693 isolate->heap()->PrintToJSONObject(Heap::kOld, &jsobj); | |
| 694 } | |
| 695 } | |
| 696 | |
| 697 | |
| 698 #if defined(DEBUG) | 685 #if defined(DEBUG) |
| 699 NoSafepointScope::NoSafepointScope() : StackResource(Isolate::Current()) { | 686 NoSafepointScope::NoSafepointScope() : StackResource(Isolate::Current()) { |
| 700 isolate()->IncrementNoSafepointScopeDepth(); | 687 isolate()->IncrementNoSafepointScopeDepth(); |
| 701 } | 688 } |
| 702 | 689 |
| 703 | 690 |
| 704 NoSafepointScope::~NoSafepointScope() { | 691 NoSafepointScope::~NoSafepointScope() { |
| 705 isolate()->DecrementNoSafepointScopeDepth(); | 692 isolate()->DecrementNoSafepointScopeDepth(); |
| 706 } | 693 } |
| 707 #endif // defined(DEBUG) | 694 #endif // defined(DEBUG) |
| 708 | 695 |
| 709 | 696 |
| 710 NoHeapGrowthControlScope::NoHeapGrowthControlScope() | 697 NoHeapGrowthControlScope::NoHeapGrowthControlScope() |
| 711 : StackResource(Isolate::Current()) { | 698 : StackResource(Isolate::Current()) { |
| 712 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 699 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 713 current_growth_controller_state_ = heap->GrowthControlState(); | 700 current_growth_controller_state_ = heap->GrowthControlState(); |
| 714 heap->DisableGrowthControl(); | 701 heap->DisableGrowthControl(); |
| 715 } | 702 } |
| 716 | 703 |
| 717 | 704 |
| 718 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 705 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 719 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 706 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 720 heap->SetGrowthControlState(current_growth_controller_state_); | 707 heap->SetGrowthControlState(current_growth_controller_state_); |
| 721 } | 708 } |
| 722 | 709 |
| 723 } // namespace dart | 710 } // namespace dart |
| OLD | NEW |