| 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/virtual_memory.h" | 10 #include "vm/virtual_memory.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 int heap_growth_rate, | 114 int heap_growth_rate, |
| 115 int garbage_collection_time_ratio); | 115 int garbage_collection_time_ratio); |
| 116 ~PageSpaceController(); | 116 ~PageSpaceController(); |
| 117 | 117 |
| 118 bool CanGrowPageSpace(intptr_t size_in_bytes); | 118 bool CanGrowPageSpace(intptr_t size_in_bytes); |
| 119 | 119 |
| 120 // A garbage collection is considered as successful if more than | 120 // A garbage collection is considered as successful if more than |
| 121 // heap_growth_ratio % of memory got deallocated by the garbage collector. | 121 // heap_growth_ratio % of memory got deallocated by the garbage collector. |
| 122 // In this case garbage collection will be performed next time. Otherwise | 122 // In this case garbage collection will be performed next time. Otherwise |
| 123 // the heap will grow. | 123 // the heap will grow. |
| 124 void EvaluateGarbageCollection(intptr_t in_use_before, intptr_t in_use_after, | 124 void EvaluateGarbageCollection(intptr_t used_before_in_words, |
| 125 intptr_t used_after_in_words, |
| 125 int64_t start, int64_t end); | 126 int64_t start, int64_t end); |
| 126 | 127 |
| 127 int64_t last_code_collection_in_us() { return last_code_collection_in_us_; } | 128 int64_t last_code_collection_in_us() { return last_code_collection_in_us_; } |
| 128 void set_last_code_collection_in_us(int64_t t) { | 129 void set_last_code_collection_in_us(int64_t t) { |
| 129 last_code_collection_in_us_ = t; | 130 last_code_collection_in_us_ = t; |
| 130 } | 131 } |
| 131 | 132 |
| 132 void set_is_enabled(bool state) { | 133 void set_is_enabled(bool state) { |
| 133 is_enabled_ = state; | 134 is_enabled_ = state; |
| 134 } | 135 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 public: | 172 public: |
| 172 // TODO(iposva): Determine heap sizes and tune the page size accordingly. | 173 // TODO(iposva): Determine heap sizes and tune the page size accordingly. |
| 173 static const intptr_t kPageSize = 256 * KB; | 174 static const intptr_t kPageSize = 256 * KB; |
| 174 static const intptr_t kPageAlignment = kPageSize; | 175 static const intptr_t kPageAlignment = kPageSize; |
| 175 | 176 |
| 176 enum GrowthPolicy { | 177 enum GrowthPolicy { |
| 177 kControlGrowth, | 178 kControlGrowth, |
| 178 kForceGrowth | 179 kForceGrowth |
| 179 }; | 180 }; |
| 180 | 181 |
| 181 PageSpace(Heap* heap, intptr_t max_capacity); | 182 PageSpace(Heap* heap, intptr_t max_capacity_in_words); |
| 182 ~PageSpace(); | 183 ~PageSpace(); |
| 183 | 184 |
| 184 uword TryAllocate(intptr_t size, | 185 uword TryAllocate(intptr_t size, |
| 185 HeapPage::PageType type = HeapPage::kData, | 186 HeapPage::PageType type = HeapPage::kData, |
| 186 GrowthPolicy growth_policy = kControlGrowth); | 187 GrowthPolicy growth_policy = kControlGrowth); |
| 187 | 188 |
| 188 intptr_t in_use() const { return in_use_; } | 189 intptr_t UsedInWords() const { return used_in_words_; } |
| 189 intptr_t capacity() const { return capacity_; } | 190 intptr_t CapacityInWords() const { return capacity_in_words_; } |
| 190 | 191 |
| 191 bool Contains(uword addr) const; | 192 bool Contains(uword addr) const; |
| 192 bool Contains(uword addr, HeapPage::PageType type) const; | 193 bool Contains(uword addr, HeapPage::PageType type) const; |
| 193 bool IsValidAddress(uword addr) const { | 194 bool IsValidAddress(uword addr) const { |
| 194 return Contains(addr); | 195 return Contains(addr); |
| 195 } | 196 } |
| 196 | 197 |
| 197 void VisitObjects(ObjectVisitor* visitor) const; | 198 void VisitObjects(ObjectVisitor* visitor) const; |
| 198 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 199 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
| 199 | 200 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 static const intptr_t kAllocatablePageSize = 64 * KB; | 238 static const intptr_t kAllocatablePageSize = 64 * KB; |
| 238 | 239 |
| 239 HeapPage* AllocatePage(HeapPage::PageType type); | 240 HeapPage* AllocatePage(HeapPage::PageType type); |
| 240 void FreePage(HeapPage* page, HeapPage* previous_page); | 241 void FreePage(HeapPage* page, HeapPage* previous_page); |
| 241 HeapPage* AllocateLargePage(intptr_t size, HeapPage::PageType type); | 242 HeapPage* AllocateLargePage(intptr_t size, HeapPage::PageType type); |
| 242 void FreeLargePage(HeapPage* page, HeapPage* previous_page); | 243 void FreeLargePage(HeapPage* page, HeapPage* previous_page); |
| 243 void FreePages(HeapPage* pages); | 244 void FreePages(HeapPage* pages); |
| 244 | 245 |
| 245 static intptr_t LargePageSizeFor(intptr_t size); | 246 static intptr_t LargePageSizeFor(intptr_t size); |
| 246 | 247 |
| 247 bool CanIncreaseCapacity(intptr_t increase) { | 248 bool CanIncreaseCapacityInWords(intptr_t increase_in_words) { |
| 248 ASSERT(capacity_ <= max_capacity_); | 249 ASSERT(capacity_in_words_ <= max_capacity_in_words_); |
| 249 return increase <= (max_capacity_ - capacity_); | 250 return increase_in_words <= (max_capacity_in_words_ - capacity_in_words_); |
| 250 } | 251 } |
| 251 | 252 |
| 252 FreeList freelist_[HeapPage::kNumPageTypes]; | 253 FreeList freelist_[HeapPage::kNumPageTypes]; |
| 253 | 254 |
| 254 Heap* heap_; | 255 Heap* heap_; |
| 255 | 256 |
| 256 HeapPage* pages_; | 257 HeapPage* pages_; |
| 257 HeapPage* pages_tail_; | 258 HeapPage* pages_tail_; |
| 258 HeapPage* large_pages_; | 259 HeapPage* large_pages_; |
| 259 | 260 |
| 260 // Various sizes being tracked for this generation. | 261 // Various sizes being tracked for this generation. |
| 261 intptr_t max_capacity_; | 262 intptr_t max_capacity_in_words_; |
| 262 intptr_t capacity_; | 263 intptr_t capacity_in_words_; |
| 263 intptr_t in_use_; | 264 intptr_t used_in_words_; |
| 264 | 265 |
| 265 // Keep track whether a MarkSweep is currently running. | 266 // Keep track whether a MarkSweep is currently running. |
| 266 bool sweeping_; | 267 bool sweeping_; |
| 267 | 268 |
| 268 PageSpaceController page_space_controller_; | 269 PageSpaceController page_space_controller_; |
| 269 | 270 |
| 270 friend class PageSpaceController; | 271 friend class PageSpaceController; |
| 271 | 272 |
| 272 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); | 273 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); |
| 273 }; | 274 }; |
| 274 | 275 |
| 275 } // namespace dart | 276 } // namespace dart |
| 276 | 277 |
| 277 #endif // VM_PAGES_H_ | 278 #endif // VM_PAGES_H_ |
| OLD | NEW |