5 #ifndef V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ 6 #define V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_ 8 #include "src/ast/ast-value-factory.h" 9 #include "src/globals.h" 10 #include "src/identity-map.h" 11 #include "src/interpreter/bytecodes.h" 12 #include "src/objects/smi.h" 13 #include "src/zone/zone-containers.h" 22 namespace interpreter {
25 #define SINGLETON_CONSTANT_ENTRY_TYPES(V) \ 26 V(AsyncIteratorSymbol, async_iterator_symbol) \ 27 V(ClassFieldsSymbol, class_fields_symbol) \ 28 V(EmptyObjectBoilerplateDescription, empty_object_boilerplate_description) \ 29 V(EmptyArrayBoilerplateDescription, empty_array_boilerplate_description) \ 30 V(EmptyFixedArray, empty_fixed_array) \ 31 V(HomeObjectSymbol, home_object_symbol) \ 32 V(IteratorSymbol, iterator_symbol) \ 33 V(InterpreterTrampolineSymbol, interpreter_trampoline_symbol) \ 43 static const size_t k8BitCapacity = 1u << kBitsPerByte;
46 static const size_t k16BitCapacity = (1u << 2 * kBitsPerByte) - k8BitCapacity;
49 static const size_t k32BitCapacity =
50 kMaxUInt32 - k16BitCapacity - k8BitCapacity + 1;
67 size_t Insert(
Smi smi);
68 size_t Insert(
double number);
71 size_t Insert(
const Scope* scope);
72 #define INSERT_ENTRY(NAME, ...) size_t Insert##NAME(); 73 SINGLETON_CONSTANT_ENTRY_TYPES(INSERT_ENTRY)
79 size_t InsertDeferred();
84 size_t InsertJumpTable(
size_t size);
91 void SetJumpTableSmi(
size_t index,
Smi smi);
96 OperandSize CreateReservedEntry();
100 size_t CommitReservedEntry(OperandSize operand_size,
Smi value);
103 void DiscardReservedEntry(OperandSize operand_size);
108 struct ConstantArraySlice;
112 enum class Tag : uint8_t;
115 explicit Entry(Smi smi) : smi_(smi), tag_(Tag::kSmi) {}
116 explicit Entry(
double heap_number)
117 : heap_number_(heap_number), tag_(Tag::kHeapNumber) {}
119 : raw_string_(raw_string), tag_(Tag::kRawString) {}
120 explicit Entry(
AstBigInt bigint) : bigint_(bigint), tag_(Tag::kBigInt) {}
121 explicit Entry(
const Scope* scope) : scope_(scope), tag_(Tag::kScope) {}
123 #define CONSTRUCT_ENTRY(NAME, LOWER_NAME) \ 124 static Entry NAME() { return Entry(Tag::k##NAME); } 125 SINGLETON_CONSTANT_ENTRY_TYPES(CONSTRUCT_ENTRY)
126 #undef CONSTRUCT_ENTRY 128 static Entry Deferred() {
return Entry(Tag::kDeferred); }
130 static Entry UninitializedJumpTableSmi() {
131 return Entry(Tag::kUninitializedJumpTableSmi);
134 bool IsDeferred()
const {
return tag_ == Tag::kDeferred; }
136 bool IsJumpTableEntry()
const {
137 return tag_ == Tag::kUninitializedJumpTableSmi ||
138 tag_ == Tag::kJumpTableSmi;
142 DCHECK_EQ(tag_, Tag::kDeferred);
147 void SetJumpTableSmi(
Smi smi) {
148 DCHECK_EQ(tag_, Tag::kUninitializedJumpTableSmi);
149 tag_ = Tag::kJumpTableSmi;
156 explicit Entry(Tag tag) : tag_(tag) {}
167 enum class Tag : uint8_t {
175 kUninitializedJumpTableSmi,
177 #define ENTRY_TAG(NAME, ...) k##NAME, 178 SINGLETON_CONSTANT_ENTRY_TYPES(ENTRY_TAG)
184 friend struct ConstantArraySlice;
188 index_t AllocateIndex(Entry constant_entry);
189 index_t AllocateIndexArray(Entry constant_entry,
size_t size);
192 struct ConstantArraySlice final :
public ZoneObject {
193 ConstantArraySlice(
Zone* zone,
size_t start_index,
size_t capacity,
194 OperandSize operand_size);
197 size_t Allocate(Entry entry,
size_t count = 1);
198 Entry& At(
size_t index);
199 const Entry& At(
size_t index)
const;
202 void CheckAllElementsAreUnique(
Isolate* isolate)
const;
205 inline size_t available()
const {
return capacity() - reserved() - size(); }
206 inline size_t reserved()
const {
return reserved_; }
207 inline size_t capacity()
const {
return capacity_; }
208 inline size_t size()
const {
return constants_.size(); }
209 inline size_t start_index()
const {
return start_index_; }
210 inline size_t max_index()
const {
return start_index_ + capacity() - 1; }
211 inline OperandSize operand_size()
const {
return operand_size_; }
214 const size_t start_index_;
215 const size_t capacity_;
217 OperandSize operand_size_;
220 DISALLOW_COPY_AND_ASSIGN(ConstantArraySlice);
223 ConstantArraySlice* IndexToSlice(
size_t index)
const;
224 ConstantArraySlice* OperandSizeToSlice(OperandSize operand_size)
const;
226 ConstantArraySlice* idx_slice_[3];
235 #define SINGLETON_ENTRY_FIELD(NAME, LOWER_NAME) int LOWER_NAME##_; 236 SINGLETON_CONSTANT_ENTRY_TYPES(SINGLETON_ENTRY_FIELD)
237 #undef SINGLETON_ENTRY_FIELD 246 #endif // V8_INTERPRETER_CONSTANT_ARRAY_BUILDER_H_