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

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

Issue 2601213002: [ignition] Make a DCHECK in ConstantArrayBuilder more useful (Closed)
Patch Set: 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 | « src/interpreter/constant-array-builder.h ('k') | 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return constants_[index - start_index()]; 49 return constants_[index - start_index()];
50 } 50 }
51 51
52 void ConstantArrayBuilder::ConstantArraySlice::InsertAt(size_t index, 52 void ConstantArrayBuilder::ConstantArraySlice::InsertAt(size_t index,
53 Handle<Object> object) { 53 Handle<Object> object) {
54 DCHECK_GE(index, start_index()); 54 DCHECK_GE(index, start_index());
55 DCHECK_LT(index, start_index() + size()); 55 DCHECK_LT(index, start_index() + size());
56 constants_[index - start_index()] = object; 56 constants_[index - start_index()] = object;
57 } 57 }
58 58
59 bool ConstantArrayBuilder::ConstantArraySlice::AllElementsAreUnique() const { 59 #if DEBUG
60 void ConstantArrayBuilder::ConstantArraySlice::CheckAllElementsAreUnique()
61 const {
60 std::set<Object*> elements; 62 std::set<Object*> elements;
61 for (auto constant : constants_) { 63 for (auto constant : constants_) {
62 if (elements.find(*constant) != elements.end()) return false; 64 if (elements.find(*constant) != elements.end()) {
65 std::ostringstream os;
66 os << "Duplicate constant found: " << Brief(*constant);
67 FATAL(os.str().c_str());
68 }
63 elements.insert(*constant); 69 elements.insert(*constant);
64 } 70 }
65 return true;
66 } 71 }
72 #endif
67 73
68 STATIC_CONST_MEMBER_DEFINITION const size_t ConstantArrayBuilder::k8BitCapacity; 74 STATIC_CONST_MEMBER_DEFINITION const size_t ConstantArrayBuilder::k8BitCapacity;
69 STATIC_CONST_MEMBER_DEFINITION const size_t 75 STATIC_CONST_MEMBER_DEFINITION const size_t
70 ConstantArrayBuilder::k16BitCapacity; 76 ConstantArrayBuilder::k16BitCapacity;
71 STATIC_CONST_MEMBER_DEFINITION const size_t 77 STATIC_CONST_MEMBER_DEFINITION const size_t
72 ConstantArrayBuilder::k32BitCapacity; 78 ConstantArrayBuilder::k32BitCapacity;
73 79
74 ConstantArrayBuilder::ConstantArrayBuilder(Zone* zone, 80 ConstantArrayBuilder::ConstantArrayBuilder(Zone* zone,
75 Handle<Object> the_hole_value) 81 Handle<Object> the_hole_value)
76 : constants_map_(16, base::KeyEqualityMatcher<Address>(), 82 : constants_map_(16, base::KeyEqualityMatcher<Address>(),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 134
129 Handle<FixedArray> fixed_array = isolate->factory()->NewFixedArray( 135 Handle<FixedArray> fixed_array = isolate->factory()->NewFixedArray(
130 static_cast<int>(size()), PretenureFlag::TENURED); 136 static_cast<int>(size()), PretenureFlag::TENURED);
131 int array_index = 0; 137 int array_index = 0;
132 for (const ConstantArraySlice* slice : idx_slice_) { 138 for (const ConstantArraySlice* slice : idx_slice_) {
133 if (array_index == fixed_array->length()) { 139 if (array_index == fixed_array->length()) {
134 break; 140 break;
135 } 141 }
136 DCHECK(array_index == 0 || 142 DCHECK(array_index == 0 ||
137 base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index))); 143 base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index)));
144 #if DEBUG
138 // Different slices might contain the same element due to reservations, but 145 // 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 146 // all elements within a slice should be unique. If this DCHECK fails, then
140 // the AST nodes are not being internalized within a CanonicalHandleScope. 147 // the AST nodes are not being internalized within a CanonicalHandleScope.
141 DCHECK(slice->AllElementsAreUnique()); 148 slice->CheckAllElementsAreUnique();
149 #endif
142 // Copy objects from slice into array. 150 // Copy objects from slice into array.
143 for (size_t i = 0; i < slice->size(); ++i) { 151 for (size_t i = 0; i < slice->size(); ++i) {
144 fixed_array->set(array_index++, *slice->At(slice->start_index() + i)); 152 fixed_array->set(array_index++, *slice->At(slice->start_index() + i));
145 } 153 }
146 // Insert holes where reservations led to unused slots. 154 // Insert holes where reservations led to unused slots.
147 size_t padding = 155 size_t padding =
148 std::min(static_cast<size_t>(fixed_array->length() - array_index), 156 std::min(static_cast<size_t>(fixed_array->length() - array_index),
149 slice->capacity() - slice->size()); 157 slice->capacity() - slice->size());
150 for (size_t i = 0; i < padding; i++) { 158 for (size_t i = 0; i < padding; i++) {
151 fixed_array->set(array_index++, *the_hole_value()); 159 fixed_array->set(array_index++, *the_hole_value());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return index; 254 return index;
247 } 255 }
248 256
249 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) { 257 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) {
250 OperandSizeToSlice(operand_size)->Unreserve(); 258 OperandSizeToSlice(operand_size)->Unreserve();
251 } 259 }
252 260
253 } // namespace interpreter 261 } // namespace interpreter
254 } // namespace internal 262 } // namespace internal
255 } // namespace v8 263 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/constant-array-builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698