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