Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: src/heap/heap.cc

Issue 1326793002: [heap] Separate ObjectStats out into its own class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/heap/heap.h" 5 #include "src/heap/heap.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
11 #include "src/base/utils/random-number-generator.h" 11 #include "src/base/utils/random-number-generator.h"
12 #include "src/bootstrapper.h" 12 #include "src/bootstrapper.h"
13 #include "src/codegen.h" 13 #include "src/codegen.h"
14 #include "src/compilation-cache.h" 14 #include "src/compilation-cache.h"
15 #include "src/conversions.h" 15 #include "src/conversions.h"
16 #include "src/cpu-profiler.h" 16 #include "src/cpu-profiler.h"
17 #include "src/debug/debug.h" 17 #include "src/debug/debug.h"
18 #include "src/deoptimizer.h" 18 #include "src/deoptimizer.h"
19 #include "src/global-handles.h" 19 #include "src/global-handles.h"
20 #include "src/heap/gc-idle-time-handler.h" 20 #include "src/heap/gc-idle-time-handler.h"
21 #include "src/heap/gc-tracer.h" 21 #include "src/heap/gc-tracer.h"
22 #include "src/heap/incremental-marking.h" 22 #include "src/heap/incremental-marking.h"
23 #include "src/heap/mark-compact-inl.h" 23 #include "src/heap/mark-compact-inl.h"
24 #include "src/heap/mark-compact.h" 24 #include "src/heap/mark-compact.h"
25 #include "src/heap/memory-reducer.h" 25 #include "src/heap/memory-reducer.h"
26 #include "src/heap/object-stats.h"
26 #include "src/heap/objects-visiting-inl.h" 27 #include "src/heap/objects-visiting-inl.h"
27 #include "src/heap/objects-visiting.h" 28 #include "src/heap/objects-visiting.h"
28 #include "src/heap/store-buffer.h" 29 #include "src/heap/store-buffer.h"
29 #include "src/heap-profiler.h" 30 #include "src/heap-profiler.h"
30 #include "src/interpreter/interpreter.h" 31 #include "src/interpreter/interpreter.h"
31 #include "src/runtime-profiler.h" 32 #include "src/runtime-profiler.h"
32 #include "src/scopeinfo.h" 33 #include "src/scopeinfo.h"
33 #include "src/snapshot/natives.h" 34 #include "src/snapshot/natives.h"
34 #include "src/snapshot/serialize.h" 35 #include "src/snapshot/serialize.h"
35 #include "src/snapshot/snapshot.h" 36 #include "src/snapshot/snapshot.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 max_alive_after_gc_(0), 116 max_alive_after_gc_(0),
116 min_in_mutator_(kMaxInt), 117 min_in_mutator_(kMaxInt),
117 marking_time_(0.0), 118 marking_time_(0.0),
118 sweeping_time_(0.0), 119 sweeping_time_(0.0),
119 last_idle_notification_time_(0.0), 120 last_idle_notification_time_(0.0),
120 last_gc_time_(0.0), 121 last_gc_time_(0.0),
121 mark_compact_collector_(this), 122 mark_compact_collector_(this),
122 store_buffer_(this), 123 store_buffer_(this),
123 incremental_marking_(this), 124 incremental_marking_(this),
124 memory_reducer_(nullptr), 125 memory_reducer_(nullptr),
126 object_stats_(nullptr),
125 full_codegen_bytes_generated_(0), 127 full_codegen_bytes_generated_(0),
126 crankshaft_codegen_bytes_generated_(0), 128 crankshaft_codegen_bytes_generated_(0),
127 new_space_allocation_counter_(0), 129 new_space_allocation_counter_(0),
128 old_generation_allocation_counter_(0), 130 old_generation_allocation_counter_(0),
129 old_generation_size_at_last_gc_(0), 131 old_generation_size_at_last_gc_(0),
130 gcs_since_last_deopt_(0), 132 gcs_since_last_deopt_(0),
131 allocation_sites_scratchpad_length_(0), 133 allocation_sites_scratchpad_length_(0),
132 ring_buffer_full_(false), 134 ring_buffer_full_(false),
133 ring_buffer_end_(0), 135 ring_buffer_end_(0),
134 promotion_queue_(this), 136 promotion_queue_(this),
(...skipping 19 matching lines...) Expand all
154 DCHECK((max_old_generation_size_ & (Page::kPageSize - 1)) == 0); 156 DCHECK((max_old_generation_size_ & (Page::kPageSize - 1)) == 0);
155 157
156 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength); 158 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength);
157 set_native_contexts_list(NULL); 159 set_native_contexts_list(NULL);
158 set_allocation_sites_list(Smi::FromInt(0)); 160 set_allocation_sites_list(Smi::FromInt(0));
159 set_encountered_weak_collections(Smi::FromInt(0)); 161 set_encountered_weak_collections(Smi::FromInt(0));
160 set_encountered_weak_cells(Smi::FromInt(0)); 162 set_encountered_weak_cells(Smi::FromInt(0));
161 // Put a dummy entry in the remembered pages so we can find the list the 163 // Put a dummy entry in the remembered pages so we can find the list the
162 // minidump even if there are no real unmapped pages. 164 // minidump even if there are no real unmapped pages.
163 RememberUnmappedPage(NULL, false); 165 RememberUnmappedPage(NULL, false);
164
165 ClearObjectStats(true);
166 } 166 }
167 167
168 168
169 intptr_t Heap::Capacity() { 169 intptr_t Heap::Capacity() {
170 if (!HasBeenSetUp()) return 0; 170 if (!HasBeenSetUp()) return 0;
171 171
172 return new_space_.Capacity() + old_space_->Capacity() + 172 return new_space_.Capacity() + old_space_->Capacity() +
173 code_space_->Capacity() + map_space_->Capacity(); 173 code_space_->Capacity() + map_space_->Capacity();
174 } 174 }
175 175
(...skipping 5460 matching lines...) Expand 10 before | Expand all | Expand 10 after
5636 5636
5637 for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount); 5637 for (int i = 0; i < static_cast<int>(v8::Isolate::kUseCounterFeatureCount);
5638 i++) { 5638 i++) {
5639 deferred_counters_[i] = 0; 5639 deferred_counters_[i] = 0;
5640 } 5640 }
5641 5641
5642 tracer_ = new GCTracer(this); 5642 tracer_ = new GCTracer(this);
5643 5643
5644 memory_reducer_ = new MemoryReducer(this); 5644 memory_reducer_ = new MemoryReducer(this);
5645 5645
5646 object_stats_ = new ObjectStats(this);
5647 object_stats_->ClearObjectStats(true);
5648
5646 LOG(isolate_, IntPtrTEvent("heap-capacity", Capacity())); 5649 LOG(isolate_, IntPtrTEvent("heap-capacity", Capacity()));
5647 LOG(isolate_, IntPtrTEvent("heap-available", Available())); 5650 LOG(isolate_, IntPtrTEvent("heap-available", Available()));
5648 5651
5649 store_buffer()->SetUp(); 5652 store_buffer()->SetUp();
5650 5653
5651 mark_compact_collector()->SetUp(); 5654 mark_compact_collector()->SetUp();
5652 5655
5653 return true; 5656 return true;
5654 } 5657 }
5655 5658
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
5746 if (FLAG_verify_predictable) { 5749 if (FLAG_verify_predictable) {
5747 PrintAlloctionsHash(); 5750 PrintAlloctionsHash();
5748 } 5751 }
5749 5752
5750 if (memory_reducer_ != nullptr) { 5753 if (memory_reducer_ != nullptr) {
5751 memory_reducer_->TearDown(); 5754 memory_reducer_->TearDown();
5752 delete memory_reducer_; 5755 delete memory_reducer_;
5753 memory_reducer_ = nullptr; 5756 memory_reducer_ = nullptr;
5754 } 5757 }
5755 5758
5759 delete object_stats_;
5760 object_stats_ = nullptr;
5761
5756 WaitUntilUnmappingOfFreeChunksCompleted(); 5762 WaitUntilUnmappingOfFreeChunksCompleted();
5757 5763
5758 TearDownArrayBuffers(); 5764 TearDownArrayBuffers();
5759 5765
5760 isolate_->global_handles()->TearDown(); 5766 isolate_->global_handles()->TearDown();
5761 5767
5762 external_string_table_.TearDown(); 5768 external_string_table_.TearDown();
5763 5769
5764 mark_compact_collector()->TearDown(); 5770 mark_compact_collector()->TearDown();
5765 5771
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
6566 } else { 6572 } else {
6567 p ^= 0x1d1ed & (Page::kPageSize - 1); // I died. 6573 p ^= 0x1d1ed & (Page::kPageSize - 1); // I died.
6568 } 6574 }
6569 remembered_unmapped_pages_[remembered_unmapped_pages_index_] = 6575 remembered_unmapped_pages_[remembered_unmapped_pages_index_] =
6570 reinterpret_cast<Address>(p); 6576 reinterpret_cast<Address>(p);
6571 remembered_unmapped_pages_index_++; 6577 remembered_unmapped_pages_index_++;
6572 remembered_unmapped_pages_index_ %= kRememberedUnmappedPages; 6578 remembered_unmapped_pages_index_ %= kRememberedUnmappedPages;
6573 } 6579 }
6574 6580
6575 6581
6576 void Heap::ClearObjectStats(bool clear_last_time_stats) {
6577 memset(object_counts_, 0, sizeof(object_counts_));
6578 memset(object_sizes_, 0, sizeof(object_sizes_));
6579 if (clear_last_time_stats) {
6580 memset(object_counts_last_time_, 0, sizeof(object_counts_last_time_));
6581 memset(object_sizes_last_time_, 0, sizeof(object_sizes_last_time_));
6582 }
6583 }
6584
6585
6586 static base::LazyMutex object_stats_mutex = LAZY_MUTEX_INITIALIZER;
6587
6588
6589 void Heap::TraceObjectStat(const char* name, int count, int size, double time) {
6590 PrintIsolate(isolate_,
6591 "heap:%p, time:%f, gc:%d, type:%s, count:%d, size:%d\n",
6592 static_cast<void*>(this), time, ms_count_, name, count, size);
6593 }
6594
6595
6596 void Heap::TraceObjectStats() {
6597 base::LockGuard<base::Mutex> lock_guard(object_stats_mutex.Pointer());
6598 int index;
6599 int count;
6600 int size;
6601 int total_size = 0;
6602 double time = isolate_->time_millis_since_init();
6603 #define TRACE_OBJECT_COUNT(name) \
6604 count = static_cast<int>(object_counts_[name]); \
6605 size = static_cast<int>(object_sizes_[name]) / KB; \
6606 total_size += size; \
6607 TraceObjectStat(#name, count, size, time);
6608 INSTANCE_TYPE_LIST(TRACE_OBJECT_COUNT)
6609 #undef TRACE_OBJECT_COUNT
6610 #define TRACE_OBJECT_COUNT(name) \
6611 index = FIRST_CODE_KIND_SUB_TYPE + Code::name; \
6612 count = static_cast<int>(object_counts_[index]); \
6613 size = static_cast<int>(object_sizes_[index]) / KB; \
6614 TraceObjectStat("*CODE_" #name, count, size, time);
6615 CODE_KIND_LIST(TRACE_OBJECT_COUNT)
6616 #undef TRACE_OBJECT_COUNT
6617 #define TRACE_OBJECT_COUNT(name) \
6618 index = FIRST_FIXED_ARRAY_SUB_TYPE + name; \
6619 count = static_cast<int>(object_counts_[index]); \
6620 size = static_cast<int>(object_sizes_[index]) / KB; \
6621 TraceObjectStat("*FIXED_ARRAY_" #name, count, size, time);
6622 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(TRACE_OBJECT_COUNT)
6623 #undef TRACE_OBJECT_COUNT
6624 #define TRACE_OBJECT_COUNT(name) \
6625 index = \
6626 FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge; \
6627 count = static_cast<int>(object_counts_[index]); \
6628 size = static_cast<int>(object_sizes_[index]) / KB; \
6629 TraceObjectStat("*CODE_AGE_" #name, count, size, time);
6630 CODE_AGE_LIST_COMPLETE(TRACE_OBJECT_COUNT)
6631 #undef TRACE_OBJECT_COUNT
6632 }
6633
6634
6635 void Heap::CheckpointObjectStats() {
6636 base::LockGuard<base::Mutex> lock_guard(object_stats_mutex.Pointer());
6637 Counters* counters = isolate()->counters();
6638 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \
6639 counters->count_of_##name()->Increment( \
6640 static_cast<int>(object_counts_[name])); \
6641 counters->count_of_##name()->Decrement( \
6642 static_cast<int>(object_counts_last_time_[name])); \
6643 counters->size_of_##name()->Increment( \
6644 static_cast<int>(object_sizes_[name])); \
6645 counters->size_of_##name()->Decrement( \
6646 static_cast<int>(object_sizes_last_time_[name]));
6647 INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
6648 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6649 int index;
6650 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \
6651 index = FIRST_CODE_KIND_SUB_TYPE + Code::name; \
6652 counters->count_of_CODE_TYPE_##name()->Increment( \
6653 static_cast<int>(object_counts_[index])); \
6654 counters->count_of_CODE_TYPE_##name()->Decrement( \
6655 static_cast<int>(object_counts_last_time_[index])); \
6656 counters->size_of_CODE_TYPE_##name()->Increment( \
6657 static_cast<int>(object_sizes_[index])); \
6658 counters->size_of_CODE_TYPE_##name()->Decrement( \
6659 static_cast<int>(object_sizes_last_time_[index]));
6660 CODE_KIND_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
6661 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6662 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \
6663 index = FIRST_FIXED_ARRAY_SUB_TYPE + name; \
6664 counters->count_of_FIXED_ARRAY_##name()->Increment( \
6665 static_cast<int>(object_counts_[index])); \
6666 counters->count_of_FIXED_ARRAY_##name()->Decrement( \
6667 static_cast<int>(object_counts_last_time_[index])); \
6668 counters->size_of_FIXED_ARRAY_##name()->Increment( \
6669 static_cast<int>(object_sizes_[index])); \
6670 counters->size_of_FIXED_ARRAY_##name()->Decrement( \
6671 static_cast<int>(object_sizes_last_time_[index]));
6672 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(ADJUST_LAST_TIME_OBJECT_COUNT)
6673 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6674 #define ADJUST_LAST_TIME_OBJECT_COUNT(name) \
6675 index = \
6676 FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge; \
6677 counters->count_of_CODE_AGE_##name()->Increment( \
6678 static_cast<int>(object_counts_[index])); \
6679 counters->count_of_CODE_AGE_##name()->Decrement( \
6680 static_cast<int>(object_counts_last_time_[index])); \
6681 counters->size_of_CODE_AGE_##name()->Increment( \
6682 static_cast<int>(object_sizes_[index])); \
6683 counters->size_of_CODE_AGE_##name()->Decrement( \
6684 static_cast<int>(object_sizes_last_time_[index]));
6685 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
6686 #undef ADJUST_LAST_TIME_OBJECT_COUNT
6687
6688 MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
6689 MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
6690 ClearObjectStats();
6691 }
6692
6693
6694 void Heap::RegisterStrongRoots(Object** start, Object** end) { 6582 void Heap::RegisterStrongRoots(Object** start, Object** end) {
6695 StrongRootsList* list = new StrongRootsList(); 6583 StrongRootsList* list = new StrongRootsList();
6696 list->next = strong_roots_list_; 6584 list->next = strong_roots_list_;
6697 list->start = start; 6585 list->start = start;
6698 list->end = end; 6586 list->end = end;
6699 strong_roots_list_ = list; 6587 strong_roots_list_ = list;
6700 } 6588 }
6701 6589
6702 6590
6703 void Heap::UnregisterStrongRoots(Object** start) { 6591 void Heap::UnregisterStrongRoots(Object** start) {
6704 StrongRootsList* prev = NULL; 6592 StrongRootsList* prev = NULL;
6705 StrongRootsList* list = strong_roots_list_; 6593 StrongRootsList* list = strong_roots_list_;
6706 while (list != nullptr) { 6594 while (list != nullptr) {
6707 StrongRootsList* next = list->next; 6595 StrongRootsList* next = list->next;
6708 if (list->start == start) { 6596 if (list->start == start) {
6709 if (prev) { 6597 if (prev) {
6710 prev->next = next; 6598 prev->next = next;
6711 } else { 6599 } else {
6712 strong_roots_list_ = next; 6600 strong_roots_list_ = next;
6713 } 6601 }
6714 delete list; 6602 delete list;
6715 } else { 6603 } else {
6716 prev = list; 6604 prev = list;
6717 } 6605 }
6718 list = next; 6606 list = next;
6719 } 6607 }
6720 } 6608 }
6721 6609
6722 6610
6611 size_t Heap::NumberOfTrackedHeapObjectTypes() {
6612 return ObjectStats::OBJECT_STATS_COUNT;
6613 }
6614
6615
6616 size_t Heap::ObjectCountAtLastGC(size_t index) {
6617 if (index >= ObjectStats::OBJECT_STATS_COUNT) return 0;
6618 return object_stats_->object_count_last_gc(index);
6619 }
6620
6621
6622 size_t Heap::ObjectSizeAtLastGC(size_t index) {
6623 if (index >= ObjectStats::OBJECT_STATS_COUNT) return 0;
6624 return object_stats_->object_size_last_gc(index);
6625 }
6626
6627
6723 bool Heap::GetObjectTypeName(size_t index, const char** object_type, 6628 bool Heap::GetObjectTypeName(size_t index, const char** object_type,
6724 const char** object_sub_type) { 6629 const char** object_sub_type) {
6725 if (index >= OBJECT_STATS_COUNT) return false; 6630 if (index >= ObjectStats::OBJECT_STATS_COUNT) return false;
6726 6631
6727 switch (static_cast<int>(index)) { 6632 switch (static_cast<int>(index)) {
6728 #define COMPARE_AND_RETURN_NAME(name) \ 6633 #define COMPARE_AND_RETURN_NAME(name) \
6729 case name: \ 6634 case name: \
6730 *object_type = #name; \ 6635 *object_type = #name; \
6731 *object_sub_type = ""; \ 6636 *object_sub_type = ""; \
6732 return true; 6637 return true;
6733 INSTANCE_TYPE_LIST(COMPARE_AND_RETURN_NAME) 6638 INSTANCE_TYPE_LIST(COMPARE_AND_RETURN_NAME)
6734 #undef COMPARE_AND_RETURN_NAME 6639 #undef COMPARE_AND_RETURN_NAME
6735 #define COMPARE_AND_RETURN_NAME(name) \ 6640 #define COMPARE_AND_RETURN_NAME(name) \
6736 case FIRST_CODE_KIND_SUB_TYPE + Code::name: \ 6641 case ObjectStats::FIRST_CODE_KIND_SUB_TYPE + Code::name: \
6737 *object_type = "CODE_TYPE"; \ 6642 *object_type = "CODE_TYPE"; \
6738 *object_sub_type = "CODE_KIND/" #name; \ 6643 *object_sub_type = "CODE_KIND/" #name; \
6739 return true; 6644 return true;
6740 CODE_KIND_LIST(COMPARE_AND_RETURN_NAME) 6645 CODE_KIND_LIST(COMPARE_AND_RETURN_NAME)
6741 #undef COMPARE_AND_RETURN_NAME 6646 #undef COMPARE_AND_RETURN_NAME
6742 #define COMPARE_AND_RETURN_NAME(name) \ 6647 #define COMPARE_AND_RETURN_NAME(name) \
6743 case FIRST_FIXED_ARRAY_SUB_TYPE + name: \ 6648 case ObjectStats::FIRST_FIXED_ARRAY_SUB_TYPE + name: \
6744 *object_type = "FIXED_ARRAY_TYPE"; \ 6649 *object_type = "FIXED_ARRAY_TYPE"; \
6745 *object_sub_type = #name; \ 6650 *object_sub_type = #name; \
6746 return true; 6651 return true;
6747 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(COMPARE_AND_RETURN_NAME) 6652 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(COMPARE_AND_RETURN_NAME)
6748 #undef COMPARE_AND_RETURN_NAME 6653 #undef COMPARE_AND_RETURN_NAME
6749 #define COMPARE_AND_RETURN_NAME(name) \ 6654 #define COMPARE_AND_RETURN_NAME(name) \
6750 case FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - Code::kFirstCodeAge: \ 6655 case ObjectStats::FIRST_CODE_AGE_SUB_TYPE + Code::k##name##CodeAge - \
6751 *object_type = "CODE_TYPE"; \ 6656 Code::kFirstCodeAge: \
6752 *object_sub_type = "CODE_AGE/" #name; \ 6657 *object_type = "CODE_TYPE"; \
6658 *object_sub_type = "CODE_AGE/" #name; \
6753 return true; 6659 return true;
6754 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) 6660 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME)
6755 #undef COMPARE_AND_RETURN_NAME 6661 #undef COMPARE_AND_RETURN_NAME
6756 } 6662 }
6757 return false; 6663 return false;
6758 } 6664 }
6665
6759 } // namespace internal 6666 } // namespace internal
6760 } // namespace v8 6667 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698