OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/heap/mark-compact.h" | 5 #include "src/heap/mark-compact.h" |
6 | 6 |
7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/base/sys-info.h" | 9 #include "src/base/sys-info.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 234 } |
235 #endif // VERIFY_HEAP | 235 #endif // VERIFY_HEAP |
236 | 236 |
237 | 237 |
238 void MarkCompactCollector::SetUp() { | 238 void MarkCompactCollector::SetUp() { |
239 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0); | 239 DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0); |
240 DCHECK(strcmp(Marking::kBlackBitPattern, "11") == 0); | 240 DCHECK(strcmp(Marking::kBlackBitPattern, "11") == 0); |
241 DCHECK(strcmp(Marking::kGreyBitPattern, "10") == 0); | 241 DCHECK(strcmp(Marking::kGreyBitPattern, "10") == 0); |
242 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0); | 242 DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0); |
243 | 243 |
244 free_list_old_space_.Reset(new FreeList(heap_->old_space())); | |
245 free_list_code_space_.Reset(new FreeList(heap_->code_space())); | |
246 free_list_map_space_.Reset(new FreeList(heap_->map_space())); | |
247 EnsureMarkingDequeIsReserved(); | 244 EnsureMarkingDequeIsReserved(); |
248 EnsureMarkingDequeIsCommitted(kMinMarkingDequeSize); | 245 EnsureMarkingDequeIsCommitted(kMinMarkingDequeSize); |
249 | 246 |
250 if (FLAG_flush_code) { | 247 if (FLAG_flush_code) { |
251 code_flusher_ = new CodeFlusher(isolate()); | 248 code_flusher_ = new CodeFlusher(isolate()); |
252 if (FLAG_trace_code_flushing) { | 249 if (FLAG_trace_code_flushing) { |
253 PrintF("[code-flushing is now on]\n"); | 250 PrintF("[code-flushing is now on]\n"); |
254 } | 251 } |
255 } | 252 } |
256 } | 253 } |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 } | 465 } |
469 | 466 |
470 Heap* heap_; | 467 Heap* heap_; |
471 AllocationSpace space_to_start_; | 468 AllocationSpace space_to_start_; |
472 | 469 |
473 DISALLOW_COPY_AND_ASSIGN(SweeperTask); | 470 DISALLOW_COPY_AND_ASSIGN(SweeperTask); |
474 }; | 471 }; |
475 | 472 |
476 | 473 |
477 void MarkCompactCollector::StartSweeperThreads() { | 474 void MarkCompactCollector::StartSweeperThreads() { |
478 DCHECK(free_list_old_space_.get()->IsEmpty()); | |
479 DCHECK(free_list_code_space_.get()->IsEmpty()); | |
480 DCHECK(free_list_map_space_.get()->IsEmpty()); | |
481 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 475 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
482 new SweeperTask(heap(), OLD_SPACE), v8::Platform::kShortRunningTask); | 476 new SweeperTask(heap(), OLD_SPACE), v8::Platform::kShortRunningTask); |
483 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 477 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
484 new SweeperTask(heap(), CODE_SPACE), v8::Platform::kShortRunningTask); | 478 new SweeperTask(heap(), CODE_SPACE), v8::Platform::kShortRunningTask); |
485 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 479 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
486 new SweeperTask(heap(), MAP_SPACE), v8::Platform::kShortRunningTask); | 480 new SweeperTask(heap(), MAP_SPACE), v8::Platform::kShortRunningTask); |
487 } | 481 } |
488 | 482 |
489 | 483 |
490 void MarkCompactCollector::SweepOrWaitUntilSweepingCompleted(Page* page) { | 484 void MarkCompactCollector::SweepOrWaitUntilSweepingCompleted(Page* page) { |
(...skipping 2814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3305 HeapObject* heap_object = HeapObject::cast(object); | 3299 HeapObject* heap_object = HeapObject::cast(object); |
3306 MapWord map_word = heap_object->map_word(); | 3300 MapWord map_word = heap_object->map_word(); |
3307 if (map_word.IsForwardingAddress()) { | 3301 if (map_word.IsForwardingAddress()) { |
3308 return map_word.ToForwardingAddress(); | 3302 return map_word.ToForwardingAddress(); |
3309 } | 3303 } |
3310 } | 3304 } |
3311 return object; | 3305 return object; |
3312 } | 3306 } |
3313 }; | 3307 }; |
3314 | 3308 |
3315 | |
3316 enum SweepingMode { SWEEP_ONLY, SWEEP_AND_VISIT_LIVE_OBJECTS }; | 3309 enum SweepingMode { SWEEP_ONLY, SWEEP_AND_VISIT_LIVE_OBJECTS }; |
3317 | 3310 |
3318 | |
3319 enum SkipListRebuildingMode { REBUILD_SKIP_LIST, IGNORE_SKIP_LIST }; | 3311 enum SkipListRebuildingMode { REBUILD_SKIP_LIST, IGNORE_SKIP_LIST }; |
3320 | 3312 |
3321 | |
3322 enum FreeSpaceTreatmentMode { IGNORE_FREE_SPACE, ZAP_FREE_SPACE }; | 3313 enum FreeSpaceTreatmentMode { IGNORE_FREE_SPACE, ZAP_FREE_SPACE }; |
3323 | 3314 |
3324 | |
3325 template <MarkCompactCollector::SweepingParallelism mode> | |
3326 static intptr_t Free(PagedSpace* space, FreeList* free_list, Address start, | |
3327 int size) { | |
3328 if (mode == MarkCompactCollector::SWEEP_ON_MAIN_THREAD) { | |
3329 DCHECK(free_list == NULL); | |
3330 return space->Free(start, size); | |
3331 } else { | |
3332 return size - free_list->Free(start, size); | |
3333 } | |
3334 } | |
3335 | |
3336 | |
3337 // Sweeps a page. After sweeping the page can be iterated. | 3315 // Sweeps a page. After sweeping the page can be iterated. |
3338 // Slots in live objects pointing into evacuation candidates are updated | 3316 // Slots in live objects pointing into evacuation candidates are updated |
3339 // if requested. | 3317 // if requested. |
3340 // Returns the size of the biggest continuous freed memory chunk in bytes. | 3318 // Returns the size of the biggest continuous freed memory chunk in bytes. |
3341 template <SweepingMode sweeping_mode, | 3319 template <SweepingMode sweeping_mode, |
3342 MarkCompactCollector::SweepingParallelism parallelism, | 3320 MarkCompactCollector::SweepingParallelism parallelism, |
3343 SkipListRebuildingMode skip_list_mode, | 3321 SkipListRebuildingMode skip_list_mode, |
3344 FreeSpaceTreatmentMode free_space_mode> | 3322 FreeSpaceTreatmentMode free_space_mode> |
3345 static int Sweep(PagedSpace* space, FreeList* free_list, Page* p, | 3323 static int Sweep(PagedSpace* space, Page* p, ObjectVisitor* v) { |
3346 ObjectVisitor* v) { | |
3347 DCHECK(!p->IsEvacuationCandidate() && !p->SweepingDone()); | 3324 DCHECK(!p->IsEvacuationCandidate() && !p->SweepingDone()); |
3348 DCHECK_EQ(skip_list_mode == REBUILD_SKIP_LIST, | 3325 DCHECK_EQ(skip_list_mode == REBUILD_SKIP_LIST, |
3349 space->identity() == CODE_SPACE); | 3326 space->identity() == CODE_SPACE); |
3350 DCHECK((p->skip_list() == NULL) || (skip_list_mode == REBUILD_SKIP_LIST)); | 3327 DCHECK((p->skip_list() == NULL) || (skip_list_mode == REBUILD_SKIP_LIST)); |
3351 DCHECK(parallelism == MarkCompactCollector::SWEEP_ON_MAIN_THREAD || | 3328 DCHECK(parallelism == MarkCompactCollector::SWEEP_ON_MAIN_THREAD || |
3352 sweeping_mode == SWEEP_ONLY); | 3329 sweeping_mode == SWEEP_ONLY); |
3353 | 3330 |
3354 Address free_start = p->area_start(); | 3331 Address free_start = p->area_start(); |
3355 DCHECK(reinterpret_cast<intptr_t>(free_start) % (32 * kPointerSize) == 0); | 3332 DCHECK(reinterpret_cast<intptr_t>(free_start) % (32 * kPointerSize) == 0); |
3356 | 3333 |
(...skipping 12 matching lines...) Expand all Loading... |
3369 LiveObjectIterator<kBlackObjects> it(p); | 3346 LiveObjectIterator<kBlackObjects> it(p); |
3370 HeapObject* object = NULL; | 3347 HeapObject* object = NULL; |
3371 while ((object = it.Next()) != NULL) { | 3348 while ((object = it.Next()) != NULL) { |
3372 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object))); | 3349 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object))); |
3373 Address free_end = object->address(); | 3350 Address free_end = object->address(); |
3374 if (free_end != free_start) { | 3351 if (free_end != free_start) { |
3375 int size = static_cast<int>(free_end - free_start); | 3352 int size = static_cast<int>(free_end - free_start); |
3376 if (free_space_mode == ZAP_FREE_SPACE) { | 3353 if (free_space_mode == ZAP_FREE_SPACE) { |
3377 memset(free_start, 0xcc, size); | 3354 memset(free_start, 0xcc, size); |
3378 } | 3355 } |
3379 freed_bytes = Free<parallelism>(space, free_list, free_start, size); | 3356 freed_bytes = space->UnaccountedFree(free_start, size, true); |
3380 max_freed_bytes = Max(freed_bytes, max_freed_bytes); | 3357 max_freed_bytes = Max(freed_bytes, max_freed_bytes); |
3381 } | 3358 } |
3382 Map* map = object->synchronized_map(); | 3359 Map* map = object->synchronized_map(); |
3383 int size = object->SizeFromMap(map); | 3360 int size = object->SizeFromMap(map); |
3384 if (sweeping_mode == SWEEP_AND_VISIT_LIVE_OBJECTS) { | 3361 if (sweeping_mode == SWEEP_AND_VISIT_LIVE_OBJECTS) { |
3385 object->IterateBody(map->instance_type(), size, v); | 3362 object->IterateBody(map->instance_type(), size, v); |
3386 } | 3363 } |
3387 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list != NULL) { | 3364 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list != NULL) { |
3388 int new_region_start = SkipList::RegionNumber(free_end); | 3365 int new_region_start = SkipList::RegionNumber(free_end); |
3389 int new_region_end = | 3366 int new_region_end = |
3390 SkipList::RegionNumber(free_end + size - kPointerSize); | 3367 SkipList::RegionNumber(free_end + size - kPointerSize); |
3391 if (new_region_start != curr_region || new_region_end != curr_region) { | 3368 if (new_region_start != curr_region || new_region_end != curr_region) { |
3392 skip_list->AddObject(free_end, size); | 3369 skip_list->AddObject(free_end, size); |
3393 curr_region = new_region_end; | 3370 curr_region = new_region_end; |
3394 } | 3371 } |
3395 } | 3372 } |
3396 free_start = free_end + size; | 3373 free_start = free_end + size; |
3397 } | 3374 } |
3398 | 3375 |
3399 // Clear the mark bits of that page and reset live bytes count. | 3376 // Clear the mark bits of that page and reset live bytes count. |
3400 Bitmap::Clear(p); | 3377 Bitmap::Clear(p); |
3401 | 3378 |
3402 if (free_start != p->area_end()) { | 3379 if (free_start != p->area_end()) { |
3403 int size = static_cast<int>(p->area_end() - free_start); | 3380 int size = static_cast<int>(p->area_end() - free_start); |
3404 if (free_space_mode == ZAP_FREE_SPACE) { | 3381 if (free_space_mode == ZAP_FREE_SPACE) { |
3405 memset(free_start, 0xcc, size); | 3382 memset(free_start, 0xcc, size); |
3406 } | 3383 } |
3407 freed_bytes = Free<parallelism>(space, free_list, free_start, size); | 3384 freed_bytes = space->UnaccountedFree(free_start, size, true); |
3408 max_freed_bytes = Max(freed_bytes, max_freed_bytes); | 3385 max_freed_bytes = Max(freed_bytes, max_freed_bytes); |
3409 } | 3386 } |
3410 p->concurrent_sweeping_state().SetValue(Page::kSweepingDone); | 3387 p->concurrent_sweeping_state().SetValue(Page::kSweepingDone); |
3411 return FreeList::GuaranteedAllocatable(static_cast<int>(max_freed_bytes)); | 3388 return FreeList::GuaranteedAllocatable(static_cast<int>(max_freed_bytes)); |
3412 } | 3389 } |
3413 | 3390 |
3414 | 3391 |
3415 void MarkCompactCollector::InvalidateCode(Code* code) { | 3392 void MarkCompactCollector::InvalidateCode(Code* code) { |
3416 if (heap_->incremental_marking()->IsCompacting() && | 3393 if (heap_->incremental_marking()->IsCompacting() && |
3417 !ShouldSkipEvacuationSlotRecording(code)) { | 3394 !ShouldSkipEvacuationSlotRecording(code)) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3509 } | 3486 } |
3510 | 3487 |
3511 | 3488 |
3512 void MarkCompactCollector::SweepAbortedPages() { | 3489 void MarkCompactCollector::SweepAbortedPages() { |
3513 // Second pass on aborted pages. | 3490 // Second pass on aborted pages. |
3514 for (Page* p : evacuation_candidates_) { | 3491 for (Page* p : evacuation_candidates_) { |
3515 if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) { | 3492 if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) { |
3516 p->ClearFlag(MemoryChunk::COMPACTION_WAS_ABORTED); | 3493 p->ClearFlag(MemoryChunk::COMPACTION_WAS_ABORTED); |
3517 p->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); | 3494 p->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); |
3518 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); | 3495 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); |
| 3496 List<Page*>* pages = swept_pages(space->identity()); |
3519 switch (space->identity()) { | 3497 switch (space->identity()) { |
3520 case OLD_SPACE: | 3498 case OLD_SPACE: |
3521 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, IGNORE_SKIP_LIST, | 3499 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, IGNORE_SKIP_LIST, |
3522 IGNORE_FREE_SPACE>(space, nullptr, p, nullptr); | 3500 IGNORE_FREE_SPACE>(space, p, nullptr); |
3523 break; | 3501 break; |
3524 case CODE_SPACE: | 3502 case CODE_SPACE: |
3525 if (FLAG_zap_code_space) { | 3503 if (FLAG_zap_code_space) { |
3526 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST, | 3504 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST, |
3527 ZAP_FREE_SPACE>(space, NULL, p, nullptr); | 3505 ZAP_FREE_SPACE>(space, p, nullptr); |
3528 } else { | 3506 } else { |
3529 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST, | 3507 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST, |
3530 IGNORE_FREE_SPACE>(space, NULL, p, nullptr); | 3508 IGNORE_FREE_SPACE>(space, p, nullptr); |
3531 } | 3509 } |
3532 break; | 3510 break; |
3533 default: | 3511 default: |
3534 UNREACHABLE(); | 3512 UNREACHABLE(); |
3535 break; | 3513 break; |
3536 } | 3514 } |
| 3515 { |
| 3516 base::LockGuard<base::Mutex> guard(&swept_pages_mutex_); |
| 3517 pages->Add(p); |
| 3518 } |
3537 } | 3519 } |
3538 } | 3520 } |
3539 } | 3521 } |
3540 | 3522 |
3541 | 3523 |
3542 void MarkCompactCollector::EvacuateNewSpaceAndCandidates() { | 3524 void MarkCompactCollector::EvacuateNewSpaceAndCandidates() { |
3543 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_EVACUATE); | 3525 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_EVACUATE); |
3544 Heap::RelocationLock relocation_lock(heap()); | 3526 Heap::RelocationLock relocation_lock(heap()); |
3545 | 3527 |
3546 { | 3528 { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3656 PrintF("Sweeping 0x%" V8PRIxPTR " during evacuation.\n", | 3638 PrintF("Sweeping 0x%" V8PRIxPTR " during evacuation.\n", |
3657 reinterpret_cast<intptr_t>(p)); | 3639 reinterpret_cast<intptr_t>(p)); |
3658 } | 3640 } |
3659 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); | 3641 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); |
3660 p->ClearFlag(MemoryChunk::RESCAN_ON_EVACUATION); | 3642 p->ClearFlag(MemoryChunk::RESCAN_ON_EVACUATION); |
3661 p->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); | 3643 p->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); |
3662 | 3644 |
3663 switch (space->identity()) { | 3645 switch (space->identity()) { |
3664 case OLD_SPACE: | 3646 case OLD_SPACE: |
3665 Sweep<SWEEP_AND_VISIT_LIVE_OBJECTS, SWEEP_ON_MAIN_THREAD, | 3647 Sweep<SWEEP_AND_VISIT_LIVE_OBJECTS, SWEEP_ON_MAIN_THREAD, |
3666 IGNORE_SKIP_LIST, IGNORE_FREE_SPACE>(space, NULL, p, | 3648 IGNORE_SKIP_LIST, IGNORE_FREE_SPACE>(space, p, |
3667 &updating_visitor); | 3649 &updating_visitor); |
3668 break; | 3650 break; |
3669 case CODE_SPACE: | 3651 case CODE_SPACE: |
3670 if (FLAG_zap_code_space) { | 3652 if (FLAG_zap_code_space) { |
3671 Sweep<SWEEP_AND_VISIT_LIVE_OBJECTS, SWEEP_ON_MAIN_THREAD, | 3653 Sweep<SWEEP_AND_VISIT_LIVE_OBJECTS, SWEEP_ON_MAIN_THREAD, |
3672 REBUILD_SKIP_LIST, ZAP_FREE_SPACE>(space, NULL, p, | 3654 REBUILD_SKIP_LIST, ZAP_FREE_SPACE>(space, p, |
3673 &updating_visitor); | 3655 &updating_visitor); |
3674 } else { | 3656 } else { |
3675 Sweep<SWEEP_AND_VISIT_LIVE_OBJECTS, SWEEP_ON_MAIN_THREAD, | 3657 Sweep<SWEEP_AND_VISIT_LIVE_OBJECTS, SWEEP_ON_MAIN_THREAD, |
3676 REBUILD_SKIP_LIST, IGNORE_FREE_SPACE>(space, NULL, p, | 3658 REBUILD_SKIP_LIST, IGNORE_FREE_SPACE>(space, p, |
3677 &updating_visitor); | 3659 &updating_visitor); |
3678 } | 3660 } |
3679 break; | 3661 break; |
3680 default: | 3662 default: |
3681 UNREACHABLE(); | 3663 UNREACHABLE(); |
3682 break; | 3664 break; |
3683 } | 3665 } |
3684 } | 3666 } |
3685 } | 3667 } |
3686 } | 3668 } |
(...skipping 10 matching lines...) Expand all Loading... |
3697 EvacuationWeakObjectRetainer evacuation_object_retainer; | 3679 EvacuationWeakObjectRetainer evacuation_object_retainer; |
3698 heap()->ProcessWeakListRoots(&evacuation_object_retainer); | 3680 heap()->ProcessWeakListRoots(&evacuation_object_retainer); |
3699 } | 3681 } |
3700 } | 3682 } |
3701 | 3683 |
3702 | 3684 |
3703 void MarkCompactCollector::ReleaseEvacuationCandidates() { | 3685 void MarkCompactCollector::ReleaseEvacuationCandidates() { |
3704 for (Page* p : evacuation_candidates_) { | 3686 for (Page* p : evacuation_candidates_) { |
3705 if (!p->IsEvacuationCandidate()) continue; | 3687 if (!p->IsEvacuationCandidate()) continue; |
3706 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); | 3688 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); |
3707 space->Free(p->area_start(), p->area_size()); | |
3708 p->ResetLiveBytes(); | 3689 p->ResetLiveBytes(); |
3709 CHECK(p->SweepingDone()); | 3690 CHECK(p->SweepingDone()); |
3710 space->ReleasePage(p, true); | 3691 space->ReleasePage(p); |
3711 } | 3692 } |
3712 evacuation_candidates_.Rewind(0); | 3693 evacuation_candidates_.Rewind(0); |
3713 compacting_ = false; | 3694 compacting_ = false; |
3714 heap()->FreeQueuedChunks(); | 3695 heap()->FreeQueuedChunks(); |
3715 } | 3696 } |
3716 | 3697 |
3717 | 3698 |
3718 int MarkCompactCollector::SweepInParallel(PagedSpace* space, | 3699 int MarkCompactCollector::SweepInParallel(PagedSpace* space, |
3719 int required_freed_bytes, | 3700 int required_freed_bytes, |
3720 int max_pages) { | 3701 int max_pages) { |
(...skipping 18 matching lines...) Expand all Loading... |
3739 | 3720 |
3740 int MarkCompactCollector::SweepInParallel(Page* page, PagedSpace* space) { | 3721 int MarkCompactCollector::SweepInParallel(Page* page, PagedSpace* space) { |
3741 int max_freed = 0; | 3722 int max_freed = 0; |
3742 if (page->mutex()->TryLock()) { | 3723 if (page->mutex()->TryLock()) { |
3743 // If this page was already swept in the meantime, we can return here. | 3724 // If this page was already swept in the meantime, we can return here. |
3744 if (page->concurrent_sweeping_state().Value() != Page::kSweepingPending) { | 3725 if (page->concurrent_sweeping_state().Value() != Page::kSweepingPending) { |
3745 page->mutex()->Unlock(); | 3726 page->mutex()->Unlock(); |
3746 return 0; | 3727 return 0; |
3747 } | 3728 } |
3748 page->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); | 3729 page->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); |
3749 FreeList* free_list; | 3730 List<Page*>* pages = swept_pages(space->identity()); |
3750 FreeList private_free_list(space); | |
3751 if (space->identity() == OLD_SPACE) { | 3731 if (space->identity() == OLD_SPACE) { |
3752 free_list = free_list_old_space_.get(); | 3732 max_freed = Sweep<SWEEP_ONLY, SWEEP_IN_PARALLEL, IGNORE_SKIP_LIST, |
3753 max_freed = | 3733 IGNORE_FREE_SPACE>(space, page, NULL); |
3754 Sweep<SWEEP_ONLY, SWEEP_IN_PARALLEL, IGNORE_SKIP_LIST, | |
3755 IGNORE_FREE_SPACE>(space, &private_free_list, page, NULL); | |
3756 } else if (space->identity() == CODE_SPACE) { | 3734 } else if (space->identity() == CODE_SPACE) { |
3757 free_list = free_list_code_space_.get(); | 3735 max_freed = Sweep<SWEEP_ONLY, SWEEP_IN_PARALLEL, REBUILD_SKIP_LIST, |
3758 max_freed = | 3736 IGNORE_FREE_SPACE>(space, page, NULL); |
3759 Sweep<SWEEP_ONLY, SWEEP_IN_PARALLEL, REBUILD_SKIP_LIST, | |
3760 IGNORE_FREE_SPACE>(space, &private_free_list, page, NULL); | |
3761 } else { | 3737 } else { |
3762 free_list = free_list_map_space_.get(); | 3738 max_freed = Sweep<SWEEP_ONLY, SWEEP_IN_PARALLEL, IGNORE_SKIP_LIST, |
3763 max_freed = | 3739 IGNORE_FREE_SPACE>(space, page, NULL); |
3764 Sweep<SWEEP_ONLY, SWEEP_IN_PARALLEL, IGNORE_SKIP_LIST, | |
3765 IGNORE_FREE_SPACE>(space, &private_free_list, page, NULL); | |
3766 } | 3740 } |
3767 free_list->Concatenate(&private_free_list); | 3741 { |
| 3742 base::LockGuard<base::Mutex> guard(&swept_pages_mutex_); |
| 3743 pages->Add(page); |
| 3744 } |
3768 page->concurrent_sweeping_state().SetValue(Page::kSweepingDone); | 3745 page->concurrent_sweeping_state().SetValue(Page::kSweepingDone); |
3769 page->mutex()->Unlock(); | 3746 page->mutex()->Unlock(); |
3770 } | 3747 } |
3771 return max_freed; | 3748 return max_freed; |
3772 } | 3749 } |
3773 | 3750 |
3774 | 3751 |
3775 void MarkCompactCollector::StartSweepSpace(PagedSpace* space) { | 3752 void MarkCompactCollector::StartSweepSpace(PagedSpace* space) { |
3776 space->ClearStats(); | 3753 space->ClearStats(); |
3777 | 3754 |
(...skipping 13 matching lines...) Expand all Loading... |
3791 continue; | 3768 continue; |
3792 } | 3769 } |
3793 | 3770 |
3794 if (p->IsFlagSet(Page::NEVER_ALLOCATE_ON_PAGE)) { | 3771 if (p->IsFlagSet(Page::NEVER_ALLOCATE_ON_PAGE)) { |
3795 // We need to sweep the page to get it into an iterable state again. Note | 3772 // We need to sweep the page to get it into an iterable state again. Note |
3796 // that this adds unusable memory into the free list that is later on | 3773 // that this adds unusable memory into the free list that is later on |
3797 // (in the free list) dropped again. Since we only use the flag for | 3774 // (in the free list) dropped again. Since we only use the flag for |
3798 // testing this is fine. | 3775 // testing this is fine. |
3799 p->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); | 3776 p->concurrent_sweeping_state().SetValue(Page::kSweepingInProgress); |
3800 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, IGNORE_SKIP_LIST, | 3777 Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, IGNORE_SKIP_LIST, |
3801 IGNORE_FREE_SPACE>(space, nullptr, p, nullptr); | 3778 IGNORE_FREE_SPACE>(space, p, nullptr); |
3802 continue; | 3779 continue; |
3803 } | 3780 } |
3804 | 3781 |
3805 // One unused page is kept, all further are released before sweeping them. | 3782 // One unused page is kept, all further are released before sweeping them. |
3806 if (p->LiveBytes() == 0) { | 3783 if (p->LiveBytes() == 0) { |
3807 if (unused_page_present) { | 3784 if (unused_page_present) { |
3808 if (FLAG_gc_verbose) { | 3785 if (FLAG_gc_verbose) { |
3809 PrintIsolate(isolate(), "sweeping: released page: %p", p); | 3786 PrintIsolate(isolate(), "sweeping: released page: %p", p); |
3810 } | 3787 } |
3811 space->ReleasePage(p, false); | 3788 space->ReleasePage(p); |
3812 continue; | 3789 continue; |
3813 } | 3790 } |
3814 unused_page_present = true; | 3791 unused_page_present = true; |
3815 } | 3792 } |
3816 | 3793 |
3817 p->concurrent_sweeping_state().SetValue(Page::kSweepingPending); | 3794 p->concurrent_sweeping_state().SetValue(Page::kSweepingPending); |
3818 sweeping_list(space).push_back(p); | 3795 sweeping_list(space).push_back(p); |
3819 int to_sweep = p->area_size() - p->LiveBytes(); | 3796 int to_sweep = p->area_size() - p->LiveBytes(); |
3820 space->accounting_stats_.ShrinkSpace(to_sweep); | 3797 space->accounting_stats_.ShrinkSpace(to_sweep); |
3821 will_be_swept++; | 3798 will_be_swept++; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3907 MarkBit mark_bit = Marking::MarkBitFrom(host); | 3884 MarkBit mark_bit = Marking::MarkBitFrom(host); |
3908 if (Marking::IsBlack(mark_bit)) { | 3885 if (Marking::IsBlack(mark_bit)) { |
3909 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); | 3886 RelocInfo rinfo(isolate(), pc, RelocInfo::CODE_TARGET, 0, host); |
3910 RecordRelocSlot(host, &rinfo, target); | 3887 RecordRelocSlot(host, &rinfo, target); |
3911 } | 3888 } |
3912 } | 3889 } |
3913 } | 3890 } |
3914 | 3891 |
3915 } // namespace internal | 3892 } // namespace internal |
3916 } // namespace v8 | 3893 } // namespace v8 |
OLD | NEW |