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/v8.h" | 5 #include "src/v8.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/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 3104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3115 | 3115 |
3116 uint32_t mark_bit_index = p->AddressToMarkbitIndex(slot); | 3116 uint32_t mark_bit_index = p->AddressToMarkbitIndex(slot); |
3117 unsigned int start_index = mark_bit_index >> Bitmap::kBitsPerCellLog2; | 3117 unsigned int start_index = mark_bit_index >> Bitmap::kBitsPerCellLog2; |
3118 MarkBit::CellType index_in_cell = 1U | 3118 MarkBit::CellType index_in_cell = 1U |
3119 << (mark_bit_index & Bitmap::kBitIndexMask); | 3119 << (mark_bit_index & Bitmap::kBitIndexMask); |
3120 MarkBit::CellType* cells = p->markbits()->cells(); | 3120 MarkBit::CellType* cells = p->markbits()->cells(); |
3121 Address cell_base = p->area_start(); | 3121 Address cell_base = p->area_start(); |
3122 unsigned int cell_base_start_index = Bitmap::IndexToCell( | 3122 unsigned int cell_base_start_index = Bitmap::IndexToCell( |
3123 Bitmap::CellAlignIndex(p->AddressToMarkbitIndex(cell_base))); | 3123 Bitmap::CellAlignIndex(p->AddressToMarkbitIndex(cell_base))); |
3124 | 3124 |
3125 // First check if the object is in the current cell. | 3125 // Check if the slot points to the start of an object. This can happen e.g. |
| 3126 // when we left trim a fixed array. Such slots are invalid and we can remove |
| 3127 // them. |
| 3128 if ((cells[start_index] & index_in_cell) != 0) { |
| 3129 return false; |
| 3130 } |
| 3131 |
| 3132 // Check if the object is in the current cell. |
3126 MarkBit::CellType slot_mask; | 3133 MarkBit::CellType slot_mask; |
3127 if ((cells[start_index] == 0) || | 3134 if ((cells[start_index] == 0) || |
3128 (base::bits::CountTrailingZeros32(cells[start_index]) > | 3135 (base::bits::CountTrailingZeros32(cells[start_index]) > |
3129 base::bits::CountTrailingZeros32(cells[start_index] | index_in_cell))) { | 3136 base::bits::CountTrailingZeros32(cells[start_index] | index_in_cell))) { |
3130 // If we are already in the first cell, there is no live object. | 3137 // If we are already in the first cell, there is no live object. |
3131 if (start_index == cell_base_start_index) return false; | 3138 if (start_index == cell_base_start_index) return false; |
3132 | 3139 |
3133 // If not, find a cell in a preceding cell slot that has a mark bit set. | 3140 // If not, find a cell in a preceding cell slot that has a mark bit set. |
3134 do { | 3141 do { |
3135 start_index--; | 3142 start_index--; |
3136 } while (start_index > cell_base_start_index && cells[start_index] == 0); | 3143 } while (start_index > cell_base_start_index && cells[start_index] == 0); |
3137 | 3144 |
3138 // The slot must be in a dead object if there are no preceding cells that | 3145 // The slot must be in a dead object if there are no preceding cells that |
3139 // have mark bits set. | 3146 // have mark bits set. |
3140 if (cells[start_index] == 0) { | 3147 if (cells[start_index] == 0) { |
3141 return false; | 3148 return false; |
3142 } | 3149 } |
3143 | 3150 |
3144 // The object is in a preceding cell. Set the mask to find any object. | 3151 // The object is in a preceding cell. Set the mask to find any object. |
3145 slot_mask = 0xffffffff; | 3152 slot_mask = 0xffffffff; |
3146 } else { | 3153 } else { |
| 3154 // The object start is before the the slot index. Hence, in this case the |
| 3155 // slot index can not be at the beginning of the cell. |
| 3156 CHECK(index_in_cell > 1); |
3147 // We are interested in object mark bits right before the slot. | 3157 // We are interested in object mark bits right before the slot. |
3148 slot_mask = index_in_cell - 1; | 3158 slot_mask = index_in_cell - 1; |
3149 } | 3159 } |
3150 | 3160 |
3151 MarkBit::CellType current_cell = cells[start_index]; | 3161 MarkBit::CellType current_cell = cells[start_index]; |
3152 DCHECK(current_cell != 0); | 3162 CHECK(current_cell != 0); |
3153 | 3163 |
3154 // Find the last live object in the cell. | 3164 // Find the last live object in the cell. |
3155 unsigned int leading_zeros = | 3165 unsigned int leading_zeros = |
3156 base::bits::CountLeadingZeros32(current_cell & slot_mask); | 3166 base::bits::CountLeadingZeros32(current_cell & slot_mask); |
3157 DCHECK(leading_zeros != 32); | 3167 CHECK(leading_zeros != 32); |
3158 unsigned int offset = Bitmap::kBitIndexMask - leading_zeros; | 3168 unsigned int offset = Bitmap::kBitIndexMask - leading_zeros; |
3159 | 3169 |
3160 cell_base += (start_index - cell_base_start_index) * 32 * kPointerSize; | 3170 cell_base += (start_index - cell_base_start_index) * 32 * kPointerSize; |
3161 Address address = cell_base + offset * kPointerSize; | 3171 Address address = cell_base + offset * kPointerSize; |
3162 HeapObject* object = HeapObject::FromAddress(address); | 3172 HeapObject* object = HeapObject::FromAddress(address); |
3163 DCHECK(object->address() < reinterpret_cast<Address>(slot)); | 3173 CHECK(object->address() < reinterpret_cast<Address>(slot)); |
3164 if (object->address() <= slot && | 3174 if (object->address() <= slot && |
3165 (object->address() + object->Size()) > slot) { | 3175 (object->address() + object->Size()) > slot) { |
3166 // If the slot is within the last found object in the cell, the slot is | 3176 // If the slot is within the last found object in the cell, the slot is |
3167 // in a live object. | 3177 // in a live object. |
3168 *out_object = object; | 3178 *out_object = object; |
3169 return true; | 3179 return true; |
3170 } | 3180 } |
3171 return false; | 3181 return false; |
3172 } | 3182 } |
3173 | 3183 |
(...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4787 SlotsBuffer* buffer = *buffer_address; | 4797 SlotsBuffer* buffer = *buffer_address; |
4788 while (buffer != NULL) { | 4798 while (buffer != NULL) { |
4789 SlotsBuffer* next_buffer = buffer->next(); | 4799 SlotsBuffer* next_buffer = buffer->next(); |
4790 DeallocateBuffer(buffer); | 4800 DeallocateBuffer(buffer); |
4791 buffer = next_buffer; | 4801 buffer = next_buffer; |
4792 } | 4802 } |
4793 *buffer_address = NULL; | 4803 *buffer_address = NULL; |
4794 } | 4804 } |
4795 } | 4805 } |
4796 } // namespace v8::internal | 4806 } // namespace v8::internal |
OLD | NEW |