v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-dispatch-table.cc
Go to the documentation of this file.
1// Copyright 2024 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
6
12
13#ifdef V8_ENABLE_LEAPTIERING
14
15namespace v8 {
16namespace internal {
17
18void JSDispatchEntry::CheckFieldOffsets() {
19 static_assert(JSDispatchEntry::kEntrypointOffset ==
20 offsetof(JSDispatchEntry, entrypoint_));
21 static_assert(JSDispatchEntry::kCodeObjectOffset ==
22 offsetof(JSDispatchEntry, encoded_word_));
23#if defined(V8_TARGET_ARCH_64_BIT)
24#ifdef V8_TARGET_BIG_ENDIAN
25 // 2-byte parameter count is on the least significant side of encoded_word_.
26 constexpr int kBigEndianParamCountOffset = sizeof(Address) - sizeof(uint16_t);
27 static_assert(sizeof(encoded_word_) == sizeof(Address));
28 static_assert(JSDispatchEntry::kParameterCountOffset ==
29 offsetof(JSDispatchEntry, encoded_word_) +
30 kBigEndianParamCountOffset);
31#else
32 static_assert(JSDispatchEntry::kParameterCountOffset ==
33 offsetof(JSDispatchEntry, encoded_word_));
34#endif // V8_TARGET_BIG_ENDIAN
35 static_assert(kParameterCountMask == 0xffff);
36 static_assert(kParameterCountSize == 2);
37#elif defined(V8_TARGET_ARCH_32_BIT)
38 static_assert(JSDispatchEntry::kParameterCountOffset ==
39 offsetof(JSDispatchEntry, parameter_count_));
40 static_assert(kParameterCountSize ==
41 sizeof(JSDispatchEntry::parameter_count_));
42#else
43#error "Unsupported Architecture"
44#endif
45}
46
47JSDispatchHandle JSDispatchTable::PreAllocateEntries(
48 Space* space, int count, bool ensure_static_handles) {
49 DCHECK(space->BelongsTo(this));
50 DCHECK_IMPLIES(ensure_static_handles, space->is_internal_read_only_space());
51 JSDispatchHandle first;
52 for (int i = 0; i < count; ++i) {
53 uint32_t idx = AllocateEntry(space);
54 if (i == 0) {
55 first = IndexToHandle(idx);
56 } else {
57 // Pre-allocated entries should be consecutive.
58 DCHECK_EQ(IndexToHandle(idx), IndexToHandle(HandleToIndex(first) + i));
59 }
60#if V8_STATIC_DISPATCH_HANDLES_BOOL
61 if (ensure_static_handles) {
62 CHECK_EQ(IndexToHandle(idx), GetStaticHandleForReadOnlySegmentEntry(i));
63 }
64#else
65 CHECK(!ensure_static_handles);
66#endif
67 }
68 return first;
69}
70
71bool JSDispatchTable::PreAllocatedEntryNeedsInitialization(
72 Space* space, JSDispatchHandle handle) {
73 DCHECK(space->BelongsTo(this));
74 uint32_t index = HandleToIndex(handle);
75 return at(index).IsFreelistEntry();
76}
77
78void JSDispatchTable::InitializePreAllocatedEntry(Space* space,
80 Tagged<Code> code,
81 uint16_t parameter_count) {
82 DCHECK(space->BelongsTo(this));
83 uint32_t index = HandleToIndex(handle);
84 DCHECK(space->Contains(index));
85 DCHECK(at(index).IsFreelistEntry());
86 CFIMetadataWriteScope write_scope(
87 "JSDispatchTable initialize pre-allocated entry");
88 at(index).MakeJSDispatchEntry(code.address(), code->instruction_start(),
89 parameter_count, space->allocate_black());
90}
91
92#ifdef DEBUG
93bool JSDispatchTable::IsMarked(JSDispatchHandle handle) {
94 return at(HandleToIndex(handle)).IsMarked();
95}
96#endif // DEBUG
97
98void JSDispatchTable::PrintEntry(JSDispatchHandle handle) {
99 uint32_t index = HandleToIndex(handle);
100 i::PrintF("JSDispatchEntry @ %p\n", &at(index));
101 i::PrintF("* code %p\n", reinterpret_cast<void*>(GetCode(handle).address()));
102 i::PrintF("* params %d\n", at(HandleToIndex(handle)).GetParameterCount());
103 i::PrintF("* entrypoint %p\n",
104 reinterpret_cast<void*>(GetEntrypoint(handle)));
105}
106
107void JSDispatchTable::PrintCurrentTieringRequest(JSDispatchHandle handle,
108 Isolate* isolate,
109 std::ostream& os) {
110#define CASE(name, ...) \
111 if (IsTieringRequested(handle, TieringBuiltin::k##name, isolate)) { \
112 os << #name; \
113 return; \
114 }
116#undef CASE
117}
118
119} // namespace internal
120} // namespace v8
121
122#endif // V8_ENABLE_LEAPTIERING
#define BUILTIN_LIST_BASE_TIERING(TFC)
int16_t parameter_count
Definition builtins.cc:67
uint32_t count
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
void PrintF(const char *format,...)
Definition utils.cc:39
Tagged(T object) -> Tagged< T >
base::StrongAlias< JSDispatchHandleAliasTag, uint32_t > JSDispatchHandle
Definition globals.h:557
RwxMemoryWriteScope CFIMetadataWriteScope
#define CHECK(condition)
Definition logging.h:124
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485