| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 new_space_.Evacuate(); | 418 new_space_.Evacuate(); |
| 419 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); | 419 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); |
| 420 RecordAfterGC(kNew); | 420 RecordAfterGC(kNew); |
| 421 PrintStats(); | 421 PrintStats(); |
| 422 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); | 422 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); |
| 423 EndNewSpaceGC(); | 423 EndNewSpaceGC(); |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 | 426 |
| 427 void Heap::CollectNewSpaceGarbage(Thread* thread, | 427 void Heap::CollectNewSpaceGarbage(Thread* thread, |
| 428 ApiCallbacks api_callbacks, | |
| 429 GCReason reason) { | 428 GCReason reason) { |
| 430 ASSERT((reason == kNewSpace) || (reason == kFull)); | 429 ASSERT((reason == kNewSpace) || (reason == kFull)); |
| 431 if (BeginNewSpaceGC(thread)) { | 430 if (BeginNewSpaceGC(thread)) { |
| 432 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | |
| 433 RecordBeforeGC(kNew, reason); | 431 RecordBeforeGC(kNew, reason); |
| 434 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); | 432 VMTagScope tagScope(thread, VMTag::kGCNewSpaceTagId); |
| 435 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); | 433 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectNewGeneration"); |
| 436 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); | 434 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kNew)); |
| 437 new_space_.Scavenge(invoke_api_callbacks); | 435 new_space_.Scavenge(); |
| 438 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); | 436 NOT_IN_PRODUCT(isolate()->class_table()->UpdatePromoted()); |
| 439 RecordAfterGC(kNew); | 437 RecordAfterGC(kNew); |
| 440 PrintStats(); | 438 PrintStats(); |
| 441 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); | 439 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); |
| 442 EndNewSpaceGC(); | 440 EndNewSpaceGC(); |
| 443 if ((reason == kNewSpace) && old_space_.NeedsGarbageCollection()) { | 441 if ((reason == kNewSpace) && old_space_.NeedsGarbageCollection()) { |
| 444 // Old collections should call the API callbacks. | 442 // Old collections should call the API callbacks. |
| 445 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kPromotion); | 443 CollectOldSpaceGarbage(thread, kPromotion); |
| 446 } | 444 } |
| 447 } | 445 } |
| 448 } | 446 } |
| 449 | 447 |
| 450 void Heap::CollectOldSpaceGarbage(Thread* thread, | 448 void Heap::CollectOldSpaceGarbage(Thread* thread, |
| 451 ApiCallbacks api_callbacks, | |
| 452 GCReason reason) { | 449 GCReason reason) { |
| 453 ASSERT((reason != kNewSpace)); | 450 ASSERT((reason != kNewSpace)); |
| 454 if (BeginOldSpaceGC(thread)) { | 451 if (BeginOldSpaceGC(thread)) { |
| 455 bool invoke_api_callbacks = (api_callbacks == kInvokeApiCallbacks); | |
| 456 RecordBeforeGC(kOld, reason); | 452 RecordBeforeGC(kOld, reason); |
| 457 VMTagScope tagScope(thread, VMTag::kGCOldSpaceTagId); | 453 VMTagScope tagScope(thread, VMTag::kGCOldSpaceTagId); |
| 458 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectOldGeneration"); | 454 TIMELINE_FUNCTION_GC_DURATION(thread, "CollectOldGeneration"); |
| 459 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kOld)); | 455 NOT_IN_PRODUCT(UpdateClassHeapStatsBeforeGC(kOld)); |
| 460 old_space_.MarkSweep(invoke_api_callbacks); | 456 old_space_.MarkSweep(); |
| 461 RecordAfterGC(kOld); | 457 RecordAfterGC(kOld); |
| 462 PrintStats(); | 458 PrintStats(); |
| 463 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); | 459 NOT_IN_PRODUCT(PrintStatsToTimeline(&tds)); |
| 464 // Some Code objects may have been collected so invalidate handler cache. | 460 // Some Code objects may have been collected so invalidate handler cache. |
| 465 thread->isolate()->handler_info_cache()->Clear(); | 461 thread->isolate()->handler_info_cache()->Clear(); |
| 466 thread->isolate()->catch_entry_state_cache()->Clear(); | 462 thread->isolate()->catch_entry_state_cache()->Clear(); |
| 467 EndOldSpaceGC(); | 463 EndOldSpaceGC(); |
| 468 } | 464 } |
| 469 } | 465 } |
| 470 | 466 |
| 471 void Heap::CollectGarbage(Space space, | 467 void Heap::CollectGarbage(Space space, |
| 472 ApiCallbacks api_callbacks, | |
| 473 GCReason reason) { | 468 GCReason reason) { |
| 474 Thread* thread = Thread::Current(); | 469 Thread* thread = Thread::Current(); |
| 475 switch (space) { | 470 switch (space) { |
| 476 case kNew: { | 471 case kNew: { |
| 477 CollectNewSpaceGarbage(thread, api_callbacks, reason); | 472 CollectNewSpaceGarbage(thread, reason); |
| 478 break; | 473 break; |
| 479 } | 474 } |
| 480 case kOld: | 475 case kOld: |
| 481 case kCode: { | 476 case kCode: { |
| 482 CollectOldSpaceGarbage(thread, api_callbacks, reason); | 477 CollectOldSpaceGarbage(thread, reason); |
| 483 break; | 478 break; |
| 484 } | 479 } |
| 485 default: | 480 default: |
| 486 UNREACHABLE(); | 481 UNREACHABLE(); |
| 487 } | 482 } |
| 488 } | 483 } |
| 489 | 484 |
| 490 void Heap::CollectGarbage(Space space) { | 485 void Heap::CollectGarbage(Space space) { |
| 491 Thread* thread = Thread::Current(); | 486 Thread* thread = Thread::Current(); |
| 492 if (space == kOld) { | 487 if (space == kOld) { |
| 493 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kOldSpace); | 488 CollectOldSpaceGarbage(thread, kOldSpace); |
| 494 } else { | 489 } else { |
| 495 ASSERT(space == kNew); | 490 ASSERT(space == kNew); |
| 496 CollectNewSpaceGarbage(thread, kInvokeApiCallbacks, kNewSpace); | 491 CollectNewSpaceGarbage(thread, kNewSpace); |
| 497 } | 492 } |
| 498 } | 493 } |
| 499 | 494 |
| 500 void Heap::CollectAllGarbage() { | 495 void Heap::CollectAllGarbage() { |
| 501 Thread* thread = Thread::Current(); | 496 Thread* thread = Thread::Current(); |
| 502 | 497 |
| 503 // New space is evacuated so this GC will collect all dead objects | 498 // New space is evacuated so this GC will collect all dead objects |
| 504 // kept alive by a cross-generational pointer. | 499 // kept alive by a cross-generational pointer. |
| 505 EvacuateNewSpace(thread, kFull); | 500 EvacuateNewSpace(thread, kFull); |
| 506 CollectOldSpaceGarbage(thread, kInvokeApiCallbacks, kFull); | 501 CollectOldSpaceGarbage(thread, kFull); |
| 507 } | 502 } |
| 508 | 503 |
| 509 void Heap::WaitForSweeperTasks(Thread* thread) { | 504 void Heap::WaitForSweeperTasks(Thread* thread) { |
| 510 MonitorLocker ml(old_space_.tasks_lock()); | 505 MonitorLocker ml(old_space_.tasks_lock()); |
| 511 while (old_space_.tasks() > 0) { | 506 while (old_space_.tasks() > 0) { |
| 512 ml.WaitWithSafepointCheck(thread); | 507 ml.WaitWithSafepointCheck(thread); |
| 513 } | 508 } |
| 514 } | 509 } |
| 515 | 510 |
| 516 void Heap::UpdateGlobalMaxUsed() { | 511 void Heap::UpdateGlobalMaxUsed() { |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 : StackResource(thread) { | 894 : StackResource(thread) { |
| 900 Dart::vm_isolate()->heap()->WriteProtect(false); | 895 Dart::vm_isolate()->heap()->WriteProtect(false); |
| 901 } | 896 } |
| 902 | 897 |
| 903 WritableVMIsolateScope::~WritableVMIsolateScope() { | 898 WritableVMIsolateScope::~WritableVMIsolateScope() { |
| 904 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 899 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
| 905 Dart::vm_isolate()->heap()->WriteProtect(true); | 900 Dart::vm_isolate()->heap()->WriteProtect(true); |
| 906 } | 901 } |
| 907 | 902 |
| 908 } // namespace dart | 903 } // namespace dart |
| OLD | NEW |