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

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

Issue 2217833003: Fix for issue 25954. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « no previous file | no next file » | 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) 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/assert.h" 7 #include "platform/assert.h"
8 #include "vm/compiler_stats.h" 8 #include "vm/compiler_stats.h"
9 #include "vm/gc_marker.h" 9 #include "vm/gc_marker.h"
10 #include "vm/gc_sweeper.h" 10 #include "vm/gc_sweeper.h"
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 grow_heap_); 1150 grow_heap_);
1151 } 1151 }
1152 return needs_gc; 1152 return needs_gc;
1153 } 1153 }
1154 1154
1155 1155
1156 void PageSpaceController::EvaluateGarbageCollection( 1156 void PageSpaceController::EvaluateGarbageCollection(
1157 SpaceUsage before, SpaceUsage after, int64_t start, int64_t end) { 1157 SpaceUsage before, SpaceUsage after, int64_t start, int64_t end) {
1158 ASSERT(end >= start); 1158 ASSERT(end >= start);
1159 history_.AddGarbageCollectionTime(start, end); 1159 history_.AddGarbageCollectionTime(start, end);
1160 int gc_time_fraction = history_.GarbageCollectionTimeFraction(); 1160 int gc_time_fraction = history_.GarbageCollectionTimeFraction();
zra 2016/08/08 14:59:37 const intptr_t
siva 2016/08/11 17:32:48 Added const but changing it to intptr_t would mean
1161 heap_->RecordData(PageSpace::kGCTimeFraction, gc_time_fraction); 1161 heap_->RecordData(PageSpace::kGCTimeFraction, gc_time_fraction);
1162 1162
1163 // Assume garbage increases linearly with allocation: 1163 // Assume garbage increases linearly with allocation:
1164 // G = kA, and estimate k from the previous cycle. 1164 // G = kA, and estimate k from the previous cycle.
1165 intptr_t allocated_since_previous_gc = 1165 intptr_t allocated_since_previous_gc =
zra 2016/08/08 14:59:37 const ASSERT(allocated_since_previous_gc > 0);
siva 2016/08/11 17:32:48 Done.
1166 before.used_in_words - last_usage_.used_in_words; 1166 before.used_in_words - last_usage_.used_in_words;
1167 intptr_t garbage = before.used_in_words - after.used_in_words; 1167 intptr_t garbage = before.used_in_words - after.used_in_words;
zra 2016/08/08 14:59:37 const ASSERT(garbage >= 0);
siva 2016/08/11 17:32:48 Done.
1168 double k = garbage / static_cast<double>(allocated_since_previous_gc); 1168 double k = garbage / static_cast<double>(allocated_since_previous_gc);
zra 2016/08/08 14:59:37 const
siva 2016/08/11 17:32:48 Done.
1169 heap_->RecordData(PageSpace::kGarbageRatio, static_cast<int>(k * 100)); 1169 int garbage_ratio = static_cast<int>(k * 100);
zra 2016/08/08 14:59:37 const intptr_t
siva 2016/08/11 17:32:48 Added const, change to intptr_t would be coupled w
1170 heap_->RecordData(PageSpace::kGarbageRatio, garbage_ratio);
1170 1171
1171 // Define GC to be 'worthwhile' iff at least fraction t of heap is garbage. 1172 // Define GC to be 'worthwhile' iff at least fraction t of heap is garbage.
1172 double t = 1.0 - desired_utilization_; 1173 double t = 1.0 - desired_utilization_;
1173 // If we spend too much time in GC, strive for even more free space. 1174 // If we spend too much time in GC, strive for even more free space.
1174 if (gc_time_fraction > garbage_collection_time_ratio_) { 1175 if (gc_time_fraction > garbage_collection_time_ratio_) {
1175 t += (gc_time_fraction - garbage_collection_time_ratio_) / 100.0; 1176 t += (gc_time_fraction - garbage_collection_time_ratio_) / 100.0;
1176 } 1177 }
1177 1178
1178 // Find minimum 'grow_heap_' such that after increasing capacity by 1179 if (garbage_ratio == 0) {
1179 // 'grow_heap_' pages and filling them, we expect a GC to be worthwhile. 1180 // No garbage in the previous cycle so it would be hard to compute a
1180 for (grow_heap_ = 0; grow_heap_ < heap_growth_max_; ++grow_heap_) { 1181 // grow_heap_ size based on estimated garbage so we use growth ratio
1181 intptr_t limit = 1182 // instead.
1182 after.capacity_in_words + (grow_heap_ * PageSpace::kPageSizeInWords); 1183 intptr_t grow_ratio =
zra 2016/08/08 14:59:37 const
siva 2016/08/11 17:32:48 Done.
1183 intptr_t allocated_before_next_gc = limit - after.used_in_words; 1184 (static_cast<intptr_t>(after.capacity_in_words / t) -
1184 double estimated_garbage = k * allocated_before_next_gc; 1185 after.capacity_in_words) / PageSpace::kPageSizeInWords;
1185 if (t <= estimated_garbage / limit) { 1186 grow_heap_ = heap_growth_max_;
1186 break; 1187 grow_heap_ = Utils::Maximum(grow_heap_, grow_ratio);
zra 2016/08/08 14:59:37 grow_heap_ = Utils::Maximum(heap_growth_max_, grow
siva 2016/08/11 17:32:48 Done but had to introduce a static_cast as heap_gr
1188 } else {
1189 // Find minimum 'grow_heap_' such that after increasing capacity by
1190 // 'grow_heap_' pages and filling them, we expect a GC to be worthwhile.
1191 intptr_t max = heap_growth_max_;
1192 intptr_t min = 0;
1193 intptr_t adjustment = 0;
1194 // Find minimum 'grow_heap_' such that after increasing capacity by
zra 2016/08/08 14:59:37 Duplicated comment
siva 2016/08/11 17:32:48 Removed duplicate.
1195 // 'grow_heap_' pages and filling them, we expect a GC to be worthwhile.
1196 grow_heap_ = 0;
1197 while (min < max) {
1198 grow_heap_ = (max + min) / 2;
1199 intptr_t limit =
zra 2016/08/08 14:59:37 const
siva 2016/08/11 17:32:48 Done.
1200 after.capacity_in_words + (grow_heap_ * PageSpace::kPageSizeInWords);
1201 intptr_t allocated_before_next_gc = limit - after.used_in_words;
zra 2016/08/08 14:59:37 const
siva 2016/08/11 17:32:48 Done.
1202 double estimated_garbage = k * allocated_before_next_gc;
zra 2016/08/08 14:59:37 const
siva 2016/08/11 17:32:48 Done.
1203 if (t <= estimated_garbage / limit) {
1204 max = grow_heap_ - 1;
1205 adjustment = -1;
1206 } else {
1207 min = grow_heap_ + 1;
1208 adjustment = 1;
1209 }
1187 } 1210 }
1211 grow_heap_ += adjustment;
1188 } 1212 }
1189 heap_->RecordData(PageSpace::kPageGrowth, grow_heap_); 1213 heap_->RecordData(PageSpace::kPageGrowth, grow_heap_);
1190 1214
1191 // Limit shrinkage: allow growth by at least half the pages freed by GC. 1215 // Limit shrinkage: allow growth by at least half the pages freed by GC.
1192 intptr_t freed_pages = 1216 intptr_t freed_pages =
zra 2016/08/08 14:59:37 const
siva 2016/08/11 17:32:48 Done.
1193 (before.capacity_in_words - after.capacity_in_words) / 1217 (before.capacity_in_words - after.capacity_in_words) /
1194 PageSpace::kPageSizeInWords; 1218 PageSpace::kPageSizeInWords;
1195 grow_heap_ = Utils::Maximum(grow_heap_, freed_pages / 2); 1219 grow_heap_ = Utils::Maximum(grow_heap_, freed_pages / 2);
1196 heap_->RecordData(PageSpace::kAllowedGrowth, grow_heap_); 1220 heap_->RecordData(PageSpace::kAllowedGrowth, grow_heap_);
1197 last_usage_ = after; 1221 last_usage_ = after;
1198 } 1222 }
1199 1223
1200 1224
1201 void PageSpaceGarbageCollectionHistory:: 1225 void PageSpaceGarbageCollectionHistory::
1202 AddGarbageCollectionTime(int64_t start, int64_t end) { 1226 AddGarbageCollectionTime(int64_t start, int64_t end) {
(...skipping 17 matching lines...) Expand all
1220 return 0; 1244 return 0;
1221 } else { 1245 } else {
1222 ASSERT(total_time >= gc_time); 1246 ASSERT(total_time >= gc_time);
1223 int result = static_cast<int>((static_cast<double>(gc_time) / 1247 int result = static_cast<int>((static_cast<double>(gc_time) /
1224 static_cast<double>(total_time)) * 100); 1248 static_cast<double>(total_time)) * 100);
1225 return result; 1249 return result;
1226 } 1250 }
1227 } 1251 }
1228 1252
1229 } // namespace dart 1253 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698