| 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/elements.h" | 5 #include "src/elements.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/factory.h" | 9 #include "src/factory.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 DCHECK((copy_size + static_cast<int>(to_start)) <= to_base->length() && | 132 DCHECK((copy_size + static_cast<int>(to_start)) <= to_base->length() && |
| 133 (copy_size + static_cast<int>(from_start)) <= from_base->length()); | 133 (copy_size + static_cast<int>(from_start)) <= from_base->length()); |
| 134 if (copy_size == 0) return; | 134 if (copy_size == 0) return; |
| 135 FixedArray* from = FixedArray::cast(from_base); | 135 FixedArray* from = FixedArray::cast(from_base); |
| 136 FixedArray* to = FixedArray::cast(to_base); | 136 FixedArray* to = FixedArray::cast(to_base); |
| 137 DCHECK(IsFastSmiOrObjectElementsKind(from_kind)); | 137 DCHECK(IsFastSmiOrObjectElementsKind(from_kind)); |
| 138 DCHECK(IsFastSmiOrObjectElementsKind(to_kind)); | 138 DCHECK(IsFastSmiOrObjectElementsKind(to_kind)); |
| 139 Address to_address = to->address() + FixedArray::kHeaderSize; | 139 |
| 140 Address from_address = from->address() + FixedArray::kHeaderSize; | 140 WriteBarrierMode write_barrier_mode = |
| 141 CopyWords(reinterpret_cast<Object**>(to_address) + to_start, | 141 (IsFastObjectElementsKind(from_kind) && IsFastObjectElementsKind(to_kind)) |
| 142 reinterpret_cast<Object**>(from_address) + from_start, | 142 ? UPDATE_WRITE_BARRIER |
| 143 static_cast<size_t>(copy_size)); | 143 : SKIP_WRITE_BARRIER; |
| 144 if (IsFastObjectElementsKind(from_kind) && | 144 for (int i = 0; i < copy_size; i++) { |
| 145 IsFastObjectElementsKind(to_kind)) { | 145 Object* value = from->get(from_start + i); |
| 146 Heap* heap = from->GetHeap(); | 146 to->set(to_start + i, value, write_barrier_mode); |
| 147 if (!heap->InNewSpace(to)) { | |
| 148 heap->RecordWrites(to->address(), | |
| 149 to->OffsetOfElementAt(to_start), | |
| 150 copy_size); | |
| 151 } | |
| 152 heap->incremental_marking()->RecordWrites(to); | |
| 153 } | 147 } |
| 154 } | 148 } |
| 155 | 149 |
| 156 | 150 |
| 157 static void CopyDictionaryToObjectElements( | 151 static void CopyDictionaryToObjectElements( |
| 158 FixedArrayBase* from_base, uint32_t from_start, FixedArrayBase* to_base, | 152 FixedArrayBase* from_base, uint32_t from_start, FixedArrayBase* to_base, |
| 159 ElementsKind to_kind, uint32_t to_start, int raw_copy_size) { | 153 ElementsKind to_kind, uint32_t to_start, int raw_copy_size) { |
| 160 DisallowHeapAllocation no_allocation; | 154 DisallowHeapAllocation no_allocation; |
| 161 SeededNumberDictionary* from = SeededNumberDictionary::cast(from_base); | 155 SeededNumberDictionary* from = SeededNumberDictionary::cast(from_base); |
| 162 int copy_size = raw_copy_size; | 156 int copy_size = raw_copy_size; |
| 163 Heap* heap = from->GetHeap(); | |
| 164 if (raw_copy_size < 0) { | 157 if (raw_copy_size < 0) { |
| 165 DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || | 158 DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || |
| 166 raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole); | 159 raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole); |
| 167 copy_size = from->max_number_key() + 1 - from_start; | 160 copy_size = from->max_number_key() + 1 - from_start; |
| 168 if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { | 161 if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { |
| 169 int start = to_start + copy_size; | 162 int start = to_start + copy_size; |
| 170 int length = to_base->length() - start; | 163 int length = to_base->length() - start; |
| 171 if (length > 0) { | 164 if (length > 0) { |
| 172 Heap* heap = from->GetHeap(); | 165 Heap* heap = from->GetHeap(); |
| 173 MemsetPointer(FixedArray::cast(to_base)->data_start() + start, | 166 MemsetPointer(FixedArray::cast(to_base)->data_start() + start, |
| 174 heap->the_hole_value(), length); | 167 heap->the_hole_value(), length); |
| 175 } | 168 } |
| 176 } | 169 } |
| 177 } | 170 } |
| 178 DCHECK(to_base != from_base); | 171 DCHECK(to_base != from_base); |
| 179 DCHECK(IsFastSmiOrObjectElementsKind(to_kind)); | 172 DCHECK(IsFastSmiOrObjectElementsKind(to_kind)); |
| 180 if (copy_size == 0) return; | 173 if (copy_size == 0) return; |
| 181 FixedArray* to = FixedArray::cast(to_base); | 174 FixedArray* to = FixedArray::cast(to_base); |
| 182 uint32_t to_length = to->length(); | 175 uint32_t to_length = to->length(); |
| 183 if (to_start + copy_size > to_length) { | 176 if (to_start + copy_size > to_length) { |
| 184 copy_size = to_length - to_start; | 177 copy_size = to_length - to_start; |
| 185 } | 178 } |
| 179 WriteBarrierMode write_barrier_mode = IsFastObjectElementsKind(to_kind) |
| 180 ? UPDATE_WRITE_BARRIER |
| 181 : SKIP_WRITE_BARRIER; |
| 186 for (int i = 0; i < copy_size; i++) { | 182 for (int i = 0; i < copy_size; i++) { |
| 187 int entry = from->FindEntry(i + from_start); | 183 int entry = from->FindEntry(i + from_start); |
| 188 if (entry != SeededNumberDictionary::kNotFound) { | 184 if (entry != SeededNumberDictionary::kNotFound) { |
| 189 Object* value = from->ValueAt(entry); | 185 Object* value = from->ValueAt(entry); |
| 190 DCHECK(!value->IsTheHole()); | 186 DCHECK(!value->IsTheHole()); |
| 191 to->set(i + to_start, value, SKIP_WRITE_BARRIER); | 187 to->set(i + to_start, value, write_barrier_mode); |
| 192 } else { | 188 } else { |
| 193 to->set_the_hole(i + to_start); | 189 to->set_the_hole(i + to_start); |
| 194 } | 190 } |
| 195 } | 191 } |
| 196 if (IsFastObjectElementsKind(to_kind)) { | |
| 197 if (!heap->InNewSpace(to)) { | |
| 198 heap->RecordWrites(to->address(), | |
| 199 to->OffsetOfElementAt(to_start), | |
| 200 copy_size); | |
| 201 } | |
| 202 heap->incremental_marking()->RecordWrites(to); | |
| 203 } | |
| 204 } | 192 } |
| 205 | 193 |
| 206 | 194 |
| 207 // NOTE: this method violates the handlified function signature convention: | 195 // NOTE: this method violates the handlified function signature convention: |
| 208 // raw pointer parameters in the function that allocates. | 196 // raw pointer parameters in the function that allocates. |
| 209 // See ElementsAccessorBase::CopyElements() for details. | 197 // See ElementsAccessorBase::CopyElements() for details. |
| 210 static void CopyDoubleToObjectElements(FixedArrayBase* from_base, | 198 static void CopyDoubleToObjectElements(FixedArrayBase* from_base, |
| 211 uint32_t from_start, | 199 uint32_t from_start, |
| 212 FixedArrayBase* to_base, | 200 FixedArrayBase* to_base, |
| 213 uint32_t to_start, int raw_copy_size) { | 201 uint32_t to_start, int raw_copy_size) { |
| (...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2386 } | 2374 } |
| 2387 } | 2375 } |
| 2388 | 2376 |
| 2389 DCHECK(j == result_len); | 2377 DCHECK(j == result_len); |
| 2390 return result_array; | 2378 return result_array; |
| 2391 } | 2379 } |
| 2392 | 2380 |
| 2393 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 2381 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
| 2394 } // namespace internal | 2382 } // namespace internal |
| 2395 } // namespace v8 | 2383 } // namespace v8 |
| OLD | NEW |