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

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

Issue 2336553002: [interpreter] Use hashmap for ConstantArrayBuilder's constant map (Closed)
Patch Set: Rebase Created 4 years, 2 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 <set> 8 #include <set>
8 9
9 #include "src/isolate.h" 10 #include "src/isolate.h"
10 #include "src/objects-inl.h" 11 #include "src/objects-inl.h"
11 12
12 namespace v8 { 13 namespace v8 {
13 namespace internal { 14 namespace internal {
14 namespace interpreter { 15 namespace interpreter {
15 16
16 ConstantArrayBuilder::ConstantArraySlice::ConstantArraySlice( 17 ConstantArrayBuilder::ConstantArraySlice::ConstantArraySlice(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 66 }
66 67
67 STATIC_CONST_MEMBER_DEFINITION const size_t ConstantArrayBuilder::k8BitCapacity; 68 STATIC_CONST_MEMBER_DEFINITION const size_t ConstantArrayBuilder::k8BitCapacity;
68 STATIC_CONST_MEMBER_DEFINITION const size_t 69 STATIC_CONST_MEMBER_DEFINITION const size_t
69 ConstantArrayBuilder::k16BitCapacity; 70 ConstantArrayBuilder::k16BitCapacity;
70 STATIC_CONST_MEMBER_DEFINITION const size_t 71 STATIC_CONST_MEMBER_DEFINITION const size_t
71 ConstantArrayBuilder::k32BitCapacity; 72 ConstantArrayBuilder::k32BitCapacity;
72 73
73 ConstantArrayBuilder::ConstantArrayBuilder(Zone* zone, 74 ConstantArrayBuilder::ConstantArrayBuilder(Zone* zone,
74 Handle<Object> the_hole_value) 75 Handle<Object> the_hole_value)
75 : constants_map_(zone), 76 : constants_map_(std::equal_to<Address>(), 16, ZoneAllocationPolicy(zone)),
76 smi_map_(zone), 77 smi_map_(zone),
77 smi_pairs_(zone), 78 smi_pairs_(zone),
79 zone_(zone),
78 the_hole_value_(the_hole_value) { 80 the_hole_value_(the_hole_value) {
79 idx_slice_[0] = 81 idx_slice_[0] =
80 new (zone) ConstantArraySlice(zone, 0, k8BitCapacity, OperandSize::kByte); 82 new (zone) ConstantArraySlice(zone, 0, k8BitCapacity, OperandSize::kByte);
81 idx_slice_[1] = new (zone) ConstantArraySlice( 83 idx_slice_[1] = new (zone) ConstantArraySlice(
82 zone, k8BitCapacity, k16BitCapacity, OperandSize::kShort); 84 zone, k8BitCapacity, k16BitCapacity, OperandSize::kShort);
83 idx_slice_[2] = new (zone) ConstantArraySlice( 85 idx_slice_[2] = new (zone) ConstantArraySlice(
84 zone, k8BitCapacity + k16BitCapacity, k32BitCapacity, OperandSize::kQuad); 86 zone, k8BitCapacity + k16BitCapacity, k32BitCapacity, OperandSize::kQuad);
85 } 87 }
86 88
87 size_t ConstantArrayBuilder::size() const { 89 size_t ConstantArrayBuilder::size() const {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 slice->capacity() - slice->size()); 148 slice->capacity() - slice->size());
147 for (size_t i = 0; i < padding; i++) { 149 for (size_t i = 0; i < padding; i++) {
148 fixed_array->set(array_index++, *the_hole_value()); 150 fixed_array->set(array_index++, *the_hole_value());
149 } 151 }
150 } 152 }
151 DCHECK_EQ(array_index, fixed_array->length()); 153 DCHECK_EQ(array_index, fixed_array->length());
152 return fixed_array; 154 return fixed_array;
153 } 155 }
154 156
155 size_t ConstantArrayBuilder::Insert(Handle<Object> object) { 157 size_t ConstantArrayBuilder::Insert(Handle<Object> object) {
156 auto entry = constants_map_.find(object.address()); 158 return constants_map_
157 return (entry == constants_map_.end()) ? AllocateEntry(object) 159 .LookupOrInsert(object.address(), ObjectHash(object.address()),
158 : entry->second; 160 [&]() { return AllocateIndex(object); },
159 } 161 ZoneAllocationPolicy(zone_))
160 162 ->value;
161 ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateEntry(
162 Handle<Object> object) {
163 index_t index = AllocateIndex(object);
164 constants_map_[object.address()] = index;
165 return index;
166 } 163 }
167 164
168 ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateIndex( 165 ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateIndex(
169 Handle<Object> object) { 166 Handle<Object> object) {
170 for (size_t i = 0; i < arraysize(idx_slice_); ++i) { 167 for (size_t i = 0; i < arraysize(idx_slice_); ++i) {
171 if (idx_slice_[i]->available() > 0) { 168 if (idx_slice_[i]->available() > 0) {
172 return static_cast<index_t>(idx_slice_[i]->Allocate(object)); 169 return static_cast<index_t>(idx_slice_[i]->Allocate(object));
173 } 170 }
174 } 171 }
175 UNREACHABLE(); 172 UNREACHABLE();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return index; 245 return index;
249 } 246 }
250 247
251 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) { 248 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) {
252 OperandSizeToSlice(operand_size)->Unreserve(); 249 OperandSizeToSlice(operand_size)->Unreserve();
253 } 250 }
254 251
255 } // namespace interpreter 252 } // namespace interpreter
256 } // namespace internal 253 } // namespace internal
257 } // namespace v8 254 } // 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