v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
roots-inl.h
Go to the documentation of this file.
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_ROOTS_INL_H_
6#define V8_ROOTS_ROOTS_INL_H_
7
8#include "src/roots/roots.h"
9// Include the non-inl header before the rest of the headers.
10
14#include "src/handles/handles.h"
18#include "src/objects/cell.h"
22#include "src/objects/hole.h"
24#include "src/objects/map.h"
25#include "src/objects/oddball.h"
29#include "src/objects/slots.h"
30#include "src/objects/string.h"
32#include "src/objects/tagged.h"
34
35#if V8_ENABLE_WEBASSEMBLY
37#endif
38
39namespace v8 {
40namespace internal {
41
42V8_INLINE constexpr bool operator<(RootIndex lhs, RootIndex rhs) {
43 using type = typename std::underlying_type<RootIndex>::type;
44 return static_cast<type>(lhs) < static_cast<type>(rhs);
45}
46
48 using type = typename std::underlying_type<RootIndex>::type;
49 index = static_cast<RootIndex>(static_cast<type>(index) + 1);
50 return index;
51}
52
54 RootIndex* index) const {
55 FullObjectSlot location(handle_location);
56 FullObjectSlot first_root(&roots_[0]);
58 if (location >= last_root) return false;
59 if (location < first_root) return false;
60 *index = static_cast<RootIndex>(location - first_root);
61 return true;
62}
63
64template <typename T>
66 RootIndex* index) const {
67 // This can't use handle.location() because it is called from places
68 // where handle dereferencing is disallowed. Comparing the handle's
69 // location against the root handle list is safe though.
70 Address* handle_location = reinterpret_cast<Address*>(handle.address());
71 return IsRootHandleLocation(handle_location, index);
72}
73
74#define ROOT_ACCESSOR(Type, name, CamelName) \
75 IndirectHandle<Type> RootsTable::name() { \
76 return IndirectHandle<Type>( \
77 handle_at(RootIndex::k##CamelName).location()); \
78 }
80#undef ROOT_ACCESSOR
81
85
87 ReadOnlyHeap* shared_ro_heap =
89 // If this check fails in code that runs during initialization use
90 // EarlyGetReadOnlyRoots instead.
91 DCHECK(shared_ro_heap && shared_ro_heap->roots_init_complete());
92 return ReadOnlyRoots(shared_ro_heap->read_only_roots_);
93}
94
97
99 : read_only_roots_(reinterpret_cast<Address*>(
100 isolate->roots_table().read_only_roots_begin().address())) {}
101
103 : ReadOnlyRoots(isolate->factory()->read_only_roots()) {}
104
105// We use UncheckedCast below because we trust our read-only roots to
106// have the right type, and to avoid the heavy #includes that would be
107// required for checked casts.
108
109#define ROOT_ACCESSOR(Type, name, CamelName) \
110 Tagged<Type> ReadOnlyRoots::name() const { \
111 return unchecked_##name(); \
112 } \
113 Tagged<Type> ReadOnlyRoots::unchecked_##name() const { \
114 return UncheckedCast<Type>(object_at(RootIndex::k##CamelName)); \
115 }
117#undef ROOT_ACCESSOR
118
120 return value ? Tagged<Boolean>(true_value()) : Tagged<Boolean>(false_value());
121}
122
126
130
135
137 // The symbols and strings that can cause protector invalidation should
138 // reside on the same page so we can do a fast range check.
141}
142
144 return Tagged<Object>(address_at(root_index));
145}
146
148#if V8_STATIC_ROOTS_BOOL
151 StaticReadOnlyRootsPointerTable[static_cast<int>(root_index)]);
152#else
153 size_t index = static_cast<size_t>(root_index);
154 DCHECK_LT(index, kEntriesCount);
155 // Filler objects must be created before the free space map is initialized.
156 // Bootstrapping is able to handle kNullAddress being returned here.
158 root_index == RootIndex::kFreeSpaceMap);
159 return read_only_roots_[index];
160#endif
161}
162
164 size_t index = static_cast<size_t>(root_index);
165 DCHECK_LT(index, kEntriesCount);
167}
168
169} // namespace internal
170} // namespace v8
171
172#endif // V8_ROOTS_ROOTS_INL_H_
static IsolateGroup * current()
ReadOnlyHeap * shared_read_only_heap() const
static V8_INLINE PageMetadata * FromAddress(Address addr)
Address read_only_roots_[kEntriesCount]
V8_INLINE Address address_at(RootIndex root_index) const
Definition roots-inl.h:147
V8_INLINE Address first_name_for_protector() const
Definition roots-inl.h:123
V8_INLINE Tagged< Object > object_at(RootIndex root_index) const
Definition roots-inl.h:143
static constexpr size_t kEntriesCount
Definition roots.h:711
V8_INLINE void VerifyNameForProtectorsPages() const
Definition roots-inl.h:136
V8_INLINE Tagged< Boolean > boolean_value(bool value) const
Definition roots-inl.h:119
V8_INLINE Address last_name_for_protector() const
Definition roots-inl.h:127
V8_INLINE bool IsNameForProtector(Tagged< HeapObject > object) const
Definition roots-inl.h:131
V8_INLINE ReadOnlyRoots(Heap *heap)
Definition roots-inl.h:95
V8_INLINE bool is_initialized(RootIndex root_index) const
Definition roots-inl.h:163
Address roots_[kEntriesCount]
Definition roots.h:694
V8_INLINE IndirectHandle< Object > handle_at(RootIndex root_index)
Definition roots-inl.h:82
static constexpr size_t kEntriesCount
Definition roots.h:566
bool IsRootHandleLocation(Address *handle_location, RootIndex *index) const
Definition roots-inl.h:53
bool IsRootHandle(IndirectHandle< T > handle, RootIndex *index) const
Definition roots-inl.h:65
static V8_INLINE Address DecompressTagged(TOnHeapAddress on_heap_addr, Tagged_t raw_value)
V8_CONST static V8_INLINE Address base()
#define ROOT_ACCESSOR(Type, name, CamelName)
constexpr bool IsInRange(T value, U lower_limit, U higher_limit)
Definition bounds.h:20
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
ReadOnlyRoots GetReadOnlyRoots()
Definition roots-inl.h:86
Tagged(T object) -> Tagged< T >
V8_INLINE constexpr bool operator<(Builtin a, Builtin b)
Definition builtins.h:75
Handle< T > IndirectHandle
Definition globals.h:1086
V8_INLINE Builtin operator++(Builtin &builtin)
Definition builtins.h:80
static constexpr Address kNullAddress
Definition v8-internal.h:53
#define ROOT_LIST(V)
Definition roots.h:488
#define READ_ONLY_ROOT_LIST(V)
Definition roots.h:468
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define V8_INLINE
Definition v8config.h:500