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" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
| 14 DECLARE_FLAG(bool, collect_code); |
| 15 DECLARE_FLAG(bool, log_code_drop); |
| 16 |
14 // Forward declarations. | 17 // Forward declarations. |
15 class Heap; | 18 class Heap; |
16 class ObjectPointerVisitor; | 19 class ObjectPointerVisitor; |
17 | 20 |
18 // An aligned page containing old generation objects. Alignment is used to be | 21 // An aligned page containing old generation objects. Alignment is used to be |
19 // able to get to a HeapPage header quickly based on a pointer to an object. | 22 // able to get to a HeapPage header quickly based on a pointer to an object. |
20 class HeapPage { | 23 class HeapPage { |
21 public: | 24 public: |
22 enum PageType { | 25 enum PageType { |
23 kData = 0, | 26 kData = 0, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 117 |
115 bool CanGrowPageSpace(intptr_t size_in_bytes); | 118 bool CanGrowPageSpace(intptr_t size_in_bytes); |
116 | 119 |
117 // A garbage collection is considered as successful if more than | 120 // A garbage collection is considered as successful if more than |
118 // heap_growth_ratio % of memory got deallocated by the garbage collector. | 121 // heap_growth_ratio % of memory got deallocated by the garbage collector. |
119 // In this case garbage collection will be performed next time. Otherwise | 122 // In this case garbage collection will be performed next time. Otherwise |
120 // the heap will grow. | 123 // the heap will grow. |
121 void EvaluateGarbageCollection(intptr_t in_use_before, intptr_t in_use_after, | 124 void EvaluateGarbageCollection(intptr_t in_use_before, intptr_t in_use_after, |
122 int64_t start, int64_t end); | 125 int64_t start, int64_t end); |
123 | 126 |
| 127 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 last_code_collection_in_us_ = t; |
| 130 } |
| 131 |
124 void set_is_enabled(bool state) { | 132 void set_is_enabled(bool state) { |
125 is_enabled_ = state; | 133 is_enabled_ = state; |
126 } | 134 } |
127 bool is_enabled() { | 135 bool is_enabled() { |
128 return is_enabled_; | 136 return is_enabled_; |
129 } | 137 } |
130 | 138 |
131 private: | 139 private: |
132 bool is_enabled_; | 140 bool is_enabled_; |
133 | 141 |
134 // Heap growth control variable. | 142 // Heap growth control variable. |
135 intptr_t grow_heap_; | 143 intptr_t grow_heap_; |
136 | 144 |
137 // If the garbage collector was not able to free more than heap_growth_ratio_ | 145 // If the garbage collector was not able to free more than heap_growth_ratio_ |
138 // memory, then the heap is grown. Otherwise garbage collection is performed. | 146 // memory, then the heap is grown. Otherwise garbage collection is performed. |
139 int heap_growth_ratio_; | 147 int heap_growth_ratio_; |
140 | 148 |
141 // The desired percent of heap in-use after a garbage collection. | 149 // The desired percent of heap in-use after a garbage collection. |
142 // Equivalent to \frac{100-heap_growth_ratio_}{100}. | 150 // Equivalent to \frac{100-heap_growth_ratio_}{100}. |
143 double desired_utilization_; | 151 double desired_utilization_; |
144 | 152 |
145 // Number of pages we grow. | 153 // Number of pages we grow. |
146 int heap_growth_rate_; | 154 int heap_growth_rate_; |
147 | 155 |
148 // If the relative GC time stays below garbage_collection_time_ratio_ | 156 // If the relative GC time stays below garbage_collection_time_ratio_ |
149 // garbage collection can be performed. | 157 // garbage collection can be performed. |
150 int garbage_collection_time_ratio_; | 158 int garbage_collection_time_ratio_; |
151 | 159 |
| 160 // The time in microseconds of the last time we tried to collect unused |
| 161 // code. |
| 162 int64_t last_code_collection_in_us_; |
| 163 |
152 PageSpaceGarbageCollectionHistory history_; | 164 PageSpaceGarbageCollectionHistory history_; |
153 | 165 |
154 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpaceController); | 166 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpaceController); |
155 }; | 167 }; |
156 | 168 |
157 | 169 |
158 class PageSpace { | 170 class PageSpace { |
159 public: | 171 public: |
160 // TODO(iposva): Determine heap sizes and tune the page size accordingly. | 172 // TODO(iposva): Determine heap sizes and tune the page size accordingly. |
161 static const intptr_t kPageSize = 256 * KB; | 173 static const intptr_t kPageSize = 256 * KB; |
(...skipping 19 matching lines...) Expand all Loading... |
181 bool IsValidAddress(uword addr) const { | 193 bool IsValidAddress(uword addr) const { |
182 return Contains(addr); | 194 return Contains(addr); |
183 } | 195 } |
184 | 196 |
185 void VisitObjects(ObjectVisitor* visitor) const; | 197 void VisitObjects(ObjectVisitor* visitor) const; |
186 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; | 198 void VisitObjectPointers(ObjectPointerVisitor* visitor) const; |
187 | 199 |
188 RawObject* FindObject(FindObjectVisitor* visitor, | 200 RawObject* FindObject(FindObjectVisitor* visitor, |
189 HeapPage::PageType type) const; | 201 HeapPage::PageType type) const; |
190 | 202 |
| 203 // Runs a visitor that attempts to drop references to code that has not |
| 204 // been run in awhile. |
| 205 void TryDetachingCode(); |
| 206 |
191 // Collect the garbage in the page space using mark-sweep. | 207 // Collect the garbage in the page space using mark-sweep. |
192 void MarkSweep(bool invoke_api_callbacks); | 208 void MarkSweep(bool invoke_api_callbacks); |
193 | 209 |
194 void StartEndAddress(uword* start, uword* end) const; | 210 void StartEndAddress(uword* start, uword* end) const; |
195 | 211 |
196 void SetGrowthControlState(bool state) { | 212 void SetGrowthControlState(bool state) { |
197 page_space_controller_.set_is_enabled(state); | 213 page_space_controller_.set_is_enabled(state); |
198 } | 214 } |
199 | 215 |
200 bool GrowthControlState() { | 216 bool GrowthControlState() { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 PageSpaceController page_space_controller_; | 268 PageSpaceController page_space_controller_; |
253 | 269 |
254 friend class PageSpaceController; | 270 friend class PageSpaceController; |
255 | 271 |
256 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); | 272 DISALLOW_IMPLICIT_CONSTRUCTORS(PageSpace); |
257 }; | 273 }; |
258 | 274 |
259 } // namespace dart | 275 } // namespace dart |
260 | 276 |
261 #endif // VM_PAGES_H_ | 277 #endif // VM_PAGES_H_ |
OLD | NEW |