Chromium Code Reviews| Index: runtime/vm/class_table.cc |
| diff --git a/runtime/vm/class_table.cc b/runtime/vm/class_table.cc |
| index e85053a6d9cf5eb652c9f35946ae7343a929f40e..e011f218358ea199acd25ac974818c877d9361e5 100644 |
| --- a/runtime/vm/class_table.cc |
| +++ b/runtime/vm/class_table.cc |
| @@ -14,7 +14,9 @@ namespace dart { |
| DEFINE_FLAG(bool, print_class_table, false, "Print initial class table."); |
| ClassTable::ClassTable() |
| - : top_(kNumPredefinedCids), capacity_(0), table_(NULL) { |
| + : top_(kNumPredefinedCids), capacity_(0), table_(NULL), |
| + class_heap_stats_table_(NULL), |
| + predefined_class_heap_stats_table_(NULL) { |
| if (Dart::vm_isolate() == NULL) { |
| capacity_ = initial_capacity_; |
| table_ = reinterpret_cast<RawClass**>( |
| @@ -31,12 +33,26 @@ ClassTable::ClassTable() |
| table_[kFreeListElement] = vm_class_table->At(kFreeListElement); |
| table_[kDynamicCid] = vm_class_table->At(kDynamicCid); |
| table_[kVoidCid] = vm_class_table->At(kVoidCid); |
| + predefined_class_heap_stats_table_ = reinterpret_cast<ClassHeapStats*>( |
|
Ivan Posva
2013/12/12 13:53:24
Why is this allocated twice?
Cutch
2013/12/13 01:31:09
The predefined class stats table is allocated once
|
| + calloc(kNumPredefinedCids, sizeof(ClassHeapStats))); // NOLINT |
| + class_heap_stats_table_ = reinterpret_cast<ClassHeapStats*>( |
| + calloc(capacity_, sizeof(ClassHeapStats))); // NOLINT |
| + for (intptr_t i = 0; i < capacity_; i++) { |
| + class_heap_stats_table_[i].Initialize(); |
| + } |
| + } |
| + predefined_class_heap_stats_table_ = reinterpret_cast<ClassHeapStats*>( |
| + calloc(kNumPredefinedCids, sizeof(ClassHeapStats))); // NOLINT |
| + for (intptr_t i = 0; i < kNumPredefinedCids; i++) { |
| + predefined_class_heap_stats_table_[i].Initialize(); |
| } |
| } |
| ClassTable::~ClassTable() { |
| free(table_); |
| + free(predefined_class_heap_stats_table_); |
| + free(class_heap_stats_table_); |
| } |
| @@ -62,11 +78,16 @@ void ClassTable::Register(const Class& cls) { |
| intptr_t new_capacity = capacity_ + capacity_increment_; |
| RawClass** new_table = reinterpret_cast<RawClass**>( |
| realloc(table_, new_capacity * sizeof(RawClass*))); // NOLINT |
| + ClassHeapStats* new_stats_table = reinterpret_cast<ClassHeapStats*>( |
| + realloc(class_heap_stats_table_, |
| + new_capacity * sizeof(ClassHeapStats))); // NOLINT |
| for (intptr_t i = capacity_; i < new_capacity; i++) { |
| new_table[i] = NULL; |
| + new_stats_table[i].Initialize(); |
| } |
| capacity_ = new_capacity; |
| table_ = new_table; |
| + class_heap_stats_table_ = new_stats_table; |
| } |
| ASSERT(top_ < capacity_); |
| cls.set_id(top_); |
| @@ -111,4 +132,140 @@ void ClassTable::PrintToJSONStream(JSONStream* stream) { |
| } |
| } |
| + |
| +void ClassHeapStats::Initialize() { |
| + live_count_old_space = 0; |
| + live_count_new_space = 0; |
| + live_size_old_space = 0; |
| + live_size_new_space = 0; |
| + new_count_since_gc_new_space = 0; |
| + new_count_since_gc_old_space = 0; |
| + new_size_since_gc_new_space = 0; |
| + new_size_since_gc_old_space = 0; |
| +} |
| + |
| + |
| +void ClassHeapStats::ResetAtGC() { |
| + live_count_old_space = 0; |
| + live_count_new_space = 0; |
| + live_size_old_space = 0; |
| + live_size_new_space = 0; |
| + new_count_since_gc_new_space = 0; |
| + new_count_since_gc_old_space = 0; |
| + new_size_since_gc_new_space = 0; |
| + new_size_since_gc_old_space = 0; |
| +} |
| + |
| + |
| +void ClassTable::ReportAllocationNewSpace(intptr_t cid, intptr_t size) { |
| + ClassHeapStats* stats = FindClassHeapStats(cid); |
| + ASSERT(stats != NULL); |
| + ASSERT(size != 0); |
| + stats->new_count_since_gc_new_space++; |
| + if (CollectInstanceSizesForClass(cid)) { |
|
Ivan Posva
2013/12/12 13:53:24
How about avoiding the check and just updating the
Cutch
2013/12/13 01:31:09
Done.
|
| + stats->new_size_since_gc_new_space += size; |
| + } |
| +} |
| + |
| + |
| +void ClassTable::ReportAllocationOldSpace(intptr_t cid, intptr_t size) { |
| + ClassHeapStats* stats = FindClassHeapStats(cid); |
| + ASSERT(stats != NULL); |
| + ASSERT(size != 0); |
| + stats->new_count_since_gc_old_space++; |
| + if (CollectInstanceSizesForClass(cid)) { |
|
Ivan Posva
2013/12/12 13:53:24
ditto
Cutch
2013/12/13 01:31:09
Done.
|
| + stats->new_size_since_gc_old_space += size; |
| + } |
| +} |
| + |
| + |
| +// #define DEBUG_PRINT |
|
Ivan Posva
2013/12/12 13:53:24
Please make this a command line flag or remove the
Cutch
2013/12/13 01:31:09
This will be removed before committing. It's just
|
| + |
| +#if defined(DEBUG_PRINT) |
| +static void PrintClassHeapStats(intptr_t cid, const ClassHeapStats& stat) { |
| + int new_new = static_cast<int>(stat.new_count_since_gc_new_space); |
| + int new_old = static_cast<int>(stat.new_count_since_gc_old_space); |
| + int b_new = static_cast<int>(stat.new_size_since_gc_new_space); |
| + int b_old = static_cast<int>(stat.new_size_since_gc_old_space); |
| + printf("%d (%d %d) [%d %d]\n", static_cast<int>(cid), |
| + new_new, b_new, new_old, b_old); |
| +} |
| +#endif |
| + |
| + |
| +void ClassTable::Collect() { |
|
Ivan Posva
2013/12/12 13:53:24
How about only exposing ResetCounters()?
Cutch
2013/12/13 01:31:09
Done.
|
| + Isolate* isolate = Isolate::Current(); |
| + ASSERT(isolate != NULL); |
| +#if defined(DEBUG_PRINT) |
| + for (intptr_t i = 0; i < kNumPredefinedCids; i++) { |
| + const ClassHeapStats& stat = predefined_class_heap_stats_table_[i]; |
| + if ((stat.new_count_since_gc_new_space > 0) || |
| + (stat.new_count_since_gc_old_space > 0)) { |
| + PrintClassHeapStats(i, stat); |
| + } |
| + } |
| + for (intptr_t i = kNumPredefinedCids; i < top_; i++) { |
| + const ClassHeapStats& stat = class_heap_stats_table_[i]; |
| + if ((stat.new_count_since_gc_new_space > 0) || |
| + (stat.new_count_since_gc_old_space > 0)) { |
| + PrintClassHeapStats(i, stat); |
| + } |
| + } |
| +#endif |
| + ResetCounters(); |
| +} |
| + |
| + |
| +bool ClassTable::CollectInstanceSizesForClass(intptr_t cid) { |
| + // We only collect size information for classes which do not have |
| + // fixed lengths. |
| + if ((cid == kArrayCid) || |
| + RawObject::IsOneByteStringClassId(cid) || |
| + RawObject::IsTwoByteStringClassId(cid) || |
| + RawObject::IsTypedDataClassId(cid) || |
| + (cid == kContextCid)) { |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| + |
| +ClassHeapStats* ClassTable::FindClassHeapStats(intptr_t cid) { |
|
Ivan Posva
2013/12/12 13:53:24
StatsAt(intptr_t cid)
Cutch
2013/12/13 01:31:09
Done.
|
| + ASSERT(cid > 0); |
| + if (cid < kNumPredefinedCids) { |
| + return &predefined_class_heap_stats_table_[cid]; |
| + } |
| + ASSERT(cid < top_); |
| + return &class_heap_stats_table_[cid]; |
| +} |
| + |
| + |
| +void ClassTable::ResetCounters() { |
| + for (intptr_t i = 0; i < kNumPredefinedCids; i++) { |
| + predefined_class_heap_stats_table_[i].ResetAtGC(); |
| + } |
| + for (intptr_t i = kNumPredefinedCids; i < top_; i++) { |
| + class_heap_stats_table_[i].ResetAtGC(); |
| + } |
| +} |
| + |
| + |
| +void ClassTable::ReportLiveOldSpace(intptr_t cid, intptr_t size) { |
| + ClassHeapStats* stats = FindClassHeapStats(cid); |
| + ASSERT(stats != NULL); |
| + ASSERT(size != 0); |
| + stats->live_count_old_space++; |
| + stats->live_size_old_space += size; |
| +} |
| + |
| + |
| +void ClassTable::ReportLiveNewSpace(intptr_t cid, intptr_t size) { |
| + ClassHeapStats* stats = FindClassHeapStats(cid); |
| + ASSERT(stats != NULL); |
| + ASSERT(size != 0); |
| + stats->live_count_new_space++; |
| + stats->live_size_new_space += size; |
| +} |
| + |
| + |
| } // namespace dart |