Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_FRAMES_H_ |
| 6 | #define V8_FRAMES_H_ |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/allocation.h" |
| 9 | #include "src/handles.h" |
| 10 | #include "src/safepoint-table.h" |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 11 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 15 | #if V8_TARGET_ARCH_ARM64 |
| 16 | typedef uint64_t RegList; |
| 17 | #else |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 18 | typedef uint32_t RegList; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 19 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 20 | |
| 21 | // Get the number of registers in a given register list. |
| 22 | int NumRegs(RegList list); |
| 23 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 24 | void SetUpJSCallerSavedCodeData(); |
| 25 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 26 | // Return the code of the n-th saved register available to JavaScript. |
| 27 | int JSCallerSavedCode(int n); |
| 28 | |
| 29 | |
| 30 | // Forward declarations. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 31 | class ExternalCallbackScope; |
| 32 | class StackFrameIteratorBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | class ThreadLocalTop; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 34 | class Isolate; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 35 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 36 | class InnerPointerToCodeCache { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 37 | public: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 38 | struct InnerPointerToCodeCacheEntry { |
| 39 | Address inner_pointer; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 40 | Code* code; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 41 | SafepointEntry safepoint_entry; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 44 | explicit InnerPointerToCodeCache(Isolate* isolate) : isolate_(isolate) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 45 | Flush(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 46 | } |
| 47 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 48 | Code* GcSafeFindCodeForInnerPointer(Address inner_pointer); |
| 49 | Code* GcSafeCastToCode(HeapObject* object, Address inner_pointer); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 50 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 51 | void Flush() { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 52 | memset(&cache_[0], 0, sizeof(cache_)); |
| 53 | } |
| 54 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 55 | InnerPointerToCodeCacheEntry* GetCacheEntry(Address inner_pointer); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 56 | |
| 57 | private: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 58 | InnerPointerToCodeCacheEntry* cache(int index) { return &cache_[index]; } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 59 | |
| 60 | Isolate* isolate_; |
| 61 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 62 | static const int kInnerPointerToCodeCacheSize = 1024; |
| 63 | InnerPointerToCodeCacheEntry cache_[kInnerPointerToCodeCacheSize]; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 64 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 65 | DISALLOW_COPY_AND_ASSIGN(InnerPointerToCodeCache); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 69 | // Every try-block pushes the context register. |
| 70 | class TryBlockConstant : public AllStatic { |
| 71 | public: |
| 72 | static const int kElementCount = 1; |
| 73 | }; |
| 74 | |
| 75 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 76 | class StackHandlerConstants : public AllStatic { |
| 77 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 78 | static const int kNextOffset = 0 * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 79 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 80 | static const int kSize = kNextOffset + kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 81 | static const int kSlotCount = kSize >> kPointerSizeLog2; |
| 82 | }; |
| 83 | |
| 84 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 85 | class StackHandler BASE_EMBEDDED { |
| 86 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 87 | // 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 93 | // Conversion support. |
| 94 | static inline StackHandler* FromAddress(Address address); |
| 95 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 96 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 97 | DISALLOW_IMPLICIT_CONSTRUCTORS(StackHandler); |
| 98 | }; |
| 99 | |
| 100 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 101 | #define STACK_FRAME_TYPE_LIST(V) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 102 | V(ENTRY, EntryFrame) \ |
| 103 | V(ENTRY_CONSTRUCT, EntryConstructFrame) \ |
| 104 | V(EXIT, ExitFrame) \ |
| 105 | V(JAVA_SCRIPT, JavaScriptFrame) \ |
| 106 | V(OPTIMIZED, OptimizedFrame) \ |
| 107 | V(INTERPRETED, InterpretedFrame) \ |
| 108 | V(STUB, StubFrame) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | V(STUB_FAILURE_TRAMPOLINE, StubFailureTrampolineFrame) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 110 | V(INTERNAL, InternalFrame) \ |
| 111 | V(CONSTRUCT, ConstructFrame) \ |
| 112 | V(ARGUMENTS_ADAPTOR, ArgumentsAdaptorFrame) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 113 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 114 | // Every pointer in a frame has a slot id. On 32-bit platforms, doubles consume |
| 115 | // two slots. |
| 116 | // |
| 117 | // Stack slot indices >= 0 access the callee stack with slot 0 corresponding to |
| 118 | // the callee's saved return address and 1 corresponding to the saved frame |
| 119 | // pointer. Some frames have additional information stored in the fixed header, |
| 120 | // for example JSFunctions store the function context and marker in the fixed |
| 121 | // header, with slot index 2 corresponding to the current function context and 3 |
| 122 | // corresponding to the frame marker/JSFunction. |
| 123 | // |
| 124 | // slot JS frame |
| 125 | // +-----------------+-------------------------------- |
| 126 | // -n-1 | parameter 0 | ^ |
| 127 | // |- - - - - - - - -| | |
| 128 | // -n | | Caller |
| 129 | // ... | ... | frame slots |
| 130 | // -2 | parameter n-1 | (slot < 0) |
| 131 | // |- - - - - - - - -| | |
| 132 | // -1 | parameter n | v |
| 133 | // -----+-----------------+-------------------------------- |
| 134 | // 0 | return addr | ^ ^ |
| 135 | // |- - - - - - - - -| | | |
| 136 | // 1 | saved frame ptr | Fixed | |
| 137 | // |- - - - - - - - -| Header <-- frame ptr | |
| 138 | // 2 | [Constant Pool] | | | |
| 139 | // |- - - - - - - - -| | | |
| 140 | // 2+cp | Context | | if a constant pool | |
| 141 | // |- - - - - - - - -| | is used, cp = 1, | |
| 142 | // 3+cp |JSFunction/Marker| v otherwise, cp = 0 | |
| 143 | // +-----------------+---- | |
| 144 | // 4+cp | | ^ Callee |
| 145 | // |- - - - - - - - -| | frame slots |
| 146 | // ... | | Frame slots (slot >= 0) |
| 147 | // |- - - - - - - - -| | | |
| 148 | // | | v | |
| 149 | // -----+-----------------+----- <-- stack ptr ------------- |
| 150 | // |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 151 | |
| 152 | class StandardFrameConstants : public AllStatic { |
| 153 | public: |
| 154 | // Fixed part of the frame consists of return address, caller fp, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 155 | // constant pool (if FLAG_enable_embedded_constant_pool), context, and |
| 156 | // function. StandardFrame::IterateExpressions assumes that kLastObjectOffset |
| 157 | // is the last object pointer. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 158 | static const int kCPSlotSize = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 159 | FLAG_enable_embedded_constant_pool ? kPointerSize : 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 160 | static const int kFixedFrameSizeFromFp = 2 * kPointerSize + kCPSlotSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 161 | static const int kFixedFrameSizeAboveFp = kPCOnStackSize + kFPOnStackSize; |
| 162 | static const int kFixedFrameSize = |
| 163 | kFixedFrameSizeAboveFp + kFixedFrameSizeFromFp; |
| 164 | static const int kFixedSlotCountAboveFp = |
| 165 | kFixedFrameSizeAboveFp / kPointerSize; |
| 166 | static const int kFixedSlotCount = kFixedFrameSize / kPointerSize; |
| 167 | static const int kCPSlotCount = kCPSlotSize / kPointerSize; |
| 168 | static const int kExpressionsOffset = -3 * kPointerSize - kCPSlotSize; |
| 169 | static const int kMarkerOffset = -2 * kPointerSize - kCPSlotSize; |
| 170 | static const int kContextOffset = -1 * kPointerSize - kCPSlotSize; |
| 171 | static const int kConstantPoolOffset = kCPSlotSize ? -1 * kPointerSize : 0; |
| 172 | static const int kCallerFPOffset = 0 * kPointerSize; |
| 173 | static const int kCallerPCOffset = +1 * kFPOnStackSize; |
| 174 | static const int kCallerSPOffset = kCallerPCOffset + 1 * kPCOnStackSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 175 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 176 | static const int kLastObjectOffset = kContextOffset; |
| 177 | }; |
| 178 | |
| 179 | |
| 180 | class ArgumentsAdaptorFrameConstants : public AllStatic { |
| 181 | public: |
| 182 | // FP-relative. |
| 183 | static const int kLengthOffset = StandardFrameConstants::kExpressionsOffset; |
| 184 | |
| 185 | static const int kFrameSize = |
| 186 | StandardFrameConstants::kFixedFrameSize + kPointerSize; |
| 187 | }; |
| 188 | |
| 189 | |
| 190 | class InternalFrameConstants : public AllStatic { |
| 191 | public: |
| 192 | // FP-relative. |
| 193 | static const int kCodeOffset = StandardFrameConstants::kExpressionsOffset; |
| 194 | }; |
| 195 | |
| 196 | |
| 197 | class ConstructFrameConstants : public AllStatic { |
| 198 | public: |
| 199 | // FP-relative. |
| 200 | static const int kImplicitReceiverOffset = |
| 201 | StandardFrameConstants::kExpressionsOffset - 3 * kPointerSize; |
| 202 | static const int kLengthOffset = |
| 203 | StandardFrameConstants::kExpressionsOffset - 2 * kPointerSize; |
| 204 | static const int kAllocationSiteOffset = |
| 205 | StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize; |
| 206 | static const int kCodeOffset = |
| 207 | StandardFrameConstants::kExpressionsOffset - 0 * kPointerSize; |
| 208 | |
| 209 | static const int kFrameSize = |
| 210 | StandardFrameConstants::kFixedFrameSize + 4 * kPointerSize; |
| 211 | }; |
| 212 | |
| 213 | |
| 214 | class InterpreterFrameConstants : public AllStatic { |
| 215 | public: |
| 216 | // Fixed frame includes new.target and bytecode offset. |
| 217 | static const int kFixedFrameSize = |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 218 | StandardFrameConstants::kFixedFrameSize + 3 * kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 219 | static const int kFixedFrameSizeFromFp = |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 220 | StandardFrameConstants::kFixedFrameSizeFromFp + 3 * kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 221 | |
| 222 | // FP-relative. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 223 | static const int kNewTargetFromFp = |
| 224 | -StandardFrameConstants::kFixedFrameSizeFromFp - 1 * kPointerSize; |
| 225 | static const int kBytecodeArrayFromFp = |
| 226 | -StandardFrameConstants::kFixedFrameSizeFromFp - 2 * kPointerSize; |
| 227 | static const int kBytecodeOffsetFromFp = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 228 | -StandardFrameConstants::kFixedFrameSizeFromFp - 3 * kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 229 | static const int kRegisterFilePointerFromFp = |
| 230 | -StandardFrameConstants::kFixedFrameSizeFromFp - 4 * kPointerSize; |
| 231 | |
| 232 | static const int kExpressionsOffset = kRegisterFilePointerFromFp; |
| 233 | |
| 234 | // Expression index for {StandardFrame::GetExpressionAddress}. |
| 235 | static const int kBytecodeArrayExpressionIndex = -2; |
| 236 | static const int kBytecodeOffsetExpressionIndex = -1; |
| 237 | static const int kRegisterFileExpressionIndex = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 238 | |
| 239 | // Register file pointer relative. |
| 240 | static const int kLastParamFromRegisterPointer = |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 241 | StandardFrameConstants::kFixedFrameSize + 4 * kPointerSize; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 242 | |
| 243 | static const int kBytecodeOffsetFromRegisterPointer = 1 * kPointerSize; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 244 | static const int kBytecodeArrayFromRegisterPointer = 2 * kPointerSize; |
| 245 | static const int kNewTargetFromRegisterPointer = 3 * kPointerSize; |
| 246 | static const int kFunctionFromRegisterPointer = 4 * kPointerSize; |
| 247 | static const int kContextFromRegisterPointer = 5 * kPointerSize; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 248 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 249 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 250 | inline static int FPOffsetToFrameSlot(int frame_offset) { |
| 251 | return StandardFrameConstants::kFixedSlotCountAboveFp - 1 - |
| 252 | frame_offset / kPointerSize; |
| 253 | } |
| 254 | |
| 255 | inline static int FrameSlotToFPOffset(int slot) { |
| 256 | return (StandardFrameConstants::kFixedSlotCountAboveFp - 1 - slot) * |
| 257 | kPointerSize; |
| 258 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 259 | |
| 260 | // Abstract base class for all stack frames. |
| 261 | class StackFrame BASE_EMBEDDED { |
| 262 | public: |
| 263 | #define DECLARE_TYPE(type, ignore) type, |
| 264 | enum Type { |
| 265 | NONE = 0, |
| 266 | STACK_FRAME_TYPE_LIST(DECLARE_TYPE) |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 267 | NUMBER_OF_TYPES, |
| 268 | // Used by FrameScope to indicate that the stack frame is constructed |
| 269 | // manually and the FrameScope does not need to emit code. |
| 270 | MANUAL |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 271 | }; |
| 272 | #undef DECLARE_TYPE |
| 273 | |
| 274 | // Opaque data type for identifying stack frames. Used extensively |
| 275 | // by the debugger. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 276 | // ID_MIN_VALUE and ID_MAX_VALUE are specified to ensure that enumeration type |
| 277 | // has correct value range (see Issue 830 for more details). |
| 278 | enum Id { |
| 279 | ID_MIN_VALUE = kMinInt, |
| 280 | ID_MAX_VALUE = kMaxInt, |
| 281 | NO_ID = 0 |
| 282 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 283 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 284 | // Used to mark the outermost JS entry frame. |
| 285 | enum JsFrameMarker { |
| 286 | INNER_JSENTRY_FRAME = 0, |
| 287 | OUTERMOST_JSENTRY_FRAME = 1 |
| 288 | }; |
| 289 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 290 | struct State { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 291 | State() : sp(NULL), fp(NULL), pc_address(NULL), |
| 292 | constant_pool_address(NULL) { } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 293 | Address sp; |
| 294 | Address fp; |
| 295 | Address* pc_address; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 296 | Address* constant_pool_address; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 297 | }; |
| 298 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 299 | // Copy constructor; it breaks the connection to host iterator |
| 300 | // (as an iterator usually lives on stack). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 301 | StackFrame(const StackFrame& original) { |
| 302 | this->state_ = original.state_; |
| 303 | this->iterator_ = NULL; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 304 | this->isolate_ = original.isolate_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 305 | } |
| 306 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 307 | // Type testers. |
| 308 | bool is_entry() const { return type() == ENTRY; } |
| 309 | bool is_entry_construct() const { return type() == ENTRY_CONSTRUCT; } |
| 310 | bool is_exit() const { return type() == EXIT; } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 311 | bool is_optimized() const { return type() == OPTIMIZED; } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 312 | bool is_interpreted() const { return type() == INTERPRETED; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | bool is_arguments_adaptor() const { return type() == ARGUMENTS_ADAPTOR; } |
| 314 | bool is_internal() const { return type() == INTERNAL; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 315 | bool is_stub_failure_trampoline() const { |
| 316 | return type() == STUB_FAILURE_TRAMPOLINE; |
| 317 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 318 | bool is_construct() const { return type() == CONSTRUCT; } |
| 319 | virtual bool is_standard() const { return false; } |
| 320 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 321 | bool is_java_script() const { |
| 322 | Type type = this->type(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 323 | return (type == JAVA_SCRIPT) || (type == OPTIMIZED) || |
| 324 | (type == INTERPRETED); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | // Accessors. |
| 328 | Address sp() const { return state_.sp; } |
| 329 | Address fp() const { return state_.fp; } |
| 330 | Address caller_sp() const { return GetCallerStackPointer(); } |
| 331 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 332 | // If this frame is optimized and was dynamically aligned return its old |
| 333 | // unaligned frame pointer. When the frame is deoptimized its FP will shift |
| 334 | // up one word and become unaligned. |
| 335 | Address UnpaddedFP() const; |
| 336 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 337 | Address pc() const { return *pc_address(); } |
| 338 | void set_pc(Address pc) { *pc_address() = pc; } |
| 339 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 340 | Address constant_pool() const { return *constant_pool_address(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 341 | void set_constant_pool(Address constant_pool) { |
| 342 | *constant_pool_address() = constant_pool; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 345 | virtual void SetCallerFp(Address caller_fp) = 0; |
| 346 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 347 | // Manually changes value of fp in this object. |
| 348 | void UpdateFp(Address fp) { state_.fp = fp; } |
| 349 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 350 | Address* pc_address() const { return state_.pc_address; } |
| 351 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 352 | Address* constant_pool_address() const { |
| 353 | return state_.constant_pool_address; |
| 354 | } |
| 355 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 356 | // Get the id of this stack frame. |
| 357 | Id id() const { return static_cast<Id>(OffsetFrom(caller_sp())); } |
| 358 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 359 | // Get the top handler from the current stack iterator. |
| 360 | inline StackHandler* top_handler() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 361 | |
| 362 | // Get the type of this frame. |
| 363 | virtual Type type() const = 0; |
| 364 | |
| 365 | // Get the code associated with this frame. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 366 | // This method could be called during marking phase of GC. |
| 367 | virtual Code* unchecked_code() const = 0; |
| 368 | |
| 369 | // Get the code associated with this frame. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 370 | inline Code* LookupCode() const; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 371 | |
| 372 | // Get the code object that contains the given pc. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 373 | static inline Code* GetContainingCode(Isolate* isolate, Address pc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 374 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 375 | // Get the code object containing the given pc and fill in the |
| 376 | // safepoint entry and the number of stack slots. The pc must be at |
| 377 | // a safepoint. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 378 | static Code* GetSafepointData(Isolate* isolate, |
| 379 | Address pc, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 380 | SafepointEntry* safepoint_entry, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 381 | unsigned* stack_slots); |
| 382 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 383 | virtual void Iterate(ObjectVisitor* v) const = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 384 | static void IteratePc(ObjectVisitor* v, Address* pc_address, |
| 385 | Address* constant_pool_address, Code* holder); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 386 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 387 | // Sets a callback function for return-address rewriting profilers |
| 388 | // to resolve the location of a return address to the location of the |
| 389 | // profiler's stashed return address. |
| 390 | static void SetReturnAddressLocationResolver( |
| 391 | ReturnAddressLocationResolver resolver); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 392 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 393 | // Resolves pc_address through the resolution address function if one is set. |
| 394 | static inline Address* ResolveReturnAddressLocation(Address* pc_address); |
| 395 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 396 | // Printing support. |
| 397 | enum PrintMode { OVERVIEW, DETAILS }; |
| 398 | virtual void Print(StringStream* accumulator, |
| 399 | PrintMode mode, |
| 400 | int index) const { } |
| 401 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 402 | Isolate* isolate() const { return isolate_; } |
| 403 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 404 | protected: |
| 405 | inline explicit StackFrame(StackFrameIteratorBase* iterator); |
| 406 | virtual ~StackFrame() { } |
| 407 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 408 | // Compute the stack pointer for the calling frame. |
| 409 | virtual Address GetCallerStackPointer() const = 0; |
| 410 | |
| 411 | // Printing support. |
| 412 | static void PrintIndex(StringStream* accumulator, |
| 413 | PrintMode mode, |
| 414 | int index); |
| 415 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 416 | // Compute the stack frame type for the given state. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 417 | static Type ComputeType(const StackFrameIteratorBase* iterator, State* state); |
| 418 | |
| 419 | #ifdef DEBUG |
| 420 | bool can_access_heap_objects() const; |
| 421 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 422 | |
| 423 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 424 | const StackFrameIteratorBase* iterator_; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 425 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 426 | State state_; |
| 427 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 428 | static ReturnAddressLocationResolver return_address_location_resolver_; |
| 429 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 430 | // Fill in the state of the calling frame. |
| 431 | virtual void ComputeCallerState(State* state) const = 0; |
| 432 | |
| 433 | // Get the type and the state of the calling frame. |
| 434 | virtual Type GetCallerState(State* state) const; |
| 435 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 436 | static const intptr_t kIsolateTag = 1; |
| 437 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 438 | friend class StackFrameIterator; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 439 | friend class StackFrameIteratorBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 440 | friend class StackHandlerIterator; |
| 441 | friend class SafeStackFrameIterator; |
| 442 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 443 | private: |
| 444 | void operator=(const StackFrame& original); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | |
| 448 | // Entry frames are used to enter JavaScript execution from C. |
| 449 | class EntryFrame: public StackFrame { |
| 450 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 451 | Type type() const override { return ENTRY; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 452 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 453 | Code* unchecked_code() const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 454 | |
| 455 | // Garbage collection support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 456 | void Iterate(ObjectVisitor* v) const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 457 | |
| 458 | static EntryFrame* cast(StackFrame* frame) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 459 | DCHECK(frame->is_entry()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 460 | return static_cast<EntryFrame*>(frame); |
| 461 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 462 | void SetCallerFp(Address caller_fp) override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 463 | |
| 464 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 465 | inline explicit EntryFrame(StackFrameIteratorBase* iterator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 466 | |
| 467 | // The caller stack pointer for entry frames is always zero. The |
| 468 | // real information about the caller frame is available through the |
| 469 | // link to the top exit frame. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 470 | Address GetCallerStackPointer() const override { return 0; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 471 | |
| 472 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 473 | void ComputeCallerState(State* state) const override; |
| 474 | Type GetCallerState(State* state) const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 475 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 476 | friend class StackFrameIteratorBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 477 | }; |
| 478 | |
| 479 | |
| 480 | class EntryConstructFrame: public EntryFrame { |
| 481 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 482 | Type type() const override { return ENTRY_CONSTRUCT; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 483 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 484 | Code* unchecked_code() const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 485 | |
| 486 | static EntryConstructFrame* cast(StackFrame* frame) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 487 | DCHECK(frame->is_entry_construct()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 488 | return static_cast<EntryConstructFrame*>(frame); |
| 489 | } |
| 490 | |
| 491 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 492 | inline explicit EntryConstructFrame(StackFrameIteratorBase* iterator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 493 | |
| 494 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 495 | friend class StackFrameIteratorBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 496 | }; |
| 497 | |
| 498 | |
| 499 | // Exit frames are used to exit JavaScript execution and go to C. |
| 500 | class ExitFrame: public StackFrame { |
| 501 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 502 | Type type() const override { return EXIT; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 503 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 504 | Code* unchecked_code() const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 505 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 506 | Object*& code_slot() const; |
| 507 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 508 | // Garbage collection support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 509 | void Iterate(ObjectVisitor* v) const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 510 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 511 | void SetCallerFp(Address caller_fp) override; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 512 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 513 | static ExitFrame* cast(StackFrame* frame) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 514 | DCHECK(frame->is_exit()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 515 | return static_cast<ExitFrame*>(frame); |
| 516 | } |
| 517 | |
| 518 | // Compute the state and type of an exit frame given a frame |
| 519 | // pointer. Used when constructing the first stack frame seen by an |
| 520 | // iterator and the frames following entry frames. |
| 521 | static Type GetStateForFramePointer(Address fp, State* state); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 522 | static Address ComputeStackPointer(Address fp); |
| 523 | static void FillState(Address fp, Address sp, State* state); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 524 | |
| 525 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 526 | inline explicit ExitFrame(StackFrameIteratorBase* iterator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 527 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 528 | Address GetCallerStackPointer() const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 529 | |
| 530 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 531 | void ComputeCallerState(State* state) const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 532 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 533 | friend class StackFrameIteratorBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 534 | }; |
| 535 | |
| 536 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 537 | class StandardFrame: public StackFrame { |
| 538 | public: |
| 539 | // Testers. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 540 | bool is_standard() const override { return true; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 541 | |
| 542 | // Accessors. |
| 543 | inline Object* context() const; |
| 544 | |
| 545 | // Access the expressions in the stack frame including locals. |
| 546 | inline Object* GetExpression(int index) const; |
| 547 | inline void SetExpression(int index, Object* value); |
| 548 | int ComputeExpressionsCount() const; |
| 549 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 550 | void SetCallerFp(Address caller_fp) override; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 551 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 552 | static StandardFrame* cast(StackFrame* frame) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 553 | DCHECK(frame->is_standard()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 554 | return static_cast<StandardFrame*>(frame); |
| 555 | } |
| 556 | |
| 557 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 558 | inline explicit StandardFrame(StackFrameIteratorBase* iterator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 559 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 560 | void ComputeCallerState(State* state) const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 561 | |
| 562 | // Accessors. |
| 563 | inline Address caller_fp() const; |
| 564 | inline Address caller_pc() const; |
| 565 | |
| 566 | // Computes the address of the PC field in the standard frame given |
| 567 | // by the provided frame pointer. |
| 568 | static inline Address ComputePCAddress(Address fp); |
| 569 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 570 | // Computes the address of the constant pool field in the standard |
| 571 | // frame given by the provided frame pointer. |
| 572 | static inline Address ComputeConstantPoolAddress(Address fp); |
| 573 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 574 | // Iterate over expression stack including stack handlers, locals, |
| 575 | // and parts of the fixed part including context and code fields. |
| 576 | void IterateExpressions(ObjectVisitor* v) const; |
| 577 | |
| 578 | // Returns the address of the n'th expression stack element. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 579 | virtual Address GetExpressionAddress(int n) const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 580 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 581 | // Determines if the standard frame for the given frame pointer is |
| 582 | // an arguments adaptor frame. |
| 583 | static inline bool IsArgumentsAdaptorFrame(Address fp); |
| 584 | |
| 585 | // Determines if the standard frame for the given frame pointer is a |
| 586 | // construct frame. |
| 587 | static inline bool IsConstructFrame(Address fp); |
| 588 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 589 | // Used by OptimizedFrames and StubFrames. |
| 590 | void IterateCompiledFrame(ObjectVisitor* v) const; |
| 591 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 592 | private: |
| 593 | friend class StackFrame; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 594 | friend class SafeStackFrameIterator; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 595 | }; |
| 596 | |
| 597 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 598 | class FrameSummary BASE_EMBEDDED { |
| 599 | public: |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 600 | FrameSummary(Object* receiver, JSFunction* function, |
| 601 | AbstractCode* abstract_code, int code_offset, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 602 | bool is_constructor); |
| 603 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 604 | Handle<Object> receiver() { return receiver_; } |
| 605 | Handle<JSFunction> function() { return function_; } |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 606 | Handle<AbstractCode> abstract_code() { return abstract_code_; } |
| 607 | int code_offset() { return code_offset_; } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 608 | bool is_constructor() { return is_constructor_; } |
| 609 | |
| 610 | void Print(); |
| 611 | |
| 612 | private: |
| 613 | Handle<Object> receiver_; |
| 614 | Handle<JSFunction> function_; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 615 | Handle<AbstractCode> abstract_code_; |
| 616 | int code_offset_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 617 | bool is_constructor_; |
| 618 | }; |
| 619 | |
| 620 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 621 | class JavaScriptFrame: public StandardFrame { |
| 622 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 623 | Type type() const override { return JAVA_SCRIPT; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 624 | |
| 625 | // Accessors. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 626 | inline JSFunction* function() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 627 | inline Object* receiver() const; |
| 628 | inline void set_receiver(Object* value); |
| 629 | |
| 630 | // Access the parameters. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 631 | inline Address GetParameterSlot(int index) const; |
| 632 | inline Object* GetParameter(int index) const; |
| 633 | inline int ComputeParametersCount() const { |
| 634 | return GetNumberOfIncomingArguments(); |
| 635 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 636 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 637 | // Access the operand stack. |
| 638 | inline Address GetOperandSlot(int index) const; |
| 639 | inline Object* GetOperand(int index) const; |
| 640 | inline int ComputeOperandsCount() const; |
| 641 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 642 | // Generator support to preserve operand stack. |
| 643 | void SaveOperandStack(FixedArray* store) const; |
| 644 | void RestoreOperandStack(FixedArray* store); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 645 | |
| 646 | // Debugger access. |
| 647 | void SetParameterValue(int index, Object* value) const; |
| 648 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 649 | // Check if this frame is a constructor frame invoked through 'new'. |
| 650 | bool IsConstructor() const; |
| 651 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 652 | // Determines whether this frame includes inlined activations. To get details |
| 653 | // about the inlined frames use {GetFunctions} and {Summarize}. |
| 654 | bool HasInlinedFrames() const; |
| 655 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 656 | // Check if this frame has "adapted" arguments in the sense that the |
| 657 | // actual passed arguments are available in an arguments adaptor |
| 658 | // frame below it on the stack. |
| 659 | inline bool has_adapted_arguments() const; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 660 | int GetArgumentsLength() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 661 | |
| 662 | // Garbage collection support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 663 | void Iterate(ObjectVisitor* v) const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 664 | |
| 665 | // Printing support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 666 | void Print(StringStream* accumulator, PrintMode mode, |
| 667 | int index) const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 668 | |
| 669 | // Determine the code for the frame. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 670 | Code* unchecked_code() const override; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 671 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 672 | // Return a list with JSFunctions of this frame. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 673 | virtual void GetFunctions(List<JSFunction*>* functions) const; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 674 | |
| 675 | // Build a list with summaries for this frame including all inlined frames. |
| 676 | virtual void Summarize(List<FrameSummary>* frames); |
| 677 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 678 | // Lookup exception handler for current {pc}, returns -1 if none found. Also |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 679 | // returns data associated with the handler site specific to the frame type: |
| 680 | // - JavaScriptFrame : Data is the stack depth at entry of the try-block. |
| 681 | // - OptimizedFrame : Data is the stack slot count of the entire frame. |
| 682 | // - InterpretedFrame: Data is the register index holding the context. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 683 | virtual int LookupExceptionHandlerInTable( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 684 | int* data, HandlerTable::CatchPrediction* prediction); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 685 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 686 | // Architecture-specific register description. |
| 687 | static Register fp_register(); |
| 688 | static Register context_register(); |
| 689 | static Register constant_pool_pointer_register(); |
| 690 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 691 | static JavaScriptFrame* cast(StackFrame* frame) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 692 | DCHECK(frame->is_java_script()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 693 | return static_cast<JavaScriptFrame*>(frame); |
| 694 | } |
| 695 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 696 | static void PrintFunctionAndOffset(JSFunction* function, Code* code, |
| 697 | Address pc, FILE* file, |
| 698 | bool print_line_number); |
| 699 | |
| 700 | static void PrintTop(Isolate* isolate, FILE* file, bool print_args, |
| 701 | bool print_line_number); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 702 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 703 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 704 | inline explicit JavaScriptFrame(StackFrameIteratorBase* iterator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 705 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 706 | Address GetCallerStackPointer() const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 707 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 708 | virtual int GetNumberOfIncomingArguments() const; |
| 709 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 710 | // Garbage collection support. Iterates over incoming arguments, |
| 711 | // receiver, and any callee-saved registers. |
| 712 | void IterateArguments(ObjectVisitor* v) const; |
| 713 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 714 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 715 | inline Object* function_slot_object() const; |
| 716 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 717 | friend class StackFrameIteratorBase; |
| 718 | }; |
| 719 | |
| 720 | |
| 721 | class StubFrame : public StandardFrame { |
| 722 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 723 | Type type() const override { return STUB; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 724 | |
| 725 | // GC support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 726 | void Iterate(ObjectVisitor* v) const override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 727 | |
| 728 | // Determine the code for the frame. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 729 | Code* unchecked_code() const override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 730 | |
| 731 | protected: |
| 732 | inline explicit StubFrame(StackFrameIteratorBase* iterator); |
| 733 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 734 | Address GetCallerStackPointer() const override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 735 | |
| 736 | virtual int GetNumberOfIncomingArguments() const; |
| 737 | |
| 738 | friend class StackFrameIteratorBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 739 | }; |
| 740 | |
| 741 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 742 | class OptimizedFrame : public JavaScriptFrame { |
| 743 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 744 | Type type() const override { return OPTIMIZED; } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 745 | |
| 746 | // GC support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 747 | void Iterate(ObjectVisitor* v) const override; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 748 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 749 | // Return a list with JSFunctions of this frame. |
| 750 | // The functions are ordered bottom-to-top (i.e. functions.last() |
| 751 | // is the top-most activation) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 752 | void GetFunctions(List<JSFunction*>* functions) const override; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 753 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 754 | void Summarize(List<FrameSummary>* frames) override; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 755 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 756 | // Lookup exception handler for current {pc}, returns -1 if none found. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 757 | int LookupExceptionHandlerInTable( |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 758 | int* data, HandlerTable::CatchPrediction* prediction) override; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 759 | |
| 760 | DeoptimizationInputData* GetDeoptimizationData(int* deopt_index) const; |
| 761 | |
| 762 | static int StackSlotOffsetRelativeToFp(int slot_index); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 763 | |
| 764 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 765 | inline explicit OptimizedFrame(StackFrameIteratorBase* iterator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 766 | |
| 767 | private: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 768 | friend class StackFrameIteratorBase; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 769 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 770 | Object* StackSlotAt(int index) const; |
| 771 | }; |
| 772 | |
| 773 | |
| 774 | class InterpretedFrame : public JavaScriptFrame { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 775 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 776 | Type type() const override { return INTERPRETED; } |
| 777 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 778 | // Lookup exception handler for current {pc}, returns -1 if none found. |
| 779 | int LookupExceptionHandlerInTable( |
| 780 | int* data, HandlerTable::CatchPrediction* prediction) override; |
| 781 | |
| 782 | // Returns the current offset into the bytecode stream. |
| 783 | int GetBytecodeOffset() const; |
| 784 | |
| 785 | // Updates the current offset into the bytecode stream, mainly used for stack |
| 786 | // unwinding to continue execution at a different bytecode offset. |
| 787 | void PatchBytecodeOffset(int new_offset); |
| 788 | |
| 789 | // Returns the frame's current bytecode array. |
| 790 | Object* GetBytecodeArray() const; |
| 791 | |
| 792 | // Updates the frame's BytecodeArray with |bytecode_array|. Used by the |
| 793 | // debugger to swap execution onto a BytecodeArray patched with breakpoints. |
| 794 | void PatchBytecodeArray(Object* bytecode_array); |
| 795 | |
| 796 | // Access to the interpreter register file for this frame. |
| 797 | Object* GetInterpreterRegister(int register_index) const; |
| 798 | |
| 799 | // Build a list with summaries for this frame including all inlined frames. |
| 800 | void Summarize(List<FrameSummary>* frames) override; |
| 801 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 802 | protected: |
| 803 | inline explicit InterpretedFrame(StackFrameIteratorBase* iterator); |
| 804 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 805 | Address GetExpressionAddress(int n) const override; |
| 806 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 807 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 808 | friend class StackFrameIteratorBase; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 809 | }; |
| 810 | |
| 811 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 812 | // Arguments adaptor frames are automatically inserted below |
| 813 | // JavaScript frames when the actual number of parameters does not |
| 814 | // match the formal number of parameters. |
| 815 | class ArgumentsAdaptorFrame: public JavaScriptFrame { |
| 816 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 817 | Type type() const override { return ARGUMENTS_ADAPTOR; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 818 | |
| 819 | // Determine the code for the frame. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 820 | Code* unchecked_code() const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 821 | |
| 822 | static ArgumentsAdaptorFrame* cast(StackFrame* frame) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 823 | DCHECK(frame->is_arguments_adaptor()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 824 | return static_cast<ArgumentsAdaptorFrame*>(frame); |
| 825 | } |
| 826 | |
| 827 | // Printing support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 828 | void Print(StringStream* accumulator, PrintMode mode, |
| 829 | int index) const override; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 830 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 831 | static int GetLength(Address fp); |
| 832 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 833 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 834 | inline explicit ArgumentsAdaptorFrame(StackFrameIteratorBase* iterator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 835 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 836 | int GetNumberOfIncomingArguments() const override; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 837 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 838 | Address GetCallerStackPointer() const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 839 | |
| 840 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 841 | friend class StackFrameIteratorBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 842 | }; |
| 843 | |
| 844 | |
| 845 | class InternalFrame: public StandardFrame { |
| 846 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 847 | Type type() const override { return INTERNAL; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 848 | |
| 849 | // Garbage collection support. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 850 | void Iterate(ObjectVisitor* v) const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 851 | |
| 852 | // Determine the code for the frame. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 853 | Code* unchecked_code() const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 854 | |
| 855 | static InternalFrame* cast(StackFrame* frame) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 856 | DCHECK(frame->is_internal()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 857 | return static_cast<InternalFrame*>(frame); |
| 858 | } |
| 859 | |
| 860 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 861 | inline explicit InternalFrame(StackFrameIteratorBase* iterator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 862 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 863 | Address GetCallerStackPointer() const override; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 864 | |
| 865 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 866 | friend class StackFrameIteratorBase; |
| 867 | }; |
| 868 | |
| 869 | |
| 870 | class StubFailureTrampolineFrame: public StandardFrame { |
| 871 | public: |
| 872 | // sizeof(Arguments) - sizeof(Arguments*) is 3 * kPointerSize), but the |
| 873 | // presubmit script complains about using sizeof() on a type. |
| 874 | static const int kFirstRegisterParameterFrameOffset = |
| 875 | StandardFrameConstants::kMarkerOffset - 3 * kPointerSize; |
| 876 | |
| 877 | static const int kCallerStackParameterCountFrameOffset = |
| 878 | StandardFrameConstants::kMarkerOffset - 2 * kPointerSize; |
| 879 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 880 | Type type() const override { return STUB_FAILURE_TRAMPOLINE; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 881 | |
| 882 | // Get the code associated with this frame. |
| 883 | // This method could be called during marking phase of GC. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 884 | Code* unchecked_code() const override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 885 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 886 | void Iterate(ObjectVisitor* v) const override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 887 | |
| 888 | // Architecture-specific register description. |
| 889 | static Register fp_register(); |
| 890 | static Register context_register(); |
| 891 | static Register constant_pool_pointer_register(); |
| 892 | |
| 893 | protected: |
| 894 | inline explicit StubFailureTrampolineFrame( |
| 895 | StackFrameIteratorBase* iterator); |
| 896 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 897 | Address GetCallerStackPointer() const override; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 898 | |
| 899 | private: |
| 900 | friend class StackFrameIteratorBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 901 | }; |
| 902 | |
| 903 | |
| 904 | // Construct frames are special trampoline frames introduced to handle |
| 905 | // function invocations through 'new'. |
| 906 | class ConstructFrame: public InternalFrame { |
| 907 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 908 | Type type() const override { return CONSTRUCT; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 909 | |
| 910 | static ConstructFrame* cast(StackFrame* frame) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 911 | DCHECK(frame->is_construct()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 912 | return static_cast<ConstructFrame*>(frame); |
| 913 | } |
| 914 | |
| 915 | protected: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 916 | inline explicit ConstructFrame(StackFrameIteratorBase* iterator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 917 | |
| 918 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 919 | friend class StackFrameIteratorBase; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 920 | }; |
| 921 | |
| 922 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 923 | class StackFrameIteratorBase BASE_EMBEDDED { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 924 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 925 | Isolate* isolate() const { return isolate_; } |
| 926 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 927 | bool done() const { return frame_ == NULL; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 928 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 929 | protected: |
| 930 | // An iterator that iterates over a given thread's stack. |
| 931 | StackFrameIteratorBase(Isolate* isolate, bool can_access_heap_objects); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 932 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 933 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 934 | #define DECLARE_SINGLETON(ignore, type) type type##_; |
| 935 | STACK_FRAME_TYPE_LIST(DECLARE_SINGLETON) |
| 936 | #undef DECLARE_SINGLETON |
| 937 | StackFrame* frame_; |
| 938 | StackHandler* handler_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 939 | const bool can_access_heap_objects_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 940 | |
| 941 | StackHandler* handler() const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 942 | DCHECK(!done()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 943 | return handler_; |
| 944 | } |
| 945 | |
| 946 | // Get the type-specific frame singleton in a given state. |
| 947 | StackFrame* SingletonFor(StackFrame::Type type, StackFrame::State* state); |
| 948 | // A helper function, can return a NULL pointer. |
| 949 | StackFrame* SingletonFor(StackFrame::Type type); |
| 950 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 951 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 952 | friend class StackFrame; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 953 | DISALLOW_COPY_AND_ASSIGN(StackFrameIteratorBase); |
| 954 | }; |
| 955 | |
| 956 | |
| 957 | class StackFrameIterator: public StackFrameIteratorBase { |
| 958 | public: |
| 959 | // An iterator that iterates over the isolate's current thread's stack, |
| 960 | explicit StackFrameIterator(Isolate* isolate); |
| 961 | // An iterator that iterates over a given thread's stack. |
| 962 | StackFrameIterator(Isolate* isolate, ThreadLocalTop* t); |
| 963 | |
| 964 | StackFrame* frame() const { |
| 965 | DCHECK(!done()); |
| 966 | return frame_; |
| 967 | } |
| 968 | void Advance(); |
| 969 | |
| 970 | private: |
| 971 | // Go back to the first frame. |
| 972 | void Reset(ThreadLocalTop* top); |
| 973 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 974 | DISALLOW_COPY_AND_ASSIGN(StackFrameIterator); |
| 975 | }; |
| 976 | |
| 977 | |
| 978 | // Iterator that supports iterating through all JavaScript frames. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 979 | class JavaScriptFrameIterator BASE_EMBEDDED { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 980 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 981 | inline explicit JavaScriptFrameIterator(Isolate* isolate); |
| 982 | inline JavaScriptFrameIterator(Isolate* isolate, ThreadLocalTop* top); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 983 | // Skip frames until the frame with the given id is reached. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 984 | JavaScriptFrameIterator(Isolate* isolate, StackFrame::Id id); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 985 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 986 | inline JavaScriptFrame* frame() const; |
| 987 | |
| 988 | bool done() const { return iterator_.done(); } |
| 989 | void Advance(); |
| 990 | |
| 991 | // Advance to the frame holding the arguments for the current |
| 992 | // frame. This only affects the current frame if it has adapted |
| 993 | // arguments. |
| 994 | void AdvanceToArgumentsFrame(); |
| 995 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 996 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 997 | StackFrameIterator iterator_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 998 | }; |
| 999 | |
| 1000 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1001 | // NOTE: The stack trace frame iterator is an iterator that only |
| 1002 | // traverse proper JavaScript frames; that is JavaScript frames that |
| 1003 | // have proper JavaScript functions. This excludes the problematic |
| 1004 | // functions in runtime.js. |
| 1005 | class StackTraceFrameIterator: public JavaScriptFrameIterator { |
| 1006 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1007 | explicit StackTraceFrameIterator(Isolate* isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1008 | void Advance(); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1009 | |
| 1010 | private: |
| 1011 | bool IsValidFrame(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1012 | }; |
| 1013 | |
| 1014 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1015 | class SafeStackFrameIterator: public StackFrameIteratorBase { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1016 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1017 | SafeStackFrameIterator(Isolate* isolate, |
| 1018 | Address fp, Address sp, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1019 | Address js_entry_sp); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1020 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1021 | inline StackFrame* frame() const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1022 | void Advance(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1023 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1024 | StackFrame::Type top_frame_type() const { return top_frame_type_; } |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1025 | |
| 1026 | private: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1027 | void AdvanceOneFrame(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1028 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1029 | bool IsValidStackAddress(Address addr) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1030 | return low_bound_ <= addr && addr <= high_bound_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1031 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1032 | bool IsValidFrame(StackFrame* frame) const; |
| 1033 | bool IsValidCaller(StackFrame* frame); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1034 | bool IsValidExitFrame(Address fp) const; |
| 1035 | bool IsValidTop(ThreadLocalTop* top) const; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1036 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1037 | const Address low_bound_; |
| 1038 | const Address high_bound_; |
| 1039 | StackFrame::Type top_frame_type_; |
| 1040 | ExternalCallbackScope* external_callback_scope_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1041 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1042 | |
| 1043 | |
| 1044 | class StackFrameLocator BASE_EMBEDDED { |
| 1045 | public: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1046 | explicit StackFrameLocator(Isolate* isolate) : iterator_(isolate) {} |
| 1047 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1048 | // Find the nth JavaScript frame on the stack. The caller must |
| 1049 | // guarantee that such a frame exists. |
| 1050 | JavaScriptFrame* FindJavaScriptFrame(int n); |
| 1051 | |
| 1052 | private: |
| 1053 | StackFrameIterator iterator_; |
| 1054 | }; |
| 1055 | |
| 1056 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1057 | // Reads all frames on the current stack and copies them into the current |
| 1058 | // zone memory. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1059 | Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1060 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1061 | } // namespace internal |
| 1062 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1063 | |
| 1064 | #endif // V8_FRAMES_H_ |