5 #ifndef V8_ROOTS_INL_H_ 6 #define V8_ROOTS_INL_H_ 10 #include "src/feedback-vector.h" 11 #include "src/handles.h" 12 #include "src/heap/heap-inl.h" 13 #include "src/objects/api-callbacks.h" 14 #include "src/objects/descriptor-array.h" 15 #include "src/objects/literal-objects.h" 16 #include "src/objects/map.h" 17 #include "src/objects/scope-info.h" 18 #include "src/objects/slots.h" 23 V8_INLINE constexpr
bool operator<(RootIndex lhs, RootIndex rhs) {
24 typedef typename std::underlying_type<RootIndex>::type type;
25 return static_cast<type
>(lhs) < static_cast<type>(rhs);
28 V8_INLINE RootIndex operator++(RootIndex& index) {
29 typedef typename std::underlying_type<RootIndex>::type type;
30 index =
static_cast<RootIndex
>(
static_cast<type
>(index) + 1);
34 bool RootsTable::IsRootHandleLocation(Address* handle_location,
35 RootIndex* index)
const {
36 ObjectSlot location(handle_location);
37 ObjectSlot first_root(&roots_[0]);
38 ObjectSlot last_root(&roots_[kEntriesCount]);
39 if (location >= last_root)
return false;
40 if (location < first_root)
return false;
41 *index =
static_cast<RootIndex
>(location - first_root);
46 bool RootsTable::IsRootHandle(Handle<T> handle, RootIndex* index)
const {
50 Address* handle_location =
reinterpret_cast<Address*
>(handle.address());
51 return IsRootHandleLocation(handle_location, index);
54 ReadOnlyRoots::ReadOnlyRoots(Heap* heap)
55 : roots_table_(heap->isolate()->roots_table()) {}
57 ReadOnlyRoots::ReadOnlyRoots(Isolate* isolate)
58 : roots_table_(isolate->roots_table()) {}
61 #define ROOT_ACCESSOR(Type, name, CamelName) \ 62 Type ReadOnlyRoots::name() const { \ 63 return std::remove_pointer<Type>::type::cast( \ 64 roots_table_[RootIndex::k##CamelName]); \ 66 Handle<std::remove_pointer<Type>::type> ReadOnlyRoots::name##_handle() \ 68 return Handle<std::remove_pointer<Type>::type>( \ 69 bit_cast<Address*>(&roots_table_[RootIndex::k##CamelName])); \ 72 READ_ONLY_ROOT_LIST(ROOT_ACCESSOR)
75 Map ReadOnlyRoots::MapForFixedTypedArray(ExternalArrayType array_type) {
76 RootIndex root_index = RootsTable::RootIndexForFixedTypedArray(array_type);
77 return Map::cast(roots_table_[root_index]);
80 Map ReadOnlyRoots::MapForFixedTypedArray(ElementsKind elements_kind) {
81 RootIndex root_index = RootsTable::RootIndexForFixedTypedArray(elements_kind);
82 return Map::cast(roots_table_[root_index]);
85 FixedTypedArrayBase ReadOnlyRoots::EmptyFixedTypedArrayForMap(
const Map map) {
86 RootIndex root_index =
87 RootsTable::RootIndexForEmptyFixedTypedArray(map->elements_kind());
88 return FixedTypedArrayBase::cast(roots_table_[root_index]);
94 #endif // V8_ROOTS_INL_H_