Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: runtime/vm/pages.h

Issue 225303006: Corrected resubmssion of r34736. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/heap.cc ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 11 matching lines...) Expand all
215 228
216 void SetGrowthControlState(bool state) { 229 void SetGrowthControlState(bool state) {
217 page_space_controller_.set_is_enabled(state); 230 page_space_controller_.set_is_enabled(state);
218 } 231 }
219 232
220 bool GrowthControlState() { 233 bool GrowthControlState() {
221 return page_space_controller_.is_enabled(); 234 return page_space_controller_.is_enabled();
222 } 235 }
223 236
224 bool NeedExternalGC() { 237 bool NeedExternalGC() {
225 return used_in_words_ + ExternalInWords() > max_capacity_in_words_; 238 return UsedInWords() + ExternalInWords() > max_capacity_in_words_;
226 } 239 }
227 240
228 void WriteProtect(bool read_only); 241 void WriteProtect(bool read_only);
229 242
230 void AddGCTime(int64_t micros) { 243 void AddGCTime(int64_t micros) {
231 gc_time_micros_ += micros; 244 gc_time_micros_ += micros;
232 } 245 }
233 246
234 int64_t gc_time_micros() const { 247 int64_t gc_time_micros() const {
235 return gc_time_micros_; 248 return gc_time_micros_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 281
269 HeapPage* AllocatePage(HeapPage::PageType type); 282 HeapPage* AllocatePage(HeapPage::PageType type);
270 void FreePage(HeapPage* page, HeapPage* previous_page); 283 void FreePage(HeapPage* page, HeapPage* previous_page);
271 HeapPage* AllocateLargePage(intptr_t size, HeapPage::PageType type); 284 HeapPage* AllocateLargePage(intptr_t size, HeapPage::PageType type);
272 void FreeLargePage(HeapPage* page, HeapPage* previous_page); 285 void FreeLargePage(HeapPage* page, HeapPage* previous_page);
273 void FreePages(HeapPage* pages); 286 void FreePages(HeapPage* pages);
274 287
275 static intptr_t LargePageSizeInWordsFor(intptr_t size); 288 static intptr_t LargePageSizeInWordsFor(intptr_t size);
276 289
277 bool CanIncreaseCapacityInWords(intptr_t increase_in_words) { 290 bool CanIncreaseCapacityInWords(intptr_t increase_in_words) {
278 ASSERT(capacity_in_words_ <= max_capacity_in_words_); 291 ASSERT(CapacityInWords() <= max_capacity_in_words_);
279 return increase_in_words <= (max_capacity_in_words_ - capacity_in_words_); 292 return increase_in_words <= (max_capacity_in_words_ - CapacityInWords());
280 } 293 }
281 294
282 FreeList freelist_[HeapPage::kNumPageTypes]; 295 FreeList freelist_[HeapPage::kNumPageTypes];
283 296
284 Heap* heap_; 297 Heap* heap_;
285 298
286 HeapPage* pages_; 299 HeapPage* pages_;
287 HeapPage* pages_tail_; 300 HeapPage* pages_tail_;
288 HeapPage* large_pages_; 301 HeapPage* large_pages_;
289 302
290 // Various sizes being tracked for this generation. 303 // Various sizes being tracked for this generation.
291 intptr_t max_capacity_in_words_; 304 intptr_t max_capacity_in_words_;
292 intptr_t capacity_in_words_; 305 SpaceUsage usage_;
293 intptr_t used_in_words_;
294 intptr_t external_in_words_;
295 306
296 // Keep track whether a MarkSweep is currently running. 307 // Keep track whether a MarkSweep is currently running.
297 bool sweeping_; 308 bool sweeping_;
298 309
299 PageSpaceController page_space_controller_; 310 PageSpaceController page_space_controller_;
300 311
301 int64_t gc_time_micros_; 312 int64_t gc_time_micros_;
302 intptr_t collections_; 313 intptr_t collections_;
303 314
304 friend class PageSpaceController; 315 friend class PageSpaceController;
305 316
306 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); 317 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace);
307 }; 318 };
308 319
309 } // namespace dart 320 } // namespace dart
310 321
311 #endif // VM_PAGES_H_ 322 #endif // VM_PAGES_H_
OLDNEW
« no previous file with comments | « runtime/vm/heap.cc ('k') | runtime/vm/pages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698