Chromium Code Reviews| 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 #include "vm/pages.h" | 5 #include "vm/pages.h" |
| 6 | 6 |
| 7 #include "platform/address_sanitizer.h" | 7 #include "platform/address_sanitizer.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/compiler_stats.h" | 9 #include "vm/compiler_stats.h" |
| 10 #include "vm/gc_marker.h" | 10 #include "vm/gc_marker.h" |
| (...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1210 const int gc_time_fraction = history_.GarbageCollectionTimeFraction(); | 1210 const int gc_time_fraction = history_.GarbageCollectionTimeFraction(); |
| 1211 heap_->RecordData(PageSpace::kGCTimeFraction, gc_time_fraction); | 1211 heap_->RecordData(PageSpace::kGCTimeFraction, gc_time_fraction); |
| 1212 | 1212 |
| 1213 // Assume garbage increases linearly with allocation: | 1213 // Assume garbage increases linearly with allocation: |
| 1214 // G = kA, and estimate k from the previous cycle. | 1214 // G = kA, and estimate k from the previous cycle. |
| 1215 const intptr_t allocated_since_previous_gc = | 1215 const intptr_t allocated_since_previous_gc = |
| 1216 before.used_in_words - last_usage_.used_in_words; | 1216 before.used_in_words - last_usage_.used_in_words; |
| 1217 if (allocated_since_previous_gc > 0) { | 1217 if (allocated_since_previous_gc > 0) { |
| 1218 const intptr_t garbage = before.used_in_words - after.used_in_words; | 1218 const intptr_t garbage = before.used_in_words - after.used_in_words; |
| 1219 ASSERT(garbage >= 0); | 1219 ASSERT(garbage >= 0); |
| 1220 const double k = garbage / static_cast<double>(allocated_since_previous_gc); | 1220 // It makes no sense to expect that each kb alllocated will cause more than |
|
kasperl
2017/04/21 10:11:28
alllocated -> allocated
erikcorry
2017/04/21 15:51:06
Done.
| |
| 1221 // one kb of garbage, so we clamp k at 1.0. | |
| 1222 const double k = Utils::Minimum( | |
| 1223 1.0, garbage / static_cast<double>(allocated_since_previous_gc)); | |
| 1224 | |
| 1221 const int garbage_ratio = static_cast<int>(k * 100); | 1225 const int garbage_ratio = static_cast<int>(k * 100); |
| 1222 heap_->RecordData(PageSpace::kGarbageRatio, garbage_ratio); | 1226 heap_->RecordData(PageSpace::kGarbageRatio, garbage_ratio); |
| 1223 | 1227 |
| 1224 // Define GC to be 'worthwhile' iff at least fraction t of heap is garbage. | 1228 // Define GC to be 'worthwhile' iff at least fraction t of heap is garbage. |
| 1225 double t = 1.0 - desired_utilization_; | 1229 double t = 1.0 - desired_utilization_; |
| 1226 // If we spend too much time in GC, strive for even more free space. | 1230 // If we spend too much time in GC, strive for even more free space. |
| 1227 if (gc_time_fraction > garbage_collection_time_ratio_) { | 1231 if (gc_time_fraction > garbage_collection_time_ratio_) { |
| 1228 t += (gc_time_fraction - garbage_collection_time_ratio_) / 100.0; | 1232 t += (gc_time_fraction - garbage_collection_time_ratio_) / 100.0; |
| 1229 } | 1233 } |
| 1230 | 1234 |
| 1231 const intptr_t grow_ratio = | 1235 const intptr_t grow_ratio = |
| 1232 (static_cast<intptr_t>(after.capacity_in_words / desired_utilization_) - | 1236 (static_cast<intptr_t>(after.capacity_in_words / desired_utilization_) - |
| 1233 after.capacity_in_words) / | 1237 after.capacity_in_words) / |
| 1234 PageSpace::kPageSizeInWords; | 1238 PageSpace::kPageSizeInWords; |
| 1235 if (garbage_ratio == 0) { | 1239 if (garbage_ratio == 0) { |
| 1236 // No garbage in the previous cycle so it would be hard to compute a | 1240 // No garbage in the previous cycle so it would be hard to compute a |
| 1237 // grow_heap_ size based on estimated garbage so we use growth ratio | 1241 // grow_heap_ size based on estimated garbage so we use growth ratio |
| 1238 // heuristics instead. | 1242 // heuristics instead. |
| 1239 grow_heap_ = | 1243 grow_heap_ = |
| 1240 Utils::Maximum(static_cast<intptr_t>(heap_growth_max_), grow_ratio); | 1244 Utils::Maximum(static_cast<intptr_t>(heap_growth_max_), grow_ratio); |
| 1241 } else { | 1245 } else { |
| 1242 // Find minimum 'grow_heap_' such that after increasing capacity by | 1246 // Find minimum 'grow_heap_' such that after increasing capacity by |
| 1243 // 'grow_heap_' pages and filling them, we expect a GC to be worthwhile. | 1247 // 'grow_heap_' pages and filling them, we expect a GC to be worthwhile. |
| 1244 intptr_t max = heap_growth_max_; | 1248 intptr_t max = heap_growth_max_; |
| 1245 intptr_t min = 0; | 1249 intptr_t min = 0; |
| 1246 intptr_t local_grow_heap = 0; | 1250 intptr_t local_grow_heap = 0; |
| 1247 while (min < max) { | 1251 while (min < max) { |
| 1248 local_grow_heap = (max + min) / 2; | 1252 local_grow_heap = (max + min) / 2; |
| 1249 const intptr_t limit = after.capacity_in_words + | 1253 const intptr_t limit = after.capacity_in_words + |
| 1250 (grow_heap_ * PageSpace::kPageSizeInWords); | 1254 (local_grow_heap * PageSpace::kPageSizeInWords); |
| 1251 const intptr_t allocated_before_next_gc = limit - after.used_in_words; | 1255 const intptr_t allocated_before_next_gc = limit - after.used_in_words; |
| 1252 const double estimated_garbage = k * allocated_before_next_gc; | 1256 const double estimated_garbage = k * allocated_before_next_gc; |
| 1253 if (t <= estimated_garbage / limit) { | 1257 if (t <= estimated_garbage / limit) { |
| 1254 max = local_grow_heap - 1; | 1258 max = local_grow_heap - 1; |
| 1255 } else { | 1259 } else { |
| 1256 min = local_grow_heap + 1; | 1260 min = local_grow_heap + 1; |
| 1257 } | 1261 } |
| 1258 } | 1262 } |
| 1259 local_grow_heap = (max + min) / 2; | 1263 local_grow_heap = (max + min) / 2; |
| 1260 grow_heap_ = local_grow_heap; | 1264 grow_heap_ = local_grow_heap; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1303 return 0; | 1307 return 0; |
| 1304 } else { | 1308 } else { |
| 1305 ASSERT(total_time >= gc_time); | 1309 ASSERT(total_time >= gc_time); |
| 1306 int result = static_cast<int>( | 1310 int result = static_cast<int>( |
| 1307 (static_cast<double>(gc_time) / static_cast<double>(total_time)) * 100); | 1311 (static_cast<double>(gc_time) / static_cast<double>(total_time)) * 100); |
| 1308 return result; | 1312 return result; |
| 1309 } | 1313 } |
| 1310 } | 1314 } |
| 1311 | 1315 |
| 1312 } // namespace dart | 1316 } // namespace dart |
| OLD | NEW |