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 2901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2912 cell_index++, object_address += 32 * kPointerSize) { | 2912 cell_index++, object_address += 32 * kPointerSize) { |
2913 ASSERT((unsigned)cell_index == | 2913 ASSERT((unsigned)cell_index == |
2914 Bitmap::IndexToCell( | 2914 Bitmap::IndexToCell( |
2915 Bitmap::CellAlignIndex( | 2915 Bitmap::CellAlignIndex( |
2916 p->AddressToMarkbitIndex(object_address)))); | 2916 p->AddressToMarkbitIndex(object_address)))); |
2917 int live_objects = MarkWordToObjectStarts(cells[cell_index], offsets); | 2917 int live_objects = MarkWordToObjectStarts(cells[cell_index], offsets); |
2918 int live_index = 0; | 2918 int live_index = 0; |
2919 for ( ; live_objects != 0; live_objects--) { | 2919 for ( ; live_objects != 0; live_objects--) { |
2920 Address free_end = object_address + offsets[live_index++] * kPointerSize; | 2920 Address free_end = object_address + offsets[live_index++] * kPointerSize; |
2921 if (free_end != free_start) { | 2921 if (free_end != free_start) { |
2922 space->Free(free_start, static_cast<int>(free_end - free_start)); | 2922 space->AddToFreeLists(free_start, |
| 2923 static_cast<int>(free_end - free_start)); |
2923 } | 2924 } |
2924 HeapObject* live_object = HeapObject::FromAddress(free_end); | 2925 HeapObject* live_object = HeapObject::FromAddress(free_end); |
2925 ASSERT(Marking::IsBlack(Marking::MarkBitFrom(live_object))); | 2926 ASSERT(Marking::IsBlack(Marking::MarkBitFrom(live_object))); |
2926 Map* map = live_object->map(); | 2927 Map* map = live_object->map(); |
2927 int size = live_object->SizeFromMap(map); | 2928 int size = live_object->SizeFromMap(map); |
2928 if (sweeping_mode == SWEEP_AND_VISIT_LIVE_OBJECTS) { | 2929 if (sweeping_mode == SWEEP_AND_VISIT_LIVE_OBJECTS) { |
2929 live_object->IterateBody(map->instance_type(), size, v); | 2930 live_object->IterateBody(map->instance_type(), size, v); |
2930 } | 2931 } |
2931 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list != NULL) { | 2932 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list != NULL) { |
2932 int new_region_start = | 2933 int new_region_start = |
2933 SkipList::RegionNumber(free_end); | 2934 SkipList::RegionNumber(free_end); |
2934 int new_region_end = | 2935 int new_region_end = |
2935 SkipList::RegionNumber(free_end + size - kPointerSize); | 2936 SkipList::RegionNumber(free_end + size - kPointerSize); |
2936 if (new_region_start != curr_region || | 2937 if (new_region_start != curr_region || |
2937 new_region_end != curr_region) { | 2938 new_region_end != curr_region) { |
2938 skip_list->AddObject(free_end, size); | 2939 skip_list->AddObject(free_end, size); |
2939 curr_region = new_region_end; | 2940 curr_region = new_region_end; |
2940 } | 2941 } |
2941 } | 2942 } |
2942 free_start = free_end + size; | 2943 free_start = free_end + size; |
2943 } | 2944 } |
2944 // Clear marking bits for current cell. | 2945 // Clear marking bits for current cell. |
2945 cells[cell_index] = 0; | 2946 cells[cell_index] = 0; |
2946 } | 2947 } |
2947 if (free_start != p->ObjectAreaEnd()) { | 2948 if (free_start != p->ObjectAreaEnd()) { |
2948 space->Free(free_start, static_cast<int>(p->ObjectAreaEnd() - free_start)); | 2949 space->AddToFreeLists(free_start, |
| 2950 static_cast<int>(p->ObjectAreaEnd() - free_start)); |
2949 } | 2951 } |
2950 p->ResetLiveBytes(); | 2952 p->ResetLiveBytes(); |
2951 } | 2953 } |
2952 | 2954 |
2953 | 2955 |
2954 static bool SetMarkBitsUnderInvalidatedCode(Code* code, bool value) { | 2956 static bool SetMarkBitsUnderInvalidatedCode(Code* code, bool value) { |
2955 Page* p = Page::FromAddress(code->address()); | 2957 Page* p = Page::FromAddress(code->address()); |
2956 | 2958 |
2957 if (p->IsEvacuationCandidate() || | 2959 if (p->IsEvacuationCandidate() || |
2958 p->IsFlagSet(Page::RESCAN_ON_EVACUATION)) { | 2960 p->IsFlagSet(Page::RESCAN_ON_EVACUATION)) { |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3231 VerifyEvacuation(heap_); | 3233 VerifyEvacuation(heap_); |
3232 } | 3234 } |
3233 #endif | 3235 #endif |
3234 | 3236 |
3235 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_); | 3237 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_); |
3236 ASSERT(migration_slots_buffer_ == NULL); | 3238 ASSERT(migration_slots_buffer_ == NULL); |
3237 for (int i = 0; i < npages; i++) { | 3239 for (int i = 0; i < npages; i++) { |
3238 Page* p = evacuation_candidates_[i]; | 3240 Page* p = evacuation_candidates_[i]; |
3239 if (!p->IsEvacuationCandidate()) continue; | 3241 if (!p->IsEvacuationCandidate()) continue; |
3240 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); | 3242 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); |
3241 space->Free(p->ObjectAreaStart(), Page::kObjectAreaSize); | 3243 space->AddToFreeLists( |
| 3244 p->ObjectAreaStart(), |
| 3245 static_cast<int>(p->ObjectAreaEnd() - p->ObjectAreaStart())); |
3242 p->set_scan_on_scavenge(false); | 3246 p->set_scan_on_scavenge(false); |
3243 slots_buffer_allocator_.DeallocateChain(p->slots_buffer_address()); | 3247 slots_buffer_allocator_.DeallocateChain(p->slots_buffer_address()); |
3244 p->ClearEvacuationCandidate(); | 3248 p->ClearEvacuationCandidate(); |
3245 } | 3249 } |
3246 evacuation_candidates_.Rewind(0); | 3250 evacuation_candidates_.Rewind(0); |
3247 compacting_ = false; | 3251 compacting_ = false; |
3248 } | 3252 } |
3249 | 3253 |
3250 | 3254 |
3251 static const int kStartTableEntriesPerLine = 5; | 3255 static const int kStartTableEntriesPerLine = 5; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3548 Address block_address = p->ObjectAreaStart(); | 3552 Address block_address = p->ObjectAreaStart(); |
3549 | 3553 |
3550 // Skip over all the dead objects at the start of the page and mark them free. | 3554 // Skip over all the dead objects at the start of the page and mark them free. |
3551 for (cell_index = Page::kFirstUsedCell; | 3555 for (cell_index = Page::kFirstUsedCell; |
3552 cell_index < last_cell_index; | 3556 cell_index < last_cell_index; |
3553 cell_index++, block_address += 32 * kPointerSize) { | 3557 cell_index++, block_address += 32 * kPointerSize) { |
3554 if (cells[cell_index] != 0) break; | 3558 if (cells[cell_index] != 0) break; |
3555 } | 3559 } |
3556 size_t size = block_address - p->ObjectAreaStart(); | 3560 size_t size = block_address - p->ObjectAreaStart(); |
3557 if (cell_index == last_cell_index) { | 3561 if (cell_index == last_cell_index) { |
3558 freed_bytes += static_cast<int>(space->Free(p->ObjectAreaStart(), | 3562 freed_bytes += static_cast<int>(space->AddToFreeLists( |
3559 static_cast<int>(size))); | 3563 p->ObjectAreaStart(), static_cast<int>(size))); |
3560 ASSERT_EQ(0, p->LiveBytes()); | 3564 ASSERT_EQ(0, p->LiveBytes()); |
3561 return freed_bytes; | 3565 return freed_bytes; |
3562 } | 3566 } |
3563 // Grow the size of the start-of-page free space a little to get up to the | 3567 // Grow the size of the start-of-page free space a little to get up to the |
3564 // first live object. | 3568 // first live object. |
3565 Address free_end = StartOfLiveObject(block_address, cells[cell_index]); | 3569 Address free_end = StartOfLiveObject(block_address, cells[cell_index]); |
3566 // Free the first free space. | 3570 // Free the first free space. |
3567 size = free_end - p->ObjectAreaStart(); | 3571 size = free_end - p->ObjectAreaStart(); |
3568 freed_bytes += space->Free(p->ObjectAreaStart(), | 3572 freed_bytes += space->AddToFreeLists(p->ObjectAreaStart(), |
3569 static_cast<int>(size)); | 3573 static_cast<int>(size)); |
3570 // The start of the current free area is represented in undigested form by | 3574 // The start of the current free area is represented in undigested form by |
3571 // the address of the last 32-word section that contained a live object and | 3575 // the address of the last 32-word section that contained a live object and |
3572 // the marking bitmap for that cell, which describes where the live object | 3576 // the marking bitmap for that cell, which describes where the live object |
3573 // started. Unless we find a large free space in the bitmap we will not | 3577 // started. Unless we find a large free space in the bitmap we will not |
3574 // digest this pair into a real address. We start the iteration here at the | 3578 // digest this pair into a real address. We start the iteration here at the |
3575 // first word in the marking bit map that indicates a live object. | 3579 // first word in the marking bit map that indicates a live object. |
3576 Address free_start = block_address; | 3580 Address free_start = block_address; |
3577 uint32_t free_start_cell = cells[cell_index]; | 3581 uint32_t free_start_cell = cells[cell_index]; |
3578 | 3582 |
3579 for ( ; | 3583 for ( ; |
3580 cell_index < last_cell_index; | 3584 cell_index < last_cell_index; |
3581 cell_index++, block_address += 32 * kPointerSize) { | 3585 cell_index++, block_address += 32 * kPointerSize) { |
3582 ASSERT((unsigned)cell_index == | 3586 ASSERT((unsigned)cell_index == |
3583 Bitmap::IndexToCell( | 3587 Bitmap::IndexToCell( |
3584 Bitmap::CellAlignIndex( | 3588 Bitmap::CellAlignIndex( |
3585 p->AddressToMarkbitIndex(block_address)))); | 3589 p->AddressToMarkbitIndex(block_address)))); |
3586 uint32_t cell = cells[cell_index]; | 3590 uint32_t cell = cells[cell_index]; |
3587 if (cell != 0) { | 3591 if (cell != 0) { |
3588 // We have a live object. Check approximately whether it is more than 32 | 3592 // We have a live object. Check approximately whether it is more than 32 |
3589 // words since the last live object. | 3593 // words since the last live object. |
3590 if (block_address - free_start > 32 * kPointerSize) { | 3594 if (block_address - free_start > 32 * kPointerSize) { |
3591 free_start = DigestFreeStart(free_start, free_start_cell); | 3595 free_start = DigestFreeStart(free_start, free_start_cell); |
3592 if (block_address - free_start > 32 * kPointerSize) { | 3596 if (block_address - free_start > 32 * kPointerSize) { |
3593 // Now that we know the exact start of the free space it still looks | 3597 // Now that we know the exact start of the free space it still looks |
3594 // like we have a large enough free space to be worth bothering with. | 3598 // like we have a large enough free space to be worth bothering with. |
3595 // so now we need to find the start of the first live object at the | 3599 // so now we need to find the start of the first live object at the |
3596 // end of the free space. | 3600 // end of the free space. |
3597 free_end = StartOfLiveObject(block_address, cell); | 3601 free_end = StartOfLiveObject(block_address, cell); |
3598 freed_bytes += space->Free(free_start, | 3602 freed_bytes += space->AddToFreeLists( |
3599 static_cast<int>(free_end - free_start)); | 3603 free_start, static_cast<int>(free_end - free_start)); |
3600 } | 3604 } |
3601 } | 3605 } |
3602 // Update our undigested record of where the current free area started. | 3606 // Update our undigested record of where the current free area started. |
3603 free_start = block_address; | 3607 free_start = block_address; |
3604 free_start_cell = cell; | 3608 free_start_cell = cell; |
3605 // Clear marking bits for current cell. | 3609 // Clear marking bits for current cell. |
3606 cells[cell_index] = 0; | 3610 cells[cell_index] = 0; |
3607 } | 3611 } |
3608 } | 3612 } |
3609 | 3613 |
3610 // Handle the free space at the end of the page. | 3614 // Handle the free space at the end of the page. |
3611 if (block_address - free_start > 32 * kPointerSize) { | 3615 if (block_address - free_start > 32 * kPointerSize) { |
3612 free_start = DigestFreeStart(free_start, free_start_cell); | 3616 free_start = DigestFreeStart(free_start, free_start_cell); |
3613 freed_bytes += space->Free(free_start, | 3617 freed_bytes += space->AddToFreeLists( |
3614 static_cast<int>(block_address - free_start)); | 3618 free_start, static_cast<int>(block_address - free_start)); |
3615 } | 3619 } |
3616 | 3620 |
3617 p->ResetLiveBytes(); | 3621 p->ResetLiveBytes(); |
3618 return freed_bytes; | 3622 return freed_bytes; |
3619 } | 3623 } |
3620 | 3624 |
3621 | 3625 |
3622 void MarkCompactCollector::SweepSpace(PagedSpace* space, SweeperType sweeper) { | 3626 void MarkCompactCollector::SweepSpace(PagedSpace* space, SweeperType sweeper) { |
3623 space->set_was_swept_conservatively(sweeper == CONSERVATIVE || | 3627 space->set_was_swept_conservatively(sweeper == CONSERVATIVE || |
3624 sweeper == LAZY_CONSERVATIVE); | 3628 sweeper == LAZY_CONSERVATIVE); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3939 while (buffer != NULL) { | 3943 while (buffer != NULL) { |
3940 SlotsBuffer* next_buffer = buffer->next(); | 3944 SlotsBuffer* next_buffer = buffer->next(); |
3941 DeallocateBuffer(buffer); | 3945 DeallocateBuffer(buffer); |
3942 buffer = next_buffer; | 3946 buffer = next_buffer; |
3943 } | 3947 } |
3944 *buffer_address = NULL; | 3948 *buffer_address = NULL; |
3945 } | 3949 } |
3946 | 3950 |
3947 | 3951 |
3948 } } // namespace v8::internal | 3952 } } // namespace v8::internal |
OLD | NEW |