| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 | 536 |
| 537 | 537 |
| 538 void MarkCompactCollector::WaitUntilSweepingCompleted() { | 538 void MarkCompactCollector::WaitUntilSweepingCompleted() { |
| 539 if (sweeping_pending_) { | 539 if (sweeping_pending_) { |
| 540 for (int i = 0; i < FLAG_sweeper_threads; i++) { | 540 for (int i = 0; i < FLAG_sweeper_threads; i++) { |
| 541 heap()->isolate()->sweeper_threads()[i]->WaitForSweeperThread(); | 541 heap()->isolate()->sweeper_threads()[i]->WaitForSweeperThread(); |
| 542 } | 542 } |
| 543 sweeping_pending_ = false; | 543 sweeping_pending_ = false; |
| 544 StealMemoryFromSweeperThreads(heap()->paged_space(OLD_DATA_SPACE)); | 544 StealMemoryFromSweeperThreads(heap()->paged_space(OLD_DATA_SPACE)); |
| 545 StealMemoryFromSweeperThreads(heap()->paged_space(OLD_POINTER_SPACE)); | 545 StealMemoryFromSweeperThreads(heap()->paged_space(OLD_POINTER_SPACE)); |
| 546 heap()->FreeQueuedChunks(); | |
| 547 } | 546 } |
| 548 } | 547 } |
| 549 | 548 |
| 550 | 549 |
| 551 intptr_t MarkCompactCollector:: | 550 intptr_t MarkCompactCollector:: |
| 552 StealMemoryFromSweeperThreads(PagedSpace* space) { | 551 StealMemoryFromSweeperThreads(PagedSpace* space) { |
| 553 intptr_t freed_bytes = 0; | 552 intptr_t freed_bytes = 0; |
| 554 for (int i = 0; i < FLAG_sweeper_threads; i++) { | 553 for (int i = 0; i < FLAG_sweeper_threads; i++) { |
| 555 freed_bytes += heap()->isolate()->sweeper_threads()[i]->StealMemory(space); | 554 freed_bytes += heap()->isolate()->sweeper_threads()[i]->StealMemory(space); |
| 556 } | 555 } |
| 557 return freed_bytes; | 556 return freed_bytes; |
| 558 } | 557 } |
| 559 | 558 |
| 560 | 559 |
| 561 bool MarkCompactCollector::AreSweeperThreadsActivated() { | 560 bool MarkCompactCollector::AreSweeperThreadsActivated() { |
| 562 return heap()->isolate()->sweeper_threads() != NULL; | 561 return heap()->isolate()->sweeper_threads() != NULL; |
| 563 } | 562 } |
| 564 | 563 |
| 565 | 564 |
| 566 bool MarkCompactCollector::IsConcurrentSweepingInProgress() { | 565 bool MarkCompactCollector::IsConcurrentSweepingInProgress() { |
| 567 return sweeping_pending_; | 566 return sweeping_pending_; |
| 568 } | 567 } |
| 569 | 568 |
| 570 | 569 |
| 570 void MarkCompactCollector::FinalizeSweeping() { |
| 571 ASSERT(sweeping_pending_ == false); |
| 572 ReleaseEvacuationCandidates(); |
| 573 heap()->FreeQueuedChunks(); |
| 574 } |
| 575 |
| 576 |
| 571 void MarkCompactCollector::MarkInParallel() { | 577 void MarkCompactCollector::MarkInParallel() { |
| 572 for (int i = 0; i < FLAG_marking_threads; i++) { | 578 for (int i = 0; i < FLAG_marking_threads; i++) { |
| 573 heap()->isolate()->marking_threads()[i]->StartMarking(); | 579 heap()->isolate()->marking_threads()[i]->StartMarking(); |
| 574 } | 580 } |
| 575 } | 581 } |
| 576 | 582 |
| 577 | 583 |
| 578 void MarkCompactCollector::WaitUntilMarkingCompleted() { | 584 void MarkCompactCollector::WaitUntilMarkingCompleted() { |
| 579 for (int i = 0; i < FLAG_marking_threads; i++) { | 585 for (int i = 0; i < FLAG_marking_threads; i++) { |
| 580 heap()->isolate()->marking_threads()[i]->WaitForMarkingThread(); | 586 heap()->isolate()->marking_threads()[i]->WaitForMarkingThread(); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 #ifdef DEBUG | 886 #ifdef DEBUG |
| 881 ASSERT(state_ == IDLE); | 887 ASSERT(state_ == IDLE); |
| 882 state_ = PREPARE_GC; | 888 state_ = PREPARE_GC; |
| 883 #endif | 889 #endif |
| 884 | 890 |
| 885 ASSERT(!FLAG_never_compact || !FLAG_always_compact); | 891 ASSERT(!FLAG_never_compact || !FLAG_always_compact); |
| 886 | 892 |
| 887 if (AreSweeperThreadsActivated() && FLAG_concurrent_sweeping) { | 893 if (AreSweeperThreadsActivated() && FLAG_concurrent_sweeping) { |
| 888 // Instead of waiting we could also abort the sweeper threads here. | 894 // Instead of waiting we could also abort the sweeper threads here. |
| 889 WaitUntilSweepingCompleted(); | 895 WaitUntilSweepingCompleted(); |
| 896 FinalizeSweeping(); |
| 890 } | 897 } |
| 891 | 898 |
| 892 // Clear marking bits if incremental marking is aborted. | 899 // Clear marking bits if incremental marking is aborted. |
| 893 if (was_marked_incrementally_ && abort_incremental_marking_) { | 900 if (was_marked_incrementally_ && abort_incremental_marking_) { |
| 894 heap()->incremental_marking()->Abort(); | 901 heap()->incremental_marking()->Abort(); |
| 895 ClearMarkbits(); | 902 ClearMarkbits(); |
| 896 AbortCompaction(); | 903 AbortCompaction(); |
| 897 was_marked_incrementally_ = false; | 904 was_marked_incrementally_ = false; |
| 898 } | 905 } |
| 899 | 906 |
| (...skipping 2373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3273 heap_->isolate()->inner_pointer_to_code_cache()->Flush(); | 3280 heap_->isolate()->inner_pointer_to_code_cache()->Flush(); |
| 3274 | 3281 |
| 3275 #ifdef VERIFY_HEAP | 3282 #ifdef VERIFY_HEAP |
| 3276 if (FLAG_verify_heap) { | 3283 if (FLAG_verify_heap) { |
| 3277 VerifyEvacuation(heap_); | 3284 VerifyEvacuation(heap_); |
| 3278 } | 3285 } |
| 3279 #endif | 3286 #endif |
| 3280 | 3287 |
| 3281 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_); | 3288 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_); |
| 3282 ASSERT(migration_slots_buffer_ == NULL); | 3289 ASSERT(migration_slots_buffer_ == NULL); |
| 3290 } |
| 3291 |
| 3292 |
| 3293 void MarkCompactCollector::ReleaseEvacuationCandidates() { |
| 3294 int npages = evacuation_candidates_.length(); |
| 3283 for (int i = 0; i < npages; i++) { | 3295 for (int i = 0; i < npages; i++) { |
| 3284 Page* p = evacuation_candidates_[i]; | 3296 Page* p = evacuation_candidates_[i]; |
| 3285 if (!p->IsEvacuationCandidate()) continue; | 3297 if (!p->IsEvacuationCandidate()) continue; |
| 3286 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); | 3298 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); |
| 3287 space->Free(p->area_start(), p->area_size()); | 3299 space->Free(p->area_start(), p->area_size()); |
| 3288 p->set_scan_on_scavenge(false); | 3300 p->set_scan_on_scavenge(false); |
| 3289 slots_buffer_allocator_.DeallocateChain(p->slots_buffer_address()); | 3301 slots_buffer_allocator_.DeallocateChain(p->slots_buffer_address()); |
| 3290 p->ResetLiveBytes(); | 3302 p->ResetLiveBytes(); |
| 3291 space->ReleasePage(p); | 3303 space->ReleasePage(p); |
| 3292 } | 3304 } |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3717 SweepConservatively<SWEEP_IN_PARALLEL>(space, private_free_list, p); | 3729 SweepConservatively<SWEEP_IN_PARALLEL>(space, private_free_list, p); |
| 3718 free_list->Concatenate(private_free_list); | 3730 free_list->Concatenate(private_free_list); |
| 3719 } | 3731 } |
| 3720 } | 3732 } |
| 3721 } | 3733 } |
| 3722 | 3734 |
| 3723 | 3735 |
| 3724 void MarkCompactCollector::SweepSpace(PagedSpace* space, SweeperType sweeper) { | 3736 void MarkCompactCollector::SweepSpace(PagedSpace* space, SweeperType sweeper) { |
| 3725 space->set_was_swept_conservatively(sweeper == CONSERVATIVE || | 3737 space->set_was_swept_conservatively(sweeper == CONSERVATIVE || |
| 3726 sweeper == LAZY_CONSERVATIVE || | 3738 sweeper == LAZY_CONSERVATIVE || |
| 3727 sweeper == PARALLEL_CONSERVATIVE); | 3739 sweeper == PARALLEL_CONSERVATIVE || |
| 3740 sweeper == CONCURRENT_CONSERVATIVE); |
| 3728 space->ClearStats(); | 3741 space->ClearStats(); |
| 3729 | 3742 |
| 3730 PageIterator it(space); | 3743 PageIterator it(space); |
| 3731 | 3744 |
| 3732 intptr_t freed_bytes = 0; | 3745 intptr_t freed_bytes = 0; |
| 3733 int pages_swept = 0; | 3746 int pages_swept = 0; |
| 3734 bool lazy_sweeping_active = false; | 3747 bool lazy_sweeping_active = false; |
| 3735 bool unused_page_present = false; | 3748 bool unused_page_present = false; |
| 3736 | 3749 |
| 3737 while (it.has_next()) { | 3750 while (it.has_next()) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3791 if (FLAG_gc_verbose) { | 3804 if (FLAG_gc_verbose) { |
| 3792 PrintF("Sweeping 0x%" V8PRIxPTR " conservatively as needed.\n", | 3805 PrintF("Sweeping 0x%" V8PRIxPTR " conservatively as needed.\n", |
| 3793 reinterpret_cast<intptr_t>(p)); | 3806 reinterpret_cast<intptr_t>(p)); |
| 3794 } | 3807 } |
| 3795 freed_bytes += SweepConservatively<SWEEP_SEQUENTIALLY>(space, NULL, p); | 3808 freed_bytes += SweepConservatively<SWEEP_SEQUENTIALLY>(space, NULL, p); |
| 3796 pages_swept++; | 3809 pages_swept++; |
| 3797 space->SetPagesToSweep(p->next_page()); | 3810 space->SetPagesToSweep(p->next_page()); |
| 3798 lazy_sweeping_active = true; | 3811 lazy_sweeping_active = true; |
| 3799 break; | 3812 break; |
| 3800 } | 3813 } |
| 3814 case CONCURRENT_CONSERVATIVE: |
| 3801 case PARALLEL_CONSERVATIVE: { | 3815 case PARALLEL_CONSERVATIVE: { |
| 3802 if (FLAG_gc_verbose) { | 3816 if (FLAG_gc_verbose) { |
| 3803 PrintF("Sweeping 0x%" V8PRIxPTR " conservatively in parallel.\n", | 3817 PrintF("Sweeping 0x%" V8PRIxPTR " conservatively in parallel.\n", |
| 3804 reinterpret_cast<intptr_t>(p)); | 3818 reinterpret_cast<intptr_t>(p)); |
| 3805 } | 3819 } |
| 3806 p->set_parallel_sweeping(1); | 3820 p->set_parallel_sweeping(1); |
| 3807 break; | 3821 break; |
| 3808 } | 3822 } |
| 3809 case PRECISE: { | 3823 case PRECISE: { |
| 3810 if (FLAG_gc_verbose) { | 3824 if (FLAG_gc_verbose) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3836 } | 3850 } |
| 3837 | 3851 |
| 3838 | 3852 |
| 3839 void MarkCompactCollector::SweepSpaces() { | 3853 void MarkCompactCollector::SweepSpaces() { |
| 3840 GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_SWEEP); | 3854 GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_SWEEP); |
| 3841 #ifdef DEBUG | 3855 #ifdef DEBUG |
| 3842 state_ = SWEEP_SPACES; | 3856 state_ = SWEEP_SPACES; |
| 3843 #endif | 3857 #endif |
| 3844 SweeperType how_to_sweep = | 3858 SweeperType how_to_sweep = |
| 3845 FLAG_lazy_sweeping ? LAZY_CONSERVATIVE : CONSERVATIVE; | 3859 FLAG_lazy_sweeping ? LAZY_CONSERVATIVE : CONSERVATIVE; |
| 3846 if (AreSweeperThreadsActivated()) how_to_sweep = PARALLEL_CONSERVATIVE; | 3860 if (FLAG_parallel_sweeping) how_to_sweep = PARALLEL_CONSERVATIVE; |
| 3861 if (FLAG_concurrent_sweeping) how_to_sweep = CONCURRENT_CONSERVATIVE; |
| 3847 if (FLAG_expose_gc) how_to_sweep = CONSERVATIVE; | 3862 if (FLAG_expose_gc) how_to_sweep = CONSERVATIVE; |
| 3848 if (sweep_precisely_) how_to_sweep = PRECISE; | 3863 if (sweep_precisely_) how_to_sweep = PRECISE; |
| 3849 // Noncompacting collections simply sweep the spaces to clear the mark | 3864 // Noncompacting collections simply sweep the spaces to clear the mark |
| 3850 // bits and free the nonlive blocks (for old and map spaces). We sweep | 3865 // bits and free the nonlive blocks (for old and map spaces). We sweep |
| 3851 // the map space last because freeing non-live maps overwrites them and | 3866 // the map space last because freeing non-live maps overwrites them and |
| 3852 // the other spaces rely on possibly non-live maps to get the sizes for | 3867 // the other spaces rely on possibly non-live maps to get the sizes for |
| 3853 // non-live objects. | 3868 // non-live objects. |
| 3854 | 3869 |
| 3855 SweepSpace(heap()->old_pointer_space(), how_to_sweep); | 3870 SweepSpace(heap()->old_pointer_space(), how_to_sweep); |
| 3856 SweepSpace(heap()->old_data_space(), how_to_sweep); | 3871 SweepSpace(heap()->old_data_space(), how_to_sweep); |
| 3857 | 3872 |
| 3858 if (how_to_sweep == PARALLEL_CONSERVATIVE) { | 3873 if (how_to_sweep == PARALLEL_CONSERVATIVE || |
| 3874 how_to_sweep == CONCURRENT_CONSERVATIVE) { |
| 3859 // TODO(hpayer): fix race with concurrent sweeper | 3875 // TODO(hpayer): fix race with concurrent sweeper |
| 3860 StartSweeperThreads(); | 3876 StartSweeperThreads(); |
| 3861 if (FLAG_parallel_sweeping && !FLAG_concurrent_sweeping) { | 3877 } |
| 3862 WaitUntilSweepingCompleted(); | 3878 |
| 3863 } | 3879 if (how_to_sweep == PARALLEL_CONSERVATIVE) { |
| 3880 WaitUntilSweepingCompleted(); |
| 3864 } | 3881 } |
| 3865 | 3882 |
| 3866 RemoveDeadInvalidatedCode(); | 3883 RemoveDeadInvalidatedCode(); |
| 3867 SweepSpace(heap()->code_space(), PRECISE); | 3884 SweepSpace(heap()->code_space(), PRECISE); |
| 3868 | 3885 |
| 3869 SweepSpace(heap()->cell_space(), PRECISE); | 3886 SweepSpace(heap()->cell_space(), PRECISE); |
| 3870 | 3887 |
| 3871 EvacuateNewSpaceAndCandidates(); | 3888 EvacuateNewSpaceAndCandidates(); |
| 3872 | 3889 |
| 3873 // ClearNonLiveTransitions depends on precise sweeping of map space to | 3890 // ClearNonLiveTransitions depends on precise sweeping of map space to |
| 3874 // detect whether unmarked map became dead in this collection or in one | 3891 // detect whether unmarked map became dead in this collection or in one |
| 3875 // of the previous ones. | 3892 // of the previous ones. |
| 3876 SweepSpace(heap()->map_space(), PRECISE); | 3893 SweepSpace(heap()->map_space(), PRECISE); |
| 3877 | 3894 |
| 3878 // Deallocate unmarked objects and clear marked bits for marked objects. | 3895 // Deallocate unmarked objects and clear marked bits for marked objects. |
| 3879 heap_->lo_space()->FreeUnmarkedObjects(); | 3896 heap_->lo_space()->FreeUnmarkedObjects(); |
| 3897 |
| 3898 if (how_to_sweep != CONCURRENT_CONSERVATIVE) { |
| 3899 FinalizeSweeping(); |
| 3900 } |
| 3880 } | 3901 } |
| 3881 | 3902 |
| 3882 | 3903 |
| 3883 void MarkCompactCollector::EnableCodeFlushing(bool enable) { | 3904 void MarkCompactCollector::EnableCodeFlushing(bool enable) { |
| 3884 #ifdef ENABLE_DEBUGGER_SUPPORT | 3905 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 3885 if (heap()->isolate()->debug()->IsLoaded() || | 3906 if (heap()->isolate()->debug()->IsLoaded() || |
| 3886 heap()->isolate()->debug()->has_break_points()) { | 3907 heap()->isolate()->debug()->has_break_points()) { |
| 3887 enable = false; | 3908 enable = false; |
| 3888 } | 3909 } |
| 3889 #endif | 3910 #endif |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4070 while (buffer != NULL) { | 4091 while (buffer != NULL) { |
| 4071 SlotsBuffer* next_buffer = buffer->next(); | 4092 SlotsBuffer* next_buffer = buffer->next(); |
| 4072 DeallocateBuffer(buffer); | 4093 DeallocateBuffer(buffer); |
| 4073 buffer = next_buffer; | 4094 buffer = next_buffer; |
| 4074 } | 4095 } |
| 4075 *buffer_address = NULL; | 4096 *buffer_address = NULL; |
| 4076 } | 4097 } |
| 4077 | 4098 |
| 4078 | 4099 |
| 4079 } } // namespace v8::internal | 4100 } } // namespace v8::internal |
| OLD | NEW |