Home | History | Annotate | Download | only in src
      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_ROOTS_H_
      6 #define V8_ROOTS_H_
      7 
      8 #include "src/handles.h"
      9 #include "src/heap-symbols.h"
     10 #include "src/objects-definitions.h"
     11 
     12 namespace v8 {
     13 
     14 namespace internal {
     15 
     16 // Defines all the read-only roots in Heap.
     17 #define STRONG_READ_ONLY_ROOT_LIST(V)                                          \
     18   /* Cluster the most popular ones in a few cache lines here at the top.    */ \
     19   /* The first 32 entries are most often used in the startup snapshot and   */ \
     20   /* can use a shorter representation in the serialization format.          */ \
     21   V(Map, free_space_map, FreeSpaceMap)                                         \
     22   V(Map, one_pointer_filler_map, OnePointerFillerMap)                          \
     23   V(Map, two_pointer_filler_map, TwoPointerFillerMap)                          \
     24   V(Oddball, uninitialized_value, UninitializedValue)                          \
     25   V(Oddball, undefined_value, UndefinedValue)                                  \
     26   V(Oddball, the_hole_value, TheHoleValue)                                     \
     27   V(Oddball, null_value, NullValue)                                            \
     28   V(Oddball, true_value, TrueValue)                                            \
     29   V(Oddball, false_value, FalseValue)                                          \
     30   V(String, empty_string, empty_string)                                        \
     31   V(Map, meta_map, MetaMap)                                                    \
     32   V(Map, byte_array_map, ByteArrayMap)                                         \
     33   V(Map, fixed_array_map, FixedArrayMap)                                       \
     34   V(Map, fixed_cow_array_map, FixedCOWArrayMap)                                \
     35   V(Map, hash_table_map, HashTableMap)                                         \
     36   V(Map, symbol_map, SymbolMap)                                                \
     37   V(Map, one_byte_string_map, OneByteStringMap)                                \
     38   V(Map, one_byte_internalized_string_map, OneByteInternalizedStringMap)       \
     39   V(Map, scope_info_map, ScopeInfoMap)                                         \
     40   V(Map, shared_function_info_map, SharedFunctionInfoMap)                      \
     41   V(Map, code_map, CodeMap)                                                    \
     42   V(Map, function_context_map, FunctionContextMap)                             \
     43   V(Map, cell_map, CellMap)                                                    \
     44   V(Map, global_property_cell_map, GlobalPropertyCellMap)                      \
     45   V(Map, foreign_map, ForeignMap)                                              \
     46   V(Map, heap_number_map, HeapNumberMap)                                       \
     47   V(Map, transition_array_map, TransitionArrayMap)                             \
     48   V(Map, feedback_vector_map, FeedbackVectorMap)                               \
     49   V(ScopeInfo, empty_scope_info, EmptyScopeInfo)                               \
     50   V(FixedArray, empty_fixed_array, EmptyFixedArray)                            \
     51   V(DescriptorArray, empty_descriptor_array, EmptyDescriptorArray)             \
     52   /* Entries beyond the first 32                                            */ \
     53   /* The roots above this line should be boring from a GC point of view.    */ \
     54   /* This means they are never in new space and never on a page that is     */ \
     55   /* being compacted.*/                                                        \
     56   /* Oddballs */                                                               \
     57   V(Oddball, arguments_marker, ArgumentsMarker)                                \
     58   V(Oddball, exception, Exception)                                             \
     59   V(Oddball, termination_exception, TerminationException)                      \
     60   V(Oddball, optimized_out, OptimizedOut)                                      \
     61   V(Oddball, stale_register, StaleRegister)                                    \
     62   /* Context maps */                                                           \
     63   V(Map, native_context_map, NativeContextMap)                                 \
     64   V(Map, module_context_map, ModuleContextMap)                                 \
     65   V(Map, eval_context_map, EvalContextMap)                                     \
     66   V(Map, script_context_map, ScriptContextMap)                                 \
     67   V(Map, block_context_map, BlockContextMap)                                   \
     68   V(Map, catch_context_map, CatchContextMap)                                   \
     69   V(Map, with_context_map, WithContextMap)                                     \
     70   V(Map, debug_evaluate_context_map, DebugEvaluateContextMap)                  \
     71   V(Map, script_context_table_map, ScriptContextTableMap)                      \
     72   /* Maps */                                                                   \
     73   V(Map, feedback_metadata_map, FeedbackMetadataArrayMap)                      \
     74   V(Map, array_list_map, ArrayListMap)                                         \
     75   V(Map, bigint_map, BigIntMap)                                                \
     76   V(Map, object_boilerplate_description_map, ObjectBoilerplateDescriptionMap)  \
     77   V(Map, bytecode_array_map, BytecodeArrayMap)                                 \
     78   V(Map, code_data_container_map, CodeDataContainerMap)                        \
     79   V(Map, descriptor_array_map, DescriptorArrayMap)                             \
     80   V(Map, fixed_double_array_map, FixedDoubleArrayMap)                          \
     81   V(Map, global_dictionary_map, GlobalDictionaryMap)                           \
     82   V(Map, many_closures_cell_map, ManyClosuresCellMap)                          \
     83   V(Map, module_info_map, ModuleInfoMap)                                       \
     84   V(Map, mutable_heap_number_map, MutableHeapNumberMap)                        \
     85   V(Map, name_dictionary_map, NameDictionaryMap)                               \
     86   V(Map, no_closures_cell_map, NoClosuresCellMap)                              \
     87   V(Map, number_dictionary_map, NumberDictionaryMap)                           \
     88   V(Map, one_closure_cell_map, OneClosureCellMap)                              \
     89   V(Map, ordered_hash_map_map, OrderedHashMapMap)                              \
     90   V(Map, ordered_hash_set_map, OrderedHashSetMap)                              \
     91   V(Map, pre_parsed_scope_data_map, PreParsedScopeDataMap)                     \
     92   V(Map, property_array_map, PropertyArrayMap)                                 \
     93   V(Map, side_effect_call_handler_info_map, SideEffectCallHandlerInfoMap)      \
     94   V(Map, side_effect_free_call_handler_info_map,                               \
     95     SideEffectFreeCallHandlerInfoMap)                                          \
     96   V(Map, next_call_side_effect_free_call_handler_info_map,                     \
     97     NextCallSideEffectFreeCallHandlerInfoMap)                                  \
     98   V(Map, simple_number_dictionary_map, SimpleNumberDictionaryMap)              \
     99   V(Map, sloppy_arguments_elements_map, SloppyArgumentsElementsMap)            \
    100   V(Map, small_ordered_hash_map_map, SmallOrderedHashMapMap)                   \
    101   V(Map, small_ordered_hash_set_map, SmallOrderedHashSetMap)                   \
    102   V(Map, string_table_map, StringTableMap)                                     \
    103   V(Map, uncompiled_data_without_pre_parsed_scope_map,                         \
    104     UncompiledDataWithoutPreParsedScopeMap)                                    \
    105   V(Map, uncompiled_data_with_pre_parsed_scope_map,                            \
    106     UncompiledDataWithPreParsedScopeMap)                                       \
    107   V(Map, weak_fixed_array_map, WeakFixedArrayMap)                              \
    108   V(Map, weak_array_list_map, WeakArrayListMap)                                \
    109   V(Map, ephemeron_hash_table_map, EphemeronHashTableMap)                      \
    110   /* String maps */                                                            \
    111   V(Map, native_source_string_map, NativeSourceStringMap)                      \
    112   V(Map, string_map, StringMap)                                                \
    113   V(Map, cons_one_byte_string_map, ConsOneByteStringMap)                       \
    114   V(Map, cons_string_map, ConsStringMap)                                       \
    115   V(Map, thin_one_byte_string_map, ThinOneByteStringMap)                       \
    116   V(Map, thin_string_map, ThinStringMap)                                       \
    117   V(Map, sliced_string_map, SlicedStringMap)                                   \
    118   V(Map, sliced_one_byte_string_map, SlicedOneByteStringMap)                   \
    119   V(Map, external_string_map, ExternalStringMap)                               \
    120   V(Map, external_string_with_one_byte_data_map,                               \
    121     ExternalStringWithOneByteDataMap)                                          \
    122   V(Map, external_one_byte_string_map, ExternalOneByteStringMap)               \
    123   V(Map, short_external_string_map, ShortExternalStringMap)                    \
    124   V(Map, short_external_string_with_one_byte_data_map,                         \
    125     ShortExternalStringWithOneByteDataMap)                                     \
    126   V(Map, internalized_string_map, InternalizedStringMap)                       \
    127   V(Map, external_internalized_string_map, ExternalInternalizedStringMap)      \
    128   V(Map, external_internalized_string_with_one_byte_data_map,                  \
    129     ExternalInternalizedStringWithOneByteDataMap)                              \
    130   V(Map, external_one_byte_internalized_string_map,                            \
    131     ExternalOneByteInternalizedStringMap)                                      \
    132   V(Map, short_external_internalized_string_map,                               \
    133     ShortExternalInternalizedStringMap)                                        \
    134   V(Map, short_external_internalized_string_with_one_byte_data_map,            \
    135     ShortExternalInternalizedStringWithOneByteDataMap)                         \
    136   V(Map, short_external_one_byte_internalized_string_map,                      \
    137     ShortExternalOneByteInternalizedStringMap)                                 \
    138   V(Map, short_external_one_byte_string_map, ShortExternalOneByteStringMap)    \
    139   /* Array element maps */                                                     \
    140   V(Map, fixed_uint8_array_map, FixedUint8ArrayMap)                            \
    141   V(Map, fixed_int8_array_map, FixedInt8ArrayMap)                              \
    142   V(Map, fixed_uint16_array_map, FixedUint16ArrayMap)                          \
    143   V(Map, fixed_int16_array_map, FixedInt16ArrayMap)                            \
    144   V(Map, fixed_uint32_array_map, FixedUint32ArrayMap)                          \
    145   V(Map, fixed_int32_array_map, FixedInt32ArrayMap)                            \
    146   V(Map, fixed_float32_array_map, FixedFloat32ArrayMap)                        \
    147   V(Map, fixed_float64_array_map, FixedFloat64ArrayMap)                        \
    148   V(Map, fixed_uint8_clamped_array_map, FixedUint8ClampedArrayMap)             \
    149   V(Map, fixed_biguint64_array_map, FixedBigUint64ArrayMap)                    \
    150   V(Map, fixed_bigint64_array_map, FixedBigInt64ArrayMap)                      \
    151   /* Oddball maps */                                                           \
    152   V(Map, undefined_map, UndefinedMap)                                          \
    153   V(Map, the_hole_map, TheHoleMap)                                             \
    154   V(Map, null_map, NullMap)                                                    \
    155   V(Map, boolean_map, BooleanMap)                                              \
    156   V(Map, uninitialized_map, UninitializedMap)                                  \
    157   V(Map, arguments_marker_map, ArgumentsMarkerMap)                             \
    158   V(Map, exception_map, ExceptionMap)                                          \
    159   V(Map, termination_exception_map, TerminationExceptionMap)                   \
    160   V(Map, optimized_out_map, OptimizedOutMap)                                   \
    161   V(Map, stale_register_map, StaleRegisterMap)                                 \
    162   V(Map, self_reference_marker_map, SelfReferenceMarkerMap)                    \
    163   /* Canonical empty values */                                                 \
    164   V(EnumCache, empty_enum_cache, EmptyEnumCache)                               \
    165   V(PropertyArray, empty_property_array, EmptyPropertyArray)                   \
    166   V(ByteArray, empty_byte_array, EmptyByteArray)                               \
    167   V(ObjectBoilerplateDescription, empty_object_boilerplate_description,        \
    168     EmptyObjectBoilerplateDescription)                                         \
    169   V(ArrayBoilerplateDescription, empty_array_boilerplate_description,          \
    170     EmptyArrayBoilerplateDescription)                                          \
    171   V(FixedTypedArrayBase, empty_fixed_uint8_array, EmptyFixedUint8Array)        \
    172   V(FixedTypedArrayBase, empty_fixed_int8_array, EmptyFixedInt8Array)          \
    173   V(FixedTypedArrayBase, empty_fixed_uint16_array, EmptyFixedUint16Array)      \
    174   V(FixedTypedArrayBase, empty_fixed_int16_array, EmptyFixedInt16Array)        \
    175   V(FixedTypedArrayBase, empty_fixed_uint32_array, EmptyFixedUint32Array)      \
    176   V(FixedTypedArrayBase, empty_fixed_int32_array, EmptyFixedInt32Array)        \
    177   V(FixedTypedArrayBase, empty_fixed_float32_array, EmptyFixedFloat32Array)    \
    178   V(FixedTypedArrayBase, empty_fixed_float64_array, EmptyFixedFloat64Array)    \
    179   V(FixedTypedArrayBase, empty_fixed_uint8_clamped_array,                      \
    180     EmptyFixedUint8ClampedArray)                                               \
    181   V(FixedTypedArrayBase, empty_fixed_biguint64_array,                          \
    182     EmptyFixedBigUint64Array)                                                  \
    183   V(FixedTypedArrayBase, empty_fixed_bigint64_array, EmptyFixedBigInt64Array)  \
    184   V(FixedArray, empty_sloppy_arguments_elements, EmptySloppyArgumentsElements) \
    185   V(NumberDictionary, empty_slow_element_dictionary,                           \
    186     EmptySlowElementDictionary)                                                \
    187   V(FixedArray, empty_ordered_hash_map, EmptyOrderedHashMap)                   \
    188   V(FixedArray, empty_ordered_hash_set, EmptyOrderedHashSet)                   \
    189   V(FeedbackMetadata, empty_feedback_metadata, EmptyFeedbackMetadata)          \
    190   V(PropertyCell, empty_property_cell, EmptyPropertyCell)                      \
    191   V(InterceptorInfo, noop_interceptor_info, NoOpInterceptorInfo)               \
    192   V(WeakFixedArray, empty_weak_fixed_array, EmptyWeakFixedArray)               \
    193   V(WeakArrayList, empty_weak_array_list, EmptyWeakArrayList)                  \
    194   /* Special numbers */                                                        \
    195   V(HeapNumber, nan_value, NanValue)                                           \
    196   V(HeapNumber, hole_nan_value, HoleNanValue)                                  \
    197   V(HeapNumber, infinity_value, InfinityValue)                                 \
    198   V(HeapNumber, minus_zero_value, MinusZeroValue)                              \
    199   V(HeapNumber, minus_infinity_value, MinusInfinityValue)                      \
    200   /* Marker for self-references during code-generation */                      \
    201   V(HeapObject, self_reference_marker, SelfReferenceMarker)
    202 
    203 #define STRONG_MUTABLE_ROOT_LIST(V)                                          \
    204   /* Maps */                                                                 \
    205   V(Map, external_map, ExternalMap)                                          \
    206   V(Map, message_object_map, JSMessageObjectMap)                             \
    207   /* Canonical empty values */                                               \
    208   V(Script, empty_script, EmptyScript)                                       \
    209   V(FeedbackCell, many_closures_cell, ManyClosuresCell)                      \
    210   V(Cell, invalid_prototype_validity_cell, InvalidPrototypeValidityCell)     \
    211   /* Protectors */                                                           \
    212   V(Cell, array_constructor_protector, ArrayConstructorProtector)            \
    213   V(PropertyCell, no_elements_protector, NoElementsProtector)                \
    214   V(Cell, is_concat_spreadable_protector, IsConcatSpreadableProtector)       \
    215   V(PropertyCell, array_species_protector, ArraySpeciesProtector)            \
    216   V(PropertyCell, typed_array_species_protector, TypedArraySpeciesProtector) \
    217   V(PropertyCell, promise_species_protector, PromiseSpeciesProtector)        \
    218   V(Cell, string_length_protector, StringLengthProtector)                    \
    219   V(PropertyCell, array_iterator_protector, ArrayIteratorProtector)          \
    220   V(PropertyCell, array_buffer_neutering_protector,                          \
    221     ArrayBufferNeuteringProtector)                                           \
    222   V(PropertyCell, promise_hook_protector, PromiseHookProtector)              \
    223   V(Cell, promise_resolve_protector, PromiseResolveProtector)                \
    224   V(PropertyCell, promise_then_protector, PromiseThenProtector)              \
    225   /* Caches */                                                               \
    226   V(FixedArray, number_string_cache, NumberStringCache)                      \
    227   V(FixedArray, single_character_string_cache, SingleCharacterStringCache)   \
    228   V(FixedArray, string_split_cache, StringSplitCache)                        \
    229   V(FixedArray, regexp_multiple_cache, RegExpMultipleCache)                  \
    230   /* Lists and dictionaries */                                               \
    231   V(NameDictionary, empty_property_dictionary, EmptyPropertyDictionary)      \
    232   V(NameDictionary, public_symbol_table, PublicSymbolTable)                  \
    233   V(NameDictionary, api_symbol_table, ApiSymbolTable)                        \
    234   V(NameDictionary, api_private_symbol_table, ApiPrivateSymbolTable)         \
    235   V(WeakArrayList, script_list, ScriptList)                                  \
    236   V(SimpleNumberDictionary, code_stubs, CodeStubs)                           \
    237   V(FixedArray, materialized_objects, MaterializedObjects)                   \
    238   V(FixedArray, microtask_queue, MicrotaskQueue)                             \
    239   V(WeakArrayList, detached_contexts, DetachedContexts)                      \
    240   V(WeakArrayList, retaining_path_targets, RetainingPathTargets)             \
    241   V(WeakArrayList, retained_maps, RetainedMaps)                              \
    242   /* Indirection lists for isolate-independent builtins */                   \
    243   V(FixedArray, builtins_constants_table, BuiltinsConstantsTable)            \
    244   /* Feedback vectors that we need for code coverage or type profile */      \
    245   V(Object, feedback_vectors_for_profiling_tools,                            \
    246     FeedbackVectorsForProfilingTools)                                        \
    247   V(WeakArrayList, noscript_shared_function_infos,                           \
    248     NoScriptSharedFunctionInfos)                                             \
    249   V(FixedArray, serialized_objects, SerializedObjects)                       \
    250   V(FixedArray, serialized_global_proxy_sizes, SerializedGlobalProxySizes)   \
    251   V(TemplateList, message_listeners, MessageListeners)                       \
    252   /* DeserializeLazy handlers for lazy bytecode deserialization */           \
    253   V(Object, deserialize_lazy_handler, DeserializeLazyHandler)                \
    254   V(Object, deserialize_lazy_handler_wide, DeserializeLazyHandlerWide)       \
    255   V(Object, deserialize_lazy_handler_extra_wide,                             \
    256     DeserializeLazyHandlerExtraWide)                                         \
    257   /* Hash seed */                                                            \
    258   V(ByteArray, hash_seed, HashSeed)                                          \
    259   /* JS Entries */                                                           \
    260   V(Code, js_entry_code, JsEntryCode)                                        \
    261   V(Code, js_construct_entry_code, JsConstructEntryCode)                     \
    262   V(Code, js_run_microtasks_entry_code, JsRunMicrotasksEntryCode)
    263 
    264 #define STRONG_ROOT_LIST(V)     \
    265   STRONG_READ_ONLY_ROOT_LIST(V) \
    266   STRONG_MUTABLE_ROOT_LIST(V)
    267 
    268 // Entries in this list are limited to Smis and are not visited during GC.
    269 #define SMI_ROOT_LIST(V)                                                       \
    270   V(Smi, stack_limit, StackLimit)                                              \
    271   V(Smi, real_stack_limit, RealStackLimit)                                     \
    272   V(Smi, last_script_id, LastScriptId)                                         \
    273   V(Smi, last_debugging_id, LastDebuggingId)                                   \
    274   /* To distinguish the function templates, so that we can find them in the */ \
    275   /* function cache of the native context. */                                  \
    276   V(Smi, next_template_serial_number, NextTemplateSerialNumber)                \
    277   V(Smi, arguments_adaptor_deopt_pc_offset, ArgumentsAdaptorDeoptPCOffset)     \
    278   V(Smi, construct_stub_create_deopt_pc_offset,                                \
    279     ConstructStubCreateDeoptPCOffset)                                          \
    280   V(Smi, construct_stub_invoke_deopt_pc_offset,                                \
    281     ConstructStubInvokeDeoptPCOffset)                                          \
    282   V(Smi, interpreter_entry_return_pc_offset, InterpreterEntryReturnPCOffset)
    283 
    284 #define MUTABLE_ROOT_LIST(V)  \
    285   STRONG_MUTABLE_ROOT_LIST(V) \
    286   SMI_ROOT_LIST(V)            \
    287   V(StringTable, string_table, StringTable)
    288 
    289 #define ROOT_LIST(V)   \
    290   MUTABLE_ROOT_LIST(V) \
    291   STRONG_READ_ONLY_ROOT_LIST(V)
    292 
    293 class FixedTypedArrayBase;
    294 class Heap;
    295 class Isolate;
    296 class Map;
    297 class String;
    298 class Symbol;
    299 
    300 class ReadOnlyRoots {
    301  public:
    302   explicit ReadOnlyRoots(Heap* heap) : heap_(heap) {}
    303   inline explicit ReadOnlyRoots(Isolate* isolate);
    304 
    305 #define ROOT_ACCESSOR(type, name, camel_name) \
    306   inline class type* name();                  \
    307   inline Handle<type> name##_handle();
    308   STRONG_READ_ONLY_ROOT_LIST(ROOT_ACCESSOR)
    309 #undef ROOT_ACCESSOR
    310 
    311 #define STRING_ACCESSOR(name, str) \
    312   inline String* name();           \
    313   inline Handle<String> name##_handle();
    314   INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
    315 #undef STRING_ACCESSOR
    316 
    317 #define SYMBOL_ACCESSOR(name) \
    318   inline Symbol* name();      \
    319   inline Handle<Symbol> name##_handle();
    320   PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
    321 #undef SYMBOL_ACCESSOR
    322 
    323 #define SYMBOL_ACCESSOR(name, description) \
    324   inline Symbol* name();                   \
    325   inline Handle<Symbol> name##_handle();
    326   PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
    327   WELL_KNOWN_SYMBOL_LIST(SYMBOL_ACCESSOR)
    328 #undef SYMBOL_ACCESSOR
    329 
    330 // Utility type maps.
    331 #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
    332   inline Map* name##_map();                   \
    333   inline class Handle<Map> name##_map_handle();
    334   STRUCT_LIST(STRUCT_MAP_ACCESSOR)
    335 #undef STRUCT_MAP_ACCESSOR
    336 
    337 #define ALLOCATION_SITE_MAP_ACCESSOR(NAME, Name, Size, name) \
    338   inline Map* name##_map();                                  \
    339   inline class Handle<Map> name##_map_handle();
    340   ALLOCATION_SITE_LIST(ALLOCATION_SITE_MAP_ACCESSOR)
    341 #undef ALLOCATION_SITE_MAP_ACCESSOR
    342 
    343   inline FixedTypedArrayBase* EmptyFixedTypedArrayForMap(const Map* map);
    344 
    345  private:
    346   Heap* heap_;
    347 };
    348 
    349 }  // namespace internal
    350 }  // namespace v8
    351 
    352 #endif  // V8_ROOTS_H_
    353