v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
frame-states.h
Go to the documentation of this file.
1// Copyright 2015 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_COMPILER_FRAME_STATES_H_
6#define V8_COMPILER_FRAME_STATES_H_
7
9#include "src/compiler/node.h"
10#include "src/handles/handles.h"
12#include "src/utils/utils.h"
13
14namespace v8 {
15namespace internal {
16
17namespace wasm {
18class CanonicalValueType;
19class CanonicalSig;
20} // namespace wasm
21
22namespace compiler {
23
24class JSGraph;
25class Node;
26class SharedFunctionInfoRef;
27
28// Flag that describes how to combine the current environment with
29// the output of a node to obtain a framestate for lazy bailout.
31 public:
32 static const size_t kInvalidIndex = SIZE_MAX;
33
37 static OutputFrameStateCombine PokeAt(size_t index) {
38 return OutputFrameStateCombine(index);
39 }
40
41 size_t GetOffsetToPokeAt() const {
43 return parameter_;
44 }
45
46 bool IsOutputIgnored() const { return parameter_ == kInvalidIndex; }
47
48 size_t ConsumedOutputCount() const { return IsOutputIgnored() ? 0 : 1; }
49
50 bool operator==(OutputFrameStateCombine const& other) const {
51 return parameter_ == other.parameter_;
52 }
53 bool operator!=(OutputFrameStateCombine const& other) const {
54 return !(*this == other);
55 }
56
57 friend size_t hash_value(OutputFrameStateCombine const&);
58 friend std::ostream& operator<<(std::ostream&,
60
61 private:
62 explicit OutputFrameStateCombine(size_t parameter) : parameter_(parameter) {}
63
64 size_t const parameter_;
65};
66
67// The type of stack frame that a FrameState node represents.
68enum class FrameStateType {
69 kUnoptimizedFunction, // Represents an UnoptimizedJSFrame.
70 kInlinedExtraArguments, // Represents inlined extra arguments.
71 kConstructCreateStub, // Represents a frame created before creating a new
72 // object in the construct stub.
73 kConstructInvokeStub, // Represents a frame created before invoking the
74 // constructor in the construct stub.
75 kBuiltinContinuation, // Represents a continuation to a stub.
76#if V8_ENABLE_WEBASSEMBLY // ↓ WebAssembly only
77 kJSToWasmBuiltinContinuation, // Represents a lazy deopt continuation for a
78 // JS to Wasm call.
79 kWasmInlinedIntoJS, // Represents a Wasm function inlined into a
80 // JS function.
81 kLiftoffFunction, // Represents an unoptimized (liftoff) wasm
82 // function.
83#endif // ↑ WebAssembly only
84 kJavaScriptBuiltinContinuation, // Represents a continuation to a JavaScipt
85 // builtin.
86 kJavaScriptBuiltinContinuationWithCatch // Represents a continuation to a
87 // JavaScipt builtin with a catch
88 // handler.
89};
90
92 public:
110
111 int local_count() const { return local_count_; }
112 uint16_t parameter_count() const { return parameter_count_; }
113 uint16_t max_arguments() const { return max_arguments_; }
120 FrameStateType type() const { return type_; }
121 uint32_t wasm_liftoff_frame_size() const {
123 }
124 uint32_t wasm_function_index() const { return wasm_function_index_; }
125
127 // This must be in sync with TRANSLATION_JS_FRAME_OPCODE_LIST in
128 // translation-opcode.h or bad things happen.
132 }
133
134 private:
136 const uint16_t parameter_count_;
137 const uint16_t max_arguments_;
138 const int local_count_;
139#if V8_ENABLE_WEBASSEMBLY
140 const uint32_t wasm_liftoff_frame_size_ = 0;
141 const uint32_t wasm_function_index_ = -1;
142#else
143 static constexpr uint32_t wasm_liftoff_frame_size_ = 0;
144 static constexpr uint32_t wasm_function_index_ = -1;
145#endif
148};
149
152
153#if V8_ENABLE_WEBASSEMBLY
154class JSToWasmFrameStateFunctionInfo : public FrameStateFunctionInfo {
155 public:
156 JSToWasmFrameStateFunctionInfo(FrameStateType type, uint16_t parameter_count,
157 int local_count,
159 const wasm::CanonicalSig* signature)
160 : FrameStateFunctionInfo(type, parameter_count, 0, local_count,
161 shared_info, {}),
162 signature_(signature) {
163 DCHECK_NOT_NULL(signature);
164 }
165
166 const wasm::CanonicalSig* signature() const { return signature_; }
167
168 private:
169 const wasm::CanonicalSig* const signature_;
170};
171#endif // V8_ENABLE_WEBASSEMBLY
172
173class FrameStateInfo final {
174 public:
181
184 : info_->type();
185 }
190 : info_->shared_info();
191 }
193 return info_ == nullptr ? MaybeIndirectHandle<BytecodeArray>()
194 : info_->bytecode_array();
195 }
196 uint16_t parameter_count() const {
197 return info_ == nullptr ? 0 : info_->parameter_count();
198 }
199 uint16_t max_arguments() const {
200 return info_ == nullptr ? 0 : info_->max_arguments();
201 }
202 int local_count() const {
203 return info_ == nullptr ? 0 : info_->local_count();
204 }
205 int stack_count() const {
206 return type() == FrameStateType::kUnoptimizedFunction ? 1 : 0;
207 }
208 const FrameStateFunctionInfo* function_info() const { return info_; }
209
210 private:
214};
215
218
219size_t hash_value(FrameStateInfo const&);
220
221std::ostream& operator<<(std::ostream&, FrameStateInfo const&);
222
224
225class FrameState;
226
228 JSGraph* graph, Builtin name, Node* context, Node* const* parameters,
231 const wasm::CanonicalSig* signature = nullptr);
232
233#if V8_ENABLE_WEBASSEMBLY
234FrameState CreateJSWasmCallBuiltinContinuationFrameState(
235 JSGraph* jsgraph, Node* context, Node* outer_frame_state,
236 const wasm::CanonicalSig* signature);
237#endif // V8_ENABLE_WEBASSEMBLY
238
240 JSGraph* graph, SharedFunctionInfoRef shared, Builtin name, Node* target,
241 Node* context, Node* const* stack_parameters, int stack_parameter_count,
243
245 JSGraph* graph, SharedFunctionInfoRef shared, Node* target, Node* context,
246 Node* receiver, Node* outer_frame_state);
247
248// Creates GenericLazyDeoptContinuationFrameState if
249// --experimental-stack-trace-frames is enabled, returns outer_frame_state
250// otherwise.
251Node* CreateInlinedApiFunctionFrameState(JSGraph* graph,
252 SharedFunctionInfoRef shared,
253 Node* target, Node* context,
254 Node* receiver,
255 Node* outer_frame_state);
256
257// Creates a FrameState otherwise identical to `frame_state` except the
258// OutputFrameStateCombine is changed.
259FrameState CloneFrameState(JSGraph* jsgraph, FrameState frame_state,
260 OutputFrameStateCombine changed_state_combine);
261
262} // namespace compiler
263} // namespace internal
264} // namespace v8
265
266#endif // V8_COMPILER_FRAME_STATES_H_
JSGraph * jsgraph
int16_t parameter_count
Definition builtins.cc:67
const MaybeIndirectHandle< BytecodeArray > bytecode_array_
static bool IsJSFunctionType(FrameStateType type)
const IndirectHandle< SharedFunctionInfo > shared_info_
IndirectHandle< SharedFunctionInfo > shared_info() const
FrameStateFunctionInfo(FrameStateType type, uint16_t parameter_count, uint16_t max_arguments, int local_count, IndirectHandle< SharedFunctionInfo > shared_info, MaybeIndirectHandle< BytecodeArray > bytecode_array, uint32_t wasm_liftoff_frame_size=0, uint32_t wasm_function_index=-1)
MaybeIndirectHandle< BytecodeArray > bytecode_array() const
static constexpr uint32_t wasm_liftoff_frame_size_
FrameStateInfo(BytecodeOffset bailout_id, OutputFrameStateCombine state_combine, const FrameStateFunctionInfo *info)
OutputFrameStateCombine state_combine() const
const FrameStateFunctionInfo *const info_
MaybeIndirectHandle< SharedFunctionInfo > shared_info() const
MaybeIndirectHandle< BytecodeArray > bytecode_array() const
OutputFrameStateCombine const frame_state_combine_
const FrameStateFunctionInfo * function_info() const
friend std::ostream & operator<<(std::ostream &, OutputFrameStateCombine const &)
static OutputFrameStateCombine PokeAt(size_t index)
static OutputFrameStateCombine Ignore()
bool operator==(OutputFrameStateCombine const &other) const
bool operator!=(OutputFrameStateCombine const &other) const
friend size_t hash_value(OutputFrameStateCombine const &)
TNode< Object > receiver
FrameState outer_frame_state
FrameState CloneFrameState(JSGraph *jsgraph, FrameState frame_state, OutputFrameStateCombine changed_state_combine)
FrameState CreateGenericLazyDeoptContinuationFrameState(JSGraph *graph, SharedFunctionInfoRef shared, Node *target, Node *context, Node *receiver, Node *outer_frame_state)
FrameState CreateStubBuiltinContinuationFrameState(JSGraph *jsgraph, Builtin name, Node *context, Node *const *parameters, int parameter_count, Node *outer_frame_state, ContinuationFrameStateMode mode, const wasm::CanonicalSig *signature)
size_t hash_value(const BranchParameters &p)
Node * CreateInlinedApiFunctionFrameState(JSGraph *graph, SharedFunctionInfoRef shared, Node *target, Node *context, Node *receiver, Node *outer_frame_state)
FrameState CreateJavaScriptBuiltinContinuationFrameState(JSGraph *jsgraph, SharedFunctionInfoRef shared, Builtin name, Node *target, Node *context, Node *const *stack_parameters, int stack_parameter_count, Node *outer_frame_state, ContinuationFrameStateMode mode)
bool operator!=(DeoptimizeParameters lhs, DeoptimizeParameters rhs)
bool operator==(const BranchParameters &lhs, const BranchParameters &rhs)
std::ostream & operator<<(std::ostream &os, AccessMode access_mode)
MaybeHandle< T > MaybeIndirectHandle
Definition globals.h:1109
Definition c-api.cc:87
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define V8_EXPORT_PRIVATE
Definition macros.h:460