| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 #if defined(DEBUG) | 62 #if defined(DEBUG) |
| 63 // Pattern for unused new space and swept old space. | 63 // Pattern for unused new space and swept old space. |
| 64 static const uint64_t kZap64Bits = 0xf3f3f3f3f3f3f3f3; | 64 static const uint64_t kZap64Bits = 0xf3f3f3f3f3f3f3f3; |
| 65 static const uint32_t kZap32Bits = 0xf3f3f3f3; | 65 static const uint32_t kZap32Bits = 0xf3f3f3f3; |
| 66 static const uint8_t kZapByte = 0xf3; | 66 static const uint8_t kZapByte = 0xf3; |
| 67 #endif // DEBUG | 67 #endif // DEBUG |
| 68 | 68 |
| 69 ~Heap(); | 69 ~Heap(); |
| 70 | 70 |
| 71 Scavenger* new_space() const { return new_space_; } | 71 Scavenger* new_space() { return &new_space_; } |
| 72 PageSpace* old_space() const { return old_space_; } | 72 PageSpace* old_space() { return &old_space_; } |
| 73 | 73 |
| 74 uword Allocate(intptr_t size, Space space) { | 74 uword Allocate(intptr_t size, Space space) { |
| 75 ASSERT(!read_only_); | 75 ASSERT(!read_only_); |
| 76 switch (space) { | 76 switch (space) { |
| 77 case kNew: | 77 case kNew: |
| 78 // Do not attempt to allocate very large objects in new space. | 78 // Do not attempt to allocate very large objects in new space. |
| 79 if (!IsAllocatableInNewSpace(size)) { | 79 if (!IsAllocatableInNewSpace(size)) { |
| 80 return AllocateOld(size, HeapPage::kData); | 80 return AllocateOld(size, HeapPage::kData); |
| 81 } | 81 } |
| 82 return AllocateNew(size); | 82 return AllocateNew(size); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // Enables growth control on the page space heaps. This should be | 129 // Enables growth control on the page space heaps. This should be |
| 130 // called before any user code is executed. | 130 // called before any user code is executed. |
| 131 void EnableGrowthControl() { SetGrowthControlState(true); } | 131 void EnableGrowthControl() { SetGrowthControlState(true); } |
| 132 void DisableGrowthControl() { SetGrowthControlState(false); } | 132 void DisableGrowthControl() { SetGrowthControlState(false); } |
| 133 void SetGrowthControlState(bool state); | 133 void SetGrowthControlState(bool state); |
| 134 bool GrowthControlState(); | 134 bool GrowthControlState(); |
| 135 | 135 |
| 136 // Protect access to the heap. | 136 // Protect access to the heap. |
| 137 void WriteProtect(bool read_only); | 137 void WriteProtect(bool read_only); |
| 138 void WriteProtectCode(bool read_only) { | 138 void WriteProtectCode(bool read_only) { |
| 139 old_space_->WriteProtectCode(read_only); | 139 old_space_.WriteProtectCode(read_only); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // Accessors for inlined allocation in generated code. | 142 // Accessors for inlined allocation in generated code. |
| 143 uword TopAddress(Space space); | 143 uword TopAddress(Space space); |
| 144 static intptr_t TopOffset(Space space); |
| 144 uword EndAddress(Space space); | 145 uword EndAddress(Space space); |
| 145 Space SpaceForAllocation(intptr_t class_id) const; | 146 static intptr_t EndOffset(Space space); |
| 147 static Space SpaceForAllocation(intptr_t class_id); |
| 146 | 148 |
| 147 // Initialize the heap and register it with the isolate. | 149 // Initialize the heap and register it with the isolate. |
| 148 static void Init(Isolate* isolate, | 150 static void Init(Isolate* isolate, |
| 149 intptr_t max_new_gen_words, | 151 intptr_t max_new_gen_words, |
| 150 intptr_t max_old_gen_words, | 152 intptr_t max_old_gen_words, |
| 151 intptr_t max_external_words); | 153 intptr_t max_external_words); |
| 152 | 154 |
| 153 // Verify that all pointers in the heap point to the heap. | 155 // Verify that all pointers in the heap point to the heap. |
| 154 bool Verify(MarkExpectation mark_expectation = kForbidMarked) const; | 156 bool Verify(MarkExpectation mark_expectation = kForbidMarked) const; |
| 155 | 157 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 223 |
| 222 bool gc_in_progress() const { return gc_in_progress_; } | 224 bool gc_in_progress() const { return gc_in_progress_; } |
| 223 | 225 |
| 224 static bool IsAllocatableInNewSpace(intptr_t size) { | 226 static bool IsAllocatableInNewSpace(intptr_t size) { |
| 225 return size <= kNewAllocatableSize; | 227 return size <= kNewAllocatableSize; |
| 226 } | 228 } |
| 227 | 229 |
| 228 void PrintToJSONObject(Space space, JSONObject* object) const; | 230 void PrintToJSONObject(Space space, JSONObject* object) const; |
| 229 | 231 |
| 230 // The heap map contains the sizes and class ids for the objects in each page. | 232 // The heap map contains the sizes and class ids for the objects in each page. |
| 231 void PrintHeapMapToJSONStream(Isolate* isolate, JSONStream* stream) const { | 233 void PrintHeapMapToJSONStream(Isolate* isolate, JSONStream* stream) { |
| 232 return old_space_->PrintHeapMapToJSONStream(isolate, stream); | 234 return old_space_.PrintHeapMapToJSONStream(isolate, stream); |
| 233 } | 235 } |
| 234 | 236 |
| 235 Isolate* isolate() const { return isolate_; } | 237 Isolate* isolate() const { return isolate_; } |
| 236 | 238 |
| 237 bool ShouldPretenure(intptr_t class_id) const; | 239 bool ShouldPretenure(intptr_t class_id) const; |
| 238 | 240 |
| 239 private: | 241 private: |
| 240 class GCStats : public ValueObject { | 242 class GCStats : public ValueObject { |
| 241 public: | 243 public: |
| 242 GCStats() {} | 244 GCStats() {} |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 void UpdatePretenurePolicy(); | 300 void UpdatePretenurePolicy(); |
| 299 | 301 |
| 300 // If this heap is non-empty, updates start and end to the smallest range that | 302 // If this heap is non-empty, updates start and end to the smallest range that |
| 301 // contains both the original [start, end) and the [lowest, highest) addresses | 303 // contains both the original [start, end) and the [lowest, highest) addresses |
| 302 // of this heap. | 304 // of this heap. |
| 303 void GetMergedAddressRange(uword* start, uword* end) const; | 305 void GetMergedAddressRange(uword* start, uword* end) const; |
| 304 | 306 |
| 305 Isolate* isolate_; | 307 Isolate* isolate_; |
| 306 | 308 |
| 307 // The different spaces used for allocation. | 309 // The different spaces used for allocation. |
| 308 Scavenger* new_space_; | 310 Scavenger new_space_; |
| 309 PageSpace* old_space_; | 311 PageSpace old_space_; |
| 310 | 312 |
| 311 WeakTable* new_weak_tables_[kNumWeakSelectors]; | 313 WeakTable* new_weak_tables_[kNumWeakSelectors]; |
| 312 WeakTable* old_weak_tables_[kNumWeakSelectors]; | 314 WeakTable* old_weak_tables_[kNumWeakSelectors]; |
| 313 | 315 |
| 314 // GC stats collection. | 316 // GC stats collection. |
| 315 GCStats stats_; | 317 GCStats stats_; |
| 316 | 318 |
| 317 // This heap is in read-only mode: No allocation is allowed. | 319 // This heap is in read-only mode: No allocation is allowed. |
| 318 bool read_only_; | 320 bool read_only_; |
| 319 | 321 |
| 320 // GC on the heap is in progress. | 322 // GC on the heap is in progress. |
| 321 bool gc_in_progress_; | 323 bool gc_in_progress_; |
| 322 | 324 |
| 323 int pretenure_policy_; | 325 int pretenure_policy_; |
| 324 | 326 |
| 325 friend class ServiceEvent; | 327 friend class ServiceEvent; |
| 326 friend class GCTestHelper; | |
| 327 friend class PageSpace; // VerifyGC | 328 friend class PageSpace; // VerifyGC |
| 328 DISALLOW_COPY_AND_ASSIGN(Heap); | 329 DISALLOW_COPY_AND_ASSIGN(Heap); |
| 329 }; | 330 }; |
| 330 | 331 |
| 331 | 332 |
| 332 // Within a NoSafepointScope, the thread must not reach any safepoint. Used | 333 // Within a NoSafepointScope, the thread must not reach any safepoint. Used |
| 333 // around code that manipulates raw object pointers directly without handles. | 334 // around code that manipulates raw object pointers directly without handles. |
| 334 #if defined(DEBUG) | 335 #if defined(DEBUG) |
| 335 class NoSafepointScope : public StackResource { | 336 class NoSafepointScope : public StackResource { |
| 336 public: | 337 public: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 366 NoHeapGrowthControlScope(); | 367 NoHeapGrowthControlScope(); |
| 367 ~NoHeapGrowthControlScope(); | 368 ~NoHeapGrowthControlScope(); |
| 368 private: | 369 private: |
| 369 bool current_growth_controller_state_; | 370 bool current_growth_controller_state_; |
| 370 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope); | 371 DISALLOW_COPY_AND_ASSIGN(NoHeapGrowthControlScope); |
| 371 }; | 372 }; |
| 372 | 373 |
| 373 } // namespace dart | 374 } // namespace dart |
| 374 | 375 |
| 375 #endif // VM_HEAP_H_ | 376 #endif // VM_HEAP_H_ |
| OLD | NEW |