| 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/compiler_stats.h" | 9 #include "vm/compiler_stats.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 RawObject* raw_obj = code_space_->FindObject(visitor); | 170 RawObject* raw_obj = code_space_->FindObject(visitor); |
| 171 ASSERT((raw_obj == Object::null()) || | 171 ASSERT((raw_obj == Object::null()) || |
| 172 (raw_obj->GetClassId() == kInstructionsCid)); | 172 (raw_obj->GetClassId() == kInstructionsCid)); |
| 173 return reinterpret_cast<RawInstructions*>(raw_obj); | 173 return reinterpret_cast<RawInstructions*>(raw_obj); |
| 174 } | 174 } |
| 175 | 175 |
| 176 | 176 |
| 177 void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) { | 177 void Heap::CollectGarbage(Space space, ApiCallbacks api_callbacks) { |
| 178 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 178 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
| 179 switch (space) { | 179 switch (space) { |
| 180 case kNew: | 180 case kNew: { |
| 181 new_space_->Scavenge(invoke_api_callbacks); | 181 new_space_->Scavenge(invoke_api_callbacks, |
| 182 GCReasonToString(kNewSpace)); |
| 182 if (new_space_->HadPromotionFailure()) { | 183 if (new_space_->HadPromotionFailure()) { |
| 183 old_space_->MarkSweep(true); | 184 old_space_->MarkSweep(true, |
| 185 GCReasonToString(kPromotionFailure)); |
| 184 } | 186 } |
| 185 break; | 187 break; |
| 188 } |
| 186 case kOld: | 189 case kOld: |
| 187 old_space_->MarkSweep(invoke_api_callbacks); | 190 old_space_->MarkSweep(invoke_api_callbacks, |
| 191 GCReasonToString(kOldSpace)); |
| 188 break; | 192 break; |
| 189 case kCode: | 193 case kCode: |
| 190 UNIMPLEMENTED(); | 194 UNIMPLEMENTED(); |
| 191 code_space_->MarkSweep(invoke_api_callbacks); | 195 code_space_->MarkSweep(invoke_api_callbacks, |
| 196 GCReasonToString(kCodeSpace)); |
| 192 break; | 197 break; |
| 193 default: | 198 default: |
| 194 UNREACHABLE(); | 199 UNREACHABLE(); |
| 195 } | 200 } |
| 196 if (FLAG_verbose_gc) { | 201 if (FLAG_verbose_gc) { |
| 197 PrintSizes(); | 202 PrintSizes(); |
| 198 } | 203 } |
| 199 } | 204 } |
| 200 | 205 |
| 201 | 206 |
| 202 void Heap::CollectGarbage(Space space) { | 207 void Heap::CollectGarbage(Space space) { |
| 203 ApiCallbacks api_callbacks; | 208 ApiCallbacks api_callbacks; |
| 204 if (space == kOld) { | 209 if (space == kOld) { |
| 205 api_callbacks = kInvokeApiCallbacks; | 210 api_callbacks = kInvokeApiCallbacks; |
| 206 } else { | 211 } else { |
| 207 api_callbacks = kIgnoreApiCallbacks; | 212 api_callbacks = kIgnoreApiCallbacks; |
| 208 } | 213 } |
| 209 CollectGarbage(space, api_callbacks); | 214 CollectGarbage(space, api_callbacks); |
| 210 } | 215 } |
| 211 | 216 |
| 212 | 217 |
| 213 void Heap::CollectAllGarbage() { | 218 void Heap::CollectAllGarbage() { |
| 214 new_space_->Scavenge(kInvokeApiCallbacks); | 219 const char* gc_reason = GCReasonToString(kFull); |
| 215 old_space_->MarkSweep(kInvokeApiCallbacks); | 220 new_space_->Scavenge(kInvokeApiCallbacks, gc_reason); |
| 221 old_space_->MarkSweep(kInvokeApiCallbacks, gc_reason); |
| 216 // TODO(iposva): Merge old and code space. | 222 // TODO(iposva): Merge old and code space. |
| 217 // code_space_->MarkSweep(kInvokeApiCallbacks); | 223 // code_space_->MarkSweep(kInvokeApiCallbacks, gc_reason); |
| 218 if (FLAG_verbose_gc) { | 224 if (FLAG_verbose_gc) { |
| 219 PrintSizes(); | 225 PrintSizes(); |
| 220 } | 226 } |
| 221 } | 227 } |
| 222 | 228 |
| 223 | 229 |
| 224 void Heap::EnableGrowthControl() { | 230 void Heap::EnableGrowthControl() { |
| 225 old_space_->EnableGrowthControl(); | 231 old_space_->EnableGrowthControl(); |
| 226 } | 232 } |
| 227 | 233 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 HeapProfilerWeakRootVisitor weak_root_visitor(&root_visitor); | 332 HeapProfilerWeakRootVisitor weak_root_visitor(&root_visitor); |
| 327 isolate->VisitWeakPersistentHandles(&weak_root_visitor, true); | 333 isolate->VisitWeakPersistentHandles(&weak_root_visitor, true); |
| 328 | 334 |
| 329 // Dump the current and VM isolate heaps. | 335 // Dump the current and VM isolate heaps. |
| 330 HeapProfilerObjectVisitor object_visitor(isolate, &profiler); | 336 HeapProfilerObjectVisitor object_visitor(isolate, &profiler); |
| 331 isolate->heap()->IterateObjects(&object_visitor); | 337 isolate->heap()->IterateObjects(&object_visitor); |
| 332 vm_isolate->heap()->IterateObjects(&object_visitor); | 338 vm_isolate->heap()->IterateObjects(&object_visitor); |
| 333 } | 339 } |
| 334 | 340 |
| 335 | 341 |
| 342 const char* Heap::GCReasonToString(GCReason gc_reason) { |
| 343 switch (gc_reason) { |
| 344 case kNewSpace: |
| 345 return "new space"; |
| 346 case kPromotionFailure: |
| 347 return "promotion failure"; |
| 348 case kOldSpace: |
| 349 return "old space"; |
| 350 case kCodeSpace: |
| 351 return "code space"; |
| 352 case kFull: |
| 353 return "full"; |
| 354 case kGCAtAlloc: |
| 355 return "debugging"; |
| 356 case kGCTestCase: |
| 357 return "test case"; |
| 358 default: |
| 359 UNREACHABLE(); |
| 360 return ""; |
| 361 } |
| 362 } |
| 363 |
| 364 |
| 336 #if defined(DEBUG) | 365 #if defined(DEBUG) |
| 337 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { | 366 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { |
| 338 isolate()->IncrementNoGCScopeDepth(); | 367 isolate()->IncrementNoGCScopeDepth(); |
| 339 } | 368 } |
| 340 | 369 |
| 341 | 370 |
| 342 NoGCScope::~NoGCScope() { | 371 NoGCScope::~NoGCScope() { |
| 343 isolate()->DecrementNoGCScopeDepth(); | 372 isolate()->DecrementNoGCScopeDepth(); |
| 344 } | 373 } |
| 345 #endif // defined(DEBUG) | 374 #endif // defined(DEBUG) |
| 346 | 375 |
| 347 } // namespace dart | 376 } // namespace dart |
| OLD | NEW |