blob: f6806d7563ba89b83bc1f60cd517de9cb3edffee [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_FRAMES_H_
6#define V8_FRAMES_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/allocation.h"
9#include "src/handles.h"
10#include "src/safepoint-table.h"
Ben Murdochb8e0da22011-05-16 14:20:40 +010011
Steve Blocka7e24c12009-10-30 11:49:00 +000012namespace v8 {
13namespace internal {
14
Ben Murdochb8a8cc12014-11-26 15:28:44 +000015#if V8_TARGET_ARCH_ARM64
16typedef uint64_t RegList;
17#else
Steve Blocka7e24c12009-10-30 11:49:00 +000018typedef uint32_t RegList;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000019#endif
Steve Blocka7e24c12009-10-30 11:49:00 +000020
21// Get the number of registers in a given register list.
22int NumRegs(RegList list);
23
Ben Murdochb8a8cc12014-11-26 15:28:44 +000024void SetUpJSCallerSavedCodeData();
25
Steve Blocka7e24c12009-10-30 11:49:00 +000026// Return the code of the n-th saved register available to JavaScript.
27int JSCallerSavedCode(int n);
28
29
30// Forward declarations.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031class ExternalCallbackScope;
32class StackFrameIteratorBase;
Steve Blocka7e24c12009-10-30 11:49:00 +000033class ThreadLocalTop;
Steve Block44f0eee2011-05-26 01:26:41 +010034class Isolate;
Steve Blocka7e24c12009-10-30 11:49:00 +000035
Ben Murdoch3ef787d2012-04-12 10:51:47 +010036class InnerPointerToCodeCache {
Kristian Monsen80d68ea2010-09-08 11:05:35 +010037 public:
Ben Murdoch3ef787d2012-04-12 10:51:47 +010038 struct InnerPointerToCodeCacheEntry {
39 Address inner_pointer;
Kristian Monsen80d68ea2010-09-08 11:05:35 +010040 Code* code;
Ben Murdochb8e0da22011-05-16 14:20:40 +010041 SafepointEntry safepoint_entry;
Kristian Monsen80d68ea2010-09-08 11:05:35 +010042 };
43
Ben Murdoch3ef787d2012-04-12 10:51:47 +010044 explicit InnerPointerToCodeCache(Isolate* isolate) : isolate_(isolate) {
Steve Block44f0eee2011-05-26 01:26:41 +010045 Flush();
Kristian Monsen80d68ea2010-09-08 11:05:35 +010046 }
47
Ben Murdoch3ef787d2012-04-12 10:51:47 +010048 Code* GcSafeFindCodeForInnerPointer(Address inner_pointer);
49 Code* GcSafeCastToCode(HeapObject* object, Address inner_pointer);
Kristian Monsen80d68ea2010-09-08 11:05:35 +010050
Steve Block44f0eee2011-05-26 01:26:41 +010051 void Flush() {
Kristian Monsen80d68ea2010-09-08 11:05:35 +010052 memset(&cache_[0], 0, sizeof(cache_));
53 }
54
Ben Murdoch3ef787d2012-04-12 10:51:47 +010055 InnerPointerToCodeCacheEntry* GetCacheEntry(Address inner_pointer);
Kristian Monsen80d68ea2010-09-08 11:05:35 +010056
57 private:
Ben Murdoch3ef787d2012-04-12 10:51:47 +010058 InnerPointerToCodeCacheEntry* cache(int index) { return &cache_[index]; }
Steve Block44f0eee2011-05-26 01:26:41 +010059
60 Isolate* isolate_;
61
Ben Murdoch3ef787d2012-04-12 10:51:47 +010062 static const int kInnerPointerToCodeCacheSize = 1024;
63 InnerPointerToCodeCacheEntry cache_[kInnerPointerToCodeCacheSize];
Steve Block44f0eee2011-05-26 01:26:41 +010064
Ben Murdoch3ef787d2012-04-12 10:51:47 +010065 DISALLOW_COPY_AND_ASSIGN(InnerPointerToCodeCache);
Kristian Monsen80d68ea2010-09-08 11:05:35 +010066};
67
68
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000069// Every try-block pushes the context register.
70class TryBlockConstant : public AllStatic {
71 public:
72 static const int kElementCount = 1;
73};
74
75
Ben Murdochb8a8cc12014-11-26 15:28:44 +000076class StackHandlerConstants : public AllStatic {
77 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000078 static const int kNextOffset = 0 * kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000080 static const int kSize = kNextOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081 static const int kSlotCount = kSize >> kPointerSizeLog2;
82};
83
84
Steve Blocka7e24c12009-10-30 11:49:00 +000085class StackHandler BASE_EMBEDDED {
86 public:
Steve Blocka7e24c12009-10-30 11:49:00 +000087 // Get the address of this stack handler.
88 inline Address address() const;
89
90 // Get the next stack handler in the chain.
91 inline StackHandler* next() const;
92
Steve Blocka7e24c12009-10-30 11:49:00 +000093 // Conversion support.
94 static inline StackHandler* FromAddress(Address address);
95
Steve Blocka7e24c12009-10-30 11:49:00 +000096 private:
Steve Blocka7e24c12009-10-30 11:49:00 +000097 DISALLOW_IMPLICIT_CONSTRUCTORS(StackHandler);
98};
99
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000100#define STACK_FRAME_TYPE_LIST(V) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000101 V(ENTRY, EntryFrame) \
102 V(ENTRY_CONSTRUCT, EntryConstructFrame) \
103 V(EXIT, ExitFrame) \
104 V(JAVA_SCRIPT, JavaScriptFrame) \
105 V(OPTIMIZED, OptimizedFrame) \
Ben Murdochda12d292016-06-02 14:46:10 +0100106 V(WASM, WasmFrame) \
107 V(WASM_TO_JS, WasmToJsFrame) \
108 V(JS_TO_WASM, JsToWasmFrame) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000109 V(INTERPRETED, InterpretedFrame) \
110 V(STUB, StubFrame) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000111 V(STUB_FAILURE_TRAMPOLINE, StubFailureTrampolineFrame) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000112 V(INTERNAL, InternalFrame) \
113 V(CONSTRUCT, ConstructFrame) \
114 V(ARGUMENTS_ADAPTOR, ArgumentsAdaptorFrame)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000115
Ben Murdoch097c5b22016-05-18 11:27:45 +0100116// Every pointer in a frame has a slot id. On 32-bit platforms, doubles consume
117// two slots.
118//
119// Stack slot indices >= 0 access the callee stack with slot 0 corresponding to
120// the callee's saved return address and 1 corresponding to the saved frame
121// pointer. Some frames have additional information stored in the fixed header,
122// for example JSFunctions store the function context and marker in the fixed
123// header, with slot index 2 corresponding to the current function context and 3
124// corresponding to the frame marker/JSFunction.
125//
126// slot JS frame
127// +-----------------+--------------------------------
128// -n-1 | parameter 0 | ^
129// |- - - - - - - - -| |
130// -n | | Caller
131// ... | ... | frame slots
132// -2 | parameter n-1 | (slot < 0)
133// |- - - - - - - - -| |
134// -1 | parameter n | v
135// -----+-----------------+--------------------------------
136// 0 | return addr | ^ ^
137// |- - - - - - - - -| | |
138// 1 | saved frame ptr | Fixed |
139// |- - - - - - - - -| Header <-- frame ptr |
140// 2 | [Constant Pool] | | |
141// |- - - - - - - - -| | |
Ben Murdochda12d292016-06-02 14:46:10 +0100142// 2+cp |Context/Frm. Type| v if a constant pool |
143// |-----------------+---- is used, cp = 1, |
144// 3+cp | | ^ otherwise, cp = 0 |
145// |- - - - - - - - -| | |
146// 4+cp | | | Callee
147// |- - - - - - - - -| | frame slots
148// ... | | Frame slots (slot >= 0)
149// |- - - - - - - - -| | |
150// | | v |
151// -----+-----------------+----- <-- stack ptr -------------
152//
153class CommonFrameConstants : public AllStatic {
154 public:
155 static const int kCallerFPOffset = 0 * kPointerSize;
156 static const int kCallerPCOffset = kCallerFPOffset + 1 * kFPOnStackSize;
157 static const int kCallerSPOffset = kCallerPCOffset + 1 * kPCOnStackSize;
158
159 // Fixed part of the frame consists of return address, caller fp,
160 // constant pool (if FLAG_enable_embedded_constant_pool), context, and
161 // function. StandardFrame::IterateExpressions assumes that kLastObjectOffset
162 // is the last object pointer.
163 static const int kFixedFrameSizeAboveFp = kPCOnStackSize + kFPOnStackSize;
164 static const int kFixedSlotCountAboveFp =
165 kFixedFrameSizeAboveFp / kPointerSize;
166 static const int kCPSlotSize =
167 FLAG_enable_embedded_constant_pool ? kPointerSize : 0;
168 static const int kCPSlotCount = kCPSlotSize / kPointerSize;
169 static const int kConstantPoolOffset = kCPSlotSize ? -1 * kPointerSize : 0;
170 static const int kContextOrFrameTypeSize = kPointerSize;
171 static const int kContextOrFrameTypeOffset =
172 -(kCPSlotSize + kContextOrFrameTypeSize);
173};
174
175// StandardFrames are used for interpreted, full-codegen and optimized
176// JavaScript frames. They always have a context below the saved fp/constant
177// pool and below that the JSFunction of the executing function.
178//
179// slot JS frame
180// +-----------------+--------------------------------
181// -n-1 | parameter 0 | ^
182// |- - - - - - - - -| |
183// -n | | Caller
184// ... | ... | frame slots
185// -2 | parameter n-1 | (slot < 0)
186// |- - - - - - - - -| |
187// -1 | parameter n | v
188// -----+-----------------+--------------------------------
189// 0 | return addr | ^ ^
190// |- - - - - - - - -| | |
191// 1 | saved frame ptr | Fixed |
192// |- - - - - - - - -| Header <-- frame ptr |
193// 2 | [Constant Pool] | | |
194// |- - - - - - - - -| | |
Ben Murdoch097c5b22016-05-18 11:27:45 +0100195// 2+cp | Context | | if a constant pool |
196// |- - - - - - - - -| | is used, cp = 1, |
Ben Murdochda12d292016-06-02 14:46:10 +0100197// 3+cp | JSFunction | v otherwise, cp = 0 |
Ben Murdoch097c5b22016-05-18 11:27:45 +0100198// +-----------------+---- |
199// 4+cp | | ^ Callee
200// |- - - - - - - - -| | frame slots
201// ... | | Frame slots (slot >= 0)
202// |- - - - - - - - -| | |
203// | | v |
204// -----+-----------------+----- <-- stack ptr -------------
205//
Ben Murdochda12d292016-06-02 14:46:10 +0100206class StandardFrameConstants : public CommonFrameConstants {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000207 public:
Ben Murdochda12d292016-06-02 14:46:10 +0100208 static const int kFixedFrameSizeFromFp = 2 * kPointerSize + kCPSlotSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000209 static const int kFixedFrameSize =
210 kFixedFrameSizeAboveFp + kFixedFrameSizeFromFp;
Ben Murdochda12d292016-06-02 14:46:10 +0100211 static const int kFixedSlotCountFromFp = kFixedFrameSizeFromFp / kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000212 static const int kFixedSlotCount = kFixedFrameSize / kPointerSize;
Ben Murdochda12d292016-06-02 14:46:10 +0100213 static const int kContextOffset = kContextOrFrameTypeOffset;
214 static const int kFunctionOffset = -2 * kPointerSize - kCPSlotSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000215 static const int kExpressionsOffset = -3 * kPointerSize - kCPSlotSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000216 static const int kLastObjectOffset = kContextOffset;
217};
218
Ben Murdochda12d292016-06-02 14:46:10 +0100219// TypedFrames have a SMI type maker value below the saved FP/constant pool to
220// distinguish them from StandardFrames, which have a context in that position
221// instead.
222//
223// slot JS frame
224// +-----------------+--------------------------------
225// -n-1 | parameter 0 | ^
226// |- - - - - - - - -| |
227// -n | | Caller
228// ... | ... | frame slots
229// -2 | parameter n-1 | (slot < 0)
230// |- - - - - - - - -| |
231// -1 | parameter n | v
232// -----+-----------------+--------------------------------
233// 0 | return addr | ^ ^
234// |- - - - - - - - -| | |
235// 1 | saved frame ptr | Fixed |
236// |- - - - - - - - -| Header <-- frame ptr |
237// 2 | [Constant Pool] | | |
238// |- - - - - - - - -| | |
239// 2+cp |Frame Type Marker| v if a constant pool |
240// |-----------------+---- is used, cp = 1, |
241// 3+cp | | ^ otherwise, cp = 0 |
242// |- - - - - - - - -| | |
243// 4+cp | | | Callee
244// |- - - - - - - - -| | frame slots
245// ... | | Frame slots (slot >= 0)
246// |- - - - - - - - -| | |
247// | | v |
248// -----+-----------------+----- <-- stack ptr -------------
249//
250class TypedFrameConstants : public CommonFrameConstants {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000251 public:
Ben Murdochda12d292016-06-02 14:46:10 +0100252 static const int kFrameTypeSize = kContextOrFrameTypeSize;
253 static const int kFrameTypeOffset = kContextOrFrameTypeOffset;
254 static const int kFixedFrameSizeFromFp = kCPSlotSize + kFrameTypeSize;
255 static const int kFixedSlotCountFromFp = kFixedFrameSizeFromFp / kPointerSize;
256 static const int kFixedFrameSize =
257 StandardFrameConstants::kFixedFrameSizeAboveFp + kFixedFrameSizeFromFp;
258 static const int kFixedSlotCount = kFixedFrameSize / kPointerSize;
259 static const int kFirstPushedFrameValueOffset =
260 -StandardFrameConstants::kCPSlotSize - kFrameTypeSize - kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000261};
262
Ben Murdochda12d292016-06-02 14:46:10 +0100263#define TYPED_FRAME_PUSHED_VALUE_OFFSET(x) \
264 (TypedFrameConstants::kFirstPushedFrameValueOffset - (x)*kPointerSize)
265#define TYPED_FRAME_SIZE(count) \
266 (TypedFrameConstants::kFixedFrameSize + (count)*kPointerSize)
267#define TYPED_FRAME_SIZE_FROM_SP(count) \
268 (TypedFrameConstants::kFixedFrameSizeFromFp + (count)*kPointerSize)
269#define DEFINE_TYPED_FRAME_SIZES(count) \
270 static const int kFixedFrameSize = TYPED_FRAME_SIZE(count); \
271 static const int kFixedSlotCount = kFixedFrameSize / kPointerSize; \
272 static const int kFixedFrameSizeFromFp = TYPED_FRAME_SIZE_FROM_SP(count); \
273 static const int kFixedSlotCountFromFp = kFixedFrameSizeFromFp / kPointerSize
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000274
Ben Murdochda12d292016-06-02 14:46:10 +0100275class ArgumentsAdaptorFrameConstants : public TypedFrameConstants {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000276 public:
277 // FP-relative.
Ben Murdochda12d292016-06-02 14:46:10 +0100278 static const int kFunctionOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0);
279 static const int kLengthOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(1);
280 DEFINE_TYPED_FRAME_SIZES(2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000281};
282
Ben Murdochda12d292016-06-02 14:46:10 +0100283class InternalFrameConstants : public TypedFrameConstants {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000284 public:
285 // FP-relative.
Ben Murdochda12d292016-06-02 14:46:10 +0100286 static const int kCodeOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0);
287 DEFINE_TYPED_FRAME_SIZES(1);
288};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000289
Ben Murdochda12d292016-06-02 14:46:10 +0100290class FrameDropperFrameConstants : public InternalFrameConstants {
291 public:
292 // FP-relative.
293 static const int kFunctionOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(1);
294 DEFINE_TYPED_FRAME_SIZES(2);
295};
296
297class ConstructFrameConstants : public TypedFrameConstants {
298 public:
299 // FP-relative.
300 static const int kContextOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0);
301 static const int kAllocationSiteOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(1);
302 static const int kLengthOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(2);
303 static const int kImplicitReceiverOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(3);
304 DEFINE_TYPED_FRAME_SIZES(4);
305};
306
307class StubFailureTrampolineFrameConstants : public InternalFrameConstants {
308 public:
309 static const int kArgumentsArgumentsOffset =
310 TYPED_FRAME_PUSHED_VALUE_OFFSET(0);
311 static const int kArgumentsLengthOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(1);
312 static const int kArgumentsPointerOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(2);
313 static const int kFixedHeaderBottomOffset = kArgumentsPointerOffset;
314 DEFINE_TYPED_FRAME_SIZES(3);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000315};
316
317
318class InterpreterFrameConstants : public AllStatic {
319 public:
320 // Fixed frame includes new.target and bytecode offset.
321 static const int kFixedFrameSize =
Ben Murdoch097c5b22016-05-18 11:27:45 +0100322 StandardFrameConstants::kFixedFrameSize + 3 * kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000323 static const int kFixedFrameSizeFromFp =
Ben Murdoch097c5b22016-05-18 11:27:45 +0100324 StandardFrameConstants::kFixedFrameSizeFromFp + 3 * kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000325
326 // FP-relative.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100327 static const int kNewTargetFromFp =
328 -StandardFrameConstants::kFixedFrameSizeFromFp - 1 * kPointerSize;
329 static const int kBytecodeArrayFromFp =
330 -StandardFrameConstants::kFixedFrameSizeFromFp - 2 * kPointerSize;
331 static const int kBytecodeOffsetFromFp =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000332 -StandardFrameConstants::kFixedFrameSizeFromFp - 3 * kPointerSize;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100333 static const int kRegisterFilePointerFromFp =
334 -StandardFrameConstants::kFixedFrameSizeFromFp - 4 * kPointerSize;
335
336 static const int kExpressionsOffset = kRegisterFilePointerFromFp;
337
338 // Expression index for {StandardFrame::GetExpressionAddress}.
339 static const int kBytecodeArrayExpressionIndex = -2;
340 static const int kBytecodeOffsetExpressionIndex = -1;
341 static const int kRegisterFileExpressionIndex = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000342
343 // Register file pointer relative.
344 static const int kLastParamFromRegisterPointer =
Ben Murdoch097c5b22016-05-18 11:27:45 +0100345 StandardFrameConstants::kFixedFrameSize + 4 * kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000346
347 static const int kBytecodeOffsetFromRegisterPointer = 1 * kPointerSize;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100348 static const int kBytecodeArrayFromRegisterPointer = 2 * kPointerSize;
349 static const int kNewTargetFromRegisterPointer = 3 * kPointerSize;
350 static const int kFunctionFromRegisterPointer = 4 * kPointerSize;
351 static const int kContextFromRegisterPointer = 5 * kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000352};
Steve Blocka7e24c12009-10-30 11:49:00 +0000353
Ben Murdoch097c5b22016-05-18 11:27:45 +0100354inline static int FPOffsetToFrameSlot(int frame_offset) {
355 return StandardFrameConstants::kFixedSlotCountAboveFp - 1 -
356 frame_offset / kPointerSize;
357}
358
359inline static int FrameSlotToFPOffset(int slot) {
360 return (StandardFrameConstants::kFixedSlotCountAboveFp - 1 - slot) *
361 kPointerSize;
362}
Steve Blocka7e24c12009-10-30 11:49:00 +0000363
364// Abstract base class for all stack frames.
365class StackFrame BASE_EMBEDDED {
366 public:
367#define DECLARE_TYPE(type, ignore) type,
368 enum Type {
369 NONE = 0,
370 STACK_FRAME_TYPE_LIST(DECLARE_TYPE)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100371 NUMBER_OF_TYPES,
372 // Used by FrameScope to indicate that the stack frame is constructed
373 // manually and the FrameScope does not need to emit code.
374 MANUAL
Steve Blocka7e24c12009-10-30 11:49:00 +0000375 };
376#undef DECLARE_TYPE
377
378 // Opaque data type for identifying stack frames. Used extensively
379 // by the debugger.
Iain Merrick75681382010-08-19 15:07:18 +0100380 // ID_MIN_VALUE and ID_MAX_VALUE are specified to ensure that enumeration type
381 // has correct value range (see Issue 830 for more details).
382 enum Id {
383 ID_MIN_VALUE = kMinInt,
384 ID_MAX_VALUE = kMaxInt,
385 NO_ID = 0
386 };
Steve Blocka7e24c12009-10-30 11:49:00 +0000387
Steve Block053d10c2011-06-13 19:13:29 +0100388 // Used to mark the outermost JS entry frame.
389 enum JsFrameMarker {
390 INNER_JSENTRY_FRAME = 0,
391 OUTERMOST_JSENTRY_FRAME = 1
392 };
393
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100394 struct State {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000395 State() : sp(NULL), fp(NULL), pc_address(NULL),
396 constant_pool_address(NULL) { }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100397 Address sp;
398 Address fp;
399 Address* pc_address;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000400 Address* constant_pool_address;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100401 };
402
Ben Murdoch8b112d22011-06-08 16:22:53 +0100403 // Copy constructor; it breaks the connection to host iterator
404 // (as an iterator usually lives on stack).
Steve Block6ded16b2010-05-10 14:33:55 +0100405 StackFrame(const StackFrame& original) {
406 this->state_ = original.state_;
407 this->iterator_ = NULL;
Ben Murdoch8b112d22011-06-08 16:22:53 +0100408 this->isolate_ = original.isolate_;
Steve Block6ded16b2010-05-10 14:33:55 +0100409 }
410
Steve Blocka7e24c12009-10-30 11:49:00 +0000411 // Type testers.
412 bool is_entry() const { return type() == ENTRY; }
413 bool is_entry_construct() const { return type() == ENTRY_CONSTRUCT; }
414 bool is_exit() const { return type() == EXIT; }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100415 bool is_optimized() const { return type() == OPTIMIZED; }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100416 bool is_interpreted() const { return type() == INTERPRETED; }
Ben Murdochda12d292016-06-02 14:46:10 +0100417 bool is_wasm() const { return type() == WASM; }
418 bool is_wasm_to_js() const { return type() == WASM_TO_JS; }
419 bool is_js_to_wasm() const { return type() == JS_TO_WASM; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000420 bool is_arguments_adaptor() const { return type() == ARGUMENTS_ADAPTOR; }
421 bool is_internal() const { return type() == INTERNAL; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000422 bool is_stub_failure_trampoline() const {
423 return type() == STUB_FAILURE_TRAMPOLINE;
424 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000425 bool is_construct() const { return type() == CONSTRUCT; }
426 virtual bool is_standard() const { return false; }
427
Ben Murdochb0fe1622011-05-05 13:52:32 +0100428 bool is_java_script() const {
429 Type type = this->type();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000430 return (type == JAVA_SCRIPT) || (type == OPTIMIZED) ||
431 (type == INTERPRETED);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100432 }
433
Steve Blocka7e24c12009-10-30 11:49:00 +0000434 // Accessors.
435 Address sp() const { return state_.sp; }
436 Address fp() const { return state_.fp; }
437 Address caller_sp() const { return GetCallerStackPointer(); }
438
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000439 // If this frame is optimized and was dynamically aligned return its old
440 // unaligned frame pointer. When the frame is deoptimized its FP will shift
441 // up one word and become unaligned.
442 Address UnpaddedFP() const;
443
Steve Blocka7e24c12009-10-30 11:49:00 +0000444 Address pc() const { return *pc_address(); }
445 void set_pc(Address pc) { *pc_address() = pc; }
446
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000447 Address constant_pool() const { return *constant_pool_address(); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448 void set_constant_pool(Address constant_pool) {
449 *constant_pool_address() = constant_pool;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000450 }
451
Steve Block6ded16b2010-05-10 14:33:55 +0100452 virtual void SetCallerFp(Address caller_fp) = 0;
453
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000454 // Manually changes value of fp in this object.
455 void UpdateFp(Address fp) { state_.fp = fp; }
456
Steve Blocka7e24c12009-10-30 11:49:00 +0000457 Address* pc_address() const { return state_.pc_address; }
458
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000459 Address* constant_pool_address() const {
460 return state_.constant_pool_address;
461 }
462
Steve Blocka7e24c12009-10-30 11:49:00 +0000463 // Get the id of this stack frame.
464 Id id() const { return static_cast<Id>(OffsetFrom(caller_sp())); }
465
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000466 // Get the top handler from the current stack iterator.
467 inline StackHandler* top_handler() const;
Steve Blocka7e24c12009-10-30 11:49:00 +0000468
469 // Get the type of this frame.
470 virtual Type type() const = 0;
471
472 // Get the code associated with this frame.
Iain Merrick75681382010-08-19 15:07:18 +0100473 // This method could be called during marking phase of GC.
474 virtual Code* unchecked_code() const = 0;
475
476 // Get the code associated with this frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100477 inline Code* LookupCode() const;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100478
479 // Get the code object that contains the given pc.
Steve Block44f0eee2011-05-26 01:26:41 +0100480 static inline Code* GetContainingCode(Isolate* isolate, Address pc);
Steve Blocka7e24c12009-10-30 11:49:00 +0000481
Ben Murdochb0fe1622011-05-05 13:52:32 +0100482 // Get the code object containing the given pc and fill in the
483 // safepoint entry and the number of stack slots. The pc must be at
484 // a safepoint.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100485 static Code* GetSafepointData(Isolate* isolate,
486 Address pc,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100487 SafepointEntry* safepoint_entry,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100488 unsigned* stack_slots);
489
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100490 virtual void Iterate(ObjectVisitor* v) const = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000491 static void IteratePc(ObjectVisitor* v, Address* pc_address,
492 Address* constant_pool_address, Code* holder);
Steve Blocka7e24c12009-10-30 11:49:00 +0000493
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100494 // Sets a callback function for return-address rewriting profilers
495 // to resolve the location of a return address to the location of the
496 // profiler's stashed return address.
497 static void SetReturnAddressLocationResolver(
498 ReturnAddressLocationResolver resolver);
Steve Blocka7e24c12009-10-30 11:49:00 +0000499
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000500 // Resolves pc_address through the resolution address function if one is set.
501 static inline Address* ResolveReturnAddressLocation(Address* pc_address);
502
Steve Blocka7e24c12009-10-30 11:49:00 +0000503 // Printing support.
504 enum PrintMode { OVERVIEW, DETAILS };
505 virtual void Print(StringStream* accumulator,
506 PrintMode mode,
507 int index) const { }
508
Ben Murdoch8b112d22011-06-08 16:22:53 +0100509 Isolate* isolate() const { return isolate_; }
510
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000511 protected:
512 inline explicit StackFrame(StackFrameIteratorBase* iterator);
513 virtual ~StackFrame() { }
514
Steve Blocka7e24c12009-10-30 11:49:00 +0000515 // Compute the stack pointer for the calling frame.
516 virtual Address GetCallerStackPointer() const = 0;
517
518 // Printing support.
519 static void PrintIndex(StringStream* accumulator,
520 PrintMode mode,
521 int index);
522
Steve Blocka7e24c12009-10-30 11:49:00 +0000523 // Compute the stack frame type for the given state.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000524 static Type ComputeType(const StackFrameIteratorBase* iterator, State* state);
525
526#ifdef DEBUG
527 bool can_access_heap_objects() const;
528#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000529
530 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000531 const StackFrameIteratorBase* iterator_;
Ben Murdoch8b112d22011-06-08 16:22:53 +0100532 Isolate* isolate_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000533 State state_;
534
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000535 static ReturnAddressLocationResolver return_address_location_resolver_;
536
Steve Blocka7e24c12009-10-30 11:49:00 +0000537 // Fill in the state of the calling frame.
538 virtual void ComputeCallerState(State* state) const = 0;
539
540 // Get the type and the state of the calling frame.
541 virtual Type GetCallerState(State* state) const;
542
Ben Murdoch8b112d22011-06-08 16:22:53 +0100543 static const intptr_t kIsolateTag = 1;
544
Steve Blocka7e24c12009-10-30 11:49:00 +0000545 friend class StackFrameIterator;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000546 friend class StackFrameIteratorBase;
Steve Blocka7e24c12009-10-30 11:49:00 +0000547 friend class StackHandlerIterator;
548 friend class SafeStackFrameIterator;
549
Steve Block6ded16b2010-05-10 14:33:55 +0100550 private:
551 void operator=(const StackFrame& original);
Steve Blocka7e24c12009-10-30 11:49:00 +0000552};
553
554
555// Entry frames are used to enter JavaScript execution from C.
556class EntryFrame: public StackFrame {
557 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000558 Type type() const override { return ENTRY; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000559
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000560 Code* unchecked_code() const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000561
562 // Garbage collection support.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000563 void Iterate(ObjectVisitor* v) const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000564
565 static EntryFrame* cast(StackFrame* frame) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000566 DCHECK(frame->is_entry());
Steve Blocka7e24c12009-10-30 11:49:00 +0000567 return static_cast<EntryFrame*>(frame);
568 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000569 void SetCallerFp(Address caller_fp) override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000570
571 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000572 inline explicit EntryFrame(StackFrameIteratorBase* iterator);
Steve Blocka7e24c12009-10-30 11:49:00 +0000573
574 // The caller stack pointer for entry frames is always zero. The
575 // real information about the caller frame is available through the
576 // link to the top exit frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000577 Address GetCallerStackPointer() const override { return 0; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000578
579 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000580 void ComputeCallerState(State* state) const override;
581 Type GetCallerState(State* state) const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000582
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000583 friend class StackFrameIteratorBase;
Steve Blocka7e24c12009-10-30 11:49:00 +0000584};
585
586
587class EntryConstructFrame: public EntryFrame {
588 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000589 Type type() const override { return ENTRY_CONSTRUCT; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000590
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000591 Code* unchecked_code() const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000592
593 static EntryConstructFrame* cast(StackFrame* frame) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000594 DCHECK(frame->is_entry_construct());
Steve Blocka7e24c12009-10-30 11:49:00 +0000595 return static_cast<EntryConstructFrame*>(frame);
596 }
597
598 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000599 inline explicit EntryConstructFrame(StackFrameIteratorBase* iterator);
Steve Blocka7e24c12009-10-30 11:49:00 +0000600
601 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000602 friend class StackFrameIteratorBase;
Steve Blocka7e24c12009-10-30 11:49:00 +0000603};
604
605
606// Exit frames are used to exit JavaScript execution and go to C.
607class ExitFrame: public StackFrame {
608 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000609 Type type() const override { return EXIT; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000610
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000611 Code* unchecked_code() const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000612
Steve Blockd0582a62009-12-15 09:54:21 +0000613 Object*& code_slot() const;
614
Steve Blocka7e24c12009-10-30 11:49:00 +0000615 // Garbage collection support.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000616 void Iterate(ObjectVisitor* v) const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000617
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000618 void SetCallerFp(Address caller_fp) override;
Steve Block6ded16b2010-05-10 14:33:55 +0100619
Steve Blocka7e24c12009-10-30 11:49:00 +0000620 static ExitFrame* cast(StackFrame* frame) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000621 DCHECK(frame->is_exit());
Steve Blocka7e24c12009-10-30 11:49:00 +0000622 return static_cast<ExitFrame*>(frame);
623 }
624
625 // Compute the state and type of an exit frame given a frame
626 // pointer. Used when constructing the first stack frame seen by an
627 // iterator and the frames following entry frames.
628 static Type GetStateForFramePointer(Address fp, State* state);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100629 static Address ComputeStackPointer(Address fp);
630 static void FillState(Address fp, Address sp, State* state);
Steve Blocka7e24c12009-10-30 11:49:00 +0000631
632 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000633 inline explicit ExitFrame(StackFrameIteratorBase* iterator);
Steve Blocka7e24c12009-10-30 11:49:00 +0000634
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000635 Address GetCallerStackPointer() const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000636
637 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000638 void ComputeCallerState(State* state) const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000639
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000640 friend class StackFrameIteratorBase;
Steve Blocka7e24c12009-10-30 11:49:00 +0000641};
642
643
Steve Blocka7e24c12009-10-30 11:49:00 +0000644class StandardFrame: public StackFrame {
645 public:
646 // Testers.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000647 bool is_standard() const override { return true; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000648
649 // Accessors.
650 inline Object* context() const;
651
652 // Access the expressions in the stack frame including locals.
653 inline Object* GetExpression(int index) const;
654 inline void SetExpression(int index, Object* value);
655 int ComputeExpressionsCount() const;
656
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000657 void SetCallerFp(Address caller_fp) override;
Steve Block6ded16b2010-05-10 14:33:55 +0100658
Steve Blocka7e24c12009-10-30 11:49:00 +0000659 static StandardFrame* cast(StackFrame* frame) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000660 DCHECK(frame->is_standard());
Steve Blocka7e24c12009-10-30 11:49:00 +0000661 return static_cast<StandardFrame*>(frame);
662 }
663
664 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000665 inline explicit StandardFrame(StackFrameIteratorBase* iterator);
Steve Blocka7e24c12009-10-30 11:49:00 +0000666
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000667 void ComputeCallerState(State* state) const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000668
669 // Accessors.
670 inline Address caller_fp() const;
671 inline Address caller_pc() const;
672
673 // Computes the address of the PC field in the standard frame given
674 // by the provided frame pointer.
675 static inline Address ComputePCAddress(Address fp);
676
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000677 // Computes the address of the constant pool field in the standard
678 // frame given by the provided frame pointer.
679 static inline Address ComputeConstantPoolAddress(Address fp);
680
Steve Blocka7e24c12009-10-30 11:49:00 +0000681 // Iterate over expression stack including stack handlers, locals,
682 // and parts of the fixed part including context and code fields.
683 void IterateExpressions(ObjectVisitor* v) const;
684
685 // Returns the address of the n'th expression stack element.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100686 virtual Address GetExpressionAddress(int n) const;
Steve Blocka7e24c12009-10-30 11:49:00 +0000687
Steve Blocka7e24c12009-10-30 11:49:00 +0000688 // Determines if the standard frame for the given frame pointer is
689 // an arguments adaptor frame.
690 static inline bool IsArgumentsAdaptorFrame(Address fp);
691
692 // Determines if the standard frame for the given frame pointer is a
693 // construct frame.
694 static inline bool IsConstructFrame(Address fp);
695
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000696 // Used by OptimizedFrames and StubFrames.
697 void IterateCompiledFrame(ObjectVisitor* v) const;
698
Steve Blocka7e24c12009-10-30 11:49:00 +0000699 private:
700 friend class StackFrame;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000701 friend class SafeStackFrameIterator;
Steve Blocka7e24c12009-10-30 11:49:00 +0000702};
703
704
Ben Murdochb0fe1622011-05-05 13:52:32 +0100705class FrameSummary BASE_EMBEDDED {
706 public:
Ben Murdoch097c5b22016-05-18 11:27:45 +0100707 FrameSummary(Object* receiver, JSFunction* function,
708 AbstractCode* abstract_code, int code_offset,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000709 bool is_constructor);
710
Ben Murdochb0fe1622011-05-05 13:52:32 +0100711 Handle<Object> receiver() { return receiver_; }
712 Handle<JSFunction> function() { return function_; }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100713 Handle<AbstractCode> abstract_code() { return abstract_code_; }
714 int code_offset() { return code_offset_; }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100715 bool is_constructor() { return is_constructor_; }
716
717 void Print();
718
719 private:
720 Handle<Object> receiver_;
721 Handle<JSFunction> function_;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100722 Handle<AbstractCode> abstract_code_;
723 int code_offset_;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100724 bool is_constructor_;
725};
726
Ben Murdochda12d292016-06-02 14:46:10 +0100727class JavaScriptFrame : public StandardFrame {
Steve Blocka7e24c12009-10-30 11:49:00 +0000728 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000729 Type type() const override { return JAVA_SCRIPT; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000730
731 // Accessors.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000732 inline JSFunction* function() const;
Steve Blocka7e24c12009-10-30 11:49:00 +0000733 inline Object* receiver() const;
734 inline void set_receiver(Object* value);
735
736 // Access the parameters.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100737 inline Address GetParameterSlot(int index) const;
738 inline Object* GetParameter(int index) const;
739 inline int ComputeParametersCount() const {
740 return GetNumberOfIncomingArguments();
741 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000742
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000743 // Access the operand stack.
744 inline Address GetOperandSlot(int index) const;
745 inline Object* GetOperand(int index) const;
746 inline int ComputeOperandsCount() const;
747
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000748 // Generator support to preserve operand stack.
749 void SaveOperandStack(FixedArray* store) const;
750 void RestoreOperandStack(FixedArray* store);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000751
752 // Debugger access.
753 void SetParameterValue(int index, Object* value) const;
754
Steve Blocka7e24c12009-10-30 11:49:00 +0000755 // Check if this frame is a constructor frame invoked through 'new'.
756 bool IsConstructor() const;
757
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000758 // Determines whether this frame includes inlined activations. To get details
759 // about the inlined frames use {GetFunctions} and {Summarize}.
760 bool HasInlinedFrames() const;
761
Steve Blocka7e24c12009-10-30 11:49:00 +0000762 // Check if this frame has "adapted" arguments in the sense that the
763 // actual passed arguments are available in an arguments adaptor
764 // frame below it on the stack.
765 inline bool has_adapted_arguments() const;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000766 int GetArgumentsLength() const;
Steve Blocka7e24c12009-10-30 11:49:00 +0000767
768 // Garbage collection support.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000769 void Iterate(ObjectVisitor* v) const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000770
771 // Printing support.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000772 void Print(StringStream* accumulator, PrintMode mode,
773 int index) const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000774
775 // Determine the code for the frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000776 Code* unchecked_code() const override;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000777
Ben Murdochb0fe1622011-05-05 13:52:32 +0100778 // Return a list with JSFunctions of this frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000779 virtual void GetFunctions(List<JSFunction*>* functions) const;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100780
781 // Build a list with summaries for this frame including all inlined frames.
782 virtual void Summarize(List<FrameSummary>* frames);
783
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000784 // Lookup exception handler for current {pc}, returns -1 if none found. Also
Ben Murdoch097c5b22016-05-18 11:27:45 +0100785 // returns data associated with the handler site specific to the frame type:
786 // - JavaScriptFrame : Data is the stack depth at entry of the try-block.
787 // - OptimizedFrame : Data is the stack slot count of the entire frame.
788 // - InterpretedFrame: Data is the register index holding the context.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000789 virtual int LookupExceptionHandlerInTable(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100790 int* data, HandlerTable::CatchPrediction* prediction);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000791
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000792 // Architecture-specific register description.
793 static Register fp_register();
794 static Register context_register();
795 static Register constant_pool_pointer_register();
796
Steve Blocka7e24c12009-10-30 11:49:00 +0000797 static JavaScriptFrame* cast(StackFrame* frame) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000798 DCHECK(frame->is_java_script());
Steve Blocka7e24c12009-10-30 11:49:00 +0000799 return static_cast<JavaScriptFrame*>(frame);
800 }
801
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000802 static void PrintFunctionAndOffset(JSFunction* function, Code* code,
803 Address pc, FILE* file,
804 bool print_line_number);
805
806 static void PrintTop(Isolate* isolate, FILE* file, bool print_args,
807 bool print_line_number);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100808
Steve Blocka7e24c12009-10-30 11:49:00 +0000809 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000810 inline explicit JavaScriptFrame(StackFrameIteratorBase* iterator);
Steve Blocka7e24c12009-10-30 11:49:00 +0000811
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000812 Address GetCallerStackPointer() const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000813
Ben Murdoch8b112d22011-06-08 16:22:53 +0100814 virtual int GetNumberOfIncomingArguments() const;
815
Ben Murdochb0fe1622011-05-05 13:52:32 +0100816 // Garbage collection support. Iterates over incoming arguments,
817 // receiver, and any callee-saved registers.
818 void IterateArguments(ObjectVisitor* v) const;
819
Steve Blocka7e24c12009-10-30 11:49:00 +0000820 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000821 inline Object* function_slot_object() const;
822
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000823 friend class StackFrameIteratorBase;
824};
825
826
827class StubFrame : public StandardFrame {
828 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000829 Type type() const override { return STUB; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000830
831 // GC support.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000832 void Iterate(ObjectVisitor* v) const override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000833
834 // Determine the code for the frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000835 Code* unchecked_code() const override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000836
837 protected:
838 inline explicit StubFrame(StackFrameIteratorBase* iterator);
839
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000840 Address GetCallerStackPointer() const override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000841
842 virtual int GetNumberOfIncomingArguments() const;
843
844 friend class StackFrameIteratorBase;
Steve Blocka7e24c12009-10-30 11:49:00 +0000845};
846
847
Ben Murdochb0fe1622011-05-05 13:52:32 +0100848class OptimizedFrame : public JavaScriptFrame {
849 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000850 Type type() const override { return OPTIMIZED; }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100851
852 // GC support.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000853 void Iterate(ObjectVisitor* v) const override;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000854
Ben Murdochb0fe1622011-05-05 13:52:32 +0100855 // Return a list with JSFunctions of this frame.
856 // The functions are ordered bottom-to-top (i.e. functions.last()
857 // is the top-most activation)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000858 void GetFunctions(List<JSFunction*>* functions) const override;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100859
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000860 void Summarize(List<FrameSummary>* frames) override;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100861
Ben Murdoch097c5b22016-05-18 11:27:45 +0100862 // Lookup exception handler for current {pc}, returns -1 if none found.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000863 int LookupExceptionHandlerInTable(
Ben Murdoch097c5b22016-05-18 11:27:45 +0100864 int* data, HandlerTable::CatchPrediction* prediction) override;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000865
866 DeoptimizationInputData* GetDeoptimizationData(int* deopt_index) const;
867
868 static int StackSlotOffsetRelativeToFp(int slot_index);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100869
870 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000871 inline explicit OptimizedFrame(StackFrameIteratorBase* iterator);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100872
873 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000874 friend class StackFrameIteratorBase;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000875
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000876 Object* StackSlotAt(int index) const;
877};
878
879
880class InterpretedFrame : public JavaScriptFrame {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100881 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000882 Type type() const override { return INTERPRETED; }
883
Ben Murdoch097c5b22016-05-18 11:27:45 +0100884 // Lookup exception handler for current {pc}, returns -1 if none found.
885 int LookupExceptionHandlerInTable(
886 int* data, HandlerTable::CatchPrediction* prediction) override;
887
888 // Returns the current offset into the bytecode stream.
889 int GetBytecodeOffset() const;
890
891 // Updates the current offset into the bytecode stream, mainly used for stack
892 // unwinding to continue execution at a different bytecode offset.
893 void PatchBytecodeOffset(int new_offset);
894
895 // Returns the frame's current bytecode array.
896 Object* GetBytecodeArray() const;
897
898 // Updates the frame's BytecodeArray with |bytecode_array|. Used by the
899 // debugger to swap execution onto a BytecodeArray patched with breakpoints.
900 void PatchBytecodeArray(Object* bytecode_array);
901
902 // Access to the interpreter register file for this frame.
903 Object* GetInterpreterRegister(int register_index) const;
904
905 // Build a list with summaries for this frame including all inlined frames.
906 void Summarize(List<FrameSummary>* frames) override;
907
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000908 protected:
909 inline explicit InterpretedFrame(StackFrameIteratorBase* iterator);
910
Ben Murdoch097c5b22016-05-18 11:27:45 +0100911 Address GetExpressionAddress(int n) const override;
912
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000913 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000914 friend class StackFrameIteratorBase;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100915};
916
917
Steve Blocka7e24c12009-10-30 11:49:00 +0000918// Arguments adaptor frames are automatically inserted below
919// JavaScript frames when the actual number of parameters does not
920// match the formal number of parameters.
921class ArgumentsAdaptorFrame: public JavaScriptFrame {
922 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000923 Type type() const override { return ARGUMENTS_ADAPTOR; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000924
925 // Determine the code for the frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000926 Code* unchecked_code() const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000927
928 static ArgumentsAdaptorFrame* cast(StackFrame* frame) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000929 DCHECK(frame->is_arguments_adaptor());
Steve Blocka7e24c12009-10-30 11:49:00 +0000930 return static_cast<ArgumentsAdaptorFrame*>(frame);
931 }
932
933 // Printing support.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000934 void Print(StringStream* accumulator, PrintMode mode,
935 int index) const override;
Ben Murdoch589d6972011-11-30 16:04:58 +0000936
Ben Murdoch097c5b22016-05-18 11:27:45 +0100937 static int GetLength(Address fp);
938
Steve Blocka7e24c12009-10-30 11:49:00 +0000939 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000940 inline explicit ArgumentsAdaptorFrame(StackFrameIteratorBase* iterator);
Steve Blocka7e24c12009-10-30 11:49:00 +0000941
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000942 int GetNumberOfIncomingArguments() const override;
Ben Murdoch8b112d22011-06-08 16:22:53 +0100943
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000944 Address GetCallerStackPointer() const override;
Steve Blocka7e24c12009-10-30 11:49:00 +0000945
946 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000947 friend class StackFrameIteratorBase;
Steve Blocka7e24c12009-10-30 11:49:00 +0000948};
949
Ben Murdochda12d292016-06-02 14:46:10 +0100950class WasmFrame : public StandardFrame {
951 public:
952 Type type() const override { return WASM; }
953
954 // GC support.
955 void Iterate(ObjectVisitor* v) const override;
956
957 // Printing support.
958 void Print(StringStream* accumulator, PrintMode mode,
959 int index) const override;
960
961 // Determine the code for the frame.
962 Code* unchecked_code() const override;
963
964 static WasmFrame* cast(StackFrame* frame) {
965 DCHECK(frame->is_wasm());
966 return static_cast<WasmFrame*>(frame);
967 }
968
969 protected:
970 inline explicit WasmFrame(StackFrameIteratorBase* iterator);
971
972 Address GetCallerStackPointer() const override;
973
974 private:
975 friend class StackFrameIteratorBase;
976};
977
978class WasmToJsFrame : public StubFrame {
979 public:
980 Type type() const override { return WASM_TO_JS; }
981
982 protected:
983 inline explicit WasmToJsFrame(StackFrameIteratorBase* iterator);
984
985 private:
986 friend class StackFrameIteratorBase;
987};
988
989class JsToWasmFrame : public StubFrame {
990 public:
991 Type type() const override { return JS_TO_WASM; }
992
993 protected:
994 inline explicit JsToWasmFrame(StackFrameIteratorBase* iterator);
995
996 private:
997 friend class StackFrameIteratorBase;
998};
Steve Blocka7e24c12009-10-30 11:49:00 +0000999
1000class InternalFrame: public StandardFrame {
1001 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001002 Type type() const override { return INTERNAL; }
Steve Blocka7e24c12009-10-30 11:49:00 +00001003
1004 // Garbage collection support.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001005 void Iterate(ObjectVisitor* v) const override;
Steve Blocka7e24c12009-10-30 11:49:00 +00001006
1007 // Determine the code for the frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001008 Code* unchecked_code() const override;
Steve Blocka7e24c12009-10-30 11:49:00 +00001009
1010 static InternalFrame* cast(StackFrame* frame) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001011 DCHECK(frame->is_internal());
Steve Blocka7e24c12009-10-30 11:49:00 +00001012 return static_cast<InternalFrame*>(frame);
1013 }
1014
1015 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001016 inline explicit InternalFrame(StackFrameIteratorBase* iterator);
Steve Blocka7e24c12009-10-30 11:49:00 +00001017
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001018 Address GetCallerStackPointer() const override;
Steve Blocka7e24c12009-10-30 11:49:00 +00001019
1020 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001021 friend class StackFrameIteratorBase;
1022};
1023
1024
1025class StubFailureTrampolineFrame: public StandardFrame {
1026 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001027 Type type() const override { return STUB_FAILURE_TRAMPOLINE; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001028
1029 // Get the code associated with this frame.
1030 // This method could be called during marking phase of GC.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001031 Code* unchecked_code() const override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001032
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001033 void Iterate(ObjectVisitor* v) const override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001034
1035 // Architecture-specific register description.
1036 static Register fp_register();
1037 static Register context_register();
1038 static Register constant_pool_pointer_register();
1039
1040 protected:
1041 inline explicit StubFailureTrampolineFrame(
1042 StackFrameIteratorBase* iterator);
1043
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001044 Address GetCallerStackPointer() const override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001045
1046 private:
1047 friend class StackFrameIteratorBase;
Steve Blocka7e24c12009-10-30 11:49:00 +00001048};
1049
1050
1051// Construct frames are special trampoline frames introduced to handle
1052// function invocations through 'new'.
1053class ConstructFrame: public InternalFrame {
1054 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001055 Type type() const override { return CONSTRUCT; }
Steve Blocka7e24c12009-10-30 11:49:00 +00001056
1057 static ConstructFrame* cast(StackFrame* frame) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001058 DCHECK(frame->is_construct());
Steve Blocka7e24c12009-10-30 11:49:00 +00001059 return static_cast<ConstructFrame*>(frame);
1060 }
1061
1062 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001063 inline explicit ConstructFrame(StackFrameIteratorBase* iterator);
Steve Blocka7e24c12009-10-30 11:49:00 +00001064
1065 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001066 friend class StackFrameIteratorBase;
Steve Blocka7e24c12009-10-30 11:49:00 +00001067};
1068
1069
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001070class StackFrameIteratorBase BASE_EMBEDDED {
Steve Blocka7e24c12009-10-30 11:49:00 +00001071 public:
Ben Murdoch8b112d22011-06-08 16:22:53 +01001072 Isolate* isolate() const { return isolate_; }
1073
Steve Blocka7e24c12009-10-30 11:49:00 +00001074 bool done() const { return frame_ == NULL; }
Steve Blocka7e24c12009-10-30 11:49:00 +00001075
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001076 protected:
1077 // An iterator that iterates over a given thread's stack.
1078 StackFrameIteratorBase(Isolate* isolate, bool can_access_heap_objects);
Steve Blocka7e24c12009-10-30 11:49:00 +00001079
Ben Murdoch8b112d22011-06-08 16:22:53 +01001080 Isolate* isolate_;
Steve Blocka7e24c12009-10-30 11:49:00 +00001081#define DECLARE_SINGLETON(ignore, type) type type##_;
1082 STACK_FRAME_TYPE_LIST(DECLARE_SINGLETON)
1083#undef DECLARE_SINGLETON
1084 StackFrame* frame_;
1085 StackHandler* handler_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001086 const bool can_access_heap_objects_;
Steve Blocka7e24c12009-10-30 11:49:00 +00001087
1088 StackHandler* handler() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001089 DCHECK(!done());
Steve Blocka7e24c12009-10-30 11:49:00 +00001090 return handler_;
1091 }
1092
1093 // Get the type-specific frame singleton in a given state.
1094 StackFrame* SingletonFor(StackFrame::Type type, StackFrame::State* state);
1095 // A helper function, can return a NULL pointer.
1096 StackFrame* SingletonFor(StackFrame::Type type);
1097
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001098 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00001099 friend class StackFrame;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001100 DISALLOW_COPY_AND_ASSIGN(StackFrameIteratorBase);
1101};
1102
1103
1104class StackFrameIterator: public StackFrameIteratorBase {
1105 public:
1106 // An iterator that iterates over the isolate's current thread's stack,
1107 explicit StackFrameIterator(Isolate* isolate);
1108 // An iterator that iterates over a given thread's stack.
1109 StackFrameIterator(Isolate* isolate, ThreadLocalTop* t);
1110
1111 StackFrame* frame() const {
1112 DCHECK(!done());
1113 return frame_;
1114 }
1115 void Advance();
1116
1117 private:
1118 // Go back to the first frame.
1119 void Reset(ThreadLocalTop* top);
1120
Steve Blocka7e24c12009-10-30 11:49:00 +00001121 DISALLOW_COPY_AND_ASSIGN(StackFrameIterator);
1122};
1123
Steve Blocka7e24c12009-10-30 11:49:00 +00001124// Iterator that supports iterating through all JavaScript frames.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001125class JavaScriptFrameIterator BASE_EMBEDDED {
Steve Blocka7e24c12009-10-30 11:49:00 +00001126 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001127 inline explicit JavaScriptFrameIterator(Isolate* isolate);
1128 inline JavaScriptFrameIterator(Isolate* isolate, ThreadLocalTop* top);
Steve Blocka7e24c12009-10-30 11:49:00 +00001129 // Skip frames until the frame with the given id is reached.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001130 JavaScriptFrameIterator(Isolate* isolate, StackFrame::Id id);
Steve Block44f0eee2011-05-26 01:26:41 +01001131
Steve Blocka7e24c12009-10-30 11:49:00 +00001132 inline JavaScriptFrame* frame() const;
1133
1134 bool done() const { return iterator_.done(); }
1135 void Advance();
1136
1137 // Advance to the frame holding the arguments for the current
1138 // frame. This only affects the current frame if it has adapted
1139 // arguments.
1140 void AdvanceToArgumentsFrame();
1141
Steve Blocka7e24c12009-10-30 11:49:00 +00001142 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001143 StackFrameIterator iterator_;
Steve Blocka7e24c12009-10-30 11:49:00 +00001144};
1145
Steve Blocka7e24c12009-10-30 11:49:00 +00001146// NOTE: The stack trace frame iterator is an iterator that only
1147// traverse proper JavaScript frames; that is JavaScript frames that
1148// have proper JavaScript functions. This excludes the problematic
1149// functions in runtime.js.
1150class StackTraceFrameIterator: public JavaScriptFrameIterator {
1151 public:
Ben Murdoch8b112d22011-06-08 16:22:53 +01001152 explicit StackTraceFrameIterator(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001153 void Advance();
Leon Clarke4515c472010-02-03 11:58:03 +00001154
1155 private:
1156 bool IsValidFrame();
Steve Blocka7e24c12009-10-30 11:49:00 +00001157};
1158
1159
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001160class SafeStackFrameIterator: public StackFrameIteratorBase {
Steve Blocka7e24c12009-10-30 11:49:00 +00001161 public:
Steve Block44f0eee2011-05-26 01:26:41 +01001162 SafeStackFrameIterator(Isolate* isolate,
1163 Address fp, Address sp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001164 Address js_entry_sp);
Steve Blocka7e24c12009-10-30 11:49:00 +00001165
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001166 inline StackFrame* frame() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00001167 void Advance();
Steve Blocka7e24c12009-10-30 11:49:00 +00001168
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001169 StackFrame::Type top_frame_type() const { return top_frame_type_; }
Leon Clarked91b9f72010-01-27 17:25:45 +00001170
1171 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001172 void AdvanceOneFrame();
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001173
Steve Blocka7e24c12009-10-30 11:49:00 +00001174 bool IsValidStackAddress(Address addr) const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001175 return low_bound_ <= addr && addr <= high_bound_;
Steve Blocka7e24c12009-10-30 11:49:00 +00001176 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001177 bool IsValidFrame(StackFrame* frame) const;
1178 bool IsValidCaller(StackFrame* frame);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001179 bool IsValidExitFrame(Address fp) const;
1180 bool IsValidTop(ThreadLocalTop* top) const;
Steve Blocka7e24c12009-10-30 11:49:00 +00001181
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001182 const Address low_bound_;
1183 const Address high_bound_;
1184 StackFrame::Type top_frame_type_;
1185 ExternalCallbackScope* external_callback_scope_;
Steve Blocka7e24c12009-10-30 11:49:00 +00001186};
Steve Blocka7e24c12009-10-30 11:49:00 +00001187
1188
1189class StackFrameLocator BASE_EMBEDDED {
1190 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001191 explicit StackFrameLocator(Isolate* isolate) : iterator_(isolate) {}
1192
Steve Blocka7e24c12009-10-30 11:49:00 +00001193 // Find the nth JavaScript frame on the stack. The caller must
1194 // guarantee that such a frame exists.
1195 JavaScriptFrame* FindJavaScriptFrame(int n);
1196
1197 private:
1198 StackFrameIterator iterator_;
1199};
1200
1201
Steve Block6ded16b2010-05-10 14:33:55 +01001202// Reads all frames on the current stack and copies them into the current
1203// zone memory.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001204Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone);
Steve Block6ded16b2010-05-10 14:33:55 +01001205
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001206} // namespace internal
1207} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001208
1209#endif // V8_FRAMES_H_