V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
frames-inl.h
1 // Copyright 2012 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_FRAMES_INL_H_
6 #define V8_FRAMES_INL_H_
7 
8 #include "src/frame-constants.h"
9 #include "src/frames.h"
10 #include "src/isolate.h"
11 #include "src/objects-inl.h"
12 #include "src/v8memory.h"
13 
14 namespace v8 {
15 namespace internal {
16 
18  public:
20  Address inner_pointer;
21  Code code;
22  SafepointEntry safepoint_entry;
23  };
24 
25  explicit InnerPointerToCodeCache(Isolate* isolate) : isolate_(isolate) {
26  Flush();
27  }
28 
29  void Flush() { memset(static_cast<void*>(&cache_[0]), 0, sizeof(cache_)); }
30 
31  InnerPointerToCodeCacheEntry* GetCacheEntry(Address inner_pointer);
32 
33  private:
34  InnerPointerToCodeCacheEntry* cache(int index) { return &cache_[index]; }
35 
36  Isolate* isolate_;
37 
38  static const int kInnerPointerToCodeCacheSize = 1024;
39  InnerPointerToCodeCacheEntry cache_[kInnerPointerToCodeCacheSize];
40 
41  DISALLOW_COPY_AND_ASSIGN(InnerPointerToCodeCache);
42 };
43 
44 inline Address StackHandler::address() const {
45  return reinterpret_cast<Address>(const_cast<StackHandler*>(this));
46 }
47 
48 
49 inline StackHandler* StackHandler::next() const {
50  const int offset = StackHandlerConstants::kNextOffset;
51  return FromAddress(Memory<Address>(address() + offset));
52 }
53 
54 
55 inline StackHandler* StackHandler::FromAddress(Address address) {
56  return reinterpret_cast<StackHandler*>(address);
57 }
58 
59 
60 inline StackFrame::StackFrame(StackFrameIteratorBase* iterator)
61  : iterator_(iterator), isolate_(iterator_->isolate()) {
62 }
63 
64 
65 inline StackHandler* StackFrame::top_handler() const {
66  return iterator_->handler();
67 }
68 
69 
70 inline Address* StackFrame::ResolveReturnAddressLocation(Address* pc_address) {
71  if (return_address_location_resolver_ == nullptr) {
72  return pc_address;
73  } else {
74  return reinterpret_cast<Address*>(
75  return_address_location_resolver_(
76  reinterpret_cast<uintptr_t>(pc_address)));
77  }
78 }
79 
80 inline NativeFrame::NativeFrame(StackFrameIteratorBase* iterator)
81  : StackFrame(iterator) {}
82 
83 inline Address NativeFrame::GetCallerStackPointer() const {
84  return fp() + CommonFrameConstants::kCallerSPOffset;
85 }
86 
87 inline EntryFrame::EntryFrame(StackFrameIteratorBase* iterator)
88  : StackFrame(iterator) {}
89 
90 inline ConstructEntryFrame::ConstructEntryFrame(
91  StackFrameIteratorBase* iterator)
92  : EntryFrame(iterator) {}
93 
94 inline ExitFrame::ExitFrame(StackFrameIteratorBase* iterator)
95  : StackFrame(iterator) {}
96 
97 inline BuiltinExitFrame::BuiltinExitFrame(StackFrameIteratorBase* iterator)
98  : ExitFrame(iterator) {}
99 
100 inline Object* BuiltinExitFrame::receiver_slot_object() const {
101  // The receiver is the first argument on the frame.
102  // fp[1]: return address.
103  // fp[2]: the last argument (new target).
104  // fp[4]: argc.
105  // fp[2 + argc - 1]: receiver.
106  Object* argc_slot = argc_slot_object();
107  DCHECK(argc_slot->IsSmi());
108  int argc = Smi::ToInt(argc_slot);
109 
110  const int receiverOffset =
111  BuiltinExitFrameConstants::kNewTargetOffset + (argc - 1) * kPointerSize;
112  return Memory<Object*>(fp() + receiverOffset);
113 }
114 
115 inline Object* BuiltinExitFrame::argc_slot_object() const {
116  return Memory<Object*>(fp() + BuiltinExitFrameConstants::kArgcOffset);
117 }
118 
119 inline Object* BuiltinExitFrame::target_slot_object() const {
120  return Memory<Object*>(fp() + BuiltinExitFrameConstants::kTargetOffset);
121 }
122 
123 inline Object* BuiltinExitFrame::new_target_slot_object() const {
124  return Memory<Object*>(fp() + BuiltinExitFrameConstants::kNewTargetOffset);
125 }
126 
127 inline StandardFrame::StandardFrame(StackFrameIteratorBase* iterator)
128  : StackFrame(iterator) {
129 }
130 
131 
132 inline Object* StandardFrame::GetExpression(int index) const {
133  return Memory<Object*>(GetExpressionAddress(index));
134 }
135 
136 
137 inline void StandardFrame::SetExpression(int index, Object* value) {
138  Memory<Object*>(GetExpressionAddress(index)) = value;
139 }
140 
141 
142 inline Address StandardFrame::caller_fp() const {
143  return Memory<Address>(fp() + StandardFrameConstants::kCallerFPOffset);
144 }
145 
146 
147 inline Address StandardFrame::caller_pc() const {
148  return Memory<Address>(ComputePCAddress(fp()));
149 }
150 
151 
152 inline Address StandardFrame::ComputePCAddress(Address fp) {
153  return fp + StandardFrameConstants::kCallerPCOffset;
154 }
155 
156 
157 inline Address StandardFrame::ComputeConstantPoolAddress(Address fp) {
158  return fp + StandardFrameConstants::kConstantPoolOffset;
159 }
160 
161 
162 inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) {
163  intptr_t frame_type =
164  Memory<intptr_t>(fp + TypedFrameConstants::kFrameTypeOffset);
165  return frame_type == StackFrame::TypeToMarker(StackFrame::ARGUMENTS_ADAPTOR);
166 }
167 
168 
169 inline bool StandardFrame::IsConstructFrame(Address fp) {
170  intptr_t frame_type =
171  Memory<intptr_t>(fp + TypedFrameConstants::kFrameTypeOffset);
172  return frame_type == StackFrame::TypeToMarker(StackFrame::CONSTRUCT);
173 }
174 
175 inline JavaScriptFrame::JavaScriptFrame(StackFrameIteratorBase* iterator)
176  : StandardFrame(iterator) {}
177 
178 Address JavaScriptFrame::GetParameterSlot(int index) const {
179  int param_count = ComputeParametersCount();
180  DCHECK(-1 <= index &&
181  (index < param_count ||
182  param_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel));
183  int parameter_offset = (param_count - index - 1) * kPointerSize;
184  return caller_sp() + parameter_offset;
185 }
186 
187 inline void JavaScriptFrame::set_receiver(Object* value) {
188  Memory<Object*>(GetParameterSlot(-1)) = value;
189 }
190 
191 
192 inline bool JavaScriptFrame::has_adapted_arguments() const {
193  return IsArgumentsAdaptorFrame(caller_fp());
194 }
195 
196 
197 inline Object* JavaScriptFrame::function_slot_object() const {
198  const int offset = JavaScriptFrameConstants::kFunctionOffset;
199  return Memory<Object*>(fp() + offset);
200 }
201 
202 inline StubFrame::StubFrame(StackFrameIteratorBase* iterator)
203  : StandardFrame(iterator) {
204 }
205 
206 
207 inline OptimizedFrame::OptimizedFrame(StackFrameIteratorBase* iterator)
208  : JavaScriptFrame(iterator) {
209 }
210 
211 
212 inline InterpretedFrame::InterpretedFrame(StackFrameIteratorBase* iterator)
213  : JavaScriptFrame(iterator) {}
214 
215 
216 inline ArgumentsAdaptorFrame::ArgumentsAdaptorFrame(
217  StackFrameIteratorBase* iterator) : JavaScriptFrame(iterator) {
218 }
219 
220 inline BuiltinFrame::BuiltinFrame(StackFrameIteratorBase* iterator)
221  : JavaScriptFrame(iterator) {}
222 
223 inline WasmCompiledFrame::WasmCompiledFrame(StackFrameIteratorBase* iterator)
224  : StandardFrame(iterator) {}
225 
226 inline WasmInterpreterEntryFrame::WasmInterpreterEntryFrame(
227  StackFrameIteratorBase* iterator)
228  : StandardFrame(iterator) {}
229 
230 inline WasmToJsFrame::WasmToJsFrame(StackFrameIteratorBase* iterator)
231  : StubFrame(iterator) {}
232 
233 inline JsToWasmFrame::JsToWasmFrame(StackFrameIteratorBase* iterator)
234  : StubFrame(iterator) {}
235 
236 inline CWasmEntryFrame::CWasmEntryFrame(StackFrameIteratorBase* iterator)
237  : StubFrame(iterator) {}
238 
239 inline WasmCompileLazyFrame::WasmCompileLazyFrame(
240  StackFrameIteratorBase* iterator)
241  : StandardFrame(iterator) {}
242 
243 inline InternalFrame::InternalFrame(StackFrameIteratorBase* iterator)
244  : StandardFrame(iterator) {
245 }
246 
247 inline ConstructFrame::ConstructFrame(StackFrameIteratorBase* iterator)
248  : InternalFrame(iterator) {
249 }
250 
251 inline BuiltinContinuationFrame::BuiltinContinuationFrame(
252  StackFrameIteratorBase* iterator)
253  : InternalFrame(iterator) {}
254 
255 inline JavaScriptBuiltinContinuationFrame::JavaScriptBuiltinContinuationFrame(
256  StackFrameIteratorBase* iterator)
257  : JavaScriptFrame(iterator) {}
258 
259 inline JavaScriptBuiltinContinuationWithCatchFrame::
260  JavaScriptBuiltinContinuationWithCatchFrame(
261  StackFrameIteratorBase* iterator)
262  : JavaScriptBuiltinContinuationFrame(iterator) {}
263 
264 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
265  Isolate* isolate)
266  : iterator_(isolate) {
267  if (!done()) Advance();
268 }
269 
270 inline JavaScriptFrameIterator::JavaScriptFrameIterator(
271  Isolate* isolate, ThreadLocalTop* top)
272  : iterator_(isolate, top) {
273  if (!done()) Advance();
274 }
275 
276 inline JavaScriptFrame* JavaScriptFrameIterator::frame() const {
277  // TODO(1233797): The frame hierarchy needs to change. It's
278  // problematic that we can't use the safe-cast operator to cast to
279  // the JavaScript frame type, because we may encounter arguments
280  // adaptor frames.
281  StackFrame* frame = iterator_.frame();
282  DCHECK(frame->is_java_script() || frame->is_arguments_adaptor());
283  return static_cast<JavaScriptFrame*>(frame);
284 }
285 
286 inline StandardFrame* StackTraceFrameIterator::frame() const {
287  StackFrame* frame = iterator_.frame();
288  DCHECK(frame->is_java_script() || frame->is_arguments_adaptor() ||
289  frame->is_wasm());
290  return static_cast<StandardFrame*>(frame);
291 }
292 
293 bool StackTraceFrameIterator::is_javascript() const {
294  return frame()->is_java_script();
295 }
296 
297 bool StackTraceFrameIterator::is_wasm() const { return frame()->is_wasm(); }
298 
299 JavaScriptFrame* StackTraceFrameIterator::javascript_frame() const {
300  return JavaScriptFrame::cast(frame());
301 }
302 
303 inline StackFrame* SafeStackFrameIterator::frame() const {
304  DCHECK(!done());
305  DCHECK(frame_->is_java_script() || frame_->is_exit() ||
306  frame_->is_builtin_exit() || frame_->is_wasm());
307  return frame_;
308 }
309 
310 
311 } // namespace internal
312 } // namespace v8
313 
314 #endif // V8_FRAMES_INL_H_
Definition: libplatform.h:13