Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/elements.cc

Issue 1456533002: Use proper write barriers instead of RecordWrites when copying object elements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 bool needs_write_barrier =
141 CopyWords(reinterpret_cast<Object**>(to_address) + to_start, 141 IsFastObjectElementsKind(from_kind) && IsFastObjectElementsKind(to_kind);
ulan 2015/11/17 13:51:48 We can precompute the mode here: WriteBarrierMode
Hannes Payer (out of office) 2015/11/18 09:02:17 Done.
142 reinterpret_cast<Object**>(from_address) + from_start, 142 for (int i = 0; i < copy_size; i++) {
143 static_cast<size_t>(copy_size)); 143 Object* value = from->get(from_start + i);
144 if (IsFastObjectElementsKind(from_kind) && 144 to->set(to_start + i, value,
145 IsFastObjectElementsKind(to_kind)) { 145 needs_write_barrier ? UPDATE_WRITE_BARRIER : SKIP_WRITE_BARRIER);
146 Heap* heap = from->GetHeap();
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 } 146 }
154 } 147 }
155 148
156 149
157 static void CopyDictionaryToObjectElements( 150 static void CopyDictionaryToObjectElements(
158 FixedArrayBase* from_base, uint32_t from_start, FixedArrayBase* to_base, 151 FixedArrayBase* from_base, uint32_t from_start, FixedArrayBase* to_base,
159 ElementsKind to_kind, uint32_t to_start, int raw_copy_size) { 152 ElementsKind to_kind, uint32_t to_start, int raw_copy_size) {
160 DisallowHeapAllocation no_allocation; 153 DisallowHeapAllocation no_allocation;
161 SeededNumberDictionary* from = SeededNumberDictionary::cast(from_base); 154 SeededNumberDictionary* from = SeededNumberDictionary::cast(from_base);
162 int copy_size = raw_copy_size; 155 int copy_size = raw_copy_size;
163 Heap* heap = from->GetHeap();
164 if (raw_copy_size < 0) { 156 if (raw_copy_size < 0) {
165 DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd || 157 DCHECK(raw_copy_size == ElementsAccessor::kCopyToEnd ||
166 raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole); 158 raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole);
167 copy_size = from->max_number_key() + 1 - from_start; 159 copy_size = from->max_number_key() + 1 - from_start;
168 if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { 160 if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) {
169 int start = to_start + copy_size; 161 int start = to_start + copy_size;
170 int length = to_base->length() - start; 162 int length = to_base->length() - start;
171 if (length > 0) { 163 if (length > 0) {
172 Heap* heap = from->GetHeap(); 164 Heap* heap = from->GetHeap();
173 MemsetPointer(FixedArray::cast(to_base)->data_start() + start, 165 MemsetPointer(FixedArray::cast(to_base)->data_start() + start,
174 heap->the_hole_value(), length); 166 heap->the_hole_value(), length);
175 } 167 }
176 } 168 }
177 } 169 }
178 DCHECK(to_base != from_base); 170 DCHECK(to_base != from_base);
179 DCHECK(IsFastSmiOrObjectElementsKind(to_kind)); 171 DCHECK(IsFastSmiOrObjectElementsKind(to_kind));
180 if (copy_size == 0) return; 172 if (copy_size == 0) return;
181 FixedArray* to = FixedArray::cast(to_base); 173 FixedArray* to = FixedArray::cast(to_base);
182 uint32_t to_length = to->length(); 174 uint32_t to_length = to->length();
183 if (to_start + copy_size > to_length) { 175 if (to_start + copy_size > to_length) {
184 copy_size = to_length - to_start; 176 copy_size = to_length - to_start;
185 } 177 }
178 bool needs_write_barrier = IsFastObjectElementsKind(to_kind);
186 for (int i = 0; i < copy_size; i++) { 179 for (int i = 0; i < copy_size; i++) {
187 int entry = from->FindEntry(i + from_start); 180 int entry = from->FindEntry(i + from_start);
188 if (entry != SeededNumberDictionary::kNotFound) { 181 if (entry != SeededNumberDictionary::kNotFound) {
189 Object* value = from->ValueAt(entry); 182 Object* value = from->ValueAt(entry);
190 DCHECK(!value->IsTheHole()); 183 DCHECK(!value->IsTheHole());
191 to->set(i + to_start, value, SKIP_WRITE_BARRIER); 184 to->set(i + to_start, value,
185 needs_write_barrier ? UPDATE_WRITE_BARRIER : SKIP_WRITE_BARRIER);
192 } else { 186 } else {
193 to->set_the_hole(i + to_start); 187 to->set_the_hole(i + to_start);
194 } 188 }
195 } 189 }
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 } 190 }
205 191
206 192
207 // NOTE: this method violates the handlified function signature convention: 193 // NOTE: this method violates the handlified function signature convention:
208 // raw pointer parameters in the function that allocates. 194 // raw pointer parameters in the function that allocates.
209 // See ElementsAccessorBase::CopyElements() for details. 195 // See ElementsAccessorBase::CopyElements() for details.
210 static void CopyDoubleToObjectElements(FixedArrayBase* from_base, 196 static void CopyDoubleToObjectElements(FixedArrayBase* from_base,
211 uint32_t from_start, 197 uint32_t from_start,
212 FixedArrayBase* to_base, 198 FixedArrayBase* to_base,
213 uint32_t to_start, int raw_copy_size) { 199 uint32_t to_start, int raw_copy_size) {
(...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2386 } 2372 }
2387 } 2373 }
2388 2374
2389 DCHECK(j == result_len); 2375 DCHECK(j == result_len);
2390 return result_array; 2376 return result_array;
2391 } 2377 }
2392 2378
2393 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; 2379 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL;
2394 } // namespace internal 2380 } // namespace internal
2395 } // namespace v8 2381 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698