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