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

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: Created 4 years 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 } 120 }
121 121
122 Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) { 122 Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) {
123 // First insert reserved SMI values. 123 // First insert reserved SMI values.
124 for (auto reserved_smi : smi_pairs_) { 124 for (auto reserved_smi : smi_pairs_) {
125 InsertAllocatedEntry(reserved_smi.second, 125 InsertAllocatedEntry(reserved_smi.second,
126 handle(reserved_smi.first, isolate)); 126 handle(reserved_smi.first, isolate));
127 } 127 }
128 128
129 Handle<FixedArray> fixed_array = isolate->factory()->NewFixedArray( 129 Handle<FixedArray> fixed_array = isolate->factory()->NewFixedArrayWithHoles(
130 static_cast<int>(size()), PretenureFlag::TENURED); 130 static_cast<int>(size()), PretenureFlag::TENURED);
131 int array_index = 0; 131 int array_index = 0;
132 for (const ConstantArraySlice* slice : idx_slice_) { 132 for (const ConstantArraySlice* slice : idx_slice_) {
133 if (array_index == fixed_array->length()) { 133 if (array_index >= fixed_array->length()) break;
134 break; 134
135 }
136 DCHECK(array_index == 0 || 135 DCHECK(array_index == 0 ||
137 base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index))); 136 base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index)));
138 // Different slices might contain the same element due to reservations, but 137 // Different slices might contain the same element due to reservations, but
139 // all elements within a slice should be unique. If this DCHECK fails, then 138 // all elements within a slice should be unique. If this DCHECK fails, then
140 // the AST nodes are not being internalized within a CanonicalHandleScope. 139 // the AST nodes are not being internalized within a CanonicalHandleScope.
141 DCHECK(slice->AllElementsAreUnique()); 140 DCHECK(slice->AllElementsAreUnique());
142 // Copy objects from slice into array. 141 // Copy objects from slice into array.
143 for (size_t i = 0; i < slice->size(); ++i) { 142 for (size_t i = 0; i < slice->size(); ++i) {
144 fixed_array->set(array_index++, *slice->At(slice->start_index() + i)); 143 fixed_array->set(array_index++, *slice->At(slice->start_index() + i));
145 } 144 }
146 // Insert holes where reservations led to unused slots. 145 // Leave holes where reservations led to unused slots.
147 size_t padding = 146 array_index += slice->capacity() - slice->size();
148 std::min(static_cast<size_t>(fixed_array->length() - array_index),
149 slice->capacity() - slice->size());
150 for (size_t i = 0; i < padding; i++) {
151 fixed_array->set(array_index++, *the_hole_value());
152 }
153 } 147 }
154 DCHECK_EQ(array_index, fixed_array->length());
Leszek Swirski 2016/12/16 16:50:54 I would keep this check, as a DCHECK_GE
155 return fixed_array; 148 return fixed_array;
156 } 149 }
157 150
158 size_t ConstantArrayBuilder::Insert(Handle<Object> object) { 151 size_t ConstantArrayBuilder::Insert(Handle<Object> object) {
159 return constants_map_ 152 return constants_map_
160 .LookupOrInsert(object.address(), ObjectHash(object.address()), 153 .LookupOrInsert(object.address(), ObjectHash(object.address()),
161 [&]() { return AllocateIndex(object); }, 154 [&]() { return AllocateIndex(object); },
162 ZoneAllocationPolicy(zone_)) 155 ZoneAllocationPolicy(zone_))
163 ->value; 156 ->value;
164 } 157 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return index; 239 return index;
247 } 240 }
248 241
249 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) { 242 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) {
250 OperandSizeToSlice(operand_size)->Unreserve(); 243 OperandSizeToSlice(operand_size)->Unreserve();
251 } 244 }
252 245
253 } // namespace interpreter 246 } // namespace interpreter
254 } // namespace internal 247 } // namespace internal
255 } // namespace v8 248 } // 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