| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_PAGES_H_ | 5 #ifndef VM_PAGES_H_ |
| 6 #define VM_PAGES_H_ | 6 #define VM_PAGES_H_ |
| 7 | 7 |
| 8 #include "vm/freelist.h" | 8 #include "vm/freelist.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/spaces.h" |
| 10 #include "vm/virtual_memory.h" | 11 #include "vm/virtual_memory.h" |
| 11 | 12 |
| 12 namespace dart { | 13 namespace dart { |
| 13 | 14 |
| 14 DECLARE_FLAG(bool, collect_code); | 15 DECLARE_FLAG(bool, collect_code); |
| 15 DECLARE_FLAG(bool, log_code_drop); | 16 DECLARE_FLAG(bool, log_code_drop); |
| 16 DECLARE_FLAG(bool, always_drop_code); | 17 DECLARE_FLAG(bool, always_drop_code); |
| 17 | 18 |
| 18 // Forward declarations. | 19 // Forward declarations. |
| 19 class Heap; | 20 class Heap; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // and if the relative GC time is below a given threshold, | 110 // and if the relative GC time is below a given threshold, |
| 110 // then the heap is not grown when the next GC decision is made. | 111 // then the heap is not grown when the next GC decision is made. |
| 111 // PageSpaceController controls the heap size. | 112 // PageSpaceController controls the heap size. |
| 112 class PageSpaceController { | 113 class PageSpaceController { |
| 113 public: | 114 public: |
| 114 PageSpaceController(int heap_growth_ratio, | 115 PageSpaceController(int heap_growth_ratio, |
| 115 int heap_growth_rate, | 116 int heap_growth_rate, |
| 116 int garbage_collection_time_ratio); | 117 int garbage_collection_time_ratio); |
| 117 ~PageSpaceController(); | 118 ~PageSpaceController(); |
| 118 | 119 |
| 119 bool CanGrowPageSpace(intptr_t size_in_bytes); | 120 // Returns whether growing to 'after' should trigger a GC. |
| 121 // This method can be called before allocation (e.g., pretenuring) or after |
| 122 // (e.g., promotion), as it does not change the state of the controller. |
| 123 bool NeedsGarbageCollection(SpaceUsage after) const; |
| 120 | 124 |
| 125 // Should be called after each collection to update the controller state. |
| 121 // A garbage collection is considered as successful if more than | 126 // A garbage collection is considered as successful if more than |
| 122 // heap_growth_ratio % of memory got deallocated by the garbage collector. | 127 // heap_growth_ratio % of memory got deallocated by the garbage collector. |
| 123 // In this case garbage collection will be performed next time. Otherwise | 128 // In this case garbage collection will be performed next time. Otherwise |
| 124 // the heap will grow. | 129 // the heap will grow. |
| 125 void EvaluateGarbageCollection(intptr_t used_before_in_words, | 130 void EvaluateGarbageCollection(SpaceUsage before, |
| 126 intptr_t used_after_in_words, | 131 SpaceUsage after, |
| 127 int64_t start, int64_t end); | 132 int64_t start, int64_t end); |
| 128 | 133 |
| 129 int64_t last_code_collection_in_us() { return last_code_collection_in_us_; } | 134 int64_t last_code_collection_in_us() { return last_code_collection_in_us_; } |
| 130 void set_last_code_collection_in_us(int64_t t) { | 135 void set_last_code_collection_in_us(int64_t t) { |
| 131 last_code_collection_in_us_ = t; | 136 last_code_collection_in_us_ = t; |
| 132 } | 137 } |
| 133 | 138 |
| 134 void set_is_enabled(bool state) { | 139 void set_is_enabled(bool state) { |
| 135 is_enabled_ = state; | 140 is_enabled_ = state; |
| 136 } | 141 } |
| 137 bool is_enabled() { | 142 bool is_enabled() { |
| 138 return is_enabled_; | 143 return is_enabled_; |
| 139 } | 144 } |
| 140 | 145 |
| 141 private: | 146 private: |
| 142 bool is_enabled_; | 147 bool is_enabled_; |
| 143 | 148 |
| 149 // Usage after last evaluated GC. |
| 150 SpaceUsage last_usage_; |
| 151 |
| 144 // Heap growth control variable. | 152 // Heap growth control variable. |
| 145 intptr_t grow_heap_; | 153 intptr_t grow_heap_; |
| 146 | 154 |
| 147 // If the garbage collector was not able to free more than heap_growth_ratio_ | 155 // If the garbage collector was not able to free more than heap_growth_ratio_ |
| 148 // memory, then the heap is grown. Otherwise garbage collection is performed. | 156 // memory, then the heap is grown. Otherwise garbage collection is performed. |
| 149 int heap_growth_ratio_; | 157 int heap_growth_ratio_; |
| 150 | 158 |
| 151 // The desired percent of heap in-use after a garbage collection. | 159 // The desired percent of heap in-use after a garbage collection. |
| 152 // Equivalent to \frac{100-heap_growth_ratio_}{100}. | 160 // Equivalent to \frac{100-heap_growth_ratio_}{100}. |
| 153 double desired_utilization_; | 161 double desired_utilization_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 179 kForceGrowth | 187 kForceGrowth |
| 180 }; | 188 }; |
| 181 | 189 |
| 182 PageSpace(Heap* heap, intptr_t max_capacity_in_words); | 190 PageSpace(Heap* heap, intptr_t max_capacity_in_words); |
| 183 ~PageSpace(); | 191 ~PageSpace(); |
| 184 | 192 |
| 185 uword TryAllocate(intptr_t size, | 193 uword TryAllocate(intptr_t size, |
| 186 HeapPage::PageType type = HeapPage::kData, | 194 HeapPage::PageType type = HeapPage::kData, |
| 187 GrowthPolicy growth_policy = kControlGrowth); | 195 GrowthPolicy growth_policy = kControlGrowth); |
| 188 | 196 |
| 189 intptr_t UsedInWords() const { return used_in_words_; } | 197 bool NeedsGarbageCollection() const { |
| 190 intptr_t CapacityInWords() const { return capacity_in_words_; } | 198 return page_space_controller_.NeedsGarbageCollection(usage_); |
| 199 } |
| 200 |
| 201 intptr_t UsedInWords() const { return usage_.used_in_words; } |
| 202 intptr_t CapacityInWords() const { return usage_.capacity_in_words; } |
| 191 intptr_t ExternalInWords() const { | 203 intptr_t ExternalInWords() const { |
| 192 return external_in_words_; | 204 return usage_.external_in_words; |
| 193 } | 205 } |
| 206 SpaceUsage GetCurrentUsage() const { return usage_; } |
| 194 | 207 |
| 195 bool Contains(uword addr) const; | 208 bool Contains(uword addr) const; |
| 196 bool Contains(uword addr, HeapPage::PageType type) const; | 209 bool Contains(uword addr, HeapPage::PageType type) const; |
| 197 bool IsValidAddress(uword addr) const { | 210 bool IsValidAddress(uword addr) const { |
| 198 return Contains(addr); | 211 return Contains(addr); |
| 199 } | 212 } |
| 200 | 213 |
| 201 void VisitObjects(ObjectVisitor* visitor) const; | 214 void VisitObjects(ObjectVisitor* visitor) const; |
| 202 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 215 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
| 203 | 216 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 277 |
| 265 HeapPage* AllocatePage(HeapPage::PageType type); | 278 HeapPage* AllocatePage(HeapPage::PageType type); |
| 266 void FreePage(HeapPage* page, HeapPage* previous_page); | 279 void FreePage(HeapPage* page, HeapPage* previous_page); |
| 267 HeapPage* AllocateLargePage(intptr_t size, HeapPage::PageType type); | 280 HeapPage* AllocateLargePage(intptr_t size, HeapPage::PageType type); |
| 268 void FreeLargePage(HeapPage* page, HeapPage* previous_page); | 281 void FreeLargePage(HeapPage* page, HeapPage* previous_page); |
| 269 void FreePages(HeapPage* pages); | 282 void FreePages(HeapPage* pages); |
| 270 | 283 |
| 271 static intptr_t LargePageSizeInWordsFor(intptr_t size); | 284 static intptr_t LargePageSizeInWordsFor(intptr_t size); |
| 272 | 285 |
| 273 bool CanIncreaseCapacityInWords(intptr_t increase_in_words) { | 286 bool CanIncreaseCapacityInWords(intptr_t increase_in_words) { |
| 274 ASSERT(capacity_in_words_ <= max_capacity_in_words_); | 287 ASSERT(CapacityInWords() <= max_capacity_in_words_); |
| 275 return increase_in_words <= (max_capacity_in_words_ - capacity_in_words_); | 288 return increase_in_words <= (max_capacity_in_words_ - CapacityInWords()); |
| 276 } | 289 } |
| 277 | 290 |
| 278 FreeList freelist_[HeapPage::kNumPageTypes]; | 291 FreeList freelist_[HeapPage::kNumPageTypes]; |
| 279 | 292 |
| 280 Heap* heap_; | 293 Heap* heap_; |
| 281 | 294 |
| 282 HeapPage* pages_; | 295 HeapPage* pages_; |
| 283 HeapPage* pages_tail_; | 296 HeapPage* pages_tail_; |
| 284 HeapPage* large_pages_; | 297 HeapPage* large_pages_; |
| 285 | 298 |
| 286 // Various sizes being tracked for this generation. | 299 // Various sizes being tracked for this generation. |
| 287 intptr_t max_capacity_in_words_; | 300 intptr_t max_capacity_in_words_; |
| 288 intptr_t capacity_in_words_; | 301 SpaceUsage usage_; |
| 289 intptr_t used_in_words_; | |
| 290 intptr_t external_in_words_; | |
| 291 | 302 |
| 292 // Keep track whether a MarkSweep is currently running. | 303 // Keep track whether a MarkSweep is currently running. |
| 293 bool sweeping_; | 304 bool sweeping_; |
| 294 | 305 |
| 295 PageSpaceController page_space_controller_; | 306 PageSpaceController page_space_controller_; |
| 296 | 307 |
| 297 int64_t gc_time_micros_; | 308 int64_t gc_time_micros_; |
| 298 intptr_t collections_; | 309 intptr_t collections_; |
| 299 | 310 |
| 300 friend class PageSpaceController; | 311 friend class PageSpaceController; |
| 301 | 312 |
| 302 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); | 313 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); |
| 303 }; | 314 }; |
| 304 | 315 |
| 305 } // namespace dart | 316 } // namespace dart |
| 306 | 317 |
| 307 #endif // VM_PAGES_H_ | 318 #endif // VM_PAGES_H_ |
| OLD | NEW |