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

Side by Side Diff: src/interpreter/constant-array-builder.cc

Issue 2586513002: [ignition] Prefill the constant array with holes to avoid needing to write padding holes (Closed)
Patch Set: rebase Created 3 years, 11 months 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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/interpreter/constant-array-builder.h" 5 #include "src/interpreter/constant-array-builder.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <set> 8 #include <set>
9 9
10 #include "src/isolate.h" 10 #include "src/isolate.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 } 126 }
127 127
128 Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) { 128 Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) {
129 // First insert reserved SMI values. 129 // First insert reserved SMI values.
130 for (auto reserved_smi : smi_pairs_) { 130 for (auto reserved_smi : smi_pairs_) {
131 InsertAllocatedEntry(reserved_smi.second, 131 InsertAllocatedEntry(reserved_smi.second,
132 handle(reserved_smi.first, isolate)); 132 handle(reserved_smi.first, isolate));
133 } 133 }
134 134
135 Handle<FixedArray> fixed_array = isolate->factory()->NewFixedArray( 135 Handle<FixedArray> fixed_array = isolate->factory()->NewFixedArrayWithHoles(
136 static_cast<int>(size()), PretenureFlag::TENURED); 136 static_cast<int>(size()), PretenureFlag::TENURED);
137 int array_index = 0; 137 int array_index = 0;
138 for (const ConstantArraySlice* slice : idx_slice_) { 138 for (const ConstantArraySlice* slice : idx_slice_) {
139 if (array_index == fixed_array->length()) {
140 break;
141 }
142 DCHECK(array_index == 0 || 139 DCHECK(array_index == 0 ||
143 base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index))); 140 base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index)));
144 #if DEBUG 141 #if DEBUG
145 // Different slices might contain the same element due to reservations, but 142 // Different slices might contain the same element due to reservations, but
146 // all elements within a slice should be unique. If this DCHECK fails, then 143 // all elements within a slice should be unique. If this DCHECK fails, then
147 // the AST nodes are not being internalized within a CanonicalHandleScope. 144 // the AST nodes are not being internalized within a CanonicalHandleScope.
148 slice->CheckAllElementsAreUnique(); 145 slice->CheckAllElementsAreUnique();
149 #endif 146 #endif
150 // Copy objects from slice into array. 147 // Copy objects from slice into array.
151 for (size_t i = 0; i < slice->size(); ++i) { 148 for (size_t i = 0; i < slice->size(); ++i) {
152 fixed_array->set(array_index++, *slice->At(slice->start_index() + i)); 149 fixed_array->set(array_index++, *slice->At(slice->start_index() + i));
153 } 150 }
154 // Insert holes where reservations led to unused slots. 151 // Leave holes where reservations led to unused slots.
155 size_t padding = 152 size_t padding = slice->capacity() - slice->size();
156 std::min(static_cast<size_t>(fixed_array->length() - array_index), 153 if (static_cast<size_t>(fixed_array->length() - array_index) <= padding) {
157 slice->capacity() - slice->size()); 154 break;
158 for (size_t i = 0; i < padding; i++) {
159 fixed_array->set(array_index++, *the_hole_value());
160 } 155 }
156 array_index += padding;
161 } 157 }
162 DCHECK_EQ(array_index, fixed_array->length()); 158 DCHECK_GE(array_index, fixed_array->length());
163 return fixed_array; 159 return fixed_array;
164 } 160 }
165 161
166 size_t ConstantArrayBuilder::Insert(Handle<Object> object) { 162 size_t ConstantArrayBuilder::Insert(Handle<Object> object) {
167 return constants_map_ 163 return constants_map_
168 .LookupOrInsert(object.address(), ObjectHash(object.address()), 164 .LookupOrInsert(object.address(), ObjectHash(object.address()),
169 [&]() { return AllocateIndex(object); }, 165 [&]() { return AllocateIndex(object); },
170 ZoneAllocationPolicy(zone_)) 166 ZoneAllocationPolicy(zone_))
171 ->value; 167 ->value;
172 } 168 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 return index; 250 return index;
255 } 251 }
256 252
257 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) { 253 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) {
258 OperandSizeToSlice(operand_size)->Unreserve(); 254 OperandSizeToSlice(operand_size)->Unreserve();
259 } 255 }
260 256
261 } // namespace interpreter 257 } // namespace interpreter
262 } // namespace internal 258 } // namespace internal
263 } // namespace v8 259 } // 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