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_HEAP_H_ | 5 #ifndef VM_HEAP_H_ |
6 #define VM_HEAP_H_ | 6 #define VM_HEAP_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
11 #include "vm/globals.h" | 11 #include "vm/globals.h" |
12 #include "vm/pages.h" | 12 #include "vm/pages.h" |
13 #include "vm/scavenger.h" | 13 #include "vm/scavenger.h" |
| 14 #include "vm/weak_table.h" |
14 | 15 |
15 namespace dart { | 16 namespace dart { |
16 | 17 |
17 // Forward declarations. | 18 // Forward declarations. |
18 class Isolate; | 19 class Isolate; |
19 class ObjectPointerVisitor; | 20 class ObjectPointerVisitor; |
20 class ObjectSet; | 21 class ObjectSet; |
21 class VirtualMemory; | 22 class VirtualMemory; |
22 | 23 |
23 DECLARE_FLAG(bool, verbose_gc); | 24 DECLARE_FLAG(bool, verbose_gc); |
24 DECLARE_FLAG(bool, verify_before_gc); | 25 DECLARE_FLAG(bool, verify_before_gc); |
25 DECLARE_FLAG(bool, verify_after_gc); | 26 DECLARE_FLAG(bool, verify_after_gc); |
26 DECLARE_FLAG(bool, gc_at_alloc); | 27 DECLARE_FLAG(bool, gc_at_alloc); |
27 | 28 |
28 class Heap { | 29 class Heap { |
29 public: | 30 public: |
30 enum Space { | 31 enum Space { |
31 kNew, | 32 kNew, |
32 kOld, | 33 kOld, |
33 kCode, | 34 kCode, |
34 }; | 35 }; |
35 | 36 |
| 37 enum WeakSelector { |
| 38 kPeers = 0, |
| 39 kHashes, |
| 40 kNumWeakSelectors |
| 41 }; |
| 42 |
36 enum ApiCallbacks { | 43 enum ApiCallbacks { |
37 kIgnoreApiCallbacks, | 44 kIgnoreApiCallbacks, |
38 kInvokeApiCallbacks | 45 kInvokeApiCallbacks |
39 }; | 46 }; |
40 | 47 |
41 enum GCReason { | 48 enum GCReason { |
42 kNewSpace, | 49 kNewSpace, |
43 kPromotionFailure, | 50 kPromotionFailure, |
44 kOldSpace, | 51 kOldSpace, |
45 kFull, | 52 kFull, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 void StartEndAddress(uword* start, uword* end) const; | 168 void StartEndAddress(uword* start, uword* end) const; |
162 | 169 |
163 ObjectSet* CreateAllocatedObjectSet() const; | 170 ObjectSet* CreateAllocatedObjectSet() const; |
164 | 171 |
165 // Generates a profile of the current and VM isolate heaps. | 172 // Generates a profile of the current and VM isolate heaps. |
166 void Profile(Dart_FileWriteCallback callback, void* stream) const; | 173 void Profile(Dart_FileWriteCallback callback, void* stream) const; |
167 void ProfileToFile(const char* reason) const; | 174 void ProfileToFile(const char* reason) const; |
168 | 175 |
169 static const char* GCReasonToString(GCReason gc_reason); | 176 static const char* GCReasonToString(GCReason gc_reason); |
170 | 177 |
171 // Associates a peer with an object. If an object has a peer, it is | 178 // Associate a peer with an object. A non-existent peer is equal to NULL. |
172 // replaced. A value of NULL disassociate an object from its peer. | 179 void SetPeer(RawObject* raw_obj, void* peer) { |
173 void SetPeer(RawObject* raw_obj, void* peer); | 180 SetWeakEntry(raw_obj, kPeers, reinterpret_cast<intptr_t>(peer)); |
| 181 } |
| 182 void* GetPeer(RawObject* raw_obj) const { |
| 183 return reinterpret_cast<void*>(GetWeakEntry(raw_obj, kPeers)); |
| 184 } |
| 185 int64_t PeerCount() const; |
174 | 186 |
175 // Retrieves the peer associated with an object. Returns NULL if | 187 // Associate an identity hashCode with an object. An non-existent hashCode |
176 // there is no association. | 188 // is equal to 0. |
177 void* GetPeer(RawObject* raw_obj); | 189 void SetHash(RawObject* raw_obj, intptr_t hash) { |
| 190 SetWeakEntry(raw_obj, kHashes, hash); |
| 191 } |
| 192 intptr_t GetHash(RawObject* raw_obj) const { |
| 193 return GetWeakEntry(raw_obj, kHashes); |
| 194 } |
| 195 int64_t HashCount() const; |
178 | 196 |
179 // Returns the number of objects with a peer. | 197 // Used by the GC algorithms to propagate weak entries. |
180 int64_t PeerCount() const; | 198 intptr_t GetWeakEntry(RawObject* raw_obj, WeakSelector sel) const; |
| 199 void SetWeakEntry(RawObject* raw_obj, WeakSelector sel, intptr_t val); |
| 200 |
| 201 WeakTable* GetWeakTable(Space space, WeakSelector selector) const { |
| 202 if (space == kNew) { |
| 203 return new_weak_tables_[selector]; |
| 204 } |
| 205 ASSERT(space ==kOld); |
| 206 return old_weak_tables_[selector]; |
| 207 } |
| 208 void SetWeakTable(Space space, WeakSelector selector, WeakTable* value) { |
| 209 if (space == kNew) { |
| 210 new_weak_tables_[selector] = value; |
| 211 } else { |
| 212 ASSERT(space == kOld); |
| 213 old_weak_tables_[selector] = value; |
| 214 } |
| 215 } |
181 | 216 |
182 // Stats collection. | 217 // Stats collection. |
183 void RecordTime(int id, int64_t micros) { | 218 void RecordTime(int id, int64_t micros) { |
184 ASSERT((id >= 0) && (id < GCStats::kDataEntries)); | 219 ASSERT((id >= 0) && (id < GCStats::kDataEntries)); |
185 stats_.times_[id] = micros; | 220 stats_.times_[id] = micros; |
186 } | 221 } |
187 | 222 |
188 void RecordData(int id, intptr_t value) { | 223 void RecordData(int id, intptr_t value) { |
189 ASSERT((id >= 0) && (id < GCStats::kDataEntries)); | 224 ASSERT((id >= 0) && (id < GCStats::kDataEntries)); |
190 stats_.data_[id] = value; | 225 stats_.data_[id] = value; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // GC stats collection. | 274 // GC stats collection. |
240 void RecordBeforeGC(Space space, GCReason reason); | 275 void RecordBeforeGC(Space space, GCReason reason); |
241 void RecordAfterGC(); | 276 void RecordAfterGC(); |
242 void PrintStats(); | 277 void PrintStats(); |
243 void UpdateObjectHistogram(); | 278 void UpdateObjectHistogram(); |
244 | 279 |
245 // The different spaces used for allocation. | 280 // The different spaces used for allocation. |
246 Scavenger* new_space_; | 281 Scavenger* new_space_; |
247 PageSpace* old_space_; | 282 PageSpace* old_space_; |
248 | 283 |
| 284 WeakTable* new_weak_tables_[kNumWeakSelectors]; |
| 285 WeakTable* old_weak_tables_[kNumWeakSelectors]; |
| 286 |
249 // GC stats collection. | 287 // GC stats collection. |
250 GCStats stats_; | 288 GCStats stats_; |
251 | 289 |
252 // This heap is in read-only mode: No allocation is allowed. | 290 // This heap is in read-only mode: No allocation is allowed. |
253 bool read_only_; | 291 bool read_only_; |
254 | 292 |
255 // GC on the heap is in progress. | 293 // GC on the heap is in progress. |
256 bool gc_in_progress_; | 294 bool gc_in_progress_; |
257 | 295 |
258 friend class GCTestHelper; | 296 friend class GCTestHelper; |
(...skipping 24 matching lines...) Expand all Loading... |
283 NoHeapGrowthControlScope(); | 321 NoHeapGrowthControlScope(); |
284 ~NoHeapGrowthControlScope(); | 322 ~NoHeapGrowthControlScope(); |
285 private: | 323 private: |
286 bool current_growth_controller_state_; | 324 bool current_growth_controller_state_; |
287 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope); | 325 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope); |
288 }; | 326 }; |
289 | 327 |
290 } // namespace dart | 328 } // namespace dart |
291 | 329 |
292 #endif // VM_HEAP_H_ | 330 #endif // VM_HEAP_H_ |
OLD | NEW |