| 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/pages.h" | 5 #include "vm/pages.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/compiler_stats.h" | 8 #include "vm/compiler_stats.h" |
| 9 #include "vm/gc_marker.h" | 9 #include "vm/gc_marker.h" |
| 10 #include "vm/gc_sweeper.h" | 10 #include "vm/gc_sweeper.h" |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 if (FLAG_log_code_drop) { | 438 if (FLAG_log_code_drop) { |
| 439 OS::Print("Trying to detach code.\n"); | 439 OS::Print("Trying to detach code.\n"); |
| 440 } | 440 } |
| 441 page_space_controller_.set_last_code_collection_in_us(start); | 441 page_space_controller_.set_last_code_collection_in_us(start); |
| 442 return true; | 442 return true; |
| 443 } | 443 } |
| 444 return false; | 444 return false; |
| 445 } | 445 } |
| 446 | 446 |
| 447 | 447 |
| 448 void PageSpace::WriteProtectCode(bool read_only) { |
| 449 // TODO(koda): Is this flag still useful? |
| 450 if (FLAG_write_protect_code) { |
| 451 HeapPage* current_page = pages_; |
| 452 while (current_page != NULL) { |
| 453 if (current_page->type() == HeapPage::kExecutable) { |
| 454 current_page->WriteProtect(read_only); |
| 455 } |
| 456 current_page = NextPageAnySize(current_page); |
| 457 } |
| 458 } |
| 459 } |
| 460 |
| 461 |
| 448 void PageSpace::MarkSweep(bool invoke_api_callbacks) { | 462 void PageSpace::MarkSweep(bool invoke_api_callbacks) { |
| 449 // MarkSweep is not reentrant. Make sure that is the case. | 463 // MarkSweep is not reentrant. Make sure that is the case. |
| 450 ASSERT(!sweeping_); | 464 ASSERT(!sweeping_); |
| 451 sweeping_ = true; | 465 sweeping_ = true; |
| 452 Isolate* isolate = Isolate::Current(); | 466 Isolate* isolate = Isolate::Current(); |
| 453 | 467 |
| 454 NoHandleScope no_handles(isolate); | 468 NoHandleScope no_handles(isolate); |
| 455 | 469 |
| 456 if (FLAG_print_free_list_before_gc) { | 470 if (FLAG_print_free_list_before_gc) { |
| 457 OS::Print("Data Freelist (before GC):\n"); | 471 OS::Print("Data Freelist (before GC):\n"); |
| 458 freelist_[HeapPage::kData].Print(); | 472 freelist_[HeapPage::kData].Print(); |
| 459 OS::Print("Executable Freelist (before GC):\n"); | 473 OS::Print("Executable Freelist (before GC):\n"); |
| 460 freelist_[HeapPage::kExecutable].Print(); | 474 freelist_[HeapPage::kExecutable].Print(); |
| 461 } | 475 } |
| 462 | 476 |
| 463 if (FLAG_verify_before_gc) { | 477 if (FLAG_verify_before_gc) { |
| 464 OS::PrintErr("Verifying before MarkSweep..."); | 478 OS::PrintErr("Verifying before MarkSweep..."); |
| 465 heap_->Verify(); | 479 heap_->Verify(); |
| 466 OS::PrintErr(" done.\n"); | 480 OS::PrintErr(" done.\n"); |
| 467 } | 481 } |
| 468 | 482 |
| 469 const int64_t start = OS::GetCurrentTimeMicros(); | 483 const int64_t start = OS::GetCurrentTimeMicros(); |
| 470 | 484 |
| 471 if (FLAG_write_protect_code) { | 485 // Make code pages writable. |
| 472 // Make code pages writable. | 486 WriteProtectCode(false); |
| 473 HeapPage* current_page = pages_; | |
| 474 while (current_page != NULL) { | |
| 475 if (current_page->type() == HeapPage::kExecutable) { | |
| 476 current_page->WriteProtect(false); | |
| 477 } | |
| 478 current_page = NextPageAnySize(current_page); | |
| 479 } | |
| 480 } | |
| 481 | 487 |
| 482 // Save old value before GCMarker visits the weak persistent handles. | 488 // Save old value before GCMarker visits the weak persistent handles. |
| 483 SpaceUsage usage_before = usage_; | 489 SpaceUsage usage_before = usage_; |
| 484 | 490 |
| 485 // Mark all reachable old-gen objects. | 491 // Mark all reachable old-gen objects. |
| 486 bool collect_code = FLAG_collect_code && ShouldCollectCode(); | 492 bool collect_code = FLAG_collect_code && ShouldCollectCode(); |
| 487 GCMarker marker(heap_); | 493 GCMarker marker(heap_); |
| 488 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code); | 494 marker.MarkObjects(isolate, this, invoke_api_callbacks, collect_code); |
| 489 usage_.used_in_words = marker.marked_words(); | 495 usage_.used_in_words = marker.marked_words(); |
| 490 | 496 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 bool page_in_use = sweeper.SweepLargePage(page); | 528 bool page_in_use = sweeper.SweepLargePage(page); |
| 523 if (page_in_use) { | 529 if (page_in_use) { |
| 524 prev_page = page; | 530 prev_page = page; |
| 525 } else { | 531 } else { |
| 526 FreeLargePage(page, prev_page); | 532 FreeLargePage(page, prev_page); |
| 527 } | 533 } |
| 528 // Advance to the next page. | 534 // Advance to the next page. |
| 529 page = next_page; | 535 page = next_page; |
| 530 } | 536 } |
| 531 | 537 |
| 532 if (FLAG_write_protect_code) { | 538 // Make code pages read-only. |
| 533 // Make code pages read-only. | 539 WriteProtectCode(true); |
| 534 HeapPage* current_page = pages_; | |
| 535 while (current_page != NULL) { | |
| 536 if (current_page->type() == HeapPage::kExecutable) { | |
| 537 current_page->WriteProtect(true); | |
| 538 } | |
| 539 current_page = NextPageAnySize(current_page); | |
| 540 } | |
| 541 } | |
| 542 | 540 |
| 543 int64_t end = OS::GetCurrentTimeMicros(); | 541 int64_t end = OS::GetCurrentTimeMicros(); |
| 544 | 542 |
| 545 // Record signals for growth control. Include size of external allocations. | 543 // Record signals for growth control. Include size of external allocations. |
| 546 page_space_controller_.EvaluateGarbageCollection(usage_before, usage_, | 544 page_space_controller_.EvaluateGarbageCollection(usage_before, usage_, |
| 547 start, end); | 545 start, end); |
| 548 | 546 |
| 549 heap_->RecordTime(kMarkObjects, mid1 - start); | 547 heap_->RecordTime(kMarkObjects, mid1 - start); |
| 550 heap_->RecordTime(kResetFreeLists, mid2 - mid1); | 548 heap_->RecordTime(kResetFreeLists, mid2 - mid1); |
| 551 heap_->RecordTime(kSweepPages, mid3 - mid2); | 549 heap_->RecordTime(kSweepPages, mid3 - mid2); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 return 0; | 682 return 0; |
| 685 } else { | 683 } else { |
| 686 ASSERT(total_time >= gc_time); | 684 ASSERT(total_time >= gc_time); |
| 687 int result= static_cast<int>((static_cast<double>(gc_time) / | 685 int result= static_cast<int>((static_cast<double>(gc_time) / |
| 688 static_cast<double>(total_time)) * 100); | 686 static_cast<double>(total_time)) * 100); |
| 689 return result; | 687 return result; |
| 690 } | 688 } |
| 691 } | 689 } |
| 692 | 690 |
| 693 } // namespace dart | 691 } // namespace dart |
| OLD | NEW |