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

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

Issue 51653006: Track live instance and allocation counts for classes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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
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/heap.h" 5 #include "vm/heap.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/flags.h" 9 #include "vm/flags.h"
10 #include "vm/heap_histogram.h" 10 #include "vm/heap_histogram.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 RawObject* Heap::FindOldObject(FindObjectVisitor* visitor) const { 158 RawObject* Heap::FindOldObject(FindObjectVisitor* visitor) const {
159 return old_space_->FindObject(visitor, HeapPage::kData); 159 return old_space_->FindObject(visitor, HeapPage::kData);
160 } 160 }
161 161
162 162
163 void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) { 163 void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) {
164 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); 164 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks);
165 switch (space) { 165 switch (space) {
166 case kNew: { 166 case kNew: {
167 RecordBeforeGC(kNew, kNewSpace); 167 RecordBeforeGC(kNew, kNewSpace);
168 UpdateClassHeapStatsBeforeGC(kNew);
168 new_space_->Scavenge(invoke_api_callbacks); 169 new_space_->Scavenge(invoke_api_callbacks);
169 RecordAfterGC(); 170 RecordAfterGC();
170 PrintStats(); 171 PrintStats();
171 if (new_space_->HadPromotionFailure()) { 172 if (new_space_->HadPromotionFailure()) {
172 // Old collections should call the API callbacks. 173 // Old collections should call the API callbacks.
173 CollectGarbage(kOld, kInvokeApiCallbacks); 174 CollectGarbage(kOld, kInvokeApiCallbacks);
174 } 175 }
175 break; 176 break;
176 } 177 }
177 case kOld: 178 case kOld:
178 case kCode: { 179 case kCode: {
179 bool promotion_failure = new_space_->HadPromotionFailure(); 180 bool promotion_failure = new_space_->HadPromotionFailure();
180 RecordBeforeGC(kOld, promotion_failure ? kPromotionFailure : kOldSpace); 181 RecordBeforeGC(kOld, promotion_failure ? kPromotionFailure : kOldSpace);
182 UpdateClassHeapStatsBeforeGC(kOld);
181 old_space_->MarkSweep(invoke_api_callbacks); 183 old_space_->MarkSweep(invoke_api_callbacks);
182 RecordAfterGC(); 184 RecordAfterGC();
183 PrintStats(); 185 PrintStats();
184 UpdateObjectHistogram(); 186 UpdateObjectHistogram();
185 break; 187 break;
186 } 188 }
187 default: 189 default:
188 UNREACHABLE(); 190 UNREACHABLE();
189 } 191 }
190 } 192 }
191 193
192 194
193 void Heap::UpdateObjectHistogram() { 195 void Heap::UpdateObjectHistogram() {
194 Isolate* isolate = Isolate::Current(); 196 Isolate* isolate = Isolate::Current();
195 if (isolate->object_histogram() == NULL) return; 197 if (isolate->object_histogram() == NULL) return;
196 isolate->object_histogram()->Collect(); 198 isolate->object_histogram()->Collect();
197 } 199 }
198 200
199 201
202 void Heap::UpdateClassHeapStatsBeforeGC(Heap::Space space) {
203 Isolate* isolate = Isolate::Current();
204 ClassTable* class_table = isolate->class_table();
205 if (space == kNew) {
206 class_table->ResetCountersNew();
207 } else {
208 class_table->ResetCountersOld();
209 }
210 }
211
212
200 void Heap::CollectGarbage(Space space) { 213 void Heap::CollectGarbage(Space space) {
201 ApiCallbacks api_callbacks; 214 ApiCallbacks api_callbacks;
202 if (space == kOld) { 215 if (space == kOld) {
203 api_callbacks = kInvokeApiCallbacks; 216 api_callbacks = kInvokeApiCallbacks;
204 } else { 217 } else {
205 api_callbacks = kIgnoreApiCallbacks; 218 api_callbacks = kIgnoreApiCallbacks;
206 } 219 }
207 CollectGarbage(space, api_callbacks); 220 CollectGarbage(space, api_callbacks);
208 } 221 }
209 222
210 223
211 void Heap::CollectAllGarbage() { 224 void Heap::CollectAllGarbage() {
212 RecordBeforeGC(kNew, kFull); 225 RecordBeforeGC(kNew, kFull);
226 UpdateClassHeapStatsBeforeGC(kNew);
213 new_space_->Scavenge(kInvokeApiCallbacks); 227 new_space_->Scavenge(kInvokeApiCallbacks);
214 RecordAfterGC(); 228 RecordAfterGC();
215 PrintStats(); 229 PrintStats();
216 RecordBeforeGC(kOld, kFull); 230 RecordBeforeGC(kOld, kFull);
231 UpdateClassHeapStatsBeforeGC(kOld);
217 old_space_->MarkSweep(kInvokeApiCallbacks); 232 old_space_->MarkSweep(kInvokeApiCallbacks);
218 RecordAfterGC(); 233 RecordAfterGC();
219 PrintStats(); 234 PrintStats();
220 UpdateObjectHistogram(); 235 UpdateObjectHistogram();
221 } 236 }
222 237
223 238
224 void Heap::SetGrowthControlState(bool state) { 239 void Heap::SetGrowthControlState(bool state) {
225 old_space_->SetGrowthControlState(state); 240 old_space_->SetGrowthControlState(state);
226 } 241 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 return space == kNew ? new_space_->UsedInWords() : old_space_->UsedInWords(); 329 return space == kNew ? new_space_->UsedInWords() : old_space_->UsedInWords();
315 } 330 }
316 331
317 332
318 intptr_t Heap::CapacityInWords(Space space) const { 333 intptr_t Heap::CapacityInWords(Space space) const {
319 return space == kNew ? new_space_->CapacityInWords() : 334 return space == kNew ? new_space_->CapacityInWords() :
320 old_space_->CapacityInWords(); 335 old_space_->CapacityInWords();
321 } 336 }
322 337
323 338
339 int64_t Heap::GCTimeInMicros(Space space) const {
340 if (space == kNew) {
341 return new_space_->gc_time_micros();
342 }
343 return old_space_->gc_time_micros();
344 }
345
346
347 double Heap::GCTimeInSeconds(Space space) const {
348 int64_t micros = 0;
349 if (space == kNew) {
350 micros = new_space_->gc_time_micros();
351 } else {
352 micros = old_space_->gc_time_micros();
353 }
354 double seconds = static_cast<double>(micros) /
Ivan Posva 2014/01/17 06:53:16 RoundMicrosecondsToSeconds
Cutch 2014/01/17 18:37:59 Done.
355 static_cast<double>(kMicrosecondsPerSecond);
356 return seconds;
357 }
358
359
360 intptr_t Heap::Collections(Space space) const {
361 if (space == kNew) {
362 return new_space_->collections();
363 }
364 return old_space_->collections();
365 }
366
367
324 void Heap::Profile(Dart_FileWriteCallback callback, void* stream) const { 368 void Heap::Profile(Dart_FileWriteCallback callback, void* stream) const {
325 HeapProfiler profiler(callback, stream); 369 HeapProfiler profiler(callback, stream);
326 370
327 // Dump the root set. 371 // Dump the root set.
328 HeapProfilerRootVisitor root_visitor(&profiler); 372 HeapProfilerRootVisitor root_visitor(&profiler);
329 Isolate* isolate = Isolate::Current(); 373 Isolate* isolate = Isolate::Current();
330 Isolate* vm_isolate = Dart::vm_isolate(); 374 Isolate* vm_isolate = Dart::vm_isolate();
331 isolate->VisitObjectPointers(&root_visitor, false, 375 isolate->VisitObjectPointers(&root_visitor, false,
332 StackFrameIterator::kDontValidateFrames); 376 StackFrameIterator::kDontValidateFrames);
333 HeapProfilerWeakRootVisitor weak_root_visitor(&root_visitor); 377 HeapProfilerWeakRootVisitor weak_root_visitor(&root_visitor);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 stats_.times_[3] = 0; 472 stats_.times_[3] = 0;
429 stats_.data_[0] = 0; 473 stats_.data_[0] = 0;
430 stats_.data_[1] = 0; 474 stats_.data_[1] = 0;
431 stats_.data_[2] = 0; 475 stats_.data_[2] = 0;
432 stats_.data_[3] = 0; 476 stats_.data_[3] = 0;
433 } 477 }
434 478
435 479
436 void Heap::RecordAfterGC() { 480 void Heap::RecordAfterGC() {
437 stats_.after_.micros_ = OS::GetCurrentTimeMicros(); 481 stats_.after_.micros_ = OS::GetCurrentTimeMicros();
482 int64_t delta = stats_.after_.micros_ - stats_.before_.micros_;
483 if (stats_.space_ == kNew) {
484 new_space_->AddGCTime(delta);
485 new_space_->IncrementCollections();
486 } else {
487 old_space_->AddGCTime(delta);
488 old_space_->IncrementCollections();
489 }
438 stats_.after_.new_used_in_words_ = new_space_->UsedInWords(); 490 stats_.after_.new_used_in_words_ = new_space_->UsedInWords();
439 stats_.after_.new_capacity_in_words_ = new_space_->CapacityInWords(); 491 stats_.after_.new_capacity_in_words_ = new_space_->CapacityInWords();
440 stats_.after_.old_used_in_words_ = old_space_->UsedInWords(); 492 stats_.after_.old_used_in_words_ = old_space_->UsedInWords();
441 stats_.after_.old_capacity_in_words_ = old_space_->CapacityInWords(); 493 stats_.after_.old_capacity_in_words_ = old_space_->CapacityInWords();
442 ASSERT(gc_in_progress_); 494 ASSERT(gc_in_progress_);
443 gc_in_progress_ = false; 495 gc_in_progress_ = false;
444 } 496 }
445 497
446 498
447 void Heap::PrintStats() { 499 void Heap::PrintStats() {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 heap->DisableGrowthControl(); 564 heap->DisableGrowthControl();
513 } 565 }
514 566
515 567
516 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { 568 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() {
517 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); 569 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap();
518 heap->SetGrowthControlState(current_growth_controller_state_); 570 heap->SetGrowthControlState(current_growth_controller_state_);
519 } 571 }
520 572
521 } // namespace dart 573 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698