v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
roots.cc
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#include "src/roots/roots.h"
6
7#include <type_traits>
8
15
16namespace v8 {
17namespace internal {
18
19static_assert(static_cast<int>(RootIndex::kUndefinedValue) ==
21static_assert(static_cast<int>(RootIndex::kTheHoleValue) ==
23static_assert(static_cast<int>(RootIndex::kNullValue) ==
25static_assert(static_cast<int>(RootIndex::kTrueValue) ==
27static_assert(static_cast<int>(RootIndex::kFalseValue) ==
29static_assert(static_cast<int>(RootIndex::kempty_string) ==
31
33#define ROOT_NAME(type, name, CamelName) #name,
35#undef ROOT_NAME
36};
37
39 auto bits = base::bit_cast<uint64_t>(value);
42 auto root = Cast<HeapNumber>(Tagged<Object>((*this)[pos]));
43 if (base::bit_cast<uint64_t>(root->value()) == bits) {
44 return IndirectHandle<HeapNumber>(&(*this)[pos]);
45 }
46 }
47 return {};
48}
49
51 return MapWord::FromMap(one_pointer_filler_map());
52}
53
55 visitor->VisitRootPointers(Root::kReadOnlyRootList, nullptr,
58 visitor->Synchronize(VisitorSynchronization::kReadOnlyRootList);
59}
60
61#ifdef DEBUG
62void ReadOnlyRoots::VerifyNameForProtectors() {
64 Tagged<Name> prev;
66 root_index <= RootIndex::kLastNameForProtector; ++root_index) {
67 Tagged<Name> current = Cast<Name>(object_at(root_index));
68 DCHECK(IsNameForProtector(current));
69 if (root_index != RootIndex::kFirstNameForProtector) {
70 // Make sure the objects are adjacent in memory.
71 CHECK_LT(prev.address(), current.address());
72 Address computed_address =
73 prev.address() + ALIGN_TO_ALLOCATION_ALIGNMENT(prev->Size());
74 CHECK_EQ(computed_address, current.address());
75 }
76 prev = current;
77 }
78}
79
80namespace {
81#define ROOT_TYPE_CHECK(Type, name, CamelName) \
82 bool CheckType_##name(Tagged<Type> value) { \
83 /* For the oddball subtypes, the "IsFoo" checks only check for address in \
84 * the RORoots, which is trivially true here. So, do a slow check of the \
85 * oddball kind instead. Do the casts via Tagged<Object> to satisfy cast \
86 * compatibility static_asserts in the Tagged class. */ \
87 if (std::is_same_v<Type, Undefined>) { \
88 return Cast<Oddball>(Tagged<Object>(value))->kind() == \
89 Oddball::kUndefined; \
90 } else if (std::is_same_v<Type, Null>) { \
91 return Cast<Oddball>(Tagged<Object>(value))->kind() == Oddball::kNull; \
92 } else if (std::is_same_v<Type, True>) { \
93 return Cast<Oddball>(Tagged<Object>(value))->kind() == Oddball::kTrue; \
94 } else if (std::is_same_v<Type, False>) { \
95 return Cast<Oddball>(Tagged<Object>(value))->kind() == Oddball::kFalse; \
96 } else { \
97 return Is##Type(value); \
98 } \
99 }
100
101READ_ONLY_ROOT_LIST(ROOT_TYPE_CHECK)
102#undef ROOT_TYPE_CHECK
103} // namespace
104
105void ReadOnlyRoots::VerifyTypes() {
107#define ROOT_TYPE_CHECK(Type, name, CamelName) CHECK(CheckType_##name(name()));
108
109 READ_ONLY_ROOT_LIST(ROOT_TYPE_CHECK)
110#undef ROOT_TYPE_CHECK
111}
112
113#endif
114
117#if V8_STATIC_ROOTS_BOOL
119 for (auto element : StaticReadOnlyRootsPointerTable) {
120 auto ptr = V8HeapCompressionScheme::DecompressTagged(cage_base, element);
122 read_only_roots_[static_cast<size_t>(pos)] = ptr;
123 ++pos;
124 }
125 DCHECK_EQ(static_cast<int>(pos) - 1, RootIndex::kLastReadOnlyRoot);
126#endif // V8_STATIC_ROOTS_BOOL
127}
128
129} // namespace internal
130} // namespace v8
SourcePosition pos
static const int kEmptyStringRootIndex
static const int kUndefinedValueRootIndex
static const int kFalseValueRootIndex
static const int kTrueValueRootIndex
static const int kNullValueRootIndex
static const int kTheHoleValueRootIndex
static MapWord FromMap(const Tagged< Map > map)
V8_INLINE Tagged< Object > object_at(RootIndex root_index) const
Definition roots-inl.h:143
void InitFromStaticRootsTable(Address cage_base)
Definition roots.cc:115
MapWord one_pointer_filler_map_word()
Definition roots.cc:50
void Iterate(RootVisitor *visitor)
Definition roots.cc:54
static constexpr size_t kEntriesCount
Definition roots.h:711
V8_INLINE bool IsNameForProtector(Tagged< HeapObject > object) const
Definition roots-inl.h:131
V8_INLINE bool is_initialized(RootIndex root_index) const
Definition roots-inl.h:163
virtual void VisitRootPointers(Root root, const char *description, FullObjectSlot start, FullObjectSlot end)=0
virtual void Synchronize(VisitorSynchronization::SyncTag tag)
Definition visitors.h:112
static const char * root_names_[kEntriesCount]
Definition roots.h:695
static constexpr size_t kEntriesCount
Definition roots.h:566
IndirectHandle< HeapNumber > FindHeapNumber(double value)
Definition roots.cc:38
static V8_INLINE Address DecompressTagged(TOnHeapAddress on_heap_addr, Tagged_t raw_value)
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
Definition globals.h:1796
LineAndColumn current
V8_INLINE Dest bit_cast(Source const &source)
Definition macros.h:95
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
Handle< T > IndirectHandle
Definition globals.h:1086
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define ROOT_NAME(type, name, CamelName)
#define ROOT_LIST(V)
Definition roots.h:488
#define READ_ONLY_ROOT_LIST(V)
Definition roots.h:468
#define CHECK(condition)
Definition logging.h:124
#define CHECK_LT(lhs, rhs)
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_STATIC_ROOTS_BOOL
Definition v8config.h:1001