v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
instance-type-checker.h
Go to the documentation of this file.
1// Copyright 2023 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_OBJECTS_INSTANCE_TYPE_CHECKER_H_
6#define V8_OBJECTS_INSTANCE_TYPE_CHECKER_H_
7
9#include "src/roots/roots.h"
11
12// Has to be the last include (doesn't have include guards):
14
15namespace v8 {
16namespace internal {
17
18class Map;
19
20// List of object types that have a single unique instance type.
21#define INSTANCE_TYPE_CHECKERS_SINGLE(V) \
22 TORQUE_INSTANCE_CHECKERS_SINGLE_FULLY_DEFINED(V) \
23 TORQUE_INSTANCE_CHECKERS_SINGLE_ONLY_DECLARED(V) \
24 V(BigInt, BIGINT_TYPE) \
25 V(FixedArrayExact, FIXED_ARRAY_TYPE)
26
27#define INSTANCE_TYPE_CHECKERS_RANGE(V) \
28 TORQUE_INSTANCE_CHECKERS_RANGE_FULLY_DEFINED(V) \
29 TORQUE_INSTANCE_CHECKERS_RANGE_ONLY_DECLARED(V) \
30 V(CallableJSFunction, FIRST_CALLABLE_JS_FUNCTION_TYPE, \
31 LAST_CALLABLE_JS_FUNCTION_TYPE)
32
33#define INSTANCE_TYPE_CHECKERS_CUSTOM(V) \
34 V(AbstractCode) \
35 V(ExternalString) \
36 V(FreeSpaceOrFiller) \
37 V(GcSafeCode) \
38 V(InternalizedString) \
39 V(MaybeReadOnlyJSObject) \
40 V(PropertyDictionary)
41
42#define INSTANCE_TYPE_CHECKERS(V) \
43 INSTANCE_TYPE_CHECKERS_SINGLE(V) \
44 INSTANCE_TYPE_CHECKERS_RANGE(V) \
45 INSTANCE_TYPE_CHECKERS_CUSTOM(V)
46
47namespace InstanceTypeChecker {
48#define IS_TYPE_FUNCTION_DECL(Type, ...) \
49 V8_INLINE constexpr bool Is##Type(InstanceType instance_type); \
50 V8_INLINE bool Is##Type(Tagged<Map> map);
51
53
54#undef IS_TYPE_FUNCTION_DECL
55
56#if V8_STATIC_ROOTS_BOOL
57
58// Maps for primitive objects and a select few JS objects are allocated in r/o
59// space. All JS_RECEIVER maps must come after primitive object maps, i.e. they
60// have a compressed address above the last primitive object map root. If we
61// have a receiver and need to distinguish whether it is either a primitive
62// object or a JS receiver, it suffices to check if its map is allocated above
63// the following limit address.
65 StaticReadOnlyRootsPointerTable[static_cast<size_t>(
67 ~0xFFF;
68
69// Maps for strings allocated as the first maps in r/o space, so their lower
70// bound is zero.
71constexpr Tagged_t kStringMapLowerBound = 0;
72// If we have a receiver and need to distinguish whether it is a string or not,
73// it suffices to check whether it is less-than-equal to the following value.
74constexpr Tagged_t kStringMapUpperBound =
75 StaticReadOnlyRoot::kThinOneByteStringMap;
76
77#define ASSERT_IS_LAST_STRING_MAP(instance_type, size, name, Name) \
78 static_assert(StaticReadOnlyRoot::k##Name##Map <= kStringMapUpperBound);
79STRING_TYPE_LIST(ASSERT_IS_LAST_STRING_MAP)
80#undef ASSERT_IS_LAST_STRING_MAP
81
82// For performance, the limit is chosen to be encodable as an Arm64
83// constant. See Assembler::IsImmAddSub in assembler-arm64.cc.
84//
85// If this assert fails, then you have perturbed the allocation pattern in
86// Heap::CreateReadOnlyHeapObjects. Currently this limit is ensured to exist by
87// allocating the first JSReceiver map in RO space a sufficiently large distance
88// away from the last non-JSReceiver map.
89static_assert(kNonJsReceiverMapLimit != 0 &&
90 is_uint12(kNonJsReceiverMapLimit >> 12) &&
91 ((kNonJsReceiverMapLimit & 0xFFF) == 0));
92
93#else
94
96
97#endif // V8_STATIC_ROOTS_BOOL
98} // namespace InstanceTypeChecker
99
100} // namespace internal
101} // namespace v8
102
104
105#endif // V8_OBJECTS_INSTANCE_TYPE_CHECKER_H_
#define IS_TYPE_FUNCTION_DECL(Type)
#define INSTANCE_TYPE_CHECKERS(V)
Address Tagged_t
Definition globals.h:547
#define STRING_TYPE_LIST(V)