V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
frame-states.h
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 
8 #include "src/builtins/builtins.h"
9 #include "src/handles.h"
10 #include "src/objects/shared-function-info.h"
11 #include "src/utils.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 namespace compiler {
17 
18 class JSGraph;
19 class Node;
20 class SharedFunctionInfoRef;
21 
22 // Flag that describes how to combine the current environment with
23 // the output of a node to obtain a framestate for lazy bailout.
25  public:
26  static const size_t kInvalidIndex = SIZE_MAX;
27 
28  static OutputFrameStateCombine Ignore() {
29  return OutputFrameStateCombine(kInvalidIndex);
30  }
31  static OutputFrameStateCombine PokeAt(size_t index) {
32  return OutputFrameStateCombine(index);
33  }
34 
35  size_t GetOffsetToPokeAt() const {
36  DCHECK_NE(parameter_, kInvalidIndex);
37  return parameter_;
38  }
39 
40  bool IsOutputIgnored() const { return parameter_ == kInvalidIndex; }
41 
42  size_t ConsumedOutputCount() const { return IsOutputIgnored() ? 0 : 1; }
43 
44  bool operator==(OutputFrameStateCombine const& other) const {
45  return parameter_ == other.parameter_;
46  }
47  bool operator!=(OutputFrameStateCombine const& other) const {
48  return !(*this == other);
49  }
50 
51  friend size_t hash_value(OutputFrameStateCombine const&);
52  friend std::ostream& operator<<(std::ostream&,
54 
55  private:
56  explicit OutputFrameStateCombine(size_t parameter) : parameter_(parameter) {}
57 
58  size_t const parameter_;
59 };
60 
61 
62 // The type of stack frame that a FrameState node represents.
63 enum class FrameStateType {
64  kInterpretedFunction, // Represents an InterpretedFrame.
65  kArgumentsAdaptor, // Represents an ArgumentsAdaptorFrame.
66  kConstructStub, // Represents a ConstructStubFrame.
67  kBuiltinContinuation, // Represents a continuation to a stub.
68  kJavaScriptBuiltinContinuation, // Represents a continuation to a JavaScipt
69  // builtin.
70  kJavaScriptBuiltinContinuationWithCatch // Represents a continuation to a
71  // JavaScipt builtin with a catch
72  // handler.
73 };
74 
76  public:
77  FrameStateFunctionInfo(FrameStateType type, int parameter_count,
78  int local_count,
79  Handle<SharedFunctionInfo> shared_info)
80  : type_(type),
81  parameter_count_(parameter_count),
82  local_count_(local_count),
83  shared_info_(shared_info) {}
84 
85  int local_count() const { return local_count_; }
86  int parameter_count() const { return parameter_count_; }
87  Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
88  FrameStateType type() const { return type_; }
89 
90  static bool IsJSFunctionType(FrameStateType type) {
91  return type == FrameStateType::kInterpretedFunction ||
92  type == FrameStateType::kJavaScriptBuiltinContinuation ||
93  type == FrameStateType::kJavaScriptBuiltinContinuationWithCatch;
94  }
95 
96  private:
97  FrameStateType const type_;
98  int const parameter_count_;
99  int const local_count_;
100  Handle<SharedFunctionInfo> const shared_info_;
101 };
102 
103 
104 class FrameStateInfo final {
105  public:
106  FrameStateInfo(BailoutId bailout_id, OutputFrameStateCombine state_combine,
107  const FrameStateFunctionInfo* info)
108  : bailout_id_(bailout_id),
109  frame_state_combine_(state_combine),
110  info_(info) {}
111 
112  FrameStateType type() const {
113  return info_ == nullptr ? FrameStateType::kInterpretedFunction
114  : info_->type();
115  }
116  BailoutId bailout_id() const { return bailout_id_; }
117  OutputFrameStateCombine state_combine() const { return frame_state_combine_; }
118  MaybeHandle<SharedFunctionInfo> shared_info() const {
119  return info_ == nullptr ? MaybeHandle<SharedFunctionInfo>()
120  : info_->shared_info();
121  }
122  int parameter_count() const {
123  return info_ == nullptr ? 0 : info_->parameter_count();
124  }
125  int local_count() const {
126  return info_ == nullptr ? 0 : info_->local_count();
127  }
128  const FrameStateFunctionInfo* function_info() const { return info_; }
129 
130  private:
131  BailoutId const bailout_id_;
132  OutputFrameStateCombine const frame_state_combine_;
133  const FrameStateFunctionInfo* const info_;
134 };
135 
136 bool operator==(FrameStateInfo const&, FrameStateInfo const&);
137 bool operator!=(FrameStateInfo const&, FrameStateInfo const&);
138 
139 size_t hash_value(FrameStateInfo const&);
140 
141 std::ostream& operator<<(std::ostream&, FrameStateInfo const&);
142 
143 static const int kFrameStateParametersInput = 0;
144 static const int kFrameStateLocalsInput = 1;
145 static const int kFrameStateStackInput = 2;
146 static const int kFrameStateContextInput = 3;
147 static const int kFrameStateFunctionInput = 4;
148 static const int kFrameStateOuterStateInput = 5;
149 static const int kFrameStateInputCount = kFrameStateOuterStateInput + 1;
150 
151 enum class ContinuationFrameStateMode { EAGER, LAZY, LAZY_WITH_CATCH };
152 
153 Node* CreateStubBuiltinContinuationFrameState(
154  JSGraph* graph, Builtins::Name name, Node* context, Node* const* parameters,
155  int parameter_count, Node* outer_frame_state,
156  ContinuationFrameStateMode mode);
157 
158 Node* CreateJavaScriptBuiltinContinuationFrameState(
159  JSGraph* graph, const SharedFunctionInfoRef& shared, Builtins::Name name,
160  Node* target, Node* context, Node* const* stack_parameters,
161  int stack_parameter_count, Node* outer_frame_state,
162  ContinuationFrameStateMode mode);
163 
164 } // namespace compiler
165 } // namespace internal
166 } // namespace v8
167 
168 #endif // V8_COMPILER_FRAME_STATES_H_
Definition: libplatform.h:13