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