22namespace interpreter {
25 Zone* zone,
size_t start_index,
size_t capacity,
OperandSize operand_size)
26 : start_index_(start_index),
29 operand_size_(operand_size),
35 DCHECK_LE(reserved_, capacity() - constants_.size());
46 size_t index = constants_.size();
49 constants_.push_back(entry);
51 return index + start_index();
58 return constants_[index - start_index()];
65 return constants_[index - start_index()];
69template <
typename IsolateT>
70void ConstantArrayBuilder::ConstantArraySlice::CheckAllElementsAreUnique(
71 IsolateT* isolate)
const {
72 std::set<Tagged<Smi>> smis;
73 std::set<double> heap_numbers;
74 std::set<const AstRawString*> strings;
75 std::set<const AstConsString*> cons_strings;
76 std::set<const char*> bigints;
77 std::set<const Scope*> scopes;
79 for (
const Entry& entry : constants_) {
80 bool duplicate =
false;
83 duplicate = !smis.insert(entry.smi_).second;
86 duplicate = !heap_numbers.insert(entry.heap_number_).second;
89 duplicate = !strings.insert(entry.raw_string_).second;
92 duplicate = !cons_strings.insert(entry.cons_string_).second;
95 duplicate = !bigints.insert(entry.bigint_.c_str()).second;
98 duplicate = !scopes.insert(entry.scope_).second;
101 duplicate = !deferred_objects.insert(*entry.handle_).second;
110#define CASE_TAG(NAME, ...) case Entry::Tag::k##NAME:
117 std::ostringstream os;
118 os <<
"Duplicate constant found: " <<
Brief(*entry.ToHandle(isolate))
121 size_t i = start_index();
122 for (
const Entry& prev_entry : constants_) {
123 os <<
i++ <<
": " <<
Brief(*prev_entry.ToHandle(isolate)) << std::endl;
125 FATAL(
"%s", os.str().c_str());
155 if (slice->
size() > 0) {
163 size_t index)
const {
172template <
typename IsolateT>
174 IsolateT* isolate)
const {
178 const Entry& entry = slice->
At(index);
191template <
typename IsolateT>
195 isolate->factory()->NewTrustedFixedArray(
static_cast<int>(
size()));
197 *isolate->factory()->the_hole_value(), size());
199 for (
const ConstantArraySlice* slice :
idx_slice_) {
201 DCHECK(array_index == 0 ||
206 slice->CheckAllElementsAreUnique(isolate);
209 for (
size_t i = 0;
i < slice->
size(); ++
i) {
211 slice->At(slice->start_index() +
i).ToHandle(isolate);
212 fixed_array->set(array_index++, *value);
215 size_t padding = slice->capacity() - slice->size();
216 if (
static_cast<size_t>(fixed_array->length() - array_index) <= padding) {
219 array_index += padding;
221 DCHECK_GE(array_index, fixed_array->length());
230 LocalIsolate* isolate);
237 return entry->second;
241 if (std::isnan(number))
return InsertNaN();
248 return entry->second;
253 .LookupOrInsert(
reinterpret_cast<intptr_t
>(raw_string),
255 [&]() { return AllocateIndex(Entry(raw_string)); })
261 uint32_t hash = last ==
nullptr ? 0 : last->Hash();
263 .LookupOrInsert(
reinterpret_cast<intptr_t
>(cons_string), hash,
270 .LookupOrInsert(
reinterpret_cast<intptr_t
>(bigint.
c_str()),
272 [&]() { return AllocateIndex(Entry(bigint)); })
278 .LookupOrInsert(
reinterpret_cast<intptr_t
>(scope),
284#define INSERT_ENTRY(NAME, LOWER_NAME) \
285 size_t ConstantArrayBuilder::Insert##NAME() { \
286 if (LOWER_NAME##_ < 0) { \
287 LOWER_NAME##_ = AllocateIndex(Entry::NAME()); \
289 return LOWER_NAME##_; \
312 switch (operand_size) {
355 idx_slice_[
i]->operand_size() >= minimum_operand_size) {
379 index = entry->second;
395template <
typename IsolateT>
408 return isolate->factory()->the_hole_value();
414 return isolate->factory()->template NewNumber<AllocationType::kOld>(
421 return scope_->scope_info();
422#define ENTRY_LOOKUP(Name, name) \
424 return isolate->factory()->name();
const char * c_str() const
const AstRawString * last() const
@ kUninitializedJumpTableSmi
void SetJumpTableSmi(Tagged< Smi > smi)
static Entry UninitializedJumpTableSmi()
IndirectHandle< Object > handle_
void SetDeferred(Handle< Object > handle)
const AstRawString * raw_string_
const AstConsString * cons_string_
enum v8::internal::interpreter::ConstantArrayBuilder::Entry::Tag tag_
Handle< Object > ToHandle(IsolateT *isolate) const
static const size_t k8BitCapacity
void SetJumpTableSmi(size_t index, Tagged< Smi > smi)
MaybeHandle< Object > At(size_t index, IsolateT *isolate) const
void DiscardReservedEntry(OperandSize operand_size)
ConstantArraySlice * IndexToSlice(size_t index) const
ConstantArraySlice * OperandSizeToSlice(OperandSize operand_size) const
ZoneMap< double, index_t > heap_number_map_
ConstantArrayBuilder(Zone *zone)
static const size_t k32BitCapacity
static const size_t k16BitCapacity
Handle< TrustedFixedArray > ToFixedArray(IsolateT *isolate)
ZoneMap< Tagged< Smi >, index_t > smi_map_
void SetDeferredAt(size_t index, Handle< Object > object)
base::TemplateHashMapImpl< intptr_t, index_t, base::KeyEqualityMatcher< intptr_t >, ZoneAllocationPolicy > constants_map_
index_t AllocateIndex(Entry constant_entry)
ConstantArraySlice * idx_slice_[3]
size_t InsertJumpTable(size_t size)
ZoneVector< std::pair< Tagged< Smi >, index_t > > smi_pairs_
size_t Insert(Tagged< Smi > smi)
index_t AllocateIndexArray(Entry constant_entry, size_t size)
size_t CommitReservedEntry(OperandSize operand_size, Tagged< Smi > value)
index_t AllocateReservedEntry(Tagged< Smi > value)
OperandSize CreateReservedEntry(OperandSize minimum_operand_size=OperandSize::kNone)
#define INSERT_ENTRY(NAME, LOWER_NAME)
#define ENTRY_LOOKUP(Name, name)
#define SINGLETON_CONSTANT_ENTRY_TYPES(V)
#define EXPORT_TEMPLATE_DEFINE(export)
constexpr bool IsPowerOfTwo(T value)
V8_INLINE size_t hash_value(unsigned int v)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
void MemsetTagged(Tagged_t *start, Tagged< MaybeObject > value, size_t counter)
MaybeHandle< BigInt > BigIntLiteral(IsolateT *isolate, const char *string)
#define STATIC_CONST_MEMBER_DEFINITION
#define DCHECK_LE(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define DCHECK_GT(v1, v2)
#define V8_EXPORT_PRIVATE
size_t Allocate(Entry entry, size_t count=1)
OperandSize operand_size() const
ConstantArraySlice(Zone *zone, size_t start_index, size_t capacity, OperandSize operand_size)
size_t start_index() const