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