| 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/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 class_table->ResetCountersNew(); | 362 class_table->ResetCountersNew(); |
| 363 } else { | 363 } else { |
| 364 class_table->ResetCountersOld(); | 364 class_table->ResetCountersOld(); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 | 368 |
| 369 void Heap::CollectNewSpaceGarbage(Thread* thread, | 369 void Heap::CollectNewSpaceGarbage(Thread* thread, |
| 370 ApiCallbacks api_callbacks, | 370 ApiCallbacks api_callbacks, |
| 371 GCReason reason) { | 371 GCReason reason) { |
| 372 ASSERT((reason == kNewSpace) || (reason == kFull)); |
| 372 if (BeginNewSpaceGC(thread)) { | 373 if (BeginNewSpaceGC(thread)) { |
| 373 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 374 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
| 374 RecordBeforeGC(kNew, reason); | 375 RecordBeforeGC(kNew, reason); |
| 375 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); | 376 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); |
| 376 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); | 377 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); |
| 377 UpdateClassHeapStatsBeforeGC(kNew); | 378 UpdateClassHeapStatsBeforeGC(kNew); |
| 378 new_space_.Scavenge(invoke_api_callbacks); | 379 new_space_.Scavenge(invoke_api_callbacks); |
| 379 isolate()->class_table()->UpdatePromoted(); | 380 isolate()->class_table()->UpdatePromoted(); |
| 380 UpdatePretenurePolicy(); | 381 UpdatePretenurePolicy(); |
| 381 RecordAfterGC(kNew); | 382 RecordAfterGC(kNew); |
| 382 PrintStats(); | 383 PrintStats(); |
| 383 EndNewSpaceGC(); | 384 EndNewSpaceGC(); |
| 384 if (old_space_.NeedsGarbageCollection()) { | 385 if ((reason == kNewSpace) && old_space_.NeedsGarbageCollection()) { |
| 385 // Old collections should call the API callbacks. | 386 // Old collections should call the API callbacks. |
| 386 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kPromotion); | 387 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kPromotion); |
| 387 } | 388 } |
| 388 } | 389 } |
| 389 } | 390 } |
| 390 | 391 |
| 391 | 392 |
| 392 void Heap::CollectOldSpaceGarbage(Thread* thread, | 393 void Heap::CollectOldSpaceGarbage(Thread* thread, |
| 393 ApiCallbacks api_callbacks, | 394 ApiCallbacks api_callbacks, |
| 394 GCReason reason) { | 395 GCReason reason) { |
| 396 ASSERT((reason != kNewSpace)); |
| 395 if (BeginOldSpaceGC(thread)) { | 397 if (BeginOldSpaceGC(thread)) { |
| 396 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | 398 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); |
| 397 RecordBeforeGC(kOld, reason); | 399 RecordBeforeGC(kOld, reason); |
| 398 VMTagScope tagScope(thread, VMTag::kGCOldSpaceTagId); | 400 VMTagScope tagScope(thread, VMTag::kGCOldSpaceTagId); |
| 399 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectOldGeneration"); | 401 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectOldGeneration"); |
| 400 UpdateClassHeapStatsBeforeGC(kOld); | 402 UpdateClassHeapStatsBeforeGC(kOld); |
| 401 old_space_.MarkSweep(invoke_api_callbacks); | 403 old_space_.MarkSweep(invoke_api_callbacks); |
| 402 RecordAfterGC(kOld); | 404 RecordAfterGC(kOld); |
| 403 PrintStats(); | 405 PrintStats(); |
| 404 EndOldSpaceGC(); | 406 EndOldSpaceGC(); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 Dart::vm_isolate()->heap()->WriteProtect(false); | 853 Dart::vm_isolate()->heap()->WriteProtect(false); |
| 852 } | 854 } |
| 853 | 855 |
| 854 | 856 |
| 855 WritableVMIsolateScope::~WritableVMIsolateScope() { | 857 WritableVMIsolateScope::~WritableVMIsolateScope() { |
| 856 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 858 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
| 857 Dart::vm_isolate()->heap()->WriteProtect(true); | 859 Dart::vm_isolate()->heap()->WriteProtect(true); |
| 858 } | 860 } |
| 859 | 861 |
| 860 } // namespace dart | 862 } // namespace dart |
| OLD | NEW |