Line data Source code
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/setup-isolate.h"
6 :
7 : #include "src/ast/context-slot-cache.h"
8 : #include "src/compilation-cache.h"
9 : #include "src/contexts.h"
10 : #include "src/factory.h"
11 : #include "src/heap-symbols.h"
12 : #include "src/heap/heap.h"
13 : #include "src/isolate.h"
14 : #include "src/layout-descriptor.h"
15 : #include "src/lookup-cache.h"
16 : #include "src/objects-inl.h"
17 : #include "src/objects/arguments.h"
18 : #include "src/objects/debug-objects.h"
19 : #include "src/objects/descriptor-array.h"
20 : #include "src/objects/dictionary.h"
21 : #include "src/objects/map.h"
22 : #include "src/objects/module.h"
23 : #include "src/objects/script.h"
24 : #include "src/objects/shared-function-info.h"
25 : #include "src/objects/string.h"
26 : #include "src/regexp/jsregexp.h"
27 :
28 : namespace v8 {
29 : namespace internal {
30 :
31 31 : bool SetupIsolateDelegate::SetupHeapInternal(Heap* heap) {
32 31 : return heap->CreateHeapObjects();
33 : }
34 :
35 62 : bool Heap::CreateHeapObjects() {
36 : // Create initial maps.
37 31 : if (!CreateInitialMaps()) return false;
38 31 : if (!CreateApiObjects()) return false;
39 :
40 : // Create initial objects
41 31 : CreateInitialObjects();
42 31 : CHECK_EQ(0u, gc_count_);
43 :
44 : set_native_contexts_list(undefined_value());
45 : set_allocation_sites_list(undefined_value());
46 :
47 31 : return true;
48 : }
49 :
50 : const Heap::StringTypeTable Heap::string_type_table[] = {
51 : #define STRING_TYPE_ELEMENT(type, size, name, camel_name) \
52 : {type, size, k##camel_name##MapRootIndex},
53 : STRING_TYPE_LIST(STRING_TYPE_ELEMENT)
54 : #undef STRING_TYPE_ELEMENT
55 : };
56 :
57 : const Heap::ConstantStringTable Heap::constant_string_table[] = {
58 : {"", kempty_stringRootIndex},
59 : #define CONSTANT_STRING_ELEMENT(name, contents) {contents, k##name##RootIndex},
60 : INTERNALIZED_STRING_LIST(CONSTANT_STRING_ELEMENT)
61 : #undef CONSTANT_STRING_ELEMENT
62 : };
63 :
64 : const Heap::StructTable Heap::struct_table[] = {
65 : #define STRUCT_TABLE_ELEMENT(NAME, Name, name) \
66 : {NAME##_TYPE, Name::kSize, k##Name##MapRootIndex},
67 : STRUCT_LIST(STRUCT_TABLE_ELEMENT)
68 : #undef STRUCT_TABLE_ELEMENT
69 : };
70 :
71 : namespace {
72 :
73 3472 : void FinalizePartialMap(Heap* heap, Map* map) {
74 868 : map->set_dependent_code(DependentCode::cast(heap->empty_fixed_array()));
75 868 : map->set_raw_transitions(Smi::kZero);
76 868 : map->set_instance_descriptors(heap->empty_descriptor_array());
77 : if (FLAG_unbox_double_fields) {
78 868 : map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout());
79 : }
80 868 : map->set_prototype(heap->null_value());
81 868 : map->set_constructor_or_backpointer(heap->null_value());
82 868 : }
83 :
84 : } // namespace
85 :
86 589 : bool Heap::CreateInitialMaps() {
87 : HeapObject* obj = nullptr;
88 : {
89 31 : AllocationResult allocation = AllocatePartialMap(MAP_TYPE, Map::kSize);
90 31 : if (!allocation.To(&obj)) return false;
91 : }
92 : // Map::cast cannot be used due to uninitialized map field.
93 : Map* new_meta_map = reinterpret_cast<Map*>(obj);
94 : set_meta_map(new_meta_map);
95 31 : new_meta_map->set_map_after_allocation(new_meta_map);
96 :
97 : { // Partial map allocation
98 : #define ALLOCATE_PARTIAL_MAP(instance_type, size, field_name) \
99 : { \
100 : Map* map; \
101 : if (!AllocatePartialMap((instance_type), (size)).To(&map)) return false; \
102 : set_##field_name##_map(map); \
103 : }
104 :
105 62 : ALLOCATE_PARTIAL_MAP(FIXED_ARRAY_TYPE, kVariableSizeSentinel, fixed_array);
106 : fixed_array_map()->set_elements_kind(HOLEY_ELEMENTS);
107 62 : ALLOCATE_PARTIAL_MAP(FIXED_ARRAY_TYPE, kVariableSizeSentinel,
108 : fixed_cow_array)
109 : fixed_cow_array_map()->set_elements_kind(HOLEY_ELEMENTS);
110 : DCHECK_NE(fixed_array_map(), fixed_cow_array_map());
111 :
112 62 : ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, undefined);
113 62 : ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, null);
114 62 : ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, the_hole);
115 :
116 : #undef ALLOCATE_PARTIAL_MAP
117 : }
118 :
119 : // Allocate the empty array.
120 : {
121 31 : AllocationResult allocation = AllocateEmptyFixedArray();
122 31 : if (!allocation.To(&obj)) return false;
123 : }
124 : set_empty_fixed_array(FixedArray::cast(obj));
125 :
126 : {
127 31 : AllocationResult allocation = Allocate(null_map(), OLD_SPACE);
128 31 : if (!allocation.To(&obj)) return false;
129 : }
130 : set_null_value(Oddball::cast(obj));
131 : Oddball::cast(obj)->set_kind(Oddball::kNull);
132 :
133 : {
134 31 : AllocationResult allocation = Allocate(undefined_map(), OLD_SPACE);
135 31 : if (!allocation.To(&obj)) return false;
136 : }
137 : set_undefined_value(Oddball::cast(obj));
138 : Oddball::cast(obj)->set_kind(Oddball::kUndefined);
139 : DCHECK(!InNewSpace(undefined_value()));
140 : {
141 31 : AllocationResult allocation = Allocate(the_hole_map(), OLD_SPACE);
142 31 : if (!allocation.To(&obj)) return false;
143 : }
144 : set_the_hole_value(Oddball::cast(obj));
145 : Oddball::cast(obj)->set_kind(Oddball::kTheHole);
146 :
147 : // Set preliminary exception sentinel value before actually initializing it.
148 : set_exception(null_value());
149 :
150 : // Setup the struct maps first (needed for the EnumCache).
151 713 : for (unsigned i = 0; i < arraysize(struct_table); i++) {
152 682 : const StructTable& entry = struct_table[i];
153 : Map* map;
154 1364 : if (!AllocatePartialMap(entry.type, entry.size).To(&map)) return false;
155 682 : roots_[entry.index] = map;
156 : }
157 :
158 : // Allocate the empty enum cache.
159 : {
160 31 : AllocationResult allocation = Allocate(tuple2_map(), OLD_SPACE);
161 31 : if (!allocation.To(&obj)) return false;
162 : }
163 : set_empty_enum_cache(EnumCache::cast(obj));
164 31 : EnumCache::cast(obj)->set_keys(empty_fixed_array());
165 31 : EnumCache::cast(obj)->set_indices(empty_fixed_array());
166 :
167 : // Allocate the empty descriptor array.
168 : {
169 : AllocationResult allocation =
170 31 : AllocateUninitializedFixedArray(DescriptorArray::kFirstIndex, TENURED);
171 31 : if (!allocation.To(&obj)) return false;
172 : }
173 : set_empty_descriptor_array(DescriptorArray::cast(obj));
174 : DescriptorArray::cast(obj)->set(DescriptorArray::kDescriptorLengthIndex,
175 : Smi::kZero);
176 : DescriptorArray::cast(obj)->set(DescriptorArray::kEnumCacheIndex,
177 31 : empty_enum_cache());
178 :
179 : // Fix the instance_descriptors for the existing maps.
180 31 : FinalizePartialMap(this, meta_map());
181 31 : FinalizePartialMap(this, fixed_array_map());
182 31 : FinalizePartialMap(this, fixed_cow_array_map());
183 31 : FinalizePartialMap(this, undefined_map());
184 : undefined_map()->set_is_undetectable();
185 31 : FinalizePartialMap(this, null_map());
186 : null_map()->set_is_undetectable();
187 31 : FinalizePartialMap(this, the_hole_map());
188 713 : for (unsigned i = 0; i < arraysize(struct_table); ++i) {
189 682 : const StructTable& entry = struct_table[i];
190 682 : FinalizePartialMap(this, Map::cast(roots_[entry.index]));
191 : }
192 :
193 : { // Map allocation
194 : #define ALLOCATE_MAP(instance_type, size, field_name) \
195 : { \
196 : Map* map; \
197 : if (!AllocateMap((instance_type), size).To(&map)) return false; \
198 : set_##field_name##_map(map); \
199 : }
200 :
201 : #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \
202 : ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name)
203 :
204 : #define ALLOCATE_PRIMITIVE_MAP(instance_type, size, field_name, \
205 : constructor_function_index) \
206 : { \
207 : ALLOCATE_MAP((instance_type), (size), field_name); \
208 : field_name##_map()->SetConstructorFunctionIndex( \
209 : (constructor_function_index)); \
210 : }
211 :
212 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info)
213 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, module_info)
214 62 : ALLOCATE_VARSIZE_MAP(FEEDBACK_VECTOR_TYPE, feedback_vector)
215 62 : ALLOCATE_PRIMITIVE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number,
216 : Context::NUMBER_FUNCTION_INDEX)
217 62 : ALLOCATE_MAP(MUTABLE_HEAP_NUMBER_TYPE, HeapNumber::kSize,
218 : mutable_heap_number)
219 62 : ALLOCATE_PRIMITIVE_MAP(SYMBOL_TYPE, Symbol::kSize, symbol,
220 : Context::SYMBOL_FUNCTION_INDEX)
221 62 : ALLOCATE_MAP(FOREIGN_TYPE, Foreign::kSize, foreign)
222 :
223 62 : ALLOCATE_PRIMITIVE_MAP(ODDBALL_TYPE, Oddball::kSize, boolean,
224 : Context::BOOLEAN_FUNCTION_INDEX);
225 62 : ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, uninitialized);
226 62 : ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, arguments_marker);
227 62 : ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, exception);
228 62 : ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, termination_exception);
229 62 : ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, optimized_out);
230 62 : ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, stale_register);
231 62 : ALLOCATE_VARSIZE_MAP(BIGINT_TYPE, bigint);
232 :
233 713 : for (unsigned i = 0; i < arraysize(string_type_table); i++) {
234 682 : const StringTypeTable& entry = string_type_table[i];
235 : {
236 682 : AllocationResult allocation = AllocateMap(entry.type, entry.size);
237 682 : if (!allocation.To(&obj)) return false;
238 : }
239 : Map* map = Map::cast(obj);
240 : map->SetConstructorFunctionIndex(Context::STRING_FUNCTION_INDEX);
241 : // Mark cons string maps as unstable, because their objects can change
242 : // maps during GC.
243 1364 : if (StringShape(entry.type).IsCons()) map->mark_unstable();
244 682 : roots_[entry.index] = map;
245 : }
246 :
247 : { // Create a separate external one byte string map for native sources.
248 : AllocationResult allocation =
249 : AllocateMap(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE,
250 31 : ExternalOneByteString::kShortSize);
251 31 : if (!allocation.To(&obj)) return false;
252 : Map* map = Map::cast(obj);
253 : map->SetConstructorFunctionIndex(Context::STRING_FUNCTION_INDEX);
254 : set_native_source_string_map(map);
255 : }
256 :
257 62 : ALLOCATE_VARSIZE_MAP(FIXED_DOUBLE_ARRAY_TYPE, fixed_double_array)
258 : fixed_double_array_map()->set_elements_kind(HOLEY_DOUBLE_ELEMENTS);
259 62 : ALLOCATE_VARSIZE_MAP(BYTE_ARRAY_TYPE, byte_array)
260 62 : ALLOCATE_VARSIZE_MAP(BYTECODE_ARRAY_TYPE, bytecode_array)
261 62 : ALLOCATE_VARSIZE_MAP(FREE_SPACE_TYPE, free_space)
262 62 : ALLOCATE_VARSIZE_MAP(PROPERTY_ARRAY_TYPE, property_array)
263 62 : ALLOCATE_VARSIZE_MAP(SMALL_ORDERED_HASH_MAP_TYPE, small_ordered_hash_map)
264 62 : ALLOCATE_VARSIZE_MAP(SMALL_ORDERED_HASH_SET_TYPE, small_ordered_hash_set)
265 :
266 : #define ALLOCATE_FIXED_TYPED_ARRAY_MAP(Type, type, TYPE, ctype, size) \
267 : ALLOCATE_VARSIZE_MAP(FIXED_##TYPE##_ARRAY_TYPE, fixed_##type##_array)
268 :
269 558 : TYPED_ARRAYS(ALLOCATE_FIXED_TYPED_ARRAY_MAP)
270 : #undef ALLOCATE_FIXED_TYPED_ARRAY_MAP
271 :
272 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, sloppy_arguments_elements)
273 :
274 62 : ALLOCATE_VARSIZE_MAP(CODE_TYPE, code)
275 :
276 62 : ALLOCATE_MAP(CELL_TYPE, Cell::kSize, cell)
277 62 : ALLOCATE_MAP(PROPERTY_CELL_TYPE, PropertyCell::kSize, global_property_cell)
278 62 : ALLOCATE_MAP(WEAK_CELL_TYPE, WeakCell::kSize, weak_cell)
279 62 : ALLOCATE_MAP(CELL_TYPE, Cell::kSize, no_closures_cell)
280 62 : ALLOCATE_MAP(CELL_TYPE, Cell::kSize, one_closure_cell)
281 62 : ALLOCATE_MAP(CELL_TYPE, Cell::kSize, many_closures_cell)
282 62 : ALLOCATE_MAP(FILLER_TYPE, kPointerSize, one_pointer_filler)
283 62 : ALLOCATE_MAP(FILLER_TYPE, 2 * kPointerSize, two_pointer_filler)
284 :
285 62 : ALLOCATE_VARSIZE_MAP(TRANSITION_ARRAY_TYPE, transition_array)
286 :
287 62 : ALLOCATE_VARSIZE_MAP(HASH_TABLE_TYPE, hash_table)
288 62 : ALLOCATE_VARSIZE_MAP(HASH_TABLE_TYPE, ordered_hash_table)
289 62 : ALLOCATE_VARSIZE_MAP(HASH_TABLE_TYPE, unseeded_number_dictionary)
290 :
291 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, function_context)
292 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, catch_context)
293 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, with_context)
294 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, debug_evaluate_context)
295 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, block_context)
296 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, module_context)
297 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, eval_context)
298 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, script_context)
299 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, script_context_table)
300 :
301 62 : ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, native_context)
302 : native_context_map()->set_visitor_id(kVisitNativeContext);
303 :
304 62 : ALLOCATE_MAP(SHARED_FUNCTION_INFO_TYPE, SharedFunctionInfo::kAlignedSize,
305 : shared_function_info)
306 :
307 62 : ALLOCATE_MAP(JS_MESSAGE_OBJECT_TYPE, JSMessageObject::kSize, message_object)
308 62 : ALLOCATE_MAP(JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize, external)
309 : external_map()->set_is_extensible(false);
310 : #undef ALLOCATE_PRIMITIVE_MAP
311 : #undef ALLOCATE_VARSIZE_MAP
312 : #undef ALLOCATE_MAP
313 : }
314 :
315 : {
316 31 : AllocationResult allocation = AllocateEmptyScopeInfo();
317 31 : if (!allocation.To(&obj)) return false;
318 : }
319 :
320 : set_empty_scope_info(ScopeInfo::cast(obj));
321 : {
322 31 : AllocationResult allocation = Allocate(boolean_map(), OLD_SPACE);
323 31 : if (!allocation.To(&obj)) return false;
324 : }
325 : set_true_value(Oddball::cast(obj));
326 : Oddball::cast(obj)->set_kind(Oddball::kTrue);
327 :
328 : {
329 31 : AllocationResult allocation = Allocate(boolean_map(), OLD_SPACE);
330 31 : if (!allocation.To(&obj)) return false;
331 : }
332 : set_false_value(Oddball::cast(obj));
333 : Oddball::cast(obj)->set_kind(Oddball::kFalse);
334 :
335 : { // Empty arrays
336 : {
337 : ByteArray * byte_array;
338 62 : if (!AllocateByteArray(0, TENURED).To(&byte_array)) return false;
339 : set_empty_byte_array(byte_array);
340 : }
341 :
342 : {
343 : PropertyArray* property_array;
344 62 : if (!AllocatePropertyArray(0, TENURED).To(&property_array)) return false;
345 : set_empty_property_array(property_array);
346 : }
347 :
348 : #define ALLOCATE_EMPTY_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
349 : { \
350 : FixedTypedArrayBase* obj; \
351 : if (!AllocateEmptyFixedTypedArray(kExternal##Type##Array).To(&obj)) \
352 : return false; \
353 : set_empty_fixed_##type##_array(obj); \
354 : }
355 :
356 558 : TYPED_ARRAYS(ALLOCATE_EMPTY_FIXED_TYPED_ARRAY)
357 : #undef ALLOCATE_EMPTY_FIXED_TYPED_ARRAY
358 : }
359 : DCHECK(!InNewSpace(empty_fixed_array()));
360 31 : return true;
361 : }
362 :
363 31 : bool Heap::CreateApiObjects() {
364 : HandleScope scope(isolate());
365 62 : set_message_listeners(*TemplateList::New(isolate(), 2));
366 : HeapObject* obj = nullptr;
367 : {
368 31 : AllocationResult allocation = AllocateStruct(INTERCEPTOR_INFO_TYPE);
369 31 : if (!allocation.To(&obj)) return false;
370 : }
371 : InterceptorInfo* info = InterceptorInfo::cast(obj);
372 : info->set_flags(0);
373 : set_noop_interceptor_info(info);
374 31 : return true;
375 : }
376 :
377 248 : void Heap::CreateInitialObjects() {
378 : HandleScope scope(isolate());
379 : Factory* factory = isolate()->factory();
380 :
381 : // The -0 value must be set before NewNumber works.
382 : set_minus_zero_value(*factory->NewHeapNumber(-0.0, IMMUTABLE, TENURED));
383 : DCHECK(std::signbit(minus_zero_value()->Number()));
384 :
385 : set_nan_value(*factory->NewHeapNumber(
386 : std::numeric_limits<double>::quiet_NaN(), IMMUTABLE, TENURED));
387 : set_hole_nan_value(
388 : *factory->NewHeapNumberFromBits(kHoleNanInt64, IMMUTABLE, TENURED));
389 : set_infinity_value(*factory->NewHeapNumber(V8_INFINITY, IMMUTABLE, TENURED));
390 : set_minus_infinity_value(
391 : *factory->NewHeapNumber(-V8_INFINITY, IMMUTABLE, TENURED));
392 :
393 : // Allocate initial string table.
394 62 : set_string_table(*StringTable::New(isolate(), kInitialStringTableSize));
395 :
396 : // Allocate
397 :
398 : // Finish initializing oddballs after creating the string table.
399 : Oddball::Initialize(isolate(), factory->undefined_value(), "undefined",
400 31 : factory->nan_value(), "undefined", Oddball::kUndefined);
401 :
402 : // Initialize the null_value.
403 : Oddball::Initialize(isolate(), factory->null_value(), "null",
404 31 : handle(Smi::kZero, isolate()), "object", Oddball::kNull);
405 :
406 : // Initialize the_hole_value.
407 : Oddball::Initialize(isolate(), factory->the_hole_value(), "hole",
408 : factory->hole_nan_value(), "undefined",
409 31 : Oddball::kTheHole);
410 :
411 : // Initialize the true_value.
412 : Oddball::Initialize(isolate(), factory->true_value(), "true",
413 : handle(Smi::FromInt(1), isolate()), "boolean",
414 31 : Oddball::kTrue);
415 :
416 : // Initialize the false_value.
417 : Oddball::Initialize(isolate(), factory->false_value(), "false",
418 : handle(Smi::kZero, isolate()), "boolean",
419 31 : Oddball::kFalse);
420 :
421 : set_uninitialized_value(
422 : *factory->NewOddball(factory->uninitialized_map(), "uninitialized",
423 : handle(Smi::FromInt(-1), isolate()), "undefined",
424 62 : Oddball::kUninitialized));
425 :
426 : set_arguments_marker(
427 : *factory->NewOddball(factory->arguments_marker_map(), "arguments_marker",
428 : handle(Smi::FromInt(-4), isolate()), "undefined",
429 62 : Oddball::kArgumentsMarker));
430 :
431 : set_termination_exception(*factory->NewOddball(
432 : factory->termination_exception_map(), "termination_exception",
433 62 : handle(Smi::FromInt(-3), isolate()), "undefined", Oddball::kOther));
434 :
435 : set_exception(*factory->NewOddball(factory->exception_map(), "exception",
436 : handle(Smi::FromInt(-5), isolate()),
437 62 : "undefined", Oddball::kException));
438 :
439 : set_optimized_out(*factory->NewOddball(factory->optimized_out_map(),
440 : "optimized_out",
441 : handle(Smi::FromInt(-6), isolate()),
442 62 : "undefined", Oddball::kOptimizedOut));
443 :
444 : set_stale_register(
445 : *factory->NewOddball(factory->stale_register_map(), "stale_register",
446 : handle(Smi::FromInt(-7), isolate()), "undefined",
447 62 : Oddball::kStaleRegister));
448 :
449 6200 : for (unsigned i = 0; i < arraysize(constant_string_table); i++) {
450 : Handle<String> str =
451 6169 : factory->InternalizeUtf8String(constant_string_table[i].contents);
452 12338 : roots_[constant_string_table[i].index] = *str;
453 : }
454 :
455 : // Create the code_stubs dictionary. The initial size is set to avoid
456 : // expanding the dictionary during bootstrapping.
457 62 : set_code_stubs(*UnseededNumberDictionary::New(isolate(), 128));
458 :
459 : {
460 : HandleScope scope(isolate());
461 : #define SYMBOL_INIT(name) \
462 : { \
463 : Handle<Symbol> symbol(isolate()->factory()->NewPrivateSymbol()); \
464 : roots_[k##name##RootIndex] = *symbol; \
465 : }
466 1209 : PRIVATE_SYMBOL_LIST(SYMBOL_INIT)
467 : #undef SYMBOL_INIT
468 : }
469 :
470 : {
471 : HandleScope scope(isolate());
472 : #define SYMBOL_INIT(name, description) \
473 : Handle<Symbol> name = factory->NewSymbol(); \
474 : Handle<String> name##d = factory->NewStringFromStaticChars(#description); \
475 : name->set_name(*name##d); \
476 : roots_[k##name##RootIndex] = *name;
477 651 : PUBLIC_SYMBOL_LIST(SYMBOL_INIT)
478 : #undef SYMBOL_INIT
479 :
480 : #define SYMBOL_INIT(name, description) \
481 : Handle<Symbol> name = factory->NewSymbol(); \
482 : Handle<String> name##d = factory->NewStringFromStaticChars(#description); \
483 : name->set_is_well_known_symbol(true); \
484 : name->set_name(*name##d); \
485 : roots_[k##name##RootIndex] = *name;
486 310 : WELL_KNOWN_SYMBOL_LIST(SYMBOL_INIT)
487 : #undef SYMBOL_INIT
488 :
489 : // Mark "Interesting Symbols" appropriately.
490 31 : to_string_tag_symbol->set_is_interesting_symbol(true);
491 : }
492 :
493 : Handle<NameDictionary> empty_property_dictionary =
494 31 : NameDictionary::New(isolate(), 1, TENURED, USE_CUSTOM_MINIMUM_CAPACITY);
495 : DCHECK(!empty_property_dictionary->HasSufficientCapacityToAdd(1));
496 : set_empty_property_dictionary(*empty_property_dictionary);
497 :
498 : set_public_symbol_table(*empty_property_dictionary);
499 : set_api_symbol_table(*empty_property_dictionary);
500 : set_api_private_symbol_table(*empty_property_dictionary);
501 :
502 : set_number_string_cache(
503 62 : *factory->NewFixedArray(kInitialNumberStringCacheSize * 2, TENURED));
504 :
505 : // Allocate cache for single character one byte strings.
506 : set_single_character_string_cache(
507 62 : *factory->NewFixedArray(String::kMaxOneByteCharCode + 1, TENURED));
508 :
509 : // Allocate cache for string split and regexp-multiple.
510 : set_string_split_cache(*factory->NewFixedArray(
511 62 : RegExpResultsCache::kRegExpResultsCacheSize, TENURED));
512 : set_regexp_multiple_cache(*factory->NewFixedArray(
513 62 : RegExpResultsCache::kRegExpResultsCacheSize, TENURED));
514 :
515 62 : set_undefined_cell(*factory->NewCell(factory->undefined_value()));
516 :
517 : // Microtask queue uses the empty fixed array as a sentinel for "empty".
518 : // Number of queued microtasks stored in Isolate::pending_microtask_count().
519 : set_microtask_queue(empty_fixed_array());
520 :
521 : {
522 : Handle<FixedArray> empty_sloppy_arguments_elements =
523 31 : factory->NewFixedArray(2, TENURED);
524 : empty_sloppy_arguments_elements->set_map_after_allocation(
525 31 : sloppy_arguments_elements_map(), SKIP_WRITE_BARRIER);
526 : set_empty_sloppy_arguments_elements(*empty_sloppy_arguments_elements);
527 : }
528 :
529 : {
530 31 : Handle<WeakCell> cell = factory->NewWeakCell(factory->undefined_value());
531 : set_empty_weak_cell(*cell);
532 : cell->clear();
533 : }
534 :
535 : set_detached_contexts(empty_fixed_array());
536 : set_retained_maps(ArrayList::cast(empty_fixed_array()));
537 : set_retaining_path_targets(undefined_value());
538 :
539 62 : set_weak_object_to_code_table(*WeakHashTable::New(isolate(), 16, TENURED));
540 :
541 : set_weak_new_space_object_to_code_list(
542 62 : ArrayList::cast(*(factory->NewFixedArray(16, TENURED))));
543 : weak_new_space_object_to_code_list()->SetLength(0);
544 :
545 : set_feedback_vectors_for_profiling_tools(undefined_value());
546 :
547 : set_script_list(Smi::kZero);
548 :
549 : Handle<SeededNumberDictionary> slow_element_dictionary =
550 : SeededNumberDictionary::New(isolate(), 1, TENURED,
551 31 : USE_CUSTOM_MINIMUM_CAPACITY);
552 : DCHECK(!slow_element_dictionary->HasSufficientCapacityToAdd(1));
553 : slow_element_dictionary->set_requires_slow_elements();
554 : set_empty_slow_element_dictionary(*slow_element_dictionary);
555 :
556 62 : set_materialized_objects(*factory->NewFixedArray(0, TENURED));
557 :
558 : // Handling of script id generation is in Heap::NextScriptId().
559 : set_last_script_id(Smi::FromInt(v8::UnboundScript::kNoScriptId));
560 : set_next_template_serial_number(Smi::kZero);
561 :
562 : // Allocate the empty OrderedHashTable.
563 : Handle<FixedArray> empty_ordered_hash_table =
564 31 : factory->NewFixedArray(OrderedHashMap::kHashTableStartIndex, TENURED);
565 : empty_ordered_hash_table->set_map_no_write_barrier(
566 : *factory->ordered_hash_table_map());
567 248 : for (int i = 0; i < empty_ordered_hash_table->length(); ++i) {
568 : empty_ordered_hash_table->set(i, Smi::kZero);
569 : }
570 : set_empty_ordered_hash_table(*empty_ordered_hash_table);
571 :
572 : // Allocate the empty script.
573 31 : Handle<Script> script = factory->NewScript(factory->empty_string());
574 : script->set_type(Script::TYPE_NATIVE);
575 : set_empty_script(*script);
576 :
577 : Handle<Cell> array_constructor_cell = factory->NewCell(
578 31 : handle(Smi::FromInt(Isolate::kProtectorValid), isolate()));
579 : set_array_constructor_protector(*array_constructor_cell);
580 :
581 31 : Handle<PropertyCell> cell = factory->NewPropertyCell(factory->empty_string());
582 31 : cell->set_value(Smi::FromInt(Isolate::kProtectorValid));
583 : set_array_protector(*cell);
584 :
585 31 : cell = factory->NewPropertyCell(factory->empty_string());
586 31 : cell->set_value(the_hole_value());
587 : set_empty_property_cell(*cell);
588 :
589 31 : cell = factory->NewPropertyCell(factory->empty_string());
590 31 : cell->set_value(Smi::FromInt(Isolate::kProtectorValid));
591 : set_array_iterator_protector(*cell);
592 :
593 : Handle<Cell> is_concat_spreadable_cell = factory->NewCell(
594 31 : handle(Smi::FromInt(Isolate::kProtectorValid), isolate()));
595 : set_is_concat_spreadable_protector(*is_concat_spreadable_cell);
596 :
597 31 : cell = factory->NewPropertyCell(factory->empty_string());
598 31 : cell->set_value(Smi::FromInt(Isolate::kProtectorValid));
599 : set_species_protector(*cell);
600 :
601 : Handle<Cell> string_length_overflow_cell = factory->NewCell(
602 31 : handle(Smi::FromInt(Isolate::kProtectorValid), isolate()));
603 : set_string_length_protector(*string_length_overflow_cell);
604 :
605 : Handle<Cell> fast_array_iteration_cell = factory->NewCell(
606 31 : handle(Smi::FromInt(Isolate::kProtectorValid), isolate()));
607 : set_fast_array_iteration_protector(*fast_array_iteration_cell);
608 :
609 31 : cell = factory->NewPropertyCell(factory->empty_string());
610 31 : cell->set_value(Smi::FromInt(Isolate::kProtectorValid));
611 : set_array_buffer_neutering_protector(*cell);
612 :
613 : set_serialized_templates(empty_fixed_array());
614 : set_serialized_global_proxy_sizes(empty_fixed_array());
615 :
616 : set_weak_stack_trace_list(Smi::kZero);
617 :
618 : set_noscript_shared_function_infos(Smi::kZero);
619 :
620 : // Initialize context slot cache.
621 93 : isolate_->context_slot_cache()->Clear();
622 :
623 : // Initialize descriptor cache.
624 62 : isolate_->descriptor_lookup_cache()->Clear();
625 :
626 : // Initialize compilation cache.
627 62 : isolate_->compilation_cache()->Clear();
628 31 : }
629 :
630 : } // namespace internal
631 : } // namespace v8
|