| 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/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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 (raw_obj->GetClassId() == kInstructionsCid)); | 153 (raw_obj->GetClassId() == kInstructionsCid)); |
| 154 return reinterpret_cast<RawInstructions*>(raw_obj); | 154 return reinterpret_cast<RawInstructions*>(raw_obj); |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) { | 158 void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) { |
| 159 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 159 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
| 160 switch (space) { | 160 switch (space) { |
| 161 case kNew: { | 161 case kNew: { |
| 162 RecordBeforeGC(kNew, kNewSpace); | 162 RecordBeforeGC(kNew, kNewSpace); |
| 163 UpdateClassHeapStatsBeforeGC(kNew); |
| 163 new_space_->Scavenge(invoke_api_callbacks); | 164 new_space_->Scavenge(invoke_api_callbacks); |
| 164 RecordAfterGC(); | 165 RecordAfterGC(); |
| 165 PrintStats(); | 166 PrintStats(); |
| 166 if (new_space_->HadPromotionFailure()) { | 167 if (new_space_->HadPromotionFailure()) { |
| 167 // Old collections should call the API callbacks. | 168 // Old collections should call the API callbacks. |
| 168 CollectGarbage(kOld, kInvokeApiCallbacks); | 169 CollectGarbage(kOld, kInvokeApiCallbacks); |
| 169 } | 170 } |
| 170 break; | 171 break; |
| 171 } | 172 } |
| 172 case kOld: | 173 case kOld: |
| 173 case kCode: { | 174 case kCode: { |
| 174 bool promotion_failure = new_space_->HadPromotionFailure(); | 175 bool promotion_failure = new_space_->HadPromotionFailure(); |
| 175 RecordBeforeGC(kOld, promotion_failure ? kPromotionFailure : kOldSpace); | 176 RecordBeforeGC(kOld, promotion_failure ? kPromotionFailure : kOldSpace); |
| 177 UpdateClassHeapStatsBeforeGC(kOld); |
| 176 old_space_->MarkSweep(invoke_api_callbacks); | 178 old_space_->MarkSweep(invoke_api_callbacks); |
| 177 RecordAfterGC(); | 179 RecordAfterGC(); |
| 178 PrintStats(); | 180 PrintStats(); |
| 179 UpdateObjectHistogram(); | 181 UpdateObjectHistogram(); |
| 180 break; | 182 break; |
| 181 } | 183 } |
| 182 default: | 184 default: |
| 183 UNREACHABLE(); | 185 UNREACHABLE(); |
| 184 } | 186 } |
| 185 } | 187 } |
| 186 | 188 |
| 187 | 189 |
| 188 void Heap::UpdateObjectHistogram() { | 190 void Heap::UpdateObjectHistogram() { |
| 189 Isolate* isolate = Isolate::Current(); | 191 Isolate* isolate = Isolate::Current(); |
| 190 if (isolate->object_histogram() == NULL) return; | 192 if (isolate->object_histogram() == NULL) return; |
| 191 isolate->object_histogram()->Collect(); | 193 isolate->object_histogram()->Collect(); |
| 192 } | 194 } |
| 193 | 195 |
| 194 | 196 |
| 197 void Heap::UpdateClassHeapStatsBeforeGC(Heap::Space space) { |
| 198 Isolate* isolate = Isolate::Current(); |
| 199 ClassTable* class_table = isolate->class_table(); |
| 200 if (space == kNew) { |
| 201 class_table->ResetCountersNew(); |
| 202 } else { |
| 203 class_table->ResetCountersOld(); |
| 204 } |
| 205 } |
| 206 |
| 207 |
| 195 void Heap::CollectGarbage(Space space) { | 208 void Heap::CollectGarbage(Space space) { |
| 196 ApiCallbacks api_callbacks; | 209 ApiCallbacks api_callbacks; |
| 197 if (space == kOld) { | 210 if (space == kOld) { |
| 198 api_callbacks = kInvokeApiCallbacks; | 211 api_callbacks = kInvokeApiCallbacks; |
| 199 } else { | 212 } else { |
| 200 api_callbacks = kIgnoreApiCallbacks; | 213 api_callbacks = kIgnoreApiCallbacks; |
| 201 } | 214 } |
| 202 CollectGarbage(space, api_callbacks); | 215 CollectGarbage(space, api_callbacks); |
| 203 } | 216 } |
| 204 | 217 |
| 205 | 218 |
| 206 void Heap::CollectAllGarbage() { | 219 void Heap::CollectAllGarbage() { |
| 207 RecordBeforeGC(kNew, kFull); | 220 RecordBeforeGC(kNew, kFull); |
| 221 UpdateClassHeapStatsBeforeGC(kNew); |
| 208 new_space_->Scavenge(kInvokeApiCallbacks); | 222 new_space_->Scavenge(kInvokeApiCallbacks); |
| 209 RecordAfterGC(); | 223 RecordAfterGC(); |
| 210 PrintStats(); | 224 PrintStats(); |
| 211 RecordBeforeGC(kOld, kFull); | 225 RecordBeforeGC(kOld, kFull); |
| 226 UpdateClassHeapStatsBeforeGC(kOld); |
| 212 old_space_->MarkSweep(kInvokeApiCallbacks); | 227 old_space_->MarkSweep(kInvokeApiCallbacks); |
| 213 RecordAfterGC(); | 228 RecordAfterGC(); |
| 214 PrintStats(); | 229 PrintStats(); |
| 215 UpdateObjectHistogram(); | 230 UpdateObjectHistogram(); |
| 216 } | 231 } |
| 217 | 232 |
| 218 | 233 |
| 219 void Heap::SetGrowthControlState(bool state) { | 234 void Heap::SetGrowthControlState(bool state) { |
| 220 old_space_->SetGrowthControlState(state); | 235 old_space_->SetGrowthControlState(state); |
| 221 } | 236 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 heap->DisableGrowthControl(); | 522 heap->DisableGrowthControl(); |
| 508 } | 523 } |
| 509 | 524 |
| 510 | 525 |
| 511 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 526 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 512 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 527 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 513 heap->SetGrowthControlState(current_growth_controller_state_); | 528 heap->SetGrowthControlState(current_growth_controller_state_); |
| 514 } | 529 } |
| 515 | 530 |
| 516 } // namespace dart | 531 } // namespace dart |
| OLD | NEW |