v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
code-kind.h
Go to the documentation of this file.
1// Copyright 2020 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_CODE_KIND_H_
6#define V8_OBJECTS_CODE_KIND_H_
7
8#include "src/base/bounds.h"
9#include "src/base/flags.h"
10#include "src/flags/flags.h"
11
12namespace v8 {
13namespace internal {
14
15// The order of INTERPRETED_FUNCTION to TURBOFAN_JS is important. We use it to
16// check the relative ordering of the tiers when fetching / installing optimized
17// code.
18#define CODE_KIND_LIST(V) \
19 V(BYTECODE_HANDLER) \
20 V(FOR_TESTING) \
21 V(BUILTIN) \
22 V(REGEXP) \
23 V(WASM_FUNCTION) \
24 V(WASM_TO_CAPI_FUNCTION) \
25 V(WASM_TO_JS_FUNCTION) \
26 V(JS_TO_WASM_FUNCTION) \
27 V(C_WASM_ENTRY) \
28 V(INTERPRETED_FUNCTION) \
29 V(BASELINE) \
30 V(MAGLEV) \
31 V(TURBOFAN_JS)
32
33enum class CodeKind : uint8_t {
34#define DEFINE_CODE_KIND_ENUM(name) name,
36#undef DEFINE_CODE_KIND_ENUM
37};
38static_assert(CodeKind::INTERPRETED_FUNCTION < CodeKind::BASELINE);
39static_assert(CodeKind::BASELINE < CodeKind::TURBOFAN_JS);
40
41#define V(...) +1
42static constexpr int kCodeKindCount = CODE_KIND_LIST(V);
43#undef V
44// Unlikely, but just to be safe:
45static_assert(kCodeKindCount <= std::numeric_limits<uint8_t>::max());
46
47const char* CodeKindToString(CodeKind kind);
48
49const char* CodeKindToMarker(CodeKind kind, bool context_specialized);
50
52 return kind == CodeKind::INTERPRETED_FUNCTION;
53}
54
56 return kind == CodeKind::BASELINE;
57}
58
60 static_assert(static_cast<int>(CodeKind::INTERPRETED_FUNCTION) + 1 ==
61 static_cast<int>(CodeKind::BASELINE));
62 return base::IsInRange(kind, CodeKind::INTERPRETED_FUNCTION,
63 CodeKind::BASELINE);
64}
65
67 static_assert(static_cast<int>(CodeKind::MAGLEV) + 1 ==
68 static_cast<int>(CodeKind::TURBOFAN_JS));
69 return base::IsInRange(kind, CodeKind::MAGLEV, CodeKind::TURBOFAN_JS);
70}
71
72inline constexpr bool CodeKindIsJSFunction(CodeKind kind) {
73 static_assert(static_cast<int>(CodeKind::BASELINE) + 1 ==
74 static_cast<int>(CodeKind::MAGLEV));
75 return base::IsInRange(kind, CodeKind::INTERPRETED_FUNCTION,
76 CodeKind::TURBOFAN_JS);
77}
78
80 return kind == CodeKind::BUILTIN || CodeKindIsJSFunction(kind);
81}
82
83inline constexpr bool CodeKindCanDeoptimize(CodeKind kind) {
85#if V8_ENABLE_WEBASSEMBLY
86 || (kind == CodeKind::WASM_FUNCTION && v8_flags.wasm_deopt)
87#endif
88 ;
89}
90
91inline constexpr bool CodeKindCanOSR(CodeKind kind) {
92 return kind == CodeKind::TURBOFAN_JS || kind == CodeKind::MAGLEV;
93}
94
95inline constexpr bool CodeKindCanTierUp(CodeKind kind) {
96 return CodeKindIsUnoptimizedJSFunction(kind) || kind == CodeKind::MAGLEV;
97}
98
99// TODO(jgruber): Rename or remove this predicate. Currently it means 'is this
100// kind stored either in the FeedbackVector cache, or in the OSR cache?'.
102 return kind == CodeKind::MAGLEV || kind == CodeKind::TURBOFAN_JS;
103}
104
108
111}
112
114 return kind == CodeKind::BASELINE;
115}
116
118 // Either code that uses a bytecode offset table or code that may be embedded
119 // in the snapshot, in which case the source position table is cleared.
120 return CodeKindUsesBytecodeOffsetTable(kind) || kind == CodeKind::BUILTIN ||
121 kind == CodeKind::BYTECODE_HANDLER || kind == CodeKind::FOR_TESTING;
122}
123
124inline CodeKind CodeKindForTopTier() { return CodeKind::TURBOFAN_JS; }
125
126// The dedicated CodeKindFlag enum represents all code kinds in a format
127// suitable for bit sets.
128enum class CodeKindFlag {
129#define V(name) name = 1 << static_cast<int>(CodeKind::name),
131#undef V
132};
133static_assert(kCodeKindCount <= kInt32Size * kBitsPerByte);
134
136#define V(name) kind == CodeKind::name ? CodeKindFlag::name:
137 return CODE_KIND_LIST(V) CodeKindFlag::INTERPRETED_FUNCTION;
138#undef V
139}
140
141// CodeKinds represents a set of CodeKind.
144
146 CodeKindFlag::INTERPRETED_FUNCTION | CodeKindFlag::BASELINE |
147 CodeKindFlag::MAGLEV | CodeKindFlag::TURBOFAN_JS};
149 CodeKindFlag::MAGLEV | CodeKindFlag::TURBOFAN_JS};
150
151} // namespace internal
152} // namespace v8
153
154#endif // V8_OBJECTS_CODE_KIND_H_
#define DEFINE_OPERATORS_FOR_FLAGS(Type)
Definition flags.h:100
Builtins::Kind kind
Definition builtins.cc:40
#define CODE_KIND_LIST(V)
Definition code-kind.h:18
constexpr bool IsInRange(T value, U lower_limit, U higher_limit)
Definition bounds.h:20
constexpr bool CodeKindCanOSR(CodeKind kind)
Definition code-kind.h:91
constexpr bool CodeKindIsOptimizedJSFunction(CodeKind kind)
Definition code-kind.h:66
constexpr int kBitsPerByte
Definition globals.h:682
static constexpr int kCodeKindCount
Definition code-kind.h:42
const char * CodeKindToMarker(CodeKind kind, bool context_specialized)
Definition code-kind.cc:21
const char * CodeKindToString(CodeKind kind)
Definition code-kind.cc:10
constexpr bool CodeKindCanTierUp(CodeKind kind)
Definition code-kind.h:95
constexpr bool CodeKindIsStoredInOptimizedCodeCache(CodeKind kind)
Definition code-kind.h:101
constexpr bool CodeKindIsInterpretedJSFunction(CodeKind kind)
Definition code-kind.h:51
CodeKind CodeKindForTopTier()
Definition code-kind.h:124
constexpr CodeKindFlag CodeKindToCodeKindFlag(CodeKind kind)
Definition code-kind.h:135
constexpr bool CodeKindIsBuiltinOrJSFunction(CodeKind kind)
Definition code-kind.h:79
constexpr bool CodeKindMayLackSourcePositionTable(CodeKind kind)
Definition code-kind.h:117
constexpr int kInt32Size
Definition globals.h:401
constexpr bool CodeKindIsUnoptimizedJSFunction(CodeKind kind)
Definition code-kind.h:59
static constexpr CodeKinds kOptimizedJSFunctionCodeKindsMask
Definition code-kind.h:148
constexpr bool CodeKindUsesBytecodeOrInterpreterData(CodeKind kind)
Definition code-kind.h:105
static constexpr CodeKinds kJSFunctionCodeKindsMask
Definition code-kind.h:145
V8_EXPORT_PRIVATE FlagValues v8_flags
constexpr bool CodeKindIsJSFunction(CodeKind kind)
Definition code-kind.h:72
constexpr bool CodeKindIsBaselinedJSFunction(CodeKind kind)
Definition code-kind.h:55
constexpr bool CodeKindUsesDeoptimizationData(CodeKind kind)
Definition code-kind.h:109
constexpr bool CodeKindUsesBytecodeOffsetTable(CodeKind kind)
Definition code-kind.h:113
constexpr bool CodeKindCanDeoptimize(CodeKind kind)
Definition code-kind.h:83