Chromium Code Reviews| 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 ObjectPointerVisitor; | 15 class ObjectPointerVisitor; |
| 15 class RawClass; | 16 class RawClass; |
| 16 class JSONStream; | 17 class JSONStream; |
| 17 | 18 |
| 19 class ClassHeapStats { | |
| 20 public: | |
| 21 intptr_t live_count_old_space; | |
| 22 intptr_t live_count_new_space; | |
| 23 intptr_t live_size_old_space; | |
| 24 intptr_t live_size_new_space; | |
| 25 | |
| 26 // These fields are updated by generated code: | |
| 27 intptr_t new_count_since_gc_new_space; | |
| 28 intptr_t new_count_since_gc_old_space; | |
| 29 intptr_t new_size_since_gc_new_space; | |
| 30 intptr_t new_size_since_gc_old_space; | |
| 31 | |
| 32 static intptr_t new_count_since_gc_new_space_offset() { | |
| 33 return OFFSET_OF(ClassHeapStats, new_count_since_gc_new_space); | |
| 34 } | |
| 35 static intptr_t new_count_since_gc_old_space_offset() { | |
| 36 return OFFSET_OF(ClassHeapStats, new_count_since_gc_old_space); | |
| 37 } | |
| 38 static intptr_t new_size_since_gc_new_space_offset() { | |
| 39 return OFFSET_OF(ClassHeapStats, new_size_since_gc_new_space); | |
| 40 } | |
| 41 static intptr_t new_size_since_gc_old_space_offset() { | |
| 42 return OFFSET_OF(ClassHeapStats, new_size_since_gc_old_space); | |
| 43 } | |
| 44 | |
| 45 void Initialize(); | |
| 46 void ResetAtGC(); | |
| 47 }; | |
| 48 | |
| 49 | |
| 18 class ClassTable { | 50 class ClassTable { |
| 19 public: | 51 public: |
| 20 ClassTable(); | 52 ClassTable(); |
| 21 ~ClassTable(); | 53 ~ClassTable(); |
| 22 | 54 |
| 23 RawClass* At(intptr_t index) const { | 55 RawClass* At(intptr_t index) const { |
| 24 ASSERT(IsValidIndex(index)); | 56 ASSERT(IsValidIndex(index)); |
| 25 return table_[index]; | 57 return table_[index]; |
| 26 } | 58 } |
| 27 | 59 |
| 28 intptr_t IsValidIndex(intptr_t index) const { | 60 intptr_t IsValidIndex(intptr_t index) const { |
| 29 return (index > 0) && (index < top_); | 61 return (index > 0) && (index < top_); |
| 30 } | 62 } |
| 31 | 63 |
| 32 bool HasValidClassAt(intptr_t index) const { | 64 bool HasValidClassAt(intptr_t index) const { |
| 33 ASSERT(IsValidIndex(index)); | 65 ASSERT(IsValidIndex(index)); |
| 34 return table_[index] != NULL; | 66 return table_[index] != NULL; |
| 35 } | 67 } |
| 36 | 68 |
| 37 intptr_t NumCids() const { return top_; } | 69 intptr_t NumCids() const { return top_; } |
| 38 | 70 |
| 39 void Register(const Class& cls); | 71 void Register(const Class& cls); |
| 40 | 72 |
| 41 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 73 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 42 | 74 |
| 43 void Print(); | 75 void Print(); |
| 44 | 76 |
| 45 void PrintToJSONStream(JSONStream* stream); | 77 void PrintToJSONStream(JSONStream* stream); |
| 46 | 78 |
| 47 static intptr_t table_offset() { | 79 static intptr_t table_offset() { |
|
Ivan Posva
2013/12/12 13:53:24
Why are we using the offset of the field here and
Cutch
2013/12/13 01:31:09
This function table_offset() is used by the assemb
| |
| 48 return OFFSET_OF(ClassTable, table_); | 80 return OFFSET_OF(ClassTable, table_); |
| 49 } | 81 } |
| 50 | 82 |
| 83 // Called whenever a class is allocated in the runtime. | |
| 84 void ReportAllocationNewSpace(intptr_t cid, intptr_t size); | |
| 85 void ReportAllocationOldSpace(intptr_t cid, intptr_t size); | |
| 86 | |
| 87 // Called whenever a major GC occurs. | |
| 88 void Collect(); | |
| 89 | |
| 90 // Used by the generated code. | |
| 91 uword PredefinedClassHeapStatsTableAddress() { | |
| 92 return reinterpret_cast<uword>(predefined_class_heap_stats_table_); | |
| 93 } | |
| 94 | |
| 95 // Used by generated code. | |
| 96 uword ClassStatsTableAddress() { | |
| 97 return reinterpret_cast<uword>(&class_heap_stats_table_); | |
| 98 } | |
| 99 | |
| 51 private: | 100 private: |
| 101 friend class MarkingVisitor; | |
| 52 static const int initial_capacity_ = 512; | 102 static const int initial_capacity_ = 512; |
| 53 static const int capacity_increment_ = 256; | 103 static const int capacity_increment_ = 256; |
| 54 | 104 |
| 105 static bool CollectInstanceSizesForClass(intptr_t cid); | |
| 106 | |
| 55 intptr_t top_; | 107 intptr_t top_; |
| 56 intptr_t capacity_; | 108 intptr_t capacity_; |
| 57 | 109 |
| 58 RawClass** table_; | 110 RawClass** table_; |
| 111 ClassHeapStats* class_heap_stats_table_; | |
| 112 | |
| 113 ClassHeapStats* predefined_class_heap_stats_table_; | |
| 114 | |
| 115 ClassHeapStats* FindClassHeapStats(intptr_t cid); | |
| 116 void ResetCounters(); | |
| 117 void ReportLiveOldSpace(intptr_t cid, intptr_t size); | |
| 118 void ReportLiveNewSpace(intptr_t cid, intptr_t size); | |
| 59 | 119 |
| 60 DISALLOW_COPY_AND_ASSIGN(ClassTable); | 120 DISALLOW_COPY_AND_ASSIGN(ClassTable); |
| 61 }; | 121 }; |
| 62 | 122 |
| 63 } // namespace dart | 123 } // namespace dart |
| 64 | 124 |
| 65 #endif // VM_CLASS_TABLE_H_ | 125 #endif // VM_CLASS_TABLE_H_ |
| OLD | NEW |