| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2880 cell_index++, object_address += 32 * kPointerSize) { | 2880 cell_index++, object_address += 32 * kPointerSize) { |
| 2881 ASSERT((unsigned)cell_index == | 2881 ASSERT((unsigned)cell_index == |
| 2882 Bitmap::IndexToCell( | 2882 Bitmap::IndexToCell( |
| 2883 Bitmap::CellAlignIndex( | 2883 Bitmap::CellAlignIndex( |
| 2884 p->AddressToMarkbitIndex(object_address)))); | 2884 p->AddressToMarkbitIndex(object_address)))); |
| 2885 int live_objects = MarkWordToObjectStarts(cells[cell_index], offsets); | 2885 int live_objects = MarkWordToObjectStarts(cells[cell_index], offsets); |
| 2886 int live_index = 0; | 2886 int live_index = 0; |
| 2887 for ( ; live_objects != 0; live_objects--) { | 2887 for ( ; live_objects != 0; live_objects--) { |
| 2888 Address free_end = object_address + offsets[live_index++] * kPointerSize; | 2888 Address free_end = object_address + offsets[live_index++] * kPointerSize; |
| 2889 if (free_end != free_start) { | 2889 if (free_end != free_start) { |
| 2890 space->AddToFreeLists(free_start, | 2890 space->Free(free_start, static_cast<int>(free_end - free_start)); |
| 2891 static_cast<int>(free_end - free_start)); | |
| 2892 } | 2891 } |
| 2893 HeapObject* live_object = HeapObject::FromAddress(free_end); | 2892 HeapObject* live_object = HeapObject::FromAddress(free_end); |
| 2894 ASSERT(Marking::IsBlack(Marking::MarkBitFrom(live_object))); | 2893 ASSERT(Marking::IsBlack(Marking::MarkBitFrom(live_object))); |
| 2895 Map* map = live_object->map(); | 2894 Map* map = live_object->map(); |
| 2896 int size = live_object->SizeFromMap(map); | 2895 int size = live_object->SizeFromMap(map); |
| 2897 if (sweeping_mode == SWEEP_AND_VISIT_LIVE_OBJECTS) { | 2896 if (sweeping_mode == SWEEP_AND_VISIT_LIVE_OBJECTS) { |
| 2898 live_object->IterateBody(map->instance_type(), size, v); | 2897 live_object->IterateBody(map->instance_type(), size, v); |
| 2899 } | 2898 } |
| 2900 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list != NULL) { | 2899 if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list != NULL) { |
| 2901 int new_region_start = | 2900 int new_region_start = |
| 2902 SkipList::RegionNumber(free_end); | 2901 SkipList::RegionNumber(free_end); |
| 2903 int new_region_end = | 2902 int new_region_end = |
| 2904 SkipList::RegionNumber(free_end + size - kPointerSize); | 2903 SkipList::RegionNumber(free_end + size - kPointerSize); |
| 2905 if (new_region_start != curr_region || | 2904 if (new_region_start != curr_region || |
| 2906 new_region_end != curr_region) { | 2905 new_region_end != curr_region) { |
| 2907 skip_list->AddObject(free_end, size); | 2906 skip_list->AddObject(free_end, size); |
| 2908 curr_region = new_region_end; | 2907 curr_region = new_region_end; |
| 2909 } | 2908 } |
| 2910 } | 2909 } |
| 2911 free_start = free_end + size; | 2910 free_start = free_end + size; |
| 2912 } | 2911 } |
| 2913 // Clear marking bits for current cell. | 2912 // Clear marking bits for current cell. |
| 2914 cells[cell_index] = 0; | 2913 cells[cell_index] = 0; |
| 2915 } | 2914 } |
| 2916 if (free_start != p->ObjectAreaEnd()) { | 2915 if (free_start != p->ObjectAreaEnd()) { |
| 2917 space->AddToFreeLists(free_start, | 2916 space->Free(free_start, static_cast<int>(p->ObjectAreaEnd() - free_start)); |
| 2918 static_cast<int>(p->ObjectAreaEnd() - free_start)); | |
| 2919 } | 2917 } |
| 2920 p->ResetLiveBytes(); | 2918 p->ResetLiveBytes(); |
| 2921 } | 2919 } |
| 2922 | 2920 |
| 2923 | 2921 |
| 2924 static bool SetMarkBitsUnderInvalidatedCode(Code* code, bool value) { | 2922 static bool SetMarkBitsUnderInvalidatedCode(Code* code, bool value) { |
| 2925 Page* p = Page::FromAddress(code->address()); | 2923 Page* p = Page::FromAddress(code->address()); |
| 2926 | 2924 |
| 2927 if (p->IsEvacuationCandidate() || | 2925 if (p->IsEvacuationCandidate() || |
| 2928 p->IsFlagSet(Page::RESCAN_ON_EVACUATION)) { | 2926 p->IsFlagSet(Page::RESCAN_ON_EVACUATION)) { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3201 VerifyEvacuation(heap_); | 3199 VerifyEvacuation(heap_); |
| 3202 } | 3200 } |
| 3203 #endif | 3201 #endif |
| 3204 | 3202 |
| 3205 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_); | 3203 slots_buffer_allocator_.DeallocateChain(&migration_slots_buffer_); |
| 3206 ASSERT(migration_slots_buffer_ == NULL); | 3204 ASSERT(migration_slots_buffer_ == NULL); |
| 3207 for (int i = 0; i < npages; i++) { | 3205 for (int i = 0; i < npages; i++) { |
| 3208 Page* p = evacuation_candidates_[i]; | 3206 Page* p = evacuation_candidates_[i]; |
| 3209 if (!p->IsEvacuationCandidate()) continue; | 3207 if (!p->IsEvacuationCandidate()) continue; |
| 3210 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); | 3208 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); |
| 3211 space->AddToFreeLists(p->ObjectAreaStart(), | 3209 space->Free(p->ObjectAreaStart(), Page::kObjectAreaSize); |
| 3212 p->ObjectAreaEnd() - p->ObjectAreaStart()); | |
| 3213 p->set_scan_on_scavenge(false); | 3210 p->set_scan_on_scavenge(false); |
| 3214 slots_buffer_allocator_.DeallocateChain(p->slots_buffer_address()); | 3211 slots_buffer_allocator_.DeallocateChain(p->slots_buffer_address()); |
| 3215 p->ClearEvacuationCandidate(); | 3212 p->ClearEvacuationCandidate(); |
| 3216 } | 3213 } |
| 3217 evacuation_candidates_.Rewind(0); | 3214 evacuation_candidates_.Rewind(0); |
| 3218 compacting_ = false; | 3215 compacting_ = false; |
| 3219 } | 3216 } |
| 3220 | 3217 |
| 3221 | 3218 |
| 3222 static const int kStartTableEntriesPerLine = 5; | 3219 static const int kStartTableEntriesPerLine = 5; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3519 Address block_address = p->ObjectAreaStart(); | 3516 Address block_address = p->ObjectAreaStart(); |
| 3520 | 3517 |
| 3521 // Skip over all the dead objects at the start of the page and mark them free. | 3518 // Skip over all the dead objects at the start of the page and mark them free. |
| 3522 for (cell_index = Page::kFirstUsedCell; | 3519 for (cell_index = Page::kFirstUsedCell; |
| 3523 cell_index < last_cell_index; | 3520 cell_index < last_cell_index; |
| 3524 cell_index++, block_address += 32 * kPointerSize) { | 3521 cell_index++, block_address += 32 * kPointerSize) { |
| 3525 if (cells[cell_index] != 0) break; | 3522 if (cells[cell_index] != 0) break; |
| 3526 } | 3523 } |
| 3527 size_t size = block_address - p->ObjectAreaStart(); | 3524 size_t size = block_address - p->ObjectAreaStart(); |
| 3528 if (cell_index == last_cell_index) { | 3525 if (cell_index == last_cell_index) { |
| 3529 freed_bytes += static_cast<int>(space->AddToFreeLists( | 3526 freed_bytes += static_cast<int>(space->Free(p->ObjectAreaStart(), |
| 3530 p->ObjectAreaStart(), static_cast<int>(size))); | 3527 static_cast<int>(size))); |
| 3531 ASSERT_EQ(0, p->LiveBytes()); | 3528 ASSERT_EQ(0, p->LiveBytes()); |
| 3532 return freed_bytes; | 3529 return freed_bytes; |
| 3533 } | 3530 } |
| 3534 // Grow the size of the start-of-page free space a little to get up to the | 3531 // Grow the size of the start-of-page free space a little to get up to the |
| 3535 // first live object. | 3532 // first live object. |
| 3536 Address free_end = StartOfLiveObject(block_address, cells[cell_index]); | 3533 Address free_end = StartOfLiveObject(block_address, cells[cell_index]); |
| 3537 // Free the first free space. | 3534 // Free the first free space. |
| 3538 size = free_end - p->ObjectAreaStart(); | 3535 size = free_end - p->ObjectAreaStart(); |
| 3539 freed_bytes += space->AddToFreeLists(p->ObjectAreaStart(), | 3536 freed_bytes += space->Free(p->ObjectAreaStart(), |
| 3540 static_cast<int>(size)); | 3537 static_cast<int>(size)); |
| 3541 // The start of the current free area is represented in undigested form by | 3538 // The start of the current free area is represented in undigested form by |
| 3542 // the address of the last 32-word section that contained a live object and | 3539 // the address of the last 32-word section that contained a live object and |
| 3543 // the marking bitmap for that cell, which describes where the live object | 3540 // the marking bitmap for that cell, which describes where the live object |
| 3544 // started. Unless we find a large free space in the bitmap we will not | 3541 // started. Unless we find a large free space in the bitmap we will not |
| 3545 // digest this pair into a real address. We start the iteration here at the | 3542 // digest this pair into a real address. We start the iteration here at the |
| 3546 // first word in the marking bit map that indicates a live object. | 3543 // first word in the marking bit map that indicates a live object. |
| 3547 Address free_start = block_address; | 3544 Address free_start = block_address; |
| 3548 uint32_t free_start_cell = cells[cell_index]; | 3545 uint32_t free_start_cell = cells[cell_index]; |
| 3549 | 3546 |
| 3550 for ( ; | 3547 for ( ; |
| 3551 cell_index < last_cell_index; | 3548 cell_index < last_cell_index; |
| 3552 cell_index++, block_address += 32 * kPointerSize) { | 3549 cell_index++, block_address += 32 * kPointerSize) { |
| 3553 ASSERT((unsigned)cell_index == | 3550 ASSERT((unsigned)cell_index == |
| 3554 Bitmap::IndexToCell( | 3551 Bitmap::IndexToCell( |
| 3555 Bitmap::CellAlignIndex( | 3552 Bitmap::CellAlignIndex( |
| 3556 p->AddressToMarkbitIndex(block_address)))); | 3553 p->AddressToMarkbitIndex(block_address)))); |
| 3557 uint32_t cell = cells[cell_index]; | 3554 uint32_t cell = cells[cell_index]; |
| 3558 if (cell != 0) { | 3555 if (cell != 0) { |
| 3559 // We have a live object. Check approximately whether it is more than 32 | 3556 // We have a live object. Check approximately whether it is more than 32 |
| 3560 // words since the last live object. | 3557 // words since the last live object. |
| 3561 if (block_address - free_start > 32 * kPointerSize) { | 3558 if (block_address - free_start > 32 * kPointerSize) { |
| 3562 free_start = DigestFreeStart(free_start, free_start_cell); | 3559 free_start = DigestFreeStart(free_start, free_start_cell); |
| 3563 if (block_address - free_start > 32 * kPointerSize) { | 3560 if (block_address - free_start > 32 * kPointerSize) { |
| 3564 // Now that we know the exact start of the free space it still looks | 3561 // Now that we know the exact start of the free space it still looks |
| 3565 // like we have a large enough free space to be worth bothering with. | 3562 // like we have a large enough free space to be worth bothering with. |
| 3566 // so now we need to find the start of the first live object at the | 3563 // so now we need to find the start of the first live object at the |
| 3567 // end of the free space. | 3564 // end of the free space. |
| 3568 free_end = StartOfLiveObject(block_address, cell); | 3565 free_end = StartOfLiveObject(block_address, cell); |
| 3569 freed_bytes += space->AddToFreeLists( | 3566 freed_bytes += space->Free(free_start, |
| 3570 free_start, static_cast<int>(free_end - free_start)); | 3567 static_cast<int>(free_end - free_start)); |
| 3571 } | 3568 } |
| 3572 } | 3569 } |
| 3573 // Update our undigested record of where the current free area started. | 3570 // Update our undigested record of where the current free area started. |
| 3574 free_start = block_address; | 3571 free_start = block_address; |
| 3575 free_start_cell = cell; | 3572 free_start_cell = cell; |
| 3576 // Clear marking bits for current cell. | 3573 // Clear marking bits for current cell. |
| 3577 cells[cell_index] = 0; | 3574 cells[cell_index] = 0; |
| 3578 } | 3575 } |
| 3579 } | 3576 } |
| 3580 | 3577 |
| 3581 // Handle the free space at the end of the page. | 3578 // Handle the free space at the end of the page. |
| 3582 if (block_address - free_start > 32 * kPointerSize) { | 3579 if (block_address - free_start > 32 * kPointerSize) { |
| 3583 free_start = DigestFreeStart(free_start, free_start_cell); | 3580 free_start = DigestFreeStart(free_start, free_start_cell); |
| 3584 freed_bytes += space->AddToFreeLists( | 3581 freed_bytes += space->Free(free_start, |
| 3585 free_start, static_cast<int>(block_address - free_start)); | 3582 static_cast<int>(block_address - free_start)); |
| 3586 } | 3583 } |
| 3587 | 3584 |
| 3588 p->ResetLiveBytes(); | 3585 p->ResetLiveBytes(); |
| 3589 return freed_bytes; | 3586 return freed_bytes; |
| 3590 } | 3587 } |
| 3591 | 3588 |
| 3592 | 3589 |
| 3593 void MarkCompactCollector::SweepSpace(PagedSpace* space, SweeperType sweeper) { | 3590 void MarkCompactCollector::SweepSpace(PagedSpace* space, SweeperType sweeper) { |
| 3594 space->set_was_swept_conservatively(sweeper == CONSERVATIVE || | 3591 space->set_was_swept_conservatively(sweeper == CONSERVATIVE || |
| 3595 sweeper == LAZY_CONSERVATIVE); | 3592 sweeper == LAZY_CONSERVATIVE); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3907 while (buffer != NULL) { | 3904 while (buffer != NULL) { |
| 3908 SlotsBuffer* next_buffer = buffer->next(); | 3905 SlotsBuffer* next_buffer = buffer->next(); |
| 3909 DeallocateBuffer(buffer); | 3906 DeallocateBuffer(buffer); |
| 3910 buffer = next_buffer; | 3907 buffer = next_buffer; |
| 3911 } | 3908 } |
| 3912 *buffer_address = NULL; | 3909 *buffer_address = NULL; |
| 3913 } | 3910 } |
| 3914 | 3911 |
| 3915 | 3912 |
| 3916 } } // namespace v8::internal | 3913 } } // namespace v8::internal |
| OLD | NEW |