| 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/bitfield.h" | 9 #include "vm/bitfield.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 class Class; | 14 class Class; |
| 15 class ClassStats; | 15 class ClassStats; |
| 16 class JSONArray; | 16 class JSONArray; |
| 17 class JSONObject; | 17 class JSONObject; |
| 18 class JSONStream; | 18 class JSONStream; |
| 19 template<typename T> class MallocGrowableArray; | 19 template<typename T> class MallocGrowableArray; |
| 20 class ObjectPointerVisitor; | 20 class ObjectPointerVisitor; |
| 21 class RawClass; | 21 class RawClass; |
| 22 | 22 |
| 23 #ifndef PRODUCT |
| 23 template<typename T> | 24 template<typename T> |
| 24 class AllocStats { | 25 class AllocStats { |
| 25 public: | 26 public: |
| 26 T new_count; | 27 T new_count; |
| 27 T new_size; | 28 T new_size; |
| 28 T old_count; | 29 T old_count; |
| 29 T old_size; | 30 T old_size; |
| 30 | 31 |
| 31 void ResetNew() { | 32 void ResetNew() { |
| 32 new_count = 0; | 33 new_count = 0; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 }; | 136 }; |
| 136 | 137 |
| 137 class TraceAllocationBit : | 138 class TraceAllocationBit : |
| 138 public BitField<intptr_t, bool, kTraceAllocationBit, 1> {}; | 139 public BitField<intptr_t, bool, kTraceAllocationBit, 1> {}; |
| 139 | 140 |
| 140 // Recent old at start of last new GC (used to compute promoted_*). | 141 // Recent old at start of last new GC (used to compute promoted_*). |
| 141 intptr_t old_pre_new_gc_count_; | 142 intptr_t old_pre_new_gc_count_; |
| 142 intptr_t old_pre_new_gc_size_; | 143 intptr_t old_pre_new_gc_size_; |
| 143 intptr_t state_; | 144 intptr_t state_; |
| 144 }; | 145 }; |
| 145 | 146 #endif // !PRODUCT |
| 146 | 147 |
| 147 class ClassTable { | 148 class ClassTable { |
| 148 public: | 149 public: |
| 149 ClassTable(); | 150 ClassTable(); |
| 150 // Creates a shallow copy of the original class table for some read-only | 151 // Creates a shallow copy of the original class table for some read-only |
| 151 // access, without support for stats data. | 152 // access, without support for stats data. |
| 152 explicit ClassTable(ClassTable* original); | 153 explicit ClassTable(ClassTable* original); |
| 153 ~ClassTable(); | 154 ~ClassTable(); |
| 154 | 155 |
| 155 // Thread-safe. | 156 // Thread-safe. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 188 |
| 188 #if defined(DEBUG) | 189 #if defined(DEBUG) |
| 189 void Unregister(intptr_t index); | 190 void Unregister(intptr_t index); |
| 190 #endif | 191 #endif |
| 191 | 192 |
| 192 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 193 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 193 | 194 |
| 194 void Validate(); | 195 void Validate(); |
| 195 | 196 |
| 196 void Print(); | 197 void Print(); |
| 197 #ifndef PRODUCT | |
| 198 void PrintToJSONObject(JSONObject* object); | |
| 199 #endif | |
| 200 | 198 |
| 201 // Used by the generated code. | 199 // Used by the generated code. |
| 202 static intptr_t table_offset() { | 200 static intptr_t table_offset() { |
| 203 return OFFSET_OF(ClassTable, table_); | 201 return OFFSET_OF(ClassTable, table_); |
| 204 } | 202 } |
| 205 | 203 |
| 204 // Used by the generated code. |
| 205 static intptr_t ClassOffsetFor(intptr_t cid); |
| 206 |
| 207 #ifndef PRODUCT |
| 206 // Called whenever a class is allocated in the runtime. | 208 // Called whenever a class is allocated in the runtime. |
| 207 void UpdateAllocatedNew(intptr_t cid, intptr_t size); | 209 void UpdateAllocatedNew(intptr_t cid, intptr_t size); |
| 208 void UpdateAllocatedOld(intptr_t cid, intptr_t size); | 210 void UpdateAllocatedOld(intptr_t cid, intptr_t size); |
| 209 | 211 |
| 210 // Called whenever a old GC occurs. | 212 // Called whenever a old GC occurs. |
| 211 void ResetCountersOld(); | 213 void ResetCountersOld(); |
| 212 // Called whenever a new GC occurs. | 214 // Called whenever a new GC occurs. |
| 213 void ResetCountersNew(); | 215 void ResetCountersNew(); |
| 214 // Called immediately after a new GC. | 216 // Called immediately after a new GC. |
| 215 void UpdatePromoted(); | 217 void UpdatePromoted(); |
| 216 | 218 |
| 217 // Used by the generated code. | 219 // Used by the generated code. |
| 218 static intptr_t ClassOffsetFor(intptr_t cid); | |
| 219 | |
| 220 // Used by the generated code. | |
| 221 ClassHeapStats** TableAddressFor(intptr_t cid); | 220 ClassHeapStats** TableAddressFor(intptr_t cid); |
| 222 static intptr_t TableOffsetFor(intptr_t cid); | 221 static intptr_t TableOffsetFor(intptr_t cid); |
| 223 | 222 |
| 224 // Used by the generated code. | 223 // Used by the generated code. |
| 225 static intptr_t CounterOffsetFor(intptr_t cid, bool is_new_space); | 224 static intptr_t CounterOffsetFor(intptr_t cid, bool is_new_space); |
| 226 | 225 |
| 227 // Used by the generated code. | 226 // Used by the generated code. |
| 228 static intptr_t StateOffsetFor(intptr_t cid); | 227 static intptr_t StateOffsetFor(intptr_t cid); |
| 229 | 228 |
| 230 // Used by the generated code. | 229 // Used by the generated code. |
| 231 static intptr_t SizeOffsetFor(intptr_t cid, bool is_new_space); | 230 static intptr_t SizeOffsetFor(intptr_t cid, bool is_new_space); |
| 232 | 231 |
| 233 ClassHeapStats* StatsWithUpdatedSize(intptr_t cid); | 232 ClassHeapStats* StatsWithUpdatedSize(intptr_t cid); |
| 234 | 233 |
| 235 void AllocationProfilePrintJSON(JSONStream* stream); | 234 void AllocationProfilePrintJSON(JSONStream* stream); |
| 236 void ResetAllocationAccumulators(); | 235 void ResetAllocationAccumulators(); |
| 237 | 236 |
| 237 void PrintToJSONObject(JSONObject* object); |
| 238 #endif // !PRODUCT |
| 239 |
| 238 // Deallocates table copies. Do not call during concurrent access to table. | 240 // Deallocates table copies. Do not call during concurrent access to table. |
| 239 void FreeOldTables(); | 241 void FreeOldTables(); |
| 240 | 242 |
| 241 void SetTraceAllocationFor(intptr_t cid, bool trace); | 243 void SetTraceAllocationFor(intptr_t cid, bool trace); |
| 242 bool TraceAllocationFor(intptr_t cid); | 244 bool TraceAllocationFor(intptr_t cid); |
| 243 | 245 |
| 244 private: | 246 private: |
| 245 friend class GCMarker; | 247 friend class GCMarker; |
| 246 friend class ScavengerVisitor; | 248 friend class ScavengerVisitor; |
| 247 friend class ClassHeapStatsTestHelper; | 249 friend class ClassHeapStatsTestHelper; |
| 248 static const int initial_capacity_ = 512; | 250 static const int initial_capacity_ = 512; |
| 249 static const int capacity_increment_ = 256; | 251 static const int capacity_increment_ = 256; |
| 250 | 252 |
| 251 static bool ShouldUpdateSizeForClassId(intptr_t cid); | 253 static bool ShouldUpdateSizeForClassId(intptr_t cid); |
| 252 | 254 |
| 253 intptr_t top_; | 255 intptr_t top_; |
| 254 intptr_t capacity_; | 256 intptr_t capacity_; |
| 255 | 257 |
| 256 // Copy-on-write is used for table_, with old copies stored in old_tables_. | 258 // Copy-on-write is used for table_, with old copies stored in old_tables_. |
| 257 RawClass** table_; | 259 RawClass** table_; |
| 258 MallocGrowableArray<RawClass**>* old_tables_; | 260 MallocGrowableArray<RawClass**>* old_tables_; |
| 259 | 261 |
| 262 #ifndef PRODUCT |
| 260 ClassHeapStats* class_heap_stats_table_; | 263 ClassHeapStats* class_heap_stats_table_; |
| 261 | |
| 262 ClassHeapStats* predefined_class_heap_stats_table_; | 264 ClassHeapStats* predefined_class_heap_stats_table_; |
| 263 | 265 |
| 264 // May not have updated size for variable size classes. | 266 // May not have updated size for variable size classes. |
| 265 ClassHeapStats* PreliminaryStatsAt(intptr_t cid); | 267 ClassHeapStats* PreliminaryStatsAt(intptr_t cid); |
| 266 void UpdateLiveOld(intptr_t cid, intptr_t size, intptr_t count = 1); | 268 void UpdateLiveOld(intptr_t cid, intptr_t size, intptr_t count = 1); |
| 267 void UpdateLiveNew(intptr_t cid, intptr_t size); | 269 void UpdateLiveNew(intptr_t cid, intptr_t size); |
| 270 #endif // !PRODUCT |
| 268 | 271 |
| 269 DISALLOW_COPY_AND_ASSIGN(ClassTable); | 272 DISALLOW_COPY_AND_ASSIGN(ClassTable); |
| 270 }; | 273 }; |
| 271 | 274 |
| 272 } // namespace dart | 275 } // namespace dart |
| 273 | 276 |
| 274 #endif // VM_CLASS_TABLE_H_ | 277 #endif // VM_CLASS_TABLE_H_ |
| OLD | NEW |