1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_OBJECTS_DEFINITIONS_H_
6#define V8_OBJECTS_DEFINITIONS_H_
7
8#include "src/heap-symbols.h"
9
10namespace v8 {
11
12namespace internal {
13
14// All Maps have a field instance_type containing a InstanceType.
15// It describes the type of the instances.
16//
17// As an example, a JavaScript object is a heap object and its map
18// instance_type is JS_OBJECT_TYPE.
19//
20// The names of the string instance types are intended to systematically
21// mirror their encoding in the instance_type field of the map. The default
22// encoding is considered TWO_BYTE. It is not mentioned in the name. ONE_BYTE
23// encoding is mentioned explicitly in the name. Likewise, the default
24// representation is considered sequential. It is not mentioned in the
25// name. The other representations (e.g. CONS, EXTERNAL) are explicitly
26// mentioned. Finally, the string is either a STRING_TYPE (if it is a normal
27// string) or a INTERNALIZED_STRING_TYPE (if it is a internalized string).
28//
29// NOTE: The following things are some that depend on the string types having
30// instance_types that are less than those of all other types:
31// HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
32// Object::IsString.
33//
34// NOTE: Everything following JS_VALUE_TYPE is considered a
35// JSObject for GC purposes. The first four entries here have typeof
36// 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
37//
38// NOTE: List had to be split into two, because of conditional item(s) from
39// INTL namespace. They can't just be appended to the end, because of the
40// checks we do in tests (expecting JS_FUNCTION_TYPE to be last).
41#define INSTANCE_TYPE_LIST_BEFORE_INTL(V) \
42 V(INTERNALIZED_STRING_TYPE) \
43 V(EXTERNAL_INTERNALIZED_STRING_TYPE) \
44 V(ONE_BYTE_INTERNALIZED_STRING_TYPE) \
45 V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \
46 V(UNCACHED_EXTERNAL_INTERNALIZED_STRING_TYPE) \
47 V(UNCACHED_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \
48 V(STRING_TYPE) \
49 V(CONS_STRING_TYPE) \
50 V(EXTERNAL_STRING_TYPE) \
51 V(SLICED_STRING_TYPE) \
52 V(THIN_STRING_TYPE) \
53 V(ONE_BYTE_STRING_TYPE) \
54 V(CONS_ONE_BYTE_STRING_TYPE) \
55 V(EXTERNAL_ONE_BYTE_STRING_TYPE) \
56 V(SLICED_ONE_BYTE_STRING_TYPE) \
57 V(THIN_ONE_BYTE_STRING_TYPE) \
58 V(UNCACHED_EXTERNAL_STRING_TYPE) \
59 V(UNCACHED_EXTERNAL_ONE_BYTE_STRING_TYPE) \
60 V(EMPTY_STRING_TYPE) \
61 \
62 V(SYMBOL_TYPE) \
63 V(HEAP_NUMBER_TYPE) \
64 V(BIGINT_TYPE) \
65 V(ODDBALL_TYPE) \
66 \
67 V(MAP_TYPE) \
68 V(CODE_TYPE) \
69 V(MUTABLE_HEAP_NUMBER_TYPE) \
70 V(FOREIGN_TYPE) \
71 V(BYTE_ARRAY_TYPE) \
72 V(BYTECODE_ARRAY_TYPE) \
73 V(FREE_SPACE_TYPE) \
74 \
75 V(FIXED_INT8_ARRAY_TYPE) \
76 V(FIXED_UINT8_ARRAY_TYPE) \
77 V(FIXED_INT16_ARRAY_TYPE) \
78 V(FIXED_UINT16_ARRAY_TYPE) \
79 V(FIXED_INT32_ARRAY_TYPE) \
80 V(FIXED_UINT32_ARRAY_TYPE) \
81 V(FIXED_FLOAT32_ARRAY_TYPE) \
82 V(FIXED_FLOAT64_ARRAY_TYPE) \
83 V(FIXED_UINT8_CLAMPED_ARRAY_TYPE) \
84 V(FIXED_BIGINT64_ARRAY_TYPE) \
85 V(FIXED_BIGUINT64_ARRAY_TYPE) \
86 \
87 V(FIXED_DOUBLE_ARRAY_TYPE) \
88 V(FEEDBACK_METADATA_TYPE) \
89 V(FILLER_TYPE) \
90 \
91 V(ACCESS_CHECK_INFO_TYPE) \
92 V(ACCESSOR_INFO_TYPE) \
93 V(ACCESSOR_PAIR_TYPE) \
94 V(ALIASED_ARGUMENTS_ENTRY_TYPE) \
95 V(ALLOCATION_MEMENTO_TYPE) \
96 V(ASM_WASM_DATA_TYPE) \
97 V(ASYNC_GENERATOR_REQUEST_TYPE) \
98 V(CLASS_POSITIONS_TYPE) \
99 V(DEBUG_INFO_TYPE) \
100 V(FUNCTION_TEMPLATE_INFO_TYPE) \
101 V(FUNCTION_TEMPLATE_RARE_DATA_TYPE) \
102 V(INTERCEPTOR_INFO_TYPE) \
103 V(INTERPRETER_DATA_TYPE) \
104 V(MODULE_INFO_ENTRY_TYPE) \
105 V(MODULE_TYPE) \
106 V(OBJECT_TEMPLATE_INFO_TYPE) \
107 V(PROMISE_CAPABILITY_TYPE) \
108 V(PROMISE_REACTION_TYPE) \
109 V(PROTOTYPE_INFO_TYPE) \
110 V(SCRIPT_TYPE) \
111 V(STACK_FRAME_INFO_TYPE) \
112 V(STACK_TRACE_FRAME_TYPE) \
113 V(TUPLE2_TYPE) \
114 V(TUPLE3_TYPE) \
115 V(ARRAY_BOILERPLATE_DESCRIPTION_TYPE) \
116 V(WASM_DEBUG_INFO_TYPE) \
117 V(WASM_EXCEPTION_TAG_TYPE) \
118 V(WASM_EXPORTED_FUNCTION_DATA_TYPE) \
119 \
120 V(CALLABLE_TASK_TYPE) \
121 V(CALLBACK_TASK_TYPE) \
122 V(PROMISE_FULFILL_REACTION_JOB_TASK_TYPE) \
123 V(PROMISE_REJECT_REACTION_JOB_TASK_TYPE) \
124 V(PROMISE_RESOLVE_THENABLE_JOB_TASK_TYPE) \
125 V(FINALIZATION_GROUP_CLEANUP_JOB_TASK_TYPE) \
126 \
127 V(ALLOCATION_SITE_TYPE) \
128 V(EMBEDDER_DATA_ARRAY_TYPE) \
129 \
130 V(FIXED_ARRAY_TYPE) \
131 V(OBJECT_BOILERPLATE_DESCRIPTION_TYPE) \
132 V(CLOSURE_FEEDBACK_CELL_ARRAY_TYPE) \
133 V(HASH_TABLE_TYPE) \
134 V(ORDERED_HASH_MAP_TYPE) \
135 V(ORDERED_HASH_SET_TYPE) \
136 V(ORDERED_NAME_DICTIONARY_TYPE) \
137 V(NAME_DICTIONARY_TYPE) \
138 V(GLOBAL_DICTIONARY_TYPE) \
139 V(NUMBER_DICTIONARY_TYPE) \
140 V(SIMPLE_NUMBER_DICTIONARY_TYPE) \
141 V(STRING_TABLE_TYPE) \
142 V(EPHEMERON_HASH_TABLE_TYPE) \
143 V(SCOPE_INFO_TYPE) \
144 V(SCRIPT_CONTEXT_TABLE_TYPE) \
145 \
146 V(AWAIT_CONTEXT_TYPE) \
147 V(BLOCK_CONTEXT_TYPE) \
148 V(CATCH_CONTEXT_TYPE) \
149 V(DEBUG_EVALUATE_CONTEXT_TYPE) \
150 V(EVAL_CONTEXT_TYPE) \
151 V(FUNCTION_CONTEXT_TYPE) \
152 V(MODULE_CONTEXT_TYPE) \
153 V(NATIVE_CONTEXT_TYPE) \
154 V(SCRIPT_CONTEXT_TYPE) \
155 V(WITH_CONTEXT_TYPE) \
156 \
157 V(WEAK_FIXED_ARRAY_TYPE) \
158 V(TRANSITION_ARRAY_TYPE) \
159 \
160 V(CALL_HANDLER_INFO_TYPE) \
161 V(CELL_TYPE) \
162 V(CODE_DATA_CONTAINER_TYPE) \
163 V(DESCRIPTOR_ARRAY_TYPE) \
164 V(FEEDBACK_CELL_TYPE) \
165 V(FEEDBACK_VECTOR_TYPE) \
166 V(LOAD_HANDLER_TYPE) \
167 V(PREPARSE_DATA_TYPE) \
168 V(PROPERTY_ARRAY_TYPE) \
169 V(PROPERTY_CELL_TYPE) \
170 V(SHARED_FUNCTION_INFO_TYPE) \
171 V(SMALL_ORDERED_HASH_MAP_TYPE) \
172 V(SMALL_ORDERED_HASH_SET_TYPE) \
173 V(SMALL_ORDERED_NAME_DICTIONARY_TYPE) \
174 V(STORE_HANDLER_TYPE) \
175 V(UNCOMPILED_DATA_WITHOUT_PREPARSE_DATA_TYPE) \
176 V(UNCOMPILED_DATA_WITH_PREPARSE_DATA_TYPE) \
177 V(WEAK_ARRAY_LIST_TYPE) \
178 V(WEAK_CELL_TYPE) \
179 \
180 V(JS_PROXY_TYPE) \
181 V(JS_GLOBAL_OBJECT_TYPE) \
182 V(JS_GLOBAL_PROXY_TYPE) \
183 V(JS_MODULE_NAMESPACE_TYPE) \
184 V(JS_SPECIAL_API_OBJECT_TYPE) \
185 V(JS_VALUE_TYPE) \
186 V(JS_API_OBJECT_TYPE) \
187 V(JS_OBJECT_TYPE) \
188 \
189 V(JS_ARGUMENTS_TYPE) \
190 V(JS_ARRAY_BUFFER_TYPE) \
191 V(JS_ARRAY_ITERATOR_TYPE) \
192 V(JS_ARRAY_TYPE) \
193 V(JS_ASYNC_FROM_SYNC_ITERATOR_TYPE) \
194 V(JS_ASYNC_FUNCTION_OBJECT_TYPE) \
195 V(JS_ASYNC_GENERATOR_OBJECT_TYPE) \
196 V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \
197 V(JS_DATE_TYPE) \
198 V(JS_ERROR_TYPE) \
199 V(JS_GENERATOR_OBJECT_TYPE) \
200 V(JS_MAP_TYPE) \
201 V(JS_MAP_KEY_ITERATOR_TYPE) \
202 V(JS_MAP_KEY_VALUE_ITERATOR_TYPE) \
203 V(JS_MAP_VALUE_ITERATOR_TYPE) \
204 V(JS_MESSAGE_OBJECT_TYPE) \
205 V(JS_PROMISE_TYPE) \
206 V(JS_REGEXP_TYPE) \
207 V(JS_REGEXP_STRING_ITERATOR_TYPE) \
208 V(JS_SET_TYPE) \
209 V(JS_SET_KEY_VALUE_ITERATOR_TYPE) \
210 V(JS_SET_VALUE_ITERATOR_TYPE) \
211 V(JS_STRING_ITERATOR_TYPE) \
212 V(JS_WEAK_REF_TYPE) \
213 V(JS_FINALIZATION_GROUP_CLEANUP_ITERATOR_TYPE) \
214 V(JS_FINALIZATION_GROUP_TYPE) \
215 V(JS_WEAK_MAP_TYPE) \
216 V(JS_WEAK_SET_TYPE) \
217 V(JS_TYPED_ARRAY_TYPE) \
218 V(JS_DATA_VIEW_TYPE)
219
220#define INSTANCE_TYPE_LIST_AFTER_INTL(V) \
221 V(WASM_EXCEPTION_TYPE) \
222 V(WASM_GLOBAL_TYPE) \
223 V(WASM_INSTANCE_TYPE) \
224 V(WASM_MEMORY_TYPE) \
225 V(WASM_MODULE_TYPE) \
226 V(WASM_TABLE_TYPE) \
227 V(JS_BOUND_FUNCTION_TYPE) \
228 V(JS_FUNCTION_TYPE)
229
230#ifdef V8_INTL_SUPPORT
231#define INSTANCE_TYPE_LIST(V) \
232 INSTANCE_TYPE_LIST_BEFORE_INTL(V) \
233 V(JS_INTL_V8_BREAK_ITERATOR_TYPE) \
234 V(JS_INTL_COLLATOR_TYPE) \
235 V(JS_INTL_DATE_TIME_FORMAT_TYPE) \
236 V(JS_INTL_LIST_FORMAT_TYPE) \
237 V(JS_INTL_LOCALE_TYPE) \
238 V(JS_INTL_NUMBER_FORMAT_TYPE) \
239 V(JS_INTL_PLURAL_RULES_TYPE) \
240 V(JS_INTL_RELATIVE_TIME_FORMAT_TYPE) \
241 V(JS_INTL_SEGMENT_ITERATOR_TYPE) \
242 V(JS_INTL_SEGMENTER_TYPE) \
243 INSTANCE_TYPE_LIST_AFTER_INTL(V)
244#else
245#define INSTANCE_TYPE_LIST(V) \
246 INSTANCE_TYPE_LIST_BEFORE_INTL(V) \
247 INSTANCE_TYPE_LIST_AFTER_INTL(V)
248#endif // V8_INTL_SUPPORT
249
250// Since string types are not consecutive, this macro is used to
251// iterate over them.
252#define STRING_TYPE_LIST(V) \
253 V(STRING_TYPE, kVariableSizeSentinel, string, String) \
254 V(ONE_BYTE_STRING_TYPE, kVariableSizeSentinel, one_byte_string, \
255 OneByteString) \
256 V(CONS_STRING_TYPE, ConsString::kSize, cons_string, ConsString) \
257 V(CONS_ONE_BYTE_STRING_TYPE, ConsString::kSize, cons_one_byte_string, \
258 ConsOneByteString) \
259 V(SLICED_STRING_TYPE, SlicedString::kSize, sliced_string, SlicedString) \
260 V(SLICED_ONE_BYTE_STRING_TYPE, SlicedString::kSize, sliced_one_byte_string, \
261 SlicedOneByteString) \
262 V(EXTERNAL_STRING_TYPE, ExternalTwoByteString::kSize, external_string, \
263 ExternalString) \
264 V(EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kSize, \
265 external_one_byte_string, ExternalOneByteString) \
266 V(UNCACHED_EXTERNAL_STRING_TYPE, ExternalTwoByteString::kUncachedSize, \
267 uncached_external_string, UncachedExternalString) \
268 V(UNCACHED_EXTERNAL_ONE_BYTE_STRING_TYPE, \
269 ExternalOneByteString::kUncachedSize, uncached_external_one_byte_string, \
270 UncachedExternalOneByteString) \
271 \
272 V(INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, internalized_string, \
273 InternalizedString) \
274 V(ONE_BYTE_INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, \
275 one_byte_internalized_string, OneByteInternalizedString) \
276 V(EXTERNAL_INTERNALIZED_STRING_TYPE, ExternalTwoByteString::kSize, \
277 external_internalized_string, ExternalInternalizedString) \
278 V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, ExternalOneByteString::kSize, \
279 external_one_byte_internalized_string, ExternalOneByteInternalizedString) \
280 V(UNCACHED_EXTERNAL_INTERNALIZED_STRING_TYPE, \
281 ExternalTwoByteString::kUncachedSize, \
282 uncached_external_internalized_string, UncachedExternalInternalizedString) \
283 V(UNCACHED_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, \
284 ExternalOneByteString::kUncachedSize, \
285 uncached_external_one_byte_internalized_string, \
286 UncachedExternalOneByteInternalizedString) \
287 V(THIN_STRING_TYPE, ThinString::kSize, thin_string, ThinString) \
288 V(THIN_ONE_BYTE_STRING_TYPE, ThinString::kSize, thin_one_byte_string, \
289 ThinOneByteString) \
290 V(EMPTY_STRING_TYPE, kVariableSizeSentinel, empty_string, EmptyString)
291
292// A struct is a simple object a set of object-valued fields. Including an
293// object type in this causes the compiler to generate most of the boilerplate
294// code for the class including allocation and garbage collection routines,
295// casts and predicates. All you need to define is the class, methods and
296// object verification routines. Easy, no?
297//
298// Note that for subtle reasons related to the ordering or numerical values of
299// type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
300// manually.
301#define STRUCT_LIST_GENERATOR(V, _) \
302 V(_, ACCESS_CHECK_INFO_TYPE, AccessCheckInfo, access_check_info) \
303 V(_, ACCESSOR_INFO_TYPE, AccessorInfo, accessor_info) \
304 V(_, ACCESSOR_PAIR_TYPE, AccessorPair, accessor_pair) \
305 V(_, ALIASED_ARGUMENTS_ENTRY_TYPE, AliasedArgumentsEntry, \
306 aliased_arguments_entry) \
307 V(_, ALLOCATION_MEMENTO_TYPE, AllocationMemento, allocation_memento) \
308 V(_, ASM_WASM_DATA_TYPE, AsmWasmData, asm_wasm_data) \
309 V(_, ASYNC_GENERATOR_REQUEST_TYPE, AsyncGeneratorRequest, \
310 async_generator_request) \
311 V(_, CLASS_POSITIONS_TYPE, ClassPositions, class_positions) \
312 V(_, DEBUG_INFO_TYPE, DebugInfo, debug_info) \
313 V(_, FUNCTION_TEMPLATE_INFO_TYPE, FunctionTemplateInfo, \
314 function_template_info) \
315 V(_, FUNCTION_TEMPLATE_RARE_DATA_TYPE, FunctionTemplateRareData, \
316 function_template_rare_data) \
317 V(_, INTERCEPTOR_INFO_TYPE, InterceptorInfo, interceptor_info) \
318 V(_, INTERPRETER_DATA_TYPE, InterpreterData, interpreter_data) \
319 V(_, MODULE_INFO_ENTRY_TYPE, ModuleInfoEntry, module_info_entry) \
320 V(_, MODULE_TYPE, Module, module) \
321 V(_, OBJECT_TEMPLATE_INFO_TYPE, ObjectTemplateInfo, object_template_info) \
322 V(_, PROMISE_CAPABILITY_TYPE, PromiseCapability, promise_capability) \
323 V(_, PROMISE_REACTION_TYPE, PromiseReaction, promise_reaction) \
324 V(_, PROTOTYPE_INFO_TYPE, PrototypeInfo, prototype_info) \
325 V(_, SCRIPT_TYPE, Script, script) \
326 V(_, STACK_FRAME_INFO_TYPE, StackFrameInfo, stack_frame_info) \
327 V(_, STACK_TRACE_FRAME_TYPE, StackTraceFrame, stack_trace_frame) \
328 V(_, TUPLE2_TYPE, Tuple2, tuple2) \
329 V(_, TUPLE3_TYPE, Tuple3, tuple3) \
330 V(_, ARRAY_BOILERPLATE_DESCRIPTION_TYPE, ArrayBoilerplateDescription, \
331 array_boilerplate_description) \
332 V(_, WASM_DEBUG_INFO_TYPE, WasmDebugInfo, wasm_debug_info) \
333 V(_, WASM_EXCEPTION_TAG_TYPE, WasmExceptionTag, wasm_exception_tag) \
334 V(_, WASM_EXPORTED_FUNCTION_DATA_TYPE, WasmExportedFunctionData, \
335 wasm_exported_function_data) \
336 V(_, CALLABLE_TASK_TYPE, CallableTask, callable_task) \
337 V(_, CALLBACK_TASK_TYPE, CallbackTask, callback_task) \
338 V(_, PROMISE_FULFILL_REACTION_JOB_TASK_TYPE, PromiseFulfillReactionJobTask, \
339 promise_fulfill_reaction_job_task) \
340 V(_, PROMISE_REJECT_REACTION_JOB_TASK_TYPE, PromiseRejectReactionJobTask, \
341 promise_reject_reaction_job_task) \
342 V(_, PROMISE_RESOLVE_THENABLE_JOB_TASK_TYPE, PromiseResolveThenableJobTask, \
343 promise_resolve_thenable_job_task) \
344 V(_, FINALIZATION_GROUP_CLEANUP_JOB_TASK_TYPE, \
345 FinalizationGroupCleanupJobTask, finalization_group_cleanup_job_task)
346
347// Adapts one STRUCT_LIST_GENERATOR entry to the STRUCT_LIST entry
348#define STRUCT_LIST_ADAPTER(V, NAME, Name, name) V(NAME, Name, name)
349
350// Produces (NAME, Name, name) entries.
351#define STRUCT_LIST(V) STRUCT_LIST_GENERATOR(STRUCT_LIST_ADAPTER, V)
352
353// Adapts one STRUCT_LIST_GENERATOR entry to the STRUCT_MAPS_LIST entry
354#define STRUCT_MAPS_LIST_ADAPTER(V, NAME, Name, name) \
355 V(Map, name##_map, Name##Map)
356
357// Produces (Map, struct_name_map, StructNameMap) entries
358#define STRUCT_MAPS_LIST(V) STRUCT_LIST_GENERATOR(STRUCT_MAPS_LIST_ADAPTER, V)
359
360//
361// The following macros define list of allocation size objects and list of
362// their maps.
363//
364#define ALLOCATION_SITE_LIST(V, _) \
365 V(_, ALLOCATION_SITE_TYPE, AllocationSite, WithWeakNext, allocation_site) \
366 V(_, ALLOCATION_SITE_TYPE, AllocationSite, WithoutWeakNext, \
367 allocation_site_without_weaknext)
368
369// Adapts one ALLOCATION_SITE_LIST entry to the ALLOCATION_SITE_MAPS_LIST entry
370#define ALLOCATION_SITE_MAPS_LIST_ADAPTER(V, TYPE, Name, Size, name_size) \
371 V(Map, name_size##_map, Name##Size##Map)
372
373// Produces (Map, allocation_site_name_map, AllocationSiteNameMap) entries
374#define ALLOCATION_SITE_MAPS_LIST(V) \
375 ALLOCATION_SITE_LIST(ALLOCATION_SITE_MAPS_LIST_ADAPTER, V)
376
377//
378// The following macros define list of data handler objects and list of their
379// maps.
380//
381#define DATA_HANDLER_LIST(V, _) \
382 V(_, LOAD_HANDLER_TYPE, LoadHandler, 1, load_handler1) \
383 V(_, LOAD_HANDLER_TYPE, LoadHandler, 2, load_handler2) \
384 V(_, LOAD_HANDLER_TYPE, LoadHandler, 3, load_handler3) \
385 V(_, STORE_HANDLER_TYPE, StoreHandler, 0, store_handler0) \
386 V(_, STORE_HANDLER_TYPE, StoreHandler, 1, store_handler1) \
387 V(_, STORE_HANDLER_TYPE, StoreHandler, 2, store_handler2) \
388 V(_, STORE_HANDLER_TYPE, StoreHandler, 3, store_handler3)
389
390// Adapts one DATA_HANDLER_LIST entry to the DATA_HANDLER_MAPS_LIST entry.
391#define DATA_HANDLER_MAPS_LIST_ADAPTER(V, TYPE, Name, Size, name_size) \
392 V(Map, name_size##_map, Name##Size##Map)
393
394// Produces (Map, handler_name_map, HandlerNameMap) entries
395#define DATA_HANDLER_MAPS_LIST(V) \
396 DATA_HANDLER_LIST(DATA_HANDLER_MAPS_LIST_ADAPTER, V)
397
398} // namespace internal
399} // namespace v8
400
401#endif // V8_OBJECTS_DEFINITIONS_H_
402