Line data Source code
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 :
17 : inline Address StackHandler::address() const {
18 : return reinterpret_cast<Address>(const_cast<StackHandler*>(this));
19 : }
20 :
21 :
22 : inline StackHandler* StackHandler::next() const {
23 : const int offset = StackHandlerConstants::kNextOffset;
24 1449643 : return FromAddress(Memory::Address_at(address() + offset));
25 : }
26 :
27 :
28 : inline StackHandler* StackHandler::FromAddress(Address address) {
29 : return reinterpret_cast<StackHandler*>(address);
30 : }
31 :
32 :
33 : inline StackFrame::StackFrame(StackFrameIteratorBase* iterator)
34 196303410 : : iterator_(iterator), isolate_(iterator_->isolate()) {
35 : }
36 :
37 :
38 : inline StackHandler* StackFrame::top_handler() const {
39 61901 : return iterator_->handler();
40 : }
41 :
42 :
43 : inline Address* StackFrame::ResolveReturnAddressLocation(Address* pc_address) {
44 71184553 : if (return_address_location_resolver_ == nullptr) {
45 : return pc_address;
46 : } else {
47 : return reinterpret_cast<Address*>(
48 : return_address_location_resolver_(
49 0 : reinterpret_cast<uintptr_t>(pc_address)));
50 : }
51 : }
52 :
53 :
54 : inline EntryFrame::EntryFrame(StackFrameIteratorBase* iterator)
55 21811490 : : StackFrame(iterator) {
56 : }
57 :
58 : inline ConstructEntryFrame::ConstructEntryFrame(
59 : StackFrameIteratorBase* iterator)
60 10905745 : : EntryFrame(iterator) {}
61 :
62 : inline ExitFrame::ExitFrame(StackFrameIteratorBase* iterator)
63 21811490 : : StackFrame(iterator) {
64 : }
65 :
66 : inline BuiltinExitFrame::BuiltinExitFrame(StackFrameIteratorBase* iterator)
67 10905745 : : ExitFrame(iterator) {}
68 :
69 : inline Object* BuiltinExitFrame::receiver_slot_object() const {
70 : // The receiver is the first argument on the frame.
71 : // fp[1]: return address.
72 : // fp[2]: the last argument (new target).
73 : // fp[4]: argc.
74 : // fp[2 + argc - 1]: receiver.
75 : Object* argc_slot = argc_slot_object();
76 : DCHECK(argc_slot->IsSmi());
77 : int argc = Smi::ToInt(argc_slot);
78 :
79 : const int receiverOffset =
80 37445 : BuiltinExitFrameConstants::kNewTargetOffset + (argc - 1) * kPointerSize;
81 37445 : return Memory::Object_at(fp() + receiverOffset);
82 : }
83 :
84 : inline Object* BuiltinExitFrame::argc_slot_object() const {
85 37455 : return Memory::Object_at(fp() + BuiltinExitFrameConstants::kArgcOffset);
86 : }
87 :
88 : inline Object* BuiltinExitFrame::target_slot_object() const {
89 68426 : return Memory::Object_at(fp() + BuiltinExitFrameConstants::kTargetOffset);
90 : }
91 :
92 : inline Object* BuiltinExitFrame::new_target_slot_object() const {
93 37445 : return Memory::Object_at(fp() + BuiltinExitFrameConstants::kNewTargetOffset);
94 : }
95 :
96 : inline StandardFrame::StandardFrame(StackFrameIteratorBase* iterator)
97 152680430 : : StackFrame(iterator) {
98 : }
99 :
100 :
101 : inline Object* StandardFrame::GetExpression(int index) const {
102 40253883 : return Memory::Object_at(GetExpressionAddress(index));
103 : }
104 :
105 :
106 : inline void StandardFrame::SetExpression(int index, Object* value) {
107 839540 : Memory::Object_at(GetExpressionAddress(index)) = value;
108 : }
109 :
110 :
111 : inline Address StandardFrame::caller_fp() const {
112 48304242 : return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset);
113 : }
114 :
115 :
116 : inline Address StandardFrame::caller_pc() const {
117 : return Memory::Address_at(ComputePCAddress(fp()));
118 : }
119 :
120 :
121 : inline Address StandardFrame::ComputePCAddress(Address fp) {
122 : return fp + StandardFrameConstants::kCallerPCOffset;
123 : }
124 :
125 :
126 : inline Address StandardFrame::ComputeConstantPoolAddress(Address fp) {
127 : return fp + StandardFrameConstants::kConstantPoolOffset;
128 : }
129 :
130 :
131 : inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) {
132 : intptr_t frame_type =
133 7115685 : Memory::intptr_at(fp + TypedFrameConstants::kFrameTypeOffset);
134 30218 : return frame_type == StackFrame::TypeToMarker(StackFrame::ARGUMENTS_ADAPTOR);
135 : }
136 :
137 :
138 : inline bool StandardFrame::IsConstructFrame(Address fp) {
139 : intptr_t frame_type =
140 6830996 : Memory::intptr_at(fp + TypedFrameConstants::kFrameTypeOffset);
141 6830996 : return frame_type == StackFrame::TypeToMarker(StackFrame::CONSTRUCT);
142 : }
143 :
144 : inline JavaScriptFrame::JavaScriptFrame(StackFrameIteratorBase* iterator)
145 54528725 : : StandardFrame(iterator) {}
146 :
147 7436060 : Address JavaScriptFrame::GetParameterSlot(int index) const {
148 7436060 : int param_count = ComputeParametersCount();
149 : DCHECK(-1 <= index &&
150 : (index < param_count ||
151 : param_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel));
152 7436060 : int parameter_offset = (param_count - index - 1) * kPointerSize;
153 14872120 : return caller_sp() + parameter_offset;
154 : }
155 :
156 : inline void JavaScriptFrame::set_receiver(Object* value) {
157 : Memory::Object_at(GetParameterSlot(-1)) = value;
158 : }
159 :
160 :
161 30218 : inline bool JavaScriptFrame::has_adapted_arguments() const {
162 30218 : return IsArgumentsAdaptorFrame(caller_fp());
163 : }
164 :
165 :
166 : inline Object* JavaScriptFrame::function_slot_object() const {
167 : const int offset = JavaScriptFrameConstants::kFunctionOffset;
168 49115320 : return Memory::Object_at(fp() + offset);
169 : }
170 :
171 : inline StubFrame::StubFrame(StackFrameIteratorBase* iterator)
172 43622980 : : StandardFrame(iterator) {
173 : }
174 :
175 :
176 : inline OptimizedFrame::OptimizedFrame(StackFrameIteratorBase* iterator)
177 10905745 : : JavaScriptFrame(iterator) {
178 : }
179 :
180 :
181 : inline InterpretedFrame::InterpretedFrame(StackFrameIteratorBase* iterator)
182 10905745 : : JavaScriptFrame(iterator) {}
183 :
184 :
185 : inline ArgumentsAdaptorFrame::ArgumentsAdaptorFrame(
186 10905745 : StackFrameIteratorBase* iterator) : JavaScriptFrame(iterator) {
187 : }
188 :
189 : inline BuiltinFrame::BuiltinFrame(StackFrameIteratorBase* iterator)
190 10905745 : : JavaScriptFrame(iterator) {}
191 :
192 : inline WasmCompiledFrame::WasmCompiledFrame(StackFrameIteratorBase* iterator)
193 10905745 : : StandardFrame(iterator) {}
194 :
195 : inline WasmInterpreterEntryFrame::WasmInterpreterEntryFrame(
196 : StackFrameIteratorBase* iterator)
197 10905745 : : StandardFrame(iterator) {}
198 :
199 : inline WasmToJsFrame::WasmToJsFrame(StackFrameIteratorBase* iterator)
200 10905745 : : StubFrame(iterator) {}
201 :
202 : inline JsToWasmFrame::JsToWasmFrame(StackFrameIteratorBase* iterator)
203 10905745 : : StubFrame(iterator) {}
204 :
205 : inline CWasmEntryFrame::CWasmEntryFrame(StackFrameIteratorBase* iterator)
206 10905745 : : StubFrame(iterator) {}
207 :
208 : inline InternalFrame::InternalFrame(StackFrameIteratorBase* iterator)
209 32717235 : : StandardFrame(iterator) {
210 : }
211 :
212 : inline ConstructFrame::ConstructFrame(StackFrameIteratorBase* iterator)
213 10905745 : : InternalFrame(iterator) {
214 : }
215 :
216 : inline BuiltinContinuationFrame::BuiltinContinuationFrame(
217 : StackFrameIteratorBase* iterator)
218 10905745 : : InternalFrame(iterator) {}
219 :
220 : inline JavaScriptBuiltinContinuationFrame::JavaScriptBuiltinContinuationFrame(
221 : StackFrameIteratorBase* iterator)
222 10905745 : : JavaScriptFrame(iterator) {}
223 :
224 655453 : inline JavaScriptFrameIterator::JavaScriptFrameIterator(
225 : Isolate* isolate)
226 655453 : : iterator_(isolate) {
227 655453 : if (!done()) Advance();
228 655453 : }
229 :
230 7733 : inline JavaScriptFrameIterator::JavaScriptFrameIterator(
231 : Isolate* isolate, ThreadLocalTop* top)
232 7733 : : iterator_(isolate, top) {
233 7733 : if (!done()) Advance();
234 7733 : }
235 :
236 338130 : inline JavaScriptFrame* JavaScriptFrameIterator::frame() const {
237 : // TODO(1233797): The frame hierarchy needs to change. It's
238 : // problematic that we can't use the safe-cast operator to cast to
239 : // the JavaScript frame type, because we may encounter arguments
240 : // adaptor frames.
241 699889 : StackFrame* frame = iterator_.frame();
242 : DCHECK(frame->is_java_script() || frame->is_arguments_adaptor());
243 338130 : return static_cast<JavaScriptFrame*>(frame);
244 : }
245 :
246 122365 : inline StandardFrame* StackTraceFrameIterator::frame() const {
247 1403589 : StackFrame* frame = iterator_.frame();
248 : DCHECK(frame->is_java_script() || frame->is_arguments_adaptor() ||
249 : frame->is_wasm());
250 122365 : return static_cast<StandardFrame*>(frame);
251 : }
252 :
253 : bool StackTraceFrameIterator::is_javascript() const {
254 383702 : return frame()->is_java_script();
255 : }
256 :
257 2070 : bool StackTraceFrameIterator::is_wasm() const { return frame()->is_wasm(); }
258 :
259 49974 : JavaScriptFrame* StackTraceFrameIterator::javascript_frame() const {
260 49974 : return JavaScriptFrame::cast(frame());
261 : }
262 :
263 : inline StackFrame* SafeStackFrameIterator::frame() const {
264 : DCHECK(!done());
265 : DCHECK(frame_->is_java_script() || frame_->is_exit() ||
266 : frame_->is_builtin_exit());
267 : return frame_;
268 : }
269 :
270 :
271 : } // namespace internal
272 : } // namespace v8
273 :
274 : #endif // V8_FRAMES_INL_H_
|