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 RUNTIME_VM_CLASS_TABLE_H_ | 5 #ifndef RUNTIME_VM_CLASS_TABLE_H_ |
6 #define RUNTIME_VM_CLASS_TABLE_H_ | 6 #define RUNTIME_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> |
| 20 class MallocGrowableArray; |
20 class ObjectPointerVisitor; | 21 class ObjectPointerVisitor; |
21 class RawClass; | 22 class RawClass; |
22 | 23 |
23 #ifndef PRODUCT | 24 #ifndef PRODUCT |
24 template<typename T> | 25 template <typename T> |
25 class AllocStats { | 26 class AllocStats { |
26 public: | 27 public: |
27 T new_count; | 28 T new_count; |
28 T new_size; | 29 T new_size; |
29 T old_count; | 30 T old_count; |
30 T old_size; | 31 T old_size; |
31 | 32 |
32 void ResetNew() { | 33 void ResetNew() { |
33 new_count = 0; | 34 new_count = 0; |
34 new_size = 0; | 35 new_size = 0; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 OFFSET_OF(AllocStats<intptr_t>, old_count); | 98 OFFSET_OF(AllocStats<intptr_t>, old_count); |
98 } | 99 } |
99 static intptr_t allocated_size_since_gc_new_space_offset() { | 100 static intptr_t allocated_size_since_gc_new_space_offset() { |
100 return OFFSET_OF(ClassHeapStats, recent) + | 101 return OFFSET_OF(ClassHeapStats, recent) + |
101 OFFSET_OF(AllocStats<intptr_t>, new_size); | 102 OFFSET_OF(AllocStats<intptr_t>, new_size); |
102 } | 103 } |
103 static intptr_t allocated_size_since_gc_old_space_offset() { | 104 static intptr_t allocated_size_since_gc_old_space_offset() { |
104 return OFFSET_OF(ClassHeapStats, recent) + | 105 return OFFSET_OF(ClassHeapStats, recent) + |
105 OFFSET_OF(AllocStats<intptr_t>, old_size); | 106 OFFSET_OF(AllocStats<intptr_t>, old_size); |
106 } | 107 } |
107 static intptr_t state_offset() { | 108 static intptr_t state_offset() { return OFFSET_OF(ClassHeapStats, state_); } |
108 return OFFSET_OF(ClassHeapStats, state_); | 109 static intptr_t TraceAllocationMask() { return (1 << kTraceAllocationBit); } |
109 } | |
110 static intptr_t TraceAllocationMask() { | |
111 return (1 << kTraceAllocationBit); | |
112 } | |
113 | 110 |
114 void Initialize(); | 111 void Initialize(); |
115 void ResetAtNewGC(); | 112 void ResetAtNewGC(); |
116 void ResetAtOldGC(); | 113 void ResetAtOldGC(); |
117 void ResetAccumulator(); | 114 void ResetAccumulator(); |
118 void UpdatePromotedAfterNewGC(); | 115 void UpdatePromotedAfterNewGC(); |
119 void UpdateSize(intptr_t instance_size); | 116 void UpdateSize(intptr_t instance_size); |
120 #ifndef PRODUCT | 117 #ifndef PRODUCT |
121 void PrintToJSONObject(const Class& cls, JSONObject* obj) const; | 118 void PrintToJSONObject(const Class& cls, JSONObject* obj) const; |
122 #endif | 119 #endif |
123 void Verify(); | 120 void Verify(); |
124 | 121 |
125 bool trace_allocation() const { | 122 bool trace_allocation() const { return TraceAllocationBit::decode(state_); } |
126 return TraceAllocationBit::decode(state_); | |
127 } | |
128 | 123 |
129 void set_trace_allocation(bool trace_allocation) { | 124 void set_trace_allocation(bool trace_allocation) { |
130 state_ = TraceAllocationBit::update(trace_allocation, state_); | 125 state_ = TraceAllocationBit::update(trace_allocation, state_); |
131 } | 126 } |
132 | 127 |
133 private: | 128 private: |
134 enum StateBits { | 129 enum StateBits { |
135 kTraceAllocationBit = 0, | 130 kTraceAllocationBit = 0, |
136 }; | 131 }; |
137 | 132 |
138 class TraceAllocationBit : | 133 class TraceAllocationBit |
139 public BitField<intptr_t, bool, kTraceAllocationBit, 1> {}; | 134 : public BitField<intptr_t, bool, kTraceAllocationBit, 1> {}; |
140 | 135 |
141 // Recent old at start of last new GC (used to compute promoted_*). | 136 // Recent old at start of last new GC (used to compute promoted_*). |
142 intptr_t old_pre_new_gc_count_; | 137 intptr_t old_pre_new_gc_count_; |
143 intptr_t old_pre_new_gc_size_; | 138 intptr_t old_pre_new_gc_size_; |
144 intptr_t state_; | 139 intptr_t state_; |
145 intptr_t align_; // Make SIMARM and ARM agree on the size of ClassHeapStats. | 140 intptr_t align_; // Make SIMARM and ARM agree on the size of ClassHeapStats. |
146 }; | 141 }; |
147 #endif // !PRODUCT | 142 #endif // !PRODUCT |
148 | 143 |
149 class ClassTable { | 144 class ClassTable { |
150 public: | 145 public: |
151 ClassTable(); | 146 ClassTable(); |
152 // Creates a shallow copy of the original class table for some read-only | 147 // Creates a shallow copy of the original class table for some read-only |
153 // access, without support for stats data. | 148 // access, without support for stats data. |
154 explicit ClassTable(ClassTable* original); | 149 explicit ClassTable(ClassTable* original); |
155 ~ClassTable(); | 150 ~ClassTable(); |
156 | 151 |
157 // Thread-safe. | 152 // Thread-safe. |
158 RawClass* At(intptr_t index) const { | 153 RawClass* At(intptr_t index) const { |
159 ASSERT(IsValidIndex(index)); | 154 ASSERT(IsValidIndex(index)); |
160 return table_[index]; | 155 return table_[index]; |
161 } | 156 } |
162 | 157 |
163 void SetAt(intptr_t index, RawClass* raw_cls) { | 158 void SetAt(intptr_t index, RawClass* raw_cls) { table_[index] = raw_cls; } |
164 table_[index] = raw_cls; | |
165 } | |
166 | 159 |
167 bool IsValidIndex(intptr_t index) const { | 160 bool IsValidIndex(intptr_t index) const { |
168 return (index > 0) && (index < top_); | 161 return (index > 0) && (index < top_); |
169 } | 162 } |
170 | 163 |
171 bool HasValidClassAt(intptr_t index) const { | 164 bool HasValidClassAt(intptr_t index) const { |
172 ASSERT(IsValidIndex(index)); | 165 ASSERT(IsValidIndex(index)); |
173 return table_[index] != NULL; | 166 return table_[index] != NULL; |
174 } | 167 } |
175 | 168 |
(...skipping 19 matching lines...) Expand all Loading... |
195 void Remap(intptr_t* old_to_new_cids); | 188 void Remap(intptr_t* old_to_new_cids); |
196 #endif | 189 #endif |
197 | 190 |
198 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 191 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
199 | 192 |
200 void Validate(); | 193 void Validate(); |
201 | 194 |
202 void Print(); | 195 void Print(); |
203 | 196 |
204 // Used by the generated code. | 197 // Used by the generated code. |
205 static intptr_t table_offset() { | 198 static intptr_t table_offset() { return OFFSET_OF(ClassTable, table_); } |
206 return OFFSET_OF(ClassTable, table_); | |
207 } | |
208 | 199 |
209 // Used by the generated code. | 200 // Used by the generated code. |
210 static intptr_t ClassOffsetFor(intptr_t cid); | 201 static intptr_t ClassOffsetFor(intptr_t cid); |
211 | 202 |
212 #ifndef PRODUCT | 203 #ifndef PRODUCT |
213 // Called whenever a class is allocated in the runtime. | 204 // Called whenever a class is allocated in the runtime. |
214 void UpdateAllocatedNew(intptr_t cid, intptr_t size); | 205 void UpdateAllocatedNew(intptr_t cid, intptr_t size); |
215 void UpdateAllocatedOld(intptr_t cid, intptr_t size); | 206 void UpdateAllocatedOld(intptr_t cid, intptr_t size); |
216 | 207 |
217 // Called whenever a old GC occurs. | 208 // Called whenever a old GC occurs. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 void UpdateLiveOld(intptr_t cid, intptr_t size, intptr_t count = 1); | 265 void UpdateLiveOld(intptr_t cid, intptr_t size, intptr_t count = 1); |
275 void UpdateLiveNew(intptr_t cid, intptr_t size); | 266 void UpdateLiveNew(intptr_t cid, intptr_t size); |
276 #endif // !PRODUCT | 267 #endif // !PRODUCT |
277 | 268 |
278 DISALLOW_COPY_AND_ASSIGN(ClassTable); | 269 DISALLOW_COPY_AND_ASSIGN(ClassTable); |
279 }; | 270 }; |
280 | 271 |
281 } // namespace dart | 272 } // namespace dart |
282 | 273 |
283 #endif // RUNTIME_VM_CLASS_TABLE_H_ | 274 #endif // RUNTIME_VM_CLASS_TABLE_H_ |
OLD | NEW |