1 // Copyright 2017 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 #include "src/builtins/accessors.h"
6 #include "src/codegen/compilation-cache.h"
7 #include "src/execution/isolate.h"
8 #include "src/execution/protectors.h"
9 #include "src/heap/factory.h"
10 #include "src/heap/heap-inl.h"
11 #include "src/ic/handler-configuration.h"
12 #include "src/init/heap-symbols.h"
13 #include "src/init/setup-isolate.h"
14 #include "src/interpreter/interpreter.h"
15 #include "src/objects/arguments.h"
16 #include "src/objects/cell-inl.h"
17 #include "src/objects/contexts.h"
18 #include "src/objects/data-handler.h"
19 #include "src/objects/debug-objects.h"
20 #include "src/objects/descriptor-array.h"
21 #include "src/objects/dictionary.h"
22 #include "src/objects/foreign.h"
23 #include "src/objects/heap-number.h"
24 #include "src/objects/instance-type-inl.h"
25 #include "src/objects/js-generator.h"
26 #include "src/objects/js-weak-refs.h"
27 #include "src/objects/layout-descriptor.h"
28 #include "src/objects/literal-objects-inl.h"
29 #include "src/objects/lookup-cache.h"
30 #include "src/objects/map.h"
31 #include "src/objects/microtask.h"
32 #include "src/objects/objects-inl.h"
33 #include "src/objects/oddball-inl.h"
34 #include "src/objects/ordered-hash-table.h"
35 #include "src/objects/promise.h"
36 #include "src/objects/property-descriptor-object.h"
37 #include "src/objects/script.h"
38 #include "src/objects/shared-function-info.h"
39 #include "src/objects/smi.h"
40 #include "src/objects/source-text-module.h"
41 #include "src/objects/stack-frame-info.h"
42 #include "src/objects/string.h"
43 #include "src/objects/synthetic-module.h"
44 #include "src/objects/template-objects-inl.h"
45 #include "src/objects/torque-defined-classes-inl.h"
46 #include "src/regexp/regexp.h"
47 #include "src/wasm/wasm-objects.h"
48
49 namespace v8 {
50 namespace internal {
51
52 namespace {
53
CreateSharedFunctionInfo(Isolate * isolate,Builtins::Name builtin_id,int len,FunctionKind kind=FunctionKind::kNormalFunction)54 Handle<SharedFunctionInfo> CreateSharedFunctionInfo(
55 Isolate* isolate, Builtins::Name builtin_id, int len,
56 FunctionKind kind = FunctionKind::kNormalFunction) {
57 Handle<SharedFunctionInfo> shared =
58 isolate->factory()->NewSharedFunctionInfoForBuiltin(
59 isolate->factory()->empty_string(), builtin_id, kind);
60 shared->set_internal_formal_parameter_count(len);
61 shared->set_length(len);
62 return shared;
63 }
64
65 } // namespace
66
SetupHeapInternal(Heap * heap)67 bool SetupIsolateDelegate::SetupHeapInternal(Heap* heap) {
68 return heap->CreateHeapObjects();
69 }
70
CreateHeapObjects()71 bool Heap::CreateHeapObjects() {
72 // Create initial maps.
73 if (!CreateInitialMaps()) return false;
74 CreateApiObjects();
75
76 // Create initial objects
77 CreateInitialObjects();
78 CreateInternalAccessorInfoObjects();
79 CHECK_EQ(0u, gc_count_);
80
81 set_native_contexts_list(ReadOnlyRoots(this).undefined_value());
82 set_allocation_sites_list(ReadOnlyRoots(this).undefined_value());
83 set_dirty_js_finalization_registries_list(
84 ReadOnlyRoots(this).undefined_value());
85 set_dirty_js_finalization_registries_list_tail(
86 ReadOnlyRoots(this).undefined_value());
87
88 return true;
89 }
90
91 const Heap::StringTypeTable Heap::string_type_table[] = {
92 #define STRING_TYPE_ELEMENT(type, size, name, CamelName) \
93 {type, size, RootIndex::k##CamelName##Map},
94 STRING_TYPE_LIST(STRING_TYPE_ELEMENT)
95 #undef STRING_TYPE_ELEMENT
96 };
97
98 const Heap::ConstantStringTable Heap::constant_string_table[] = {
99 {"", RootIndex::kempty_string},
100 #define CONSTANT_STRING_ELEMENT(_, name, contents) \
101 {contents, RootIndex::k##name},
102 INTERNALIZED_STRING_LIST_GENERATOR(CONSTANT_STRING_ELEMENT, /* not used */)
103 #undef CONSTANT_STRING_ELEMENT
104 };
105
106 const Heap::StructTable Heap::struct_table[] = {
107 #define STRUCT_TABLE_ELEMENT(TYPE, Name, name) \
108 {TYPE, Name::kSize, RootIndex::k##Name##Map},
109 STRUCT_LIST(STRUCT_TABLE_ELEMENT)
110 #undef STRUCT_TABLE_ELEMENT
111
112 #define ALLOCATION_SITE_ELEMENT(_, TYPE, Name, Size, name) \
113 {TYPE, Name::kSize##Size, RootIndex::k##Name##Size##Map},
114 ALLOCATION_SITE_LIST(ALLOCATION_SITE_ELEMENT, /* not used */)
115 #undef ALLOCATION_SITE_ELEMENT
116
117 #define DATA_HANDLER_ELEMENT(_, TYPE, Name, Size, name) \
118 {TYPE, Name::kSizeWithData##Size, RootIndex::k##Name##Size##Map},
119 DATA_HANDLER_LIST(DATA_HANDLER_ELEMENT, /* not used */)
120 #undef DATA_HANDLER_ELEMENT
121 };
122
AllocateMap(InstanceType instance_type,int instance_size,ElementsKind elements_kind,int inobject_properties)123 AllocationResult Heap::AllocateMap(InstanceType instance_type,
124 int instance_size,
125 ElementsKind elements_kind,
126 int inobject_properties) {
127 STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE);
128 bool is_js_object = InstanceTypeChecker::IsJSObject(instance_type);
129 bool is_wasm_object =
130 (instance_type == WASM_STRUCT_TYPE || instance_type == WASM_ARRAY_TYPE);
131 DCHECK_IMPLIES(is_js_object &&
132 !Map::CanHaveFastTransitionableElementsKind(instance_type),
133 IsDictionaryElementsKind(elements_kind) ||
134 IsTerminalElementsKind(elements_kind));
135 HeapObject result;
136 // JSObjects have maps with a mutable prototype_validity_cell, so they cannot
137 // go in RO_SPACE. Maps for managed Wasm objects have mutable subtype lists.
138 bool is_mutable = is_js_object || is_wasm_object;
139 AllocationResult allocation =
140 AllocateRaw(Map::kSize, is_mutable ? AllocationType::kMap
141 : AllocationType::kReadOnly);
142 if (!allocation.To(&result)) return allocation;
143
144 result.set_map_after_allocation(ReadOnlyRoots(this).meta_map(),
145 SKIP_WRITE_BARRIER);
146 Map map = isolate()->factory()->InitializeMap(
147 Map::cast(result), instance_type, instance_size, elements_kind,
148 inobject_properties);
149
150 return map;
151 }
152
AllocatePartialMap(InstanceType instance_type,int instance_size)153 AllocationResult Heap::AllocatePartialMap(InstanceType instance_type,
154 int instance_size) {
155 Object result;
156 AllocationResult allocation =
157 AllocateRaw(Map::kSize, AllocationType::kReadOnly);
158 if (!allocation.To(&result)) return allocation;
159 // Map::cast cannot be used due to uninitialized map field.
160 Map map = Map::unchecked_cast(result);
161 map.set_map_after_allocation(
162 Map::unchecked_cast(isolate()->root(RootIndex::kMetaMap)),
163 SKIP_WRITE_BARRIER);
164 map.set_instance_type(instance_type);
165 map.set_instance_size(instance_size);
166 // Initialize to only containing tagged fields.
167 if (FLAG_unbox_double_fields) {
168 map.set_layout_descriptor(LayoutDescriptor::FastPointerLayout(),
169 kReleaseStore);
170 }
171 // GetVisitorId requires a properly initialized LayoutDescriptor.
172 map.set_visitor_id(Map::GetVisitorId(map));
173 map.set_inobject_properties_start_or_constructor_function_index(0);
174 DCHECK(!map.IsJSObjectMap());
175 map.set_prototype_validity_cell(Smi::FromInt(Map::kPrototypeChainValid));
176 map.SetInObjectUnusedPropertyFields(0);
177 map.set_bit_field(0);
178 map.set_bit_field2(0);
179 int bit_field3 =
180 Map::Bits3::EnumLengthBits::encode(kInvalidEnumCacheSentinel) |
181 Map::Bits3::OwnsDescriptorsBit::encode(true) |
182 Map::Bits3::ConstructionCounterBits::encode(Map::kNoSlackTracking);
183 map.set_bit_field3(bit_field3);
184 DCHECK(!map.is_in_retained_map_list());
185 map.clear_padding();
186 map.set_elements_kind(TERMINAL_FAST_ELEMENTS_KIND);
187 return map;
188 }
189
FinalizePartialMap(Map map)190 void Heap::FinalizePartialMap(Map map) {
191 ReadOnlyRoots roots(this);
192 map.set_dependent_code(DependentCode::cast(roots.empty_weak_fixed_array()));
193 map.set_raw_transitions(MaybeObject::FromSmi(Smi::zero()));
194 map.SetInstanceDescriptors(isolate(), roots.empty_descriptor_array(), 0);
195 if (FLAG_unbox_double_fields) {
196 map.set_layout_descriptor(LayoutDescriptor::FastPointerLayout(),
197 kReleaseStore);
198 }
199 map.set_prototype(roots.null_value());
200 map.set_constructor_or_backpointer(roots.null_value());
201 }
202
Allocate(Map map,AllocationType allocation_type)203 AllocationResult Heap::Allocate(Map map, AllocationType allocation_type) {
204 DCHECK(map.instance_type() != MAP_TYPE);
205 int size = map.instance_size();
206 HeapObject result;
207 AllocationResult allocation = AllocateRaw(size, allocation_type);
208 if (!allocation.To(&result)) return allocation;
209 // New space objects are allocated white.
210 WriteBarrierMode write_barrier_mode =
211 allocation_type == AllocationType::kYoung ? SKIP_WRITE_BARRIER
212 : UPDATE_WRITE_BARRIER;
213 result.set_map_after_allocation(map, write_barrier_mode);
214 return result;
215 }
216
CreateInitialMaps()217 bool Heap::CreateInitialMaps() {
218 HeapObject obj;
219 {
220 AllocationResult allocation = AllocatePartialMap(MAP_TYPE, Map::kSize);
221 if (!allocation.To(&obj)) return false;
222 }
223 // Map::cast cannot be used due to uninitialized map field.
224 Map new_meta_map = Map::unchecked_cast(obj);
225 set_meta_map(new_meta_map);
226 new_meta_map.set_map_after_allocation(new_meta_map);
227
228 ReadOnlyRoots roots(this);
229 { // Partial map allocation
230 #define ALLOCATE_PARTIAL_MAP(instance_type, size, field_name) \
231 { \
232 Map map; \
233 if (!AllocatePartialMap((instance_type), (size)).To(&map)) return false; \
234 set_##field_name##_map(map); \
235 }
236
237 ALLOCATE_PARTIAL_MAP(FIXED_ARRAY_TYPE, kVariableSizeSentinel, fixed_array);
238 ALLOCATE_PARTIAL_MAP(WEAK_FIXED_ARRAY_TYPE, kVariableSizeSentinel,
239 weak_fixed_array);
240 ALLOCATE_PARTIAL_MAP(WEAK_ARRAY_LIST_TYPE, kVariableSizeSentinel,
241 weak_array_list);
242 ALLOCATE_PARTIAL_MAP(FIXED_ARRAY_TYPE, kVariableSizeSentinel,
243 fixed_cow_array)
244 DCHECK_NE(roots.fixed_array_map(), roots.fixed_cow_array_map());
245
246 ALLOCATE_PARTIAL_MAP(DESCRIPTOR_ARRAY_TYPE, kVariableSizeSentinel,
247 descriptor_array)
248
249 ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, undefined);
250 ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, null);
251 ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, the_hole);
252
253 #undef ALLOCATE_PARTIAL_MAP
254 }
255
256 // Allocate the empty array.
257 {
258 AllocationResult alloc =
259 AllocateRaw(FixedArray::SizeFor(0), AllocationType::kReadOnly);
260 if (!alloc.To(&obj)) return false;
261 obj.set_map_after_allocation(roots.fixed_array_map(), SKIP_WRITE_BARRIER);
262 FixedArray::cast(obj).set_length(0);
263 }
264 set_empty_fixed_array(FixedArray::cast(obj));
265
266 {
267 AllocationResult alloc =
268 AllocateRaw(WeakFixedArray::SizeFor(0), AllocationType::kReadOnly);
269 if (!alloc.To(&obj)) return false;
270 obj.set_map_after_allocation(roots.weak_fixed_array_map(),
271 SKIP_WRITE_BARRIER);
272 WeakFixedArray::cast(obj).set_length(0);
273 }
274 set_empty_weak_fixed_array(WeakFixedArray::cast(obj));
275
276 {
277 AllocationResult allocation = AllocateRaw(WeakArrayList::SizeForCapacity(0),
278 AllocationType::kReadOnly);
279 if (!allocation.To(&obj)) return false;
280 obj.set_map_after_allocation(roots.weak_array_list_map(),
281 SKIP_WRITE_BARRIER);
282 WeakArrayList::cast(obj).set_capacity(0);
283 WeakArrayList::cast(obj).set_length(0);
284 }
285 set_empty_weak_array_list(WeakArrayList::cast(obj));
286
287 {
288 AllocationResult allocation =
289 Allocate(roots.null_map(), AllocationType::kReadOnly);
290 if (!allocation.To(&obj)) return false;
291 }
292 set_null_value(Oddball::cast(obj));
293 Oddball::cast(obj).set_kind(Oddball::kNull);
294
295 {
296 AllocationResult allocation =
297 Allocate(roots.undefined_map(), AllocationType::kReadOnly);
298 if (!allocation.To(&obj)) return false;
299 }
300 set_undefined_value(Oddball::cast(obj));
301 Oddball::cast(obj).set_kind(Oddball::kUndefined);
302 DCHECK(!InYoungGeneration(roots.undefined_value()));
303 {
304 AllocationResult allocation =
305 Allocate(roots.the_hole_map(), AllocationType::kReadOnly);
306 if (!allocation.To(&obj)) return false;
307 }
308 set_the_hole_value(Oddball::cast(obj));
309 Oddball::cast(obj).set_kind(Oddball::kTheHole);
310
311 // Set preliminary exception sentinel value before actually initializing it.
312 set_exception(roots.null_value());
313
314 // Setup the struct maps first (needed for the EnumCache).
315 for (unsigned i = 0; i < arraysize(struct_table); i++) {
316 const StructTable& entry = struct_table[i];
317 Map map;
318 if (!AllocatePartialMap(entry.type, entry.size).To(&map)) return false;
319 roots_table()[entry.index] = map.ptr();
320 }
321
322 // Allocate the empty enum cache.
323 {
324 AllocationResult allocation =
325 Allocate(roots.enum_cache_map(), AllocationType::kReadOnly);
326 if (!allocation.To(&obj)) return false;
327 }
328 set_empty_enum_cache(EnumCache::cast(obj));
329 EnumCache::cast(obj).set_keys(roots.empty_fixed_array());
330 EnumCache::cast(obj).set_indices(roots.empty_fixed_array());
331
332 // Allocate the empty descriptor array.
333 {
334 int size = DescriptorArray::SizeFor(0);
335 if (!AllocateRaw(size, AllocationType::kReadOnly).To(&obj)) return false;
336 obj.set_map_after_allocation(roots.descriptor_array_map(),
337 SKIP_WRITE_BARRIER);
338 DescriptorArray array = DescriptorArray::cast(obj);
339 array.Initialize(roots.empty_enum_cache(), roots.undefined_value(), 0, 0);
340 }
341 set_empty_descriptor_array(DescriptorArray::cast(obj));
342
343 // Fix the instance_descriptors for the existing maps.
344 FinalizePartialMap(roots.meta_map());
345 FinalizePartialMap(roots.fixed_array_map());
346 FinalizePartialMap(roots.weak_fixed_array_map());
347 FinalizePartialMap(roots.weak_array_list_map());
348 FinalizePartialMap(roots.fixed_cow_array_map());
349 FinalizePartialMap(roots.descriptor_array_map());
350 FinalizePartialMap(roots.undefined_map());
351 roots.undefined_map().set_is_undetectable(true);
352 FinalizePartialMap(roots.null_map());
353 roots.null_map().set_is_undetectable(true);
354 FinalizePartialMap(roots.the_hole_map());
355 for (unsigned i = 0; i < arraysize(struct_table); ++i) {
356 const StructTable& entry = struct_table[i];
357 FinalizePartialMap(Map::cast(Object(roots_table()[entry.index])));
358 }
359
360 { // Map allocation
361 #define ALLOCATE_MAP(instance_type, size, field_name) \
362 { \
363 Map map; \
364 if (!AllocateMap((instance_type), size).To(&map)) return false; \
365 set_##field_name##_map(map); \
366 }
367
368 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \
369 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name)
370
371 #define ALLOCATE_PRIMITIVE_MAP(instance_type, size, field_name, \
372 constructor_function_index) \
373 { \
374 ALLOCATE_MAP((instance_type), (size), field_name); \
375 roots.field_name##_map().SetConstructorFunctionIndex( \
376 (constructor_function_index)); \
377 }
378
379 ALLOCATE_VARSIZE_MAP(SCOPE_INFO_TYPE, scope_info)
380 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, module_info)
381 ALLOCATE_VARSIZE_MAP(CLOSURE_FEEDBACK_CELL_ARRAY_TYPE,
382 closure_feedback_cell_array)
383 ALLOCATE_VARSIZE_MAP(FEEDBACK_VECTOR_TYPE, feedback_vector)
384 ALLOCATE_PRIMITIVE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number,
385 Context::NUMBER_FUNCTION_INDEX)
386 ALLOCATE_PRIMITIVE_MAP(SYMBOL_TYPE, Symbol::kSize, symbol,
387 Context::SYMBOL_FUNCTION_INDEX)
388 ALLOCATE_MAP(FOREIGN_TYPE, Foreign::kSize, foreign)
389
390 ALLOCATE_PRIMITIVE_MAP(ODDBALL_TYPE, Oddball::kSize, boolean,
391 Context::BOOLEAN_FUNCTION_INDEX);
392 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, uninitialized);
393 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, arguments_marker);
394 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, exception);
395 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, termination_exception);
396 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, optimized_out);
397 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, stale_register);
398 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, self_reference_marker);
399 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, basic_block_counters_marker);
400 ALLOCATE_VARSIZE_MAP(BIGINT_TYPE, bigint);
401
402 for (unsigned i = 0; i < arraysize(string_type_table); i++) {
403 const StringTypeTable& entry = string_type_table[i];
404 Map map;
405 if (!AllocateMap(entry.type, entry.size).To(&map)) return false;
406 map.SetConstructorFunctionIndex(Context::STRING_FUNCTION_INDEX);
407 // Mark cons string maps as unstable, because their objects can change
408 // maps during GC.
409 if (StringShape(entry.type).IsCons()) map.mark_unstable();
410 roots_table()[entry.index] = map.ptr();
411 }
412
413 ALLOCATE_VARSIZE_MAP(FIXED_DOUBLE_ARRAY_TYPE, fixed_double_array)
414 roots.fixed_double_array_map().set_elements_kind(HOLEY_DOUBLE_ELEMENTS);
415 ALLOCATE_VARSIZE_MAP(FEEDBACK_METADATA_TYPE, feedback_metadata)
416 ALLOCATE_VARSIZE_MAP(BYTE_ARRAY_TYPE, byte_array)
417 ALLOCATE_VARSIZE_MAP(BYTECODE_ARRAY_TYPE, bytecode_array)
418 ALLOCATE_VARSIZE_MAP(FREE_SPACE_TYPE, free_space)
419 ALLOCATE_VARSIZE_MAP(PROPERTY_ARRAY_TYPE, property_array)
420 ALLOCATE_VARSIZE_MAP(SMALL_ORDERED_HASH_MAP_TYPE, small_ordered_hash_map)
421 ALLOCATE_VARSIZE_MAP(SMALL_ORDERED_HASH_SET_TYPE, small_ordered_hash_set)
422 ALLOCATE_VARSIZE_MAP(SMALL_ORDERED_NAME_DICTIONARY_TYPE,
423 small_ordered_name_dictionary)
424
425 #define TORQUE_ALLOCATE_MAP(NAME, Name, name) \
426 ALLOCATE_MAP(NAME, Name::kSize, name)
427 TORQUE_DEFINED_FIXED_INSTANCE_TYPE_LIST(TORQUE_ALLOCATE_MAP);
428 #undef TORQUE_ALLOCATE_MAP
429
430 #define TORQUE_ALLOCATE_VARSIZE_MAP(NAME, Name, name) \
431 /* The DescriptorArray map is pre-allocated and initialized above. */ \
432 if (NAME != DESCRIPTOR_ARRAY_TYPE) { \
433 ALLOCATE_VARSIZE_MAP(NAME, name) \
434 }
435 TORQUE_DEFINED_VARSIZE_INSTANCE_TYPE_LIST(TORQUE_ALLOCATE_VARSIZE_MAP);
436 #undef TORQUE_ALLOCATE_VARSIZE_MAP
437
438 ALLOCATE_VARSIZE_MAP(CODE_TYPE, code)
439
440 ALLOCATE_MAP(CELL_TYPE, Cell::kSize, cell);
441 {
442 // The invalid_prototype_validity_cell is needed for JSObject maps.
443 Smi value = Smi::FromInt(Map::kPrototypeChainInvalid);
444 AllocationResult alloc = AllocateRaw(Cell::kSize, AllocationType::kOld);
445 if (!alloc.To(&obj)) return false;
446 obj.set_map_after_allocation(roots.cell_map(), SKIP_WRITE_BARRIER);
447 Cell::cast(obj).set_value(value);
448 set_invalid_prototype_validity_cell(Cell::cast(obj));
449 }
450
451 ALLOCATE_MAP(PROPERTY_CELL_TYPE, PropertyCell::kSize, global_property_cell)
452 ALLOCATE_MAP(FILLER_TYPE, kTaggedSize, one_pointer_filler)
453 ALLOCATE_MAP(FILLER_TYPE, 2 * kTaggedSize, two_pointer_filler)
454
455 // The "no closures" and "one closure" FeedbackCell maps need
456 // to be marked unstable because their objects can change maps.
457 ALLOCATE_MAP(FEEDBACK_CELL_TYPE, FeedbackCell::kAlignedSize,
458 no_closures_cell)
459 roots.no_closures_cell_map().mark_unstable();
460 ALLOCATE_MAP(FEEDBACK_CELL_TYPE, FeedbackCell::kAlignedSize,
461 one_closure_cell)
462 roots.one_closure_cell_map().mark_unstable();
463 ALLOCATE_MAP(FEEDBACK_CELL_TYPE, FeedbackCell::kAlignedSize,
464 many_closures_cell)
465
466 ALLOCATE_VARSIZE_MAP(TRANSITION_ARRAY_TYPE, transition_array)
467
468 ALLOCATE_VARSIZE_MAP(HASH_TABLE_TYPE, hash_table)
469 ALLOCATE_VARSIZE_MAP(ORDERED_HASH_MAP_TYPE, ordered_hash_map)
470 ALLOCATE_VARSIZE_MAP(ORDERED_HASH_SET_TYPE, ordered_hash_set)
471 ALLOCATE_VARSIZE_MAP(ORDERED_NAME_DICTIONARY_TYPE, ordered_name_dictionary)
472 ALLOCATE_VARSIZE_MAP(NAME_DICTIONARY_TYPE, name_dictionary)
473 ALLOCATE_VARSIZE_MAP(GLOBAL_DICTIONARY_TYPE, global_dictionary)
474 ALLOCATE_VARSIZE_MAP(NUMBER_DICTIONARY_TYPE, number_dictionary)
475 ALLOCATE_VARSIZE_MAP(SIMPLE_NUMBER_DICTIONARY_TYPE,
476 simple_number_dictionary)
477
478 ALLOCATE_VARSIZE_MAP(EMBEDDER_DATA_ARRAY_TYPE, embedder_data_array)
479 ALLOCATE_VARSIZE_MAP(EPHEMERON_HASH_TABLE_TYPE, ephemeron_hash_table)
480
481 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, array_list)
482
483 ALLOCATE_VARSIZE_MAP(SCRIPT_CONTEXT_TABLE_TYPE, script_context_table)
484
485 ALLOCATE_VARSIZE_MAP(OBJECT_BOILERPLATE_DESCRIPTION_TYPE,
486 object_boilerplate_description)
487
488 ALLOCATE_VARSIZE_MAP(COVERAGE_INFO_TYPE, coverage_info);
489
490 ALLOCATE_MAP(CALL_HANDLER_INFO_TYPE, CallHandlerInfo::kSize,
491 side_effect_call_handler_info)
492 ALLOCATE_MAP(CALL_HANDLER_INFO_TYPE, CallHandlerInfo::kSize,
493 side_effect_free_call_handler_info)
494 ALLOCATE_MAP(CALL_HANDLER_INFO_TYPE, CallHandlerInfo::kSize,
495 next_call_side_effect_free_call_handler_info)
496
497 ALLOCATE_VARSIZE_MAP(PREPARSE_DATA_TYPE, preparse_data)
498 ALLOCATE_MAP(UNCOMPILED_DATA_WITHOUT_PREPARSE_DATA_TYPE,
499 UncompiledDataWithoutPreparseData::kSize,
500 uncompiled_data_without_preparse_data)
501 ALLOCATE_MAP(UNCOMPILED_DATA_WITH_PREPARSE_DATA_TYPE,
502 UncompiledDataWithPreparseData::kSize,
503 uncompiled_data_with_preparse_data)
504 ALLOCATE_MAP(SHARED_FUNCTION_INFO_TYPE, SharedFunctionInfo::kAlignedSize,
505 shared_function_info)
506 ALLOCATE_MAP(SOURCE_TEXT_MODULE_TYPE, SourceTextModule::kSize,
507 source_text_module)
508 ALLOCATE_MAP(SYNTHETIC_MODULE_TYPE, SyntheticModule::kSize,
509 synthetic_module)
510 ALLOCATE_MAP(CODE_DATA_CONTAINER_TYPE, CodeDataContainer::kSize,
511 code_data_container)
512
513 // The wasm_rttcanon_* maps are never used for real objects, only as
514 // sentinels. They are maps so that they fit in with their subtype maps
515 // (which are real maps).
516 ALLOCATE_MAP(WASM_STRUCT_TYPE, 0, wasm_rttcanon_eqref)
517 ALLOCATE_MAP(WASM_STRUCT_TYPE, 0, wasm_rttcanon_externref)
518 ALLOCATE_MAP(WASM_STRUCT_TYPE, 0, wasm_rttcanon_funcref)
519 ALLOCATE_MAP(WASM_STRUCT_TYPE, 0, wasm_rttcanon_i31ref)
520 ALLOCATE_MAP(WASM_TYPE_INFO_TYPE, WasmTypeInfo::kSize, wasm_type_info)
521
522 ALLOCATE_MAP(WEAK_CELL_TYPE, WeakCell::kSize, weak_cell)
523
524 ALLOCATE_MAP(JS_MESSAGE_OBJECT_TYPE, JSMessageObject::kHeaderSize,
525 message_object)
526 ALLOCATE_MAP(JS_OBJECT_TYPE, JSObject::kHeaderSize + kEmbedderDataSlotSize,
527 external)
528 external_map().set_is_extensible(false);
529 #undef ALLOCATE_PRIMITIVE_MAP
530 #undef ALLOCATE_VARSIZE_MAP
531 #undef ALLOCATE_MAP
532 }
533
534 {
535 AllocationResult alloc =
536 AllocateRaw(FixedArray::SizeFor(0), AllocationType::kReadOnly);
537 if (!alloc.To(&obj)) return false;
538 obj.set_map_after_allocation(roots.scope_info_map(), SKIP_WRITE_BARRIER);
539 FixedArray::cast(obj).set_length(0);
540 }
541 set_empty_scope_info(ScopeInfo::cast(obj));
542
543 {
544 // Empty boilerplate needs a field for literal_flags
545 AllocationResult alloc =
546 AllocateRaw(FixedArray::SizeFor(1), AllocationType::kReadOnly);
547 if (!alloc.To(&obj)) return false;
548 obj.set_map_after_allocation(roots.object_boilerplate_description_map(),
549 SKIP_WRITE_BARRIER);
550
551 FixedArray::cast(obj).set_length(1);
552 FixedArray::cast(obj).set(ObjectBoilerplateDescription::kLiteralTypeOffset,
553 Smi::zero());
554 }
555 set_empty_object_boilerplate_description(
556 ObjectBoilerplateDescription::cast(obj));
557
558 {
559 // Empty array boilerplate description
560 AllocationResult alloc = Allocate(roots.array_boilerplate_description_map(),
561 AllocationType::kReadOnly);
562 if (!alloc.To(&obj)) return false;
563
564 ArrayBoilerplateDescription::cast(obj).set_constant_elements(
565 roots.empty_fixed_array());
566 ArrayBoilerplateDescription::cast(obj).set_elements_kind(
567 ElementsKind::PACKED_SMI_ELEMENTS);
568 }
569 set_empty_array_boilerplate_description(
570 ArrayBoilerplateDescription::cast(obj));
571
572 {
573 AllocationResult allocation =
574 Allocate(roots.boolean_map(), AllocationType::kReadOnly);
575 if (!allocation.To(&obj)) return false;
576 }
577 set_true_value(Oddball::cast(obj));
578 Oddball::cast(obj).set_kind(Oddball::kTrue);
579
580 {
581 AllocationResult allocation =
582 Allocate(roots.boolean_map(), AllocationType::kReadOnly);
583 if (!allocation.To(&obj)) return false;
584 }
585 set_false_value(Oddball::cast(obj));
586 Oddball::cast(obj).set_kind(Oddball::kFalse);
587
588 // Empty arrays.
589 {
590 if (!AllocateRaw(ByteArray::SizeFor(0), AllocationType::kReadOnly).To(&obj))
591 return false;
592 obj.set_map_after_allocation(roots.byte_array_map(), SKIP_WRITE_BARRIER);
593 ByteArray::cast(obj).set_length(0);
594 set_empty_byte_array(ByteArray::cast(obj));
595 }
596
597 {
598 if (!AllocateRaw(FixedArray::SizeFor(0), AllocationType::kReadOnly)
599 .To(&obj)) {
600 return false;
601 }
602 obj.set_map_after_allocation(roots.property_array_map(),
603 SKIP_WRITE_BARRIER);
604 PropertyArray::cast(obj).initialize_length(0);
605 set_empty_property_array(PropertyArray::cast(obj));
606 }
607
608 {
609 if (!AllocateRaw(FixedArray::SizeFor(0), AllocationType::kReadOnly)
610 .To(&obj)) {
611 return false;
612 }
613 obj.set_map_after_allocation(roots.closure_feedback_cell_array_map(),
614 SKIP_WRITE_BARRIER);
615 FixedArray::cast(obj).set_length(0);
616 set_empty_closure_feedback_cell_array(ClosureFeedbackCellArray::cast(obj));
617 }
618
619 // Set up the WasmTypeInfo objects for built-in generic Wasm RTTs.
620 #define ALLOCATE_TYPE_INFO(which) \
621 { \
622 int slot_count = ArrayList::kHeaderFields; \
623 if (!AllocateRaw(ArrayList::SizeFor(slot_count), AllocationType::kOld) \
624 .To(&obj)) { \
625 return false; \
626 } \
627 obj.set_map_after_allocation(roots.array_list_map()); \
628 ArrayList subtypes = ArrayList::cast(obj); \
629 subtypes.set_length(slot_count); \
630 subtypes.SetLength(0); \
631 if (!AllocateRaw(WasmTypeInfo::kSize, AllocationType::kOld).To(&obj)) { \
632 return false; \
633 } \
634 obj.set_map_after_allocation(roots.wasm_type_info_map(), \
635 SKIP_WRITE_BARRIER); \
636 WasmTypeInfo type_info = WasmTypeInfo::cast(obj); \
637 type_info.set_subtypes(subtypes); \
638 type_info.set_parent(roots.null_map()); \
639 type_info.clear_foreign_address(isolate()); \
640 wasm_rttcanon_##which##_map().set_wasm_type_info(type_info); \
641 }
642
643 ALLOCATE_TYPE_INFO(eqref)
644 ALLOCATE_TYPE_INFO(externref)
645 ALLOCATE_TYPE_INFO(funcref)
646 ALLOCATE_TYPE_INFO(i31ref)
647 #undef ALLOCATE_TYPE_INFO
648
649 DCHECK(!InYoungGeneration(roots.empty_fixed_array()));
650
651 roots.bigint_map().SetConstructorFunctionIndex(
652 Context::BIGINT_FUNCTION_INDEX);
653
654 return true;
655 }
656
CreateApiObjects()657 void Heap::CreateApiObjects() {
658 Isolate* isolate = this->isolate();
659 HandleScope scope(isolate);
660
661 set_message_listeners(*TemplateList::New(isolate, 2));
662
663 Handle<InterceptorInfo> info =
664 Handle<InterceptorInfo>::cast(isolate->factory()->NewStruct(
665 INTERCEPTOR_INFO_TYPE, AllocationType::kReadOnly));
666 info->set_flags(0);
667 set_noop_interceptor_info(*info);
668 }
669
CreateInitialObjects()670 void Heap::CreateInitialObjects() {
671 HandleScope scope(isolate());
672 Factory* factory = isolate()->factory();
673 ReadOnlyRoots roots(this);
674
675 // The -0 value must be set before NewNumber works.
676 set_minus_zero_value(
677 *factory->NewHeapNumber<AllocationType::kReadOnly>(-0.0));
678 DCHECK(std::signbit(roots.minus_zero_value().Number()));
679
680 set_nan_value(*factory->NewHeapNumber<AllocationType::kReadOnly>(
681 std::numeric_limits<double>::quiet_NaN()));
682 set_hole_nan_value(*factory->NewHeapNumberFromBits<AllocationType::kReadOnly>(
683 kHoleNanInt64));
684 set_infinity_value(
685 *factory->NewHeapNumber<AllocationType::kReadOnly>(V8_INFINITY));
686 set_minus_infinity_value(
687 *factory->NewHeapNumber<AllocationType::kReadOnly>(-V8_INFINITY));
688
689 set_hash_seed(*factory->NewByteArray(kInt64Size, AllocationType::kReadOnly));
690 InitializeHashSeed();
691
692 // There's no "current microtask" in the beginning.
693 set_current_microtask(roots.undefined_value());
694
695 set_weak_refs_keep_during_job(roots.undefined_value());
696
697 // Allocate cache for single character one byte strings.
698 set_single_character_string_cache(*factory->NewFixedArray(
699 String::kMaxOneByteCharCode + 1, AllocationType::kOld));
700
701 for (unsigned i = 0; i < arraysize(constant_string_table); i++) {
702 Handle<String> str =
703 factory->InternalizeUtf8String(constant_string_table[i].contents);
704 roots_table()[constant_string_table[i].index] = str->ptr();
705 }
706
707 // Allocate
708
709 // Finish initializing oddballs after creating the string table.
710 Oddball::Initialize(isolate(), factory->undefined_value(), "undefined",
711 factory->nan_value(), "undefined", Oddball::kUndefined);
712
713 // Initialize the null_value.
714 Oddball::Initialize(isolate(), factory->null_value(), "null",
715 handle(Smi::zero(), isolate()), "object", Oddball::kNull);
716
717 // Initialize the_hole_value.
718 Oddball::Initialize(isolate(), factory->the_hole_value(), "hole",
719 factory->hole_nan_value(), "undefined",
720 Oddball::kTheHole);
721
722 // Initialize the true_value.
723 Oddball::Initialize(isolate(), factory->true_value(), "true",
724 handle(Smi::FromInt(1), isolate()), "boolean",
725 Oddball::kTrue);
726
727 // Initialize the false_value.
728 Oddball::Initialize(isolate(), factory->false_value(), "false",
729 handle(Smi::zero(), isolate()), "boolean",
730 Oddball::kFalse);
731
732 set_uninitialized_value(
733 *factory->NewOddball(factory->uninitialized_map(), "uninitialized",
734 handle(Smi::FromInt(-1), isolate()), "undefined",
735 Oddball::kUninitialized));
736
737 set_arguments_marker(
738 *factory->NewOddball(factory->arguments_marker_map(), "arguments_marker",
739 handle(Smi::FromInt(-4), isolate()), "undefined",
740 Oddball::kArgumentsMarker));
741
742 set_termination_exception(*factory->NewOddball(
743 factory->termination_exception_map(), "termination_exception",
744 handle(Smi::FromInt(-3), isolate()), "undefined", Oddball::kOther));
745
746 set_exception(*factory->NewOddball(factory->exception_map(), "exception",
747 handle(Smi::FromInt(-5), isolate()),
748 "undefined", Oddball::kException));
749
750 set_optimized_out(*factory->NewOddball(factory->optimized_out_map(),
751 "optimized_out",
752 handle(Smi::FromInt(-6), isolate()),
753 "undefined", Oddball::kOptimizedOut));
754
755 set_stale_register(
756 *factory->NewOddball(factory->stale_register_map(), "stale_register",
757 handle(Smi::FromInt(-7), isolate()), "undefined",
758 Oddball::kStaleRegister));
759
760 // Initialize marker objects used during compilation.
761 set_self_reference_marker(*factory->NewSelfReferenceMarker());
762 set_basic_block_counters_marker(*factory->NewBasicBlockCountersMarker());
763
764 set_interpreter_entry_trampoline_for_profiling(roots.undefined_value());
765
766 {
767 HandleScope scope(isolate());
768 #define SYMBOL_INIT(_, name) \
769 { \
770 Handle<Symbol> symbol( \
771 isolate()->factory()->NewPrivateSymbol(AllocationType::kReadOnly)); \
772 roots_table()[RootIndex::k##name] = symbol->ptr(); \
773 }
774 PRIVATE_SYMBOL_LIST_GENERATOR(SYMBOL_INIT, /* not used */)
775 #undef SYMBOL_INIT
776 }
777
778 {
779 HandleScope scope(isolate());
780 #define SYMBOL_INIT(_, name, description) \
781 Handle<Symbol> name = factory->NewSymbol(AllocationType::kReadOnly); \
782 Handle<String> name##d = factory->InternalizeUtf8String(#description); \
783 name->set_description(*name##d); \
784 roots_table()[RootIndex::k##name] = name->ptr();
785 PUBLIC_SYMBOL_LIST_GENERATOR(SYMBOL_INIT, /* not used */)
786 #undef SYMBOL_INIT
787
788 #define SYMBOL_INIT(_, name, description) \
789 Handle<Symbol> name = factory->NewSymbol(AllocationType::kReadOnly); \
790 Handle<String> name##d = factory->InternalizeUtf8String(#description); \
791 name->set_is_well_known_symbol(true); \
792 name->set_description(*name##d); \
793 roots_table()[RootIndex::k##name] = name->ptr();
794 WELL_KNOWN_SYMBOL_LIST_GENERATOR(SYMBOL_INIT, /* not used */)
795 #undef SYMBOL_INIT
796
797 // Mark "Interesting Symbols" appropriately.
798 to_string_tag_symbol->set_is_interesting_symbol(true);
799 }
800
801 Handle<NameDictionary> empty_property_dictionary = NameDictionary::New(
802 isolate(), 1, AllocationType::kReadOnly, USE_CUSTOM_MINIMUM_CAPACITY);
803 DCHECK(!empty_property_dictionary->HasSufficientCapacityToAdd(1));
804 set_empty_property_dictionary(*empty_property_dictionary);
805
806 set_public_symbol_table(*empty_property_dictionary);
807 set_api_symbol_table(*empty_property_dictionary);
808 set_api_private_symbol_table(*empty_property_dictionary);
809
810 set_number_string_cache(*factory->NewFixedArray(
811 kInitialNumberStringCacheSize * 2, AllocationType::kOld));
812
813 set_basic_block_profiling_data(ArrayList::cast(roots.empty_fixed_array()));
814
815 // Allocate cache for string split and regexp-multiple.
816 set_string_split_cache(*factory->NewFixedArray(
817 RegExpResultsCache::kRegExpResultsCacheSize, AllocationType::kOld));
818 set_regexp_multiple_cache(*factory->NewFixedArray(
819 RegExpResultsCache::kRegExpResultsCacheSize, AllocationType::kOld));
820
821 // Allocate FeedbackCell for builtins.
822 Handle<FeedbackCell> many_closures_cell =
823 factory->NewManyClosuresCell(factory->undefined_value());
824 set_many_closures_cell(*many_closures_cell);
825
826 set_detached_contexts(roots.empty_weak_array_list());
827 set_retaining_path_targets(roots.empty_weak_array_list());
828
829 set_feedback_vectors_for_profiling_tools(roots.undefined_value());
830 set_pending_optimize_for_test_bytecode(roots.undefined_value());
831 set_shared_wasm_memories(roots.empty_weak_array_list());
832
833 set_script_list(roots.empty_weak_array_list());
834
835 Handle<NumberDictionary> slow_element_dictionary = NumberDictionary::New(
836 isolate(), 1, AllocationType::kReadOnly, USE_CUSTOM_MINIMUM_CAPACITY);
837 DCHECK(!slow_element_dictionary->HasSufficientCapacityToAdd(1));
838 set_empty_slow_element_dictionary(*slow_element_dictionary);
839
840 set_materialized_objects(*factory->NewFixedArray(0, AllocationType::kOld));
841
842 // Handling of script id generation is in Heap::NextScriptId().
843 set_last_script_id(Smi::FromInt(v8::UnboundScript::kNoScriptId));
844 set_last_debugging_id(Smi::FromInt(DebugInfo::kNoDebuggingId));
845 set_next_template_serial_number(Smi::zero());
846
847 // Allocate the empty OrderedHashMap.
848 Handle<OrderedHashMap> empty_ordered_hash_map =
849 OrderedHashMap::AllocateEmpty(isolate(), AllocationType::kReadOnly)
850 .ToHandleChecked();
851 set_empty_ordered_hash_map(*empty_ordered_hash_map);
852
853 // Allocate the empty OrderedHashSet.
854 Handle<OrderedHashSet> empty_ordered_hash_set =
855 OrderedHashSet::AllocateEmpty(isolate(), AllocationType::kReadOnly)
856 .ToHandleChecked();
857 set_empty_ordered_hash_set(*empty_ordered_hash_set);
858
859 // Allocate the empty OrderedNameDictionary
860 Handle<OrderedNameDictionary> empty_ordered_property_dictionary =
861 OrderedNameDictionary::AllocateEmpty(isolate(), AllocationType::kReadOnly)
862 .ToHandleChecked();
863 set_empty_ordered_property_dictionary(*empty_ordered_property_dictionary);
864
865 // Allocate the empty FeedbackMetadata.
866 Handle<FeedbackMetadata> empty_feedback_metadata =
867 factory->NewFeedbackMetadata(0, 0, AllocationType::kReadOnly);
868 set_empty_feedback_metadata(*empty_feedback_metadata);
869
870 // Canonical scope arrays.
871 Handle<ScopeInfo> global_this_binding =
872 ScopeInfo::CreateGlobalThisBinding(isolate());
873 set_global_this_binding_scope_info(*global_this_binding);
874
875 Handle<ScopeInfo> empty_function =
876 ScopeInfo::CreateForEmptyFunction(isolate());
877 set_empty_function_scope_info(*empty_function);
878
879 Handle<ScopeInfo> native_scope_info =
880 ScopeInfo::CreateForNativeContext(isolate());
881 set_native_scope_info(*native_scope_info);
882
883 // Allocate the empty script.
884 Handle<Script> script = factory->NewScript(factory->empty_string());
885 script->set_type(Script::TYPE_NATIVE);
886 // This is used for exceptions thrown with no stack frames. Such exceptions
887 // can be shared everywhere.
888 script->set_origin_options(ScriptOriginOptions(true, false));
889 set_empty_script(*script);
890
891 {
892 Handle<PropertyCell> cell = factory->NewPropertyCell(
893 factory->empty_string(), AllocationType::kReadOnly);
894 cell->set_value(roots.the_hole_value());
895 set_empty_property_cell(*cell);
896 }
897
898 // Protectors
899 {
900 Handle<PropertyCell> cell =
901 factory->NewPropertyCell(factory->empty_string());
902 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
903 set_array_constructor_protector(*cell);
904 }
905
906 {
907 Handle<PropertyCell> cell =
908 factory->NewPropertyCell(factory->empty_string());
909 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
910 set_no_elements_protector(*cell);
911 }
912
913 {
914 Handle<PropertyCell> cell =
915 factory->NewPropertyCell(factory->empty_string());
916 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
917 set_array_iterator_protector(*cell);
918 }
919
920 {
921 Handle<PropertyCell> cell =
922 factory->NewPropertyCell(factory->empty_string());
923 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
924 set_map_iterator_protector(*cell);
925 }
926
927 {
928 Handle<PropertyCell> cell =
929 factory->NewPropertyCell(factory->empty_string());
930 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
931 set_set_iterator_protector(*cell);
932 }
933
934 {
935 Handle<PropertyCell> cell =
936 factory->NewPropertyCell(factory->empty_string());
937 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
938 set_is_concat_spreadable_protector(*cell);
939 }
940
941 {
942 Handle<PropertyCell> cell =
943 factory->NewPropertyCell(factory->empty_string());
944 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
945 set_array_species_protector(*cell);
946 }
947
948 {
949 Handle<PropertyCell> cell =
950 factory->NewPropertyCell(factory->empty_string());
951 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
952 set_typed_array_species_protector(*cell);
953 }
954
955 {
956 Handle<PropertyCell> cell =
957 factory->NewPropertyCell(factory->empty_string());
958 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
959 set_promise_species_protector(*cell);
960 }
961
962 {
963 Handle<PropertyCell> cell =
964 factory->NewPropertyCell(factory->empty_string());
965 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
966 set_regexp_species_protector(*cell);
967 }
968
969 {
970 Handle<PropertyCell> cell =
971 factory->NewPropertyCell(factory->empty_string());
972 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
973 set_string_iterator_protector(*cell);
974 }
975
976 {
977 Handle<PropertyCell> cell =
978 factory->NewPropertyCell(factory->empty_string());
979 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
980 set_string_length_protector(*cell);
981 }
982
983 {
984 Handle<PropertyCell> cell =
985 factory->NewPropertyCell(factory->empty_string());
986 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
987 set_array_buffer_detaching_protector(*cell);
988 }
989
990 {
991 Handle<PropertyCell> cell =
992 factory->NewPropertyCell(factory->empty_string());
993 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
994 set_promise_hook_protector(*cell);
995 }
996
997 {
998 Handle<PropertyCell> cell =
999 factory->NewPropertyCell(factory->empty_string());
1000 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
1001 set_promise_resolve_protector(*cell);
1002 }
1003
1004 {
1005 Handle<PropertyCell> cell =
1006 factory->NewPropertyCell(factory->empty_string());
1007 cell->set_value(Smi::FromInt(Protectors::kProtectorValid));
1008 set_promise_then_protector(*cell);
1009 }
1010
1011 set_serialized_objects(roots.empty_fixed_array());
1012 set_serialized_global_proxy_sizes(roots.empty_fixed_array());
1013
1014 /* Canonical off-heap trampoline data */
1015 set_off_heap_trampoline_relocation_info(
1016 *Builtins::GenerateOffHeapTrampolineRelocInfo(isolate_));
1017
1018 set_trampoline_trivial_code_data_container(
1019 *isolate()->factory()->NewCodeDataContainer(0,
1020 AllocationType::kReadOnly));
1021
1022 set_trampoline_promise_rejection_code_data_container(
1023 *isolate()->factory()->NewCodeDataContainer(
1024 Code::IsPromiseRejectionField::encode(true),
1025 AllocationType::kReadOnly));
1026
1027 // Evaluate the hash values which will then be cached in the strings.
1028 isolate()->factory()->zero_string()->Hash();
1029 isolate()->factory()->one_string()->Hash();
1030
1031 // Initialize builtins constants table.
1032 set_builtins_constants_table(roots.empty_fixed_array());
1033
1034 // Initialize descriptor cache.
1035 isolate_->descriptor_lookup_cache()->Clear();
1036
1037 // Initialize compilation cache.
1038 isolate_->compilation_cache()->Clear();
1039
1040 // Create internal SharedFunctionInfos.
1041
1042 // Async functions:
1043 {
1044 Handle<SharedFunctionInfo> info = CreateSharedFunctionInfo(
1045 isolate(), Builtins::kAsyncFunctionAwaitRejectClosure, 1);
1046 set_async_function_await_reject_shared_fun(*info);
1047
1048 info = CreateSharedFunctionInfo(
1049 isolate(), Builtins::kAsyncFunctionAwaitResolveClosure, 1);
1050 set_async_function_await_resolve_shared_fun(*info);
1051 }
1052
1053 // Async generators:
1054 {
1055 Handle<SharedFunctionInfo> info = CreateSharedFunctionInfo(
1056 isolate(), Builtins::kAsyncGeneratorAwaitResolveClosure, 1);
1057 set_async_generator_await_resolve_shared_fun(*info);
1058
1059 info = CreateSharedFunctionInfo(
1060 isolate(), Builtins::kAsyncGeneratorAwaitRejectClosure, 1);
1061 set_async_generator_await_reject_shared_fun(*info);
1062
1063 info = CreateSharedFunctionInfo(
1064 isolate(), Builtins::kAsyncGeneratorYieldResolveClosure, 1);
1065 set_async_generator_yield_resolve_shared_fun(*info);
1066
1067 info = CreateSharedFunctionInfo(
1068 isolate(), Builtins::kAsyncGeneratorReturnResolveClosure, 1);
1069 set_async_generator_return_resolve_shared_fun(*info);
1070
1071 info = CreateSharedFunctionInfo(
1072 isolate(), Builtins::kAsyncGeneratorReturnClosedResolveClosure, 1);
1073 set_async_generator_return_closed_resolve_shared_fun(*info);
1074
1075 info = CreateSharedFunctionInfo(
1076 isolate(), Builtins::kAsyncGeneratorReturnClosedRejectClosure, 1);
1077 set_async_generator_return_closed_reject_shared_fun(*info);
1078 }
1079
1080 // AsyncIterator:
1081 {
1082 Handle<SharedFunctionInfo> info = CreateSharedFunctionInfo(
1083 isolate_, Builtins::kAsyncIteratorValueUnwrap, 1);
1084 set_async_iterator_value_unwrap_shared_fun(*info);
1085 }
1086
1087 // Promises:
1088 {
1089 Handle<SharedFunctionInfo> info = CreateSharedFunctionInfo(
1090 isolate_, Builtins::kPromiseCapabilityDefaultResolve, 1,
1091 FunctionKind::kConciseMethod);
1092 info->set_native(true);
1093 info->set_function_map_index(
1094 Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
1095 set_promise_capability_default_resolve_shared_fun(*info);
1096
1097 info = CreateSharedFunctionInfo(isolate_,
1098 Builtins::kPromiseCapabilityDefaultReject,
1099 1, FunctionKind::kConciseMethod);
1100 info->set_native(true);
1101 info->set_function_map_index(
1102 Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
1103 set_promise_capability_default_reject_shared_fun(*info);
1104
1105 info = CreateSharedFunctionInfo(
1106 isolate_, Builtins::kPromiseGetCapabilitiesExecutor, 2);
1107 set_promise_get_capabilities_executor_shared_fun(*info);
1108 }
1109
1110 // Promises / finally:
1111 {
1112 Handle<SharedFunctionInfo> info =
1113 CreateSharedFunctionInfo(isolate(), Builtins::kPromiseThenFinally, 1);
1114 info->set_native(true);
1115 set_promise_then_finally_shared_fun(*info);
1116
1117 info =
1118 CreateSharedFunctionInfo(isolate(), Builtins::kPromiseCatchFinally, 1);
1119 info->set_native(true);
1120 set_promise_catch_finally_shared_fun(*info);
1121
1122 info = CreateSharedFunctionInfo(isolate(),
1123 Builtins::kPromiseValueThunkFinally, 0);
1124 set_promise_value_thunk_finally_shared_fun(*info);
1125
1126 info = CreateSharedFunctionInfo(isolate(), Builtins::kPromiseThrowerFinally,
1127 0);
1128 set_promise_thrower_finally_shared_fun(*info);
1129 }
1130
1131 // Promise combinators:
1132 {
1133 Handle<SharedFunctionInfo> info = CreateSharedFunctionInfo(
1134 isolate_, Builtins::kPromiseAllResolveElementClosure, 1);
1135 set_promise_all_resolve_element_shared_fun(*info);
1136
1137 info = CreateSharedFunctionInfo(
1138 isolate_, Builtins::kPromiseAllSettledResolveElementClosure, 1);
1139 set_promise_all_settled_resolve_element_shared_fun(*info);
1140
1141 info = CreateSharedFunctionInfo(
1142 isolate_, Builtins::kPromiseAllSettledRejectElementClosure, 1);
1143 set_promise_all_settled_reject_element_shared_fun(*info);
1144
1145 info = CreateSharedFunctionInfo(
1146 isolate_, Builtins::kPromiseAnyRejectElementClosure, 1);
1147 set_promise_any_reject_element_shared_fun(*info);
1148 }
1149
1150 // ProxyRevoke:
1151 {
1152 Handle<SharedFunctionInfo> info =
1153 CreateSharedFunctionInfo(isolate_, Builtins::kProxyRevoke, 0);
1154 set_proxy_revoke_shared_fun(*info);
1155 }
1156 }
1157
CreateInternalAccessorInfoObjects()1158 void Heap::CreateInternalAccessorInfoObjects() {
1159 Isolate* isolate = this->isolate();
1160 HandleScope scope(isolate);
1161 Handle<AccessorInfo> accessor_info;
1162
1163 #define INIT_ACCESSOR_INFO(_, accessor_name, AccessorName, ...) \
1164 accessor_info = Accessors::Make##AccessorName##Info(isolate); \
1165 roots_table()[RootIndex::k##AccessorName##Accessor] = accessor_info->ptr();
1166 ACCESSOR_INFO_LIST_GENERATOR(INIT_ACCESSOR_INFO, /* not used */)
1167 #undef INIT_ACCESSOR_INFO
1168
1169 #define INIT_SIDE_EFFECT_FLAG(_, accessor_name, AccessorName, GetterType, \
1170 SetterType) \
1171 AccessorInfo::cast( \
1172 Object(roots_table()[RootIndex::k##AccessorName##Accessor])) \
1173 .set_getter_side_effect_type(SideEffectType::GetterType); \
1174 AccessorInfo::cast( \
1175 Object(roots_table()[RootIndex::k##AccessorName##Accessor])) \
1176 .set_setter_side_effect_type(SideEffectType::SetterType);
1177 ACCESSOR_INFO_LIST_GENERATOR(INIT_SIDE_EFFECT_FLAG, /* not used */)
1178 #undef INIT_SIDE_EFFECT_FLAG
1179 }
1180
1181 } // namespace internal
1182 } // namespace v8
1183