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_INL_H_ 6 #define V8_ROOTS_INL_H_ 7 8 #include "src/roots.h" 9 10 #include "src/heap/heap-inl.h" 11 #include "src/objects/api-callbacks.h" 12 13 namespace v8 { 14 15 namespace internal { 16 ReadOnlyRoots(Isolate * isolate)17ReadOnlyRoots::ReadOnlyRoots(Isolate* isolate) : heap_(isolate->heap()) {} 18 19 #define ROOT_ACCESSOR(type, name, camel_name) \ 20 type* ReadOnlyRoots::name() { \ 21 return type::cast(heap_->roots_[Heap::k##camel_name##RootIndex]); \ 22 } \ 23 Handle<type> ReadOnlyRoots::name##_handle() { \ 24 return Handle<type>( \ 25 bit_cast<type**>(&heap_->roots_[Heap::k##camel_name##RootIndex])); \ 26 } 27 STRONG_READ_ONLY_ROOT_LIST(ROOT_ACCESSOR) 28 #undef ROOT_ACCESSOR 29 30 #define STRING_ACCESSOR(name, str) \ 31 String* ReadOnlyRoots::name() { \ 32 return String::cast(heap_->roots_[Heap::k##name##RootIndex]); \ 33 } \ 34 Handle<String> ReadOnlyRoots::name##_handle() { \ 35 return Handle<String>( \ 36 bit_cast<String**>(&heap_->roots_[Heap::k##name##RootIndex])); \ 37 } INTERNALIZED_STRING_LIST(STRING_ACCESSOR)38INTERNALIZED_STRING_LIST(STRING_ACCESSOR) 39 #undef STRING_ACCESSOR 40 41 #define SYMBOL_ACCESSOR(name) \ 42 Symbol* ReadOnlyRoots::name() { \ 43 return Symbol::cast(heap_->roots_[Heap::k##name##RootIndex]); \ 44 } \ 45 Handle<Symbol> ReadOnlyRoots::name##_handle() { \ 46 return Handle<Symbol>( \ 47 bit_cast<Symbol**>(&heap_->roots_[Heap::k##name##RootIndex])); \ 48 } 49 PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR) 50 #undef SYMBOL_ACCESSOR 51 52 #define SYMBOL_ACCESSOR(name, description) \ 53 Symbol* ReadOnlyRoots::name() { \ 54 return Symbol::cast(heap_->roots_[Heap::k##name##RootIndex]); \ 55 } \ 56 Handle<Symbol> ReadOnlyRoots::name##_handle() { \ 57 return Handle<Symbol>( \ 58 bit_cast<Symbol**>(&heap_->roots_[Heap::k##name##RootIndex])); \ 59 } 60 PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR) 61 WELL_KNOWN_SYMBOL_LIST(SYMBOL_ACCESSOR) 62 #undef SYMBOL_ACCESSOR 63 64 #define STRUCT_MAP_ACCESSOR(NAME, Name, name) \ 65 Map* ReadOnlyRoots::name##_map() { \ 66 return Map::cast(heap_->roots_[Heap::k##Name##MapRootIndex]); \ 67 } \ 68 Handle<Map> ReadOnlyRoots::name##_map_handle() { \ 69 return Handle<Map>( \ 70 bit_cast<Map**>(&heap_->roots_[Heap::k##Name##MapRootIndex])); \ 71 } 72 STRUCT_LIST(STRUCT_MAP_ACCESSOR) 73 #undef STRUCT_MAP_ACCESSOR 74 75 #define ALLOCATION_SITE_MAP_ACCESSOR(NAME, Name, Size, name) \ 76 Map* ReadOnlyRoots::name##_map() { \ 77 return Map::cast(heap_->roots_[Heap::k##Name##Size##MapRootIndex]); \ 78 } \ 79 Handle<Map> ReadOnlyRoots::name##_map_handle() { \ 80 return Handle<Map>( \ 81 bit_cast<Map**>(&heap_->roots_[Heap::k##Name##Size##MapRootIndex])); \ 82 } 83 ALLOCATION_SITE_LIST(ALLOCATION_SITE_MAP_ACCESSOR) 84 #undef ALLOCATION_SITE_MAP_ACCESSOR 85 86 FixedTypedArrayBase* ReadOnlyRoots::EmptyFixedTypedArrayForMap(const Map* map) { 87 // TODO(delphick): All of these empty fixed type arrays are in RO_SPACE so 88 // this the method below can be moved into ReadOnlyRoots. 89 return heap_->EmptyFixedTypedArrayForMap(map); 90 } 91 92 } // namespace internal 93 94 } // namespace v8 95 96 #endif // V8_ROOTS_INL_H_ 97