| 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 #ifndef VM_CLASS_TABLE_H_ | 5 #ifndef VM_CLASS_TABLE_H_ |
| 6 #define VM_CLASS_TABLE_H_ | 6 #define VM_CLASS_TABLE_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 class Class; | 13 class Class; |
| 14 class ClassStats; | 14 class ClassStats; |
| 15 class JSONArray; | 15 class JSONArray; |
| 16 class JSONStream; | 16 class JSONStream; |
| 17 class ObjectPointerVisitor; | 17 class ObjectPointerVisitor; |
| 18 class RawClass; | 18 class RawClass; |
| 19 | 19 |
| 20 template<typename T> |
| 21 class AllocStats { |
| 22 public: |
| 23 T new_count; |
| 24 T new_size; |
| 25 T old_count; |
| 26 T old_size; |
| 27 |
| 28 void ResetNew() { |
| 29 new_count = 0; |
| 30 new_size = 0; |
| 31 } |
| 32 |
| 33 void AddNew(T size) { |
| 34 new_count++; |
| 35 new_size += size; |
| 36 } |
| 37 |
| 38 void ResetOld() { |
| 39 old_count = 0; |
| 40 old_size = 0; |
| 41 } |
| 42 |
| 43 void AddOld(T size) { |
| 44 old_count++; |
| 45 old_size += size; |
| 46 } |
| 47 |
| 48 void Reset() { |
| 49 new_count = 0; |
| 50 new_size = 0; |
| 51 old_count = 0; |
| 52 old_size = 0; |
| 53 } |
| 54 }; |
| 20 | 55 |
| 21 class ClassHeapStats { | 56 class ClassHeapStats { |
| 22 public: | 57 public: |
| 23 // Total allocated before GC. | 58 // Snapshot before GC. |
| 24 intptr_t allocated_before_gc_old_space; | 59 AllocStats<intptr_t> pre_gc; |
| 25 intptr_t allocated_before_gc_new_space; | |
| 26 intptr_t allocated_size_before_gc_old_space; | |
| 27 intptr_t allocated_size_before_gc_new_space; | |
| 28 | |
| 29 // Live after GC. | 60 // Live after GC. |
| 30 intptr_t live_after_gc_old_space; | 61 AllocStats<intptr_t> post_gc; |
| 31 intptr_t live_after_gc_new_space; | 62 // Allocations since the last GC. |
| 32 intptr_t live_size_after_gc_old_space; | 63 AllocStats<intptr_t> recent; |
| 33 intptr_t live_size_after_gc_new_space; | 64 // Accumulated (across GC) allocations . |
| 34 | 65 AllocStats<int64_t> accumulated; |
| 35 // Allocated since GC. | 66 // Snapshot of recent at the time of the last reset. |
| 36 intptr_t allocated_since_gc_new_space; | 67 AllocStats<intptr_t> last_reset; |
| 37 intptr_t allocated_since_gc_old_space; | |
| 38 intptr_t allocated_size_since_gc_new_space; | |
| 39 intptr_t allocated_size_since_gc_old_space; | |
| 40 | 68 |
| 41 static intptr_t allocated_since_gc_new_space_offset() { | 69 static intptr_t allocated_since_gc_new_space_offset() { |
| 42 return OFFSET_OF(ClassHeapStats, allocated_since_gc_new_space); | 70 return OFFSET_OF(ClassHeapStats, recent) + |
| 71 OFFSET_OF(AllocStats<intptr_t>, new_count); |
| 43 } | 72 } |
| 44 static intptr_t allocated_since_gc_old_space_offset() { | 73 static intptr_t allocated_since_gc_old_space_offset() { |
| 45 return OFFSET_OF(ClassHeapStats, allocated_since_gc_old_space); | 74 return OFFSET_OF(ClassHeapStats, recent) + |
| 75 OFFSET_OF(AllocStats<intptr_t>, old_count); |
| 46 } | 76 } |
| 47 static intptr_t allocated_size_since_gc_new_space_offset() { | 77 static intptr_t allocated_size_since_gc_new_space_offset() { |
| 48 return OFFSET_OF(ClassHeapStats, allocated_size_since_gc_new_space); | 78 return OFFSET_OF(ClassHeapStats, recent) + |
| 79 OFFSET_OF(AllocStats<intptr_t>, new_size); |
| 49 } | 80 } |
| 50 static intptr_t allocated_size_since_gc_old_space_offset() { | 81 static intptr_t allocated_size_since_gc_old_space_offset() { |
| 51 return OFFSET_OF(ClassHeapStats, allocated_size_since_gc_old_space); | 82 return OFFSET_OF(ClassHeapStats, recent) + |
| 83 OFFSET_OF(AllocStats<intptr_t>, old_size); |
| 52 } | 84 } |
| 53 | 85 |
| 54 void Initialize(); | 86 void Initialize(); |
| 55 void ResetAtNewGC(); | 87 void ResetAtNewGC(); |
| 56 void ResetAtOldGC(); | 88 void ResetAtOldGC(); |
| 89 void ResetAccumulator(); |
| 57 void UpdateSize(intptr_t instance_size); | 90 void UpdateSize(intptr_t instance_size); |
| 58 void PrintTOJSONArray(const Class& cls, JSONArray* array); | 91 void PrintTOJSONArray(const Class& cls, JSONArray* array); |
| 59 }; | 92 }; |
| 60 | 93 |
| 61 | 94 |
| 62 class ClassTable { | 95 class ClassTable { |
| 63 public: | 96 public: |
| 64 ClassTable(); | 97 ClassTable(); |
| 65 ~ClassTable(); | 98 ~ClassTable(); |
| 66 | 99 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 return reinterpret_cast<uword>(predefined_class_heap_stats_table_); | 139 return reinterpret_cast<uword>(predefined_class_heap_stats_table_); |
| 107 } | 140 } |
| 108 | 141 |
| 109 // Used by generated code. | 142 // Used by generated code. |
| 110 uword ClassStatsTableAddress() { | 143 uword ClassStatsTableAddress() { |
| 111 return reinterpret_cast<uword>(&class_heap_stats_table_); | 144 return reinterpret_cast<uword>(&class_heap_stats_table_); |
| 112 } | 145 } |
| 113 | 146 |
| 114 | 147 |
| 115 void AllocationProfilePrintToJSONStream(JSONStream* stream); | 148 void AllocationProfilePrintToJSONStream(JSONStream* stream); |
| 149 void ResetAllocationAccumulators(); |
| 116 | 150 |
| 117 private: | 151 private: |
| 118 friend class MarkingVisitor; | 152 friend class MarkingVisitor; |
| 119 friend class ScavengerVisitor; | 153 friend class ScavengerVisitor; |
| 120 friend class ClassHeapStatsTestHelper; | 154 friend class ClassHeapStatsTestHelper; |
| 121 static const int initial_capacity_ = 512; | 155 static const int initial_capacity_ = 512; |
| 122 static const int capacity_increment_ = 256; | 156 static const int capacity_increment_ = 256; |
| 123 | 157 |
| 124 static bool ShouldUpdateSizeForClassId(intptr_t cid); | 158 static bool ShouldUpdateSizeForClassId(intptr_t cid); |
| 125 | 159 |
| 126 intptr_t top_; | 160 intptr_t top_; |
| 127 intptr_t capacity_; | 161 intptr_t capacity_; |
| 128 | 162 |
| 129 RawClass** table_; | 163 RawClass** table_; |
| 130 ClassHeapStats* class_heap_stats_table_; | 164 ClassHeapStats* class_heap_stats_table_; |
| 131 | 165 |
| 132 ClassHeapStats* predefined_class_heap_stats_table_; | 166 ClassHeapStats* predefined_class_heap_stats_table_; |
| 133 | 167 |
| 134 ClassHeapStats* StatsAt(intptr_t cid); | 168 ClassHeapStats* StatsAt(intptr_t cid); |
| 135 void UpdateLiveOld(intptr_t cid, intptr_t size); | 169 void UpdateLiveOld(intptr_t cid, intptr_t size); |
| 136 void UpdateLiveNew(intptr_t cid, intptr_t size); | 170 void UpdateLiveNew(intptr_t cid, intptr_t size); |
| 137 | 171 |
| 138 DISALLOW_COPY_AND_ASSIGN(ClassTable); | 172 DISALLOW_COPY_AND_ASSIGN(ClassTable); |
| 139 }; | 173 }; |
| 140 | 174 |
| 141 } // namespace dart | 175 } // namespace dart |
| 142 | 176 |
| 143 #endif // VM_CLASS_TABLE_H_ | 177 #endif // VM_CLASS_TABLE_H_ |
| OLD | NEW |