whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_FRAMES_H_ |
| 29 | #define V8_FRAMES_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 32 | #include "handles.h" |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 33 | #include "safepoint-table.h" |
| 34 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 35 | namespace v8 { |
| 36 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | |
| 38 | typedef uint32_t RegList; |
| 39 | |
| 40 | // Get the number of registers in a given register list. |
| 41 | int NumRegs(RegList list); |
| 42 | |
| 43 | // Return the code of the n-th saved register available to JavaScript. |
| 44 | int JSCallerSavedCode(int n); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | // Forward declarations. |
| 48 | class StackFrameIterator; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | class ThreadLocalTop; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 50 | class Isolate; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 52 | class InnerPointerToCodeCache { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 53 | public: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 54 | struct InnerPointerToCodeCacheEntry { |
| 55 | Address inner_pointer; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 56 | Code* code; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 57 | SafepointEntry safepoint_entry; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 60 | explicit InnerPointerToCodeCache(Isolate* isolate) : isolate_(isolate) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 61 | Flush(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 62 | } |
| 63 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 64 | Code* GcSafeFindCodeForInnerPointer(Address inner_pointer); |
| 65 | Code* GcSafeCastToCode(HeapObject* object, Address inner_pointer); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 66 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 67 | void Flush() { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 68 | memset(&cache_[0], 0, sizeof(cache_)); |
| 69 | } |
| 70 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 71 | InnerPointerToCodeCacheEntry* GetCacheEntry(Address inner_pointer); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 72 | |
| 73 | private: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 74 | InnerPointerToCodeCacheEntry* cache(int index) { return &cache_[index]; } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 75 | |
| 76 | Isolate* isolate_; |
| 77 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 78 | static const int kInnerPointerToCodeCacheSize = 1024; |
| 79 | InnerPointerToCodeCacheEntry cache_[kInnerPointerToCodeCacheSize]; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 80 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(InnerPointerToCodeCache); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 85 | class StackHandler BASE_EMBEDDED { |
| 86 | public: |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 87 | enum Kind { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | ENTRY, |
| 89 | TRY_CATCH, |
| 90 | TRY_FINALLY |
| 91 | }; |
| 92 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 93 | static const int kKindWidth = 2; |
| 94 | static const int kOffsetWidth = 32 - kKindWidth; |
| 95 | class KindField: public BitField<StackHandler::Kind, 0, kKindWidth> {}; |
| 96 | class OffsetField: public BitField<unsigned, kKindWidth, kOffsetWidth> {}; |
| 97 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 98 | // Get the address of this stack handler. |
| 99 | inline Address address() const; |
| 100 | |
| 101 | // Get the next stack handler in the chain. |
| 102 | inline StackHandler* next() const; |
| 103 | |
| 104 | // Tells whether the given address is inside this handler. |
| 105 | inline bool includes(Address address) const; |
| 106 | |
| 107 | // Garbage collection support. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 108 | inline void Iterate(ObjectVisitor* v, Code* holder) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 109 | |
| 110 | // Conversion support. |
| 111 | static inline StackHandler* FromAddress(Address address); |
| 112 | |
| 113 | // Testers |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 114 | inline bool is_entry() const; |
| 115 | inline bool is_try_catch() const; |
| 116 | inline bool is_try_finally() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 118 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | // Accessors. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 120 | inline Kind kind() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 121 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 122 | inline Object** context_address() const; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 123 | inline Object** code_address() const; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 124 | |
| 125 | DISALLOW_IMPLICIT_CONSTRUCTORS(StackHandler); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | |
| 129 | #define STACK_FRAME_TYPE_LIST(V) \ |
| 130 | V(ENTRY, EntryFrame) \ |
| 131 | V(ENTRY_CONSTRUCT, EntryConstructFrame) \ |
| 132 | V(EXIT, ExitFrame) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | V(JAVA_SCRIPT, JavaScriptFrame) \ |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 134 | V(OPTIMIZED, OptimizedFrame) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | V(INTERNAL, InternalFrame) \ |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 136 | V(CONSTRUCT, ConstructFrame) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 137 | V(ARGUMENTS_ADAPTOR, ArgumentsAdaptorFrame) |
| 138 | |
| 139 | |
| 140 | // Abstract base class for all stack frames. |
| 141 | class StackFrame BASE_EMBEDDED { |
| 142 | public: |
| 143 | #define DECLARE_TYPE(type, ignore) type, |
| 144 | enum Type { |
| 145 | NONE = 0, |
| 146 | STACK_FRAME_TYPE_LIST(DECLARE_TYPE) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 147 | NUMBER_OF_TYPES, |
| 148 | // Used by FrameScope to indicate that the stack frame is constructed |
| 149 | // manually and the FrameScope does not need to emit code. |
| 150 | MANUAL |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 151 | }; |
| 152 | #undef DECLARE_TYPE |
| 153 | |
| 154 | // Opaque data type for identifying stack frames. Used extensively |
| 155 | // by the debugger. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 156 | // ID_MIN_VALUE and ID_MAX_VALUE are specified to ensure that enumeration type |
| 157 | // has correct value range (see Issue 830 for more details). |
| 158 | enum Id { |
| 159 | ID_MIN_VALUE = kMinInt, |
| 160 | ID_MAX_VALUE = kMaxInt, |
| 161 | NO_ID = 0 |
| 162 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 163 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 164 | // Used to mark the outermost JS entry frame. |
| 165 | enum JsFrameMarker { |
| 166 | INNER_JSENTRY_FRAME = 0, |
| 167 | OUTERMOST_JSENTRY_FRAME = 1 |
| 168 | }; |
| 169 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 170 | struct State { |
| 171 | State() : sp(NULL), fp(NULL), pc_address(NULL) { } |
| 172 | Address sp; |
| 173 | Address fp; |
| 174 | Address* pc_address; |
| 175 | }; |
| 176 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 177 | // Copy constructor; it breaks the connection to host iterator |
| 178 | // (as an iterator usually lives on stack). |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 179 | StackFrame(const StackFrame& original) { |
| 180 | this->state_ = original.state_; |
| 181 | this->iterator_ = NULL; |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 182 | this->isolate_ = original.isolate_; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 183 | } |
| 184 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 185 | // Type testers. |
| 186 | bool is_entry() const { return type() == ENTRY; } |
| 187 | bool is_entry_construct() const { return type() == ENTRY_CONSTRUCT; } |
| 188 | bool is_exit() const { return type() == EXIT; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 189 | bool is_optimized() const { return type() == OPTIMIZED; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 190 | bool is_arguments_adaptor() const { return type() == ARGUMENTS_ADAPTOR; } |
| 191 | bool is_internal() const { return type() == INTERNAL; } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 192 | bool is_construct() const { return type() == CONSTRUCT; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | virtual bool is_standard() const { return false; } |
| 194 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 195 | bool is_java_script() const { |
| 196 | Type type = this->type(); |
| 197 | return (type == JAVA_SCRIPT) || (type == OPTIMIZED); |
| 198 | } |
| 199 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 200 | // Accessors. |
| 201 | Address sp() const { return state_.sp; } |
| 202 | Address fp() const { return state_.fp; } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 203 | Address caller_sp() const { return GetCallerStackPointer(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | |
| 205 | Address pc() const { return *pc_address(); } |
| 206 | void set_pc(Address pc) { *pc_address() = pc; } |
| 207 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 208 | virtual void SetCallerFp(Address caller_fp) = 0; |
| 209 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 210 | Address* pc_address() const { return state_.pc_address; } |
| 211 | |
| 212 | // Get the id of this stack frame. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 213 | Id id() const { return static_cast<Id>(OffsetFrom(caller_sp())); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 214 | |
| 215 | // Checks if this frame includes any stack handlers. |
| 216 | bool HasHandler() const; |
| 217 | |
| 218 | // Get the type of this frame. |
| 219 | virtual Type type() const = 0; |
| 220 | |
| 221 | // Get the code associated with this frame. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 222 | // This method could be called during marking phase of GC. |
| 223 | virtual Code* unchecked_code() const = 0; |
| 224 | |
| 225 | // Get the code associated with this frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 226 | inline Code* LookupCode() const; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 227 | |
| 228 | // Get the code object that contains the given pc. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 229 | static inline Code* GetContainingCode(Isolate* isolate, Address pc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 230 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 231 | // Get the code object containing the given pc and fill in the |
| 232 | // safepoint entry and the number of stack slots. The pc must be at |
| 233 | // a safepoint. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 234 | static Code* GetSafepointData(Isolate* isolate, |
| 235 | Address pc, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 236 | SafepointEntry* safepoint_entry, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 237 | unsigned* stack_slots); |
| 238 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 239 | virtual void Iterate(ObjectVisitor* v) const = 0; |
| 240 | static void IteratePc(ObjectVisitor* v, Address* pc_address, Code* holder); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 241 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 242 | |
| 243 | // Printing support. |
| 244 | enum PrintMode { OVERVIEW, DETAILS }; |
| 245 | virtual void Print(StringStream* accumulator, |
| 246 | PrintMode mode, |
| 247 | int index) const { } |
| 248 | |
| 249 | protected: |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 250 | inline explicit StackFrame(StackFrameIterator* iterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | virtual ~StackFrame() { } |
| 252 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 253 | Isolate* isolate() const { return isolate_; } |
| 254 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | // Compute the stack pointer for the calling frame. |
| 256 | virtual Address GetCallerStackPointer() const = 0; |
| 257 | |
| 258 | // Printing support. |
| 259 | static void PrintIndex(StringStream* accumulator, |
| 260 | PrintMode mode, |
| 261 | int index); |
| 262 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 263 | // Get the top handler from the current stack iterator. |
| 264 | inline StackHandler* top_handler() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | |
| 266 | // Compute the stack frame type for the given state. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 267 | static Type ComputeType(Isolate* isolate, State* state); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 268 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | private: |
| 270 | const StackFrameIterator* iterator_; |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 271 | Isolate* isolate_; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 272 | State state_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 273 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 274 | // Fill in the state of the calling frame. |
| 275 | virtual void ComputeCallerState(State* state) const = 0; |
| 276 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | // Get the type and the state of the calling frame. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 278 | virtual Type GetCallerState(State* state) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 279 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 280 | static const intptr_t kIsolateTag = 1; |
| 281 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 282 | friend class StackFrameIterator; |
| 283 | friend class StackHandlerIterator; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 284 | friend class SafeStackFrameIterator; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 285 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 286 | private: |
| 287 | void operator=(const StackFrame& original); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | |
| 291 | // Entry frames are used to enter JavaScript execution from C. |
| 292 | class EntryFrame: public StackFrame { |
| 293 | public: |
| 294 | virtual Type type() const { return ENTRY; } |
| 295 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 296 | virtual Code* unchecked_code() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 297 | |
| 298 | // Garbage collection support. |
| 299 | virtual void Iterate(ObjectVisitor* v) const; |
| 300 | |
| 301 | static EntryFrame* cast(StackFrame* frame) { |
| 302 | ASSERT(frame->is_entry()); |
| 303 | return static_cast<EntryFrame*>(frame); |
| 304 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 305 | virtual void SetCallerFp(Address caller_fp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 306 | |
| 307 | protected: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 308 | inline explicit EntryFrame(StackFrameIterator* iterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 309 | |
| 310 | // The caller stack pointer for entry frames is always zero. The |
| 311 | // real information about the caller frame is available through the |
| 312 | // link to the top exit frame. |
| 313 | virtual Address GetCallerStackPointer() const { return 0; } |
| 314 | |
| 315 | private: |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 316 | virtual void ComputeCallerState(State* state) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 317 | virtual Type GetCallerState(State* state) const; |
| 318 | |
| 319 | friend class StackFrameIterator; |
| 320 | }; |
| 321 | |
| 322 | |
| 323 | class EntryConstructFrame: public EntryFrame { |
| 324 | public: |
| 325 | virtual Type type() const { return ENTRY_CONSTRUCT; } |
| 326 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 327 | virtual Code* unchecked_code() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 328 | |
| 329 | static EntryConstructFrame* cast(StackFrame* frame) { |
| 330 | ASSERT(frame->is_entry_construct()); |
| 331 | return static_cast<EntryConstructFrame*>(frame); |
| 332 | } |
| 333 | |
| 334 | protected: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 335 | inline explicit EntryConstructFrame(StackFrameIterator* iterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 336 | |
| 337 | private: |
| 338 | friend class StackFrameIterator; |
| 339 | }; |
| 340 | |
| 341 | |
| 342 | // Exit frames are used to exit JavaScript execution and go to C. |
| 343 | class ExitFrame: public StackFrame { |
| 344 | public: |
| 345 | virtual Type type() const { return EXIT; } |
| 346 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 347 | virtual Code* unchecked_code() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 348 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 349 | Object*& code_slot() const; |
| 350 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 351 | // Garbage collection support. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 352 | virtual void Iterate(ObjectVisitor* v) const; |
| 353 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 354 | virtual void SetCallerFp(Address caller_fp); |
| 355 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 356 | static ExitFrame* cast(StackFrame* frame) { |
| 357 | ASSERT(frame->is_exit()); |
| 358 | return static_cast<ExitFrame*>(frame); |
| 359 | } |
| 360 | |
| 361 | // Compute the state and type of an exit frame given a frame |
| 362 | // pointer. Used when constructing the first stack frame seen by an |
| 363 | // iterator and the frames following entry frames. |
| 364 | static Type GetStateForFramePointer(Address fp, State* state); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 365 | static Address ComputeStackPointer(Address fp); |
| 366 | static void FillState(Address fp, Address sp, State* state); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 367 | |
| 368 | protected: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 369 | inline explicit ExitFrame(StackFrameIterator* iterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 370 | |
| 371 | virtual Address GetCallerStackPointer() const; |
| 372 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 373 | private: |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 374 | virtual void ComputeCallerState(State* state) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 375 | |
| 376 | friend class StackFrameIterator; |
| 377 | }; |
| 378 | |
| 379 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 380 | class StandardFrame: public StackFrame { |
| 381 | public: |
| 382 | // Testers. |
| 383 | virtual bool is_standard() const { return true; } |
| 384 | |
| 385 | // Accessors. |
| 386 | inline Object* context() const; |
| 387 | |
| 388 | // Access the expressions in the stack frame including locals. |
| 389 | inline Object* GetExpression(int index) const; |
| 390 | inline void SetExpression(int index, Object* value); |
| 391 | int ComputeExpressionsCount() const; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 392 | static Object* GetExpression(Address fp, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 393 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 394 | virtual void SetCallerFp(Address caller_fp); |
| 395 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 396 | static StandardFrame* cast(StackFrame* frame) { |
| 397 | ASSERT(frame->is_standard()); |
| 398 | return static_cast<StandardFrame*>(frame); |
| 399 | } |
| 400 | |
| 401 | protected: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 402 | inline explicit StandardFrame(StackFrameIterator* iterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 403 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 404 | virtual void ComputeCallerState(State* state) const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 405 | |
| 406 | // Accessors. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 407 | inline Address caller_fp() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 408 | inline Address caller_pc() const; |
| 409 | |
| 410 | // Computes the address of the PC field in the standard frame given |
| 411 | // by the provided frame pointer. |
| 412 | static inline Address ComputePCAddress(Address fp); |
| 413 | |
| 414 | // Iterate over expression stack including stack handlers, locals, |
| 415 | // and parts of the fixed part including context and code fields. |
| 416 | void IterateExpressions(ObjectVisitor* v) const; |
| 417 | |
| 418 | // Returns the address of the n'th expression stack element. |
| 419 | Address GetExpressionAddress(int n) const; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 420 | static Address GetExpressionAddress(Address fp, int n); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 421 | |
| 422 | // Determines if the n'th expression stack element is in a stack |
| 423 | // handler or not. Requires traversing all handlers in this frame. |
| 424 | bool IsExpressionInsideHandler(int n) const; |
| 425 | |
| 426 | // Determines if the standard frame for the given frame pointer is |
| 427 | // an arguments adaptor frame. |
| 428 | static inline bool IsArgumentsAdaptorFrame(Address fp); |
| 429 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 430 | // Determines if the standard frame for the given frame pointer is a |
| 431 | // construct frame. |
| 432 | static inline bool IsConstructFrame(Address fp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | |
| 434 | private: |
| 435 | friend class StackFrame; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 436 | friend class StackFrameIterator; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | }; |
| 438 | |
| 439 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 440 | class FrameSummary BASE_EMBEDDED { |
| 441 | public: |
| 442 | FrameSummary(Object* receiver, |
| 443 | JSFunction* function, |
| 444 | Code* code, |
| 445 | int offset, |
| 446 | bool is_constructor) |
| 447 | : receiver_(receiver), |
| 448 | function_(function), |
| 449 | code_(code), |
| 450 | offset_(offset), |
| 451 | is_constructor_(is_constructor) { } |
| 452 | Handle<Object> receiver() { return receiver_; } |
| 453 | Handle<JSFunction> function() { return function_; } |
| 454 | Handle<Code> code() { return code_; } |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 455 | Address pc() { return code_->address() + offset_; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 456 | int offset() { return offset_; } |
| 457 | bool is_constructor() { return is_constructor_; } |
| 458 | |
| 459 | void Print(); |
| 460 | |
| 461 | private: |
| 462 | Handle<Object> receiver_; |
| 463 | Handle<JSFunction> function_; |
| 464 | Handle<Code> code_; |
| 465 | int offset_; |
| 466 | bool is_constructor_; |
| 467 | }; |
| 468 | |
| 469 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 470 | class JavaScriptFrame: public StandardFrame { |
| 471 | public: |
| 472 | virtual Type type() const { return JAVA_SCRIPT; } |
| 473 | |
| 474 | // Accessors. |
| 475 | inline Object* function() const; |
| 476 | inline Object* receiver() const; |
| 477 | inline void set_receiver(Object* value); |
| 478 | |
| 479 | // Access the parameters. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 480 | inline Address GetParameterSlot(int index) const; |
| 481 | inline Object* GetParameter(int index) const; |
| 482 | inline int ComputeParametersCount() const { |
| 483 | return GetNumberOfIncomingArguments(); |
| 484 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 485 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 486 | // Check if this frame is a constructor frame invoked through 'new'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 487 | bool IsConstructor() const; |
| 488 | |
| 489 | // Check if this frame has "adapted" arguments in the sense that the |
| 490 | // actual passed arguments are available in an arguments adaptor |
| 491 | // frame below it on the stack. |
| 492 | inline bool has_adapted_arguments() const; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 493 | int GetArgumentsLength() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 494 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 495 | // Garbage collection support. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | virtual void Iterate(ObjectVisitor* v) const; |
| 497 | |
| 498 | // Printing support. |
| 499 | virtual void Print(StringStream* accumulator, |
| 500 | PrintMode mode, |
| 501 | int index) const; |
| 502 | |
| 503 | // Determine the code for the frame. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 504 | virtual Code* unchecked_code() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 505 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 506 | // Returns the levels of inlining for this frame. |
| 507 | virtual int GetInlineCount() { return 1; } |
| 508 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 509 | // Return a list with JSFunctions of this frame. |
| 510 | virtual void GetFunctions(List<JSFunction*>* functions); |
| 511 | |
| 512 | // Build a list with summaries for this frame including all inlined frames. |
| 513 | virtual void Summarize(List<FrameSummary>* frames); |
| 514 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 515 | static JavaScriptFrame* cast(StackFrame* frame) { |
| 516 | ASSERT(frame->is_java_script()); |
| 517 | return static_cast<JavaScriptFrame*>(frame); |
| 518 | } |
| 519 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 520 | static void PrintTop(FILE* file, bool print_args, bool print_line_number); |
| 521 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 522 | protected: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 523 | inline explicit JavaScriptFrame(StackFrameIterator* iterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 524 | |
| 525 | virtual Address GetCallerStackPointer() const; |
| 526 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 527 | virtual int GetNumberOfIncomingArguments() const; |
| 528 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 529 | // Garbage collection support. Iterates over incoming arguments, |
| 530 | // receiver, and any callee-saved registers. |
| 531 | void IterateArguments(ObjectVisitor* v) const; |
| 532 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | private: |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 534 | inline Object* function_slot_object() const; |
| 535 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 536 | friend class StackFrameIterator; |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 537 | friend class StackTracer; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | }; |
| 539 | |
| 540 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 541 | class OptimizedFrame : public JavaScriptFrame { |
| 542 | public: |
| 543 | virtual Type type() const { return OPTIMIZED; } |
| 544 | |
| 545 | // GC support. |
| 546 | virtual void Iterate(ObjectVisitor* v) const; |
| 547 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 548 | virtual int GetInlineCount(); |
| 549 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 550 | // Return a list with JSFunctions of this frame. |
| 551 | // The functions are ordered bottom-to-top (i.e. functions.last() |
| 552 | // is the top-most activation) |
| 553 | virtual void GetFunctions(List<JSFunction*>* functions); |
| 554 | |
| 555 | virtual void Summarize(List<FrameSummary>* frames); |
| 556 | |
| 557 | DeoptimizationInputData* GetDeoptimizationData(int* deopt_index); |
| 558 | |
| 559 | protected: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 560 | inline explicit OptimizedFrame(StackFrameIterator* iterator); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 561 | |
| 562 | private: |
| 563 | friend class StackFrameIterator; |
| 564 | }; |
| 565 | |
| 566 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 567 | // Arguments adaptor frames are automatically inserted below |
| 568 | // JavaScript frames when the actual number of parameters does not |
| 569 | // match the formal number of parameters. |
| 570 | class ArgumentsAdaptorFrame: public JavaScriptFrame { |
| 571 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 572 | virtual Type type() const { return ARGUMENTS_ADAPTOR; } |
| 573 | |
| 574 | // Determine the code for the frame. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 575 | virtual Code* unchecked_code() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 576 | |
| 577 | static ArgumentsAdaptorFrame* cast(StackFrame* frame) { |
| 578 | ASSERT(frame->is_arguments_adaptor()); |
| 579 | return static_cast<ArgumentsAdaptorFrame*>(frame); |
| 580 | } |
| 581 | |
| 582 | // Printing support. |
| 583 | virtual void Print(StringStream* accumulator, |
| 584 | PrintMode mode, |
| 585 | int index) const; |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 586 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 587 | protected: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 588 | inline explicit ArgumentsAdaptorFrame(StackFrameIterator* iterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 589 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 590 | virtual int GetNumberOfIncomingArguments() const; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 591 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 592 | virtual Address GetCallerStackPointer() const; |
| 593 | |
| 594 | private: |
| 595 | friend class StackFrameIterator; |
| 596 | }; |
| 597 | |
| 598 | |
| 599 | class InternalFrame: public StandardFrame { |
| 600 | public: |
| 601 | virtual Type type() const { return INTERNAL; } |
| 602 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 603 | // Garbage collection support. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 604 | virtual void Iterate(ObjectVisitor* v) const; |
| 605 | |
| 606 | // Determine the code for the frame. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 607 | virtual Code* unchecked_code() const; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 608 | |
| 609 | static InternalFrame* cast(StackFrame* frame) { |
| 610 | ASSERT(frame->is_internal()); |
| 611 | return static_cast<InternalFrame*>(frame); |
| 612 | } |
| 613 | |
| 614 | protected: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 615 | inline explicit InternalFrame(StackFrameIterator* iterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 616 | |
| 617 | virtual Address GetCallerStackPointer() const; |
| 618 | |
| 619 | private: |
| 620 | friend class StackFrameIterator; |
| 621 | }; |
| 622 | |
| 623 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 624 | // Construct frames are special trampoline frames introduced to handle |
| 625 | // function invocations through 'new'. |
| 626 | class ConstructFrame: public InternalFrame { |
| 627 | public: |
| 628 | virtual Type type() const { return CONSTRUCT; } |
| 629 | |
| 630 | static ConstructFrame* cast(StackFrame* frame) { |
| 631 | ASSERT(frame->is_construct()); |
| 632 | return static_cast<ConstructFrame*>(frame); |
| 633 | } |
| 634 | |
| 635 | protected: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 636 | inline explicit ConstructFrame(StackFrameIterator* iterator); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 637 | |
| 638 | private: |
| 639 | friend class StackFrameIterator; |
| 640 | }; |
| 641 | |
| 642 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 643 | class StackFrameIterator BASE_EMBEDDED { |
| 644 | public: |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 645 | // An iterator that iterates over the current thread's stack, |
| 646 | // and uses current isolate. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 647 | StackFrameIterator(); |
| 648 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 649 | // An iterator that iterates over the isolate's current thread's stack, |
| 650 | explicit StackFrameIterator(Isolate* isolate); |
| 651 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 652 | // An iterator that iterates over a given thread's stack. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 653 | StackFrameIterator(Isolate* isolate, ThreadLocalTop* t); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 655 | // An iterator that can start from a given FP address. |
| 656 | // If use_top, then work as usual, if fp isn't NULL, use it, |
| 657 | // otherwise, do nothing. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 658 | StackFrameIterator(Isolate* isolate, bool use_top, Address fp, Address sp); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 659 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 660 | StackFrame* frame() const { |
| 661 | ASSERT(!done()); |
| 662 | return frame_; |
| 663 | } |
| 664 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 665 | Isolate* isolate() const { return isolate_; } |
| 666 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 667 | bool done() const { return frame_ == NULL; } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 668 | void Advance() { (this->*advance_)(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 669 | |
| 670 | // Go back to the first frame. |
| 671 | void Reset(); |
| 672 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 673 | private: |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 674 | Isolate* isolate_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 675 | #define DECLARE_SINGLETON(ignore, type) type type##_; |
| 676 | STACK_FRAME_TYPE_LIST(DECLARE_SINGLETON) |
| 677 | #undef DECLARE_SINGLETON |
| 678 | StackFrame* frame_; |
| 679 | StackHandler* handler_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 680 | ThreadLocalTop* thread_; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 681 | Address fp_; |
| 682 | Address sp_; |
| 683 | void (StackFrameIterator::*advance_)(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 684 | |
| 685 | StackHandler* handler() const { |
| 686 | ASSERT(!done()); |
| 687 | return handler_; |
| 688 | } |
| 689 | |
| 690 | // Get the type-specific frame singleton in a given state. |
| 691 | StackFrame* SingletonFor(StackFrame::Type type, StackFrame::State* state); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 692 | // A helper function, can return a NULL pointer. |
| 693 | StackFrame* SingletonFor(StackFrame::Type type); |
| 694 | |
| 695 | void AdvanceWithHandler(); |
| 696 | void AdvanceWithoutHandler(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 697 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 698 | friend class StackFrame; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 699 | friend class SafeStackFrameIterator; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 700 | DISALLOW_COPY_AND_ASSIGN(StackFrameIterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 701 | }; |
| 702 | |
| 703 | |
| 704 | // Iterator that supports iterating through all JavaScript frames. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 705 | template<typename Iterator> |
| 706 | class JavaScriptFrameIteratorTemp BASE_EMBEDDED { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 707 | public: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 708 | JavaScriptFrameIteratorTemp() { if (!done()) Advance(); } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 709 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 710 | inline explicit JavaScriptFrameIteratorTemp(Isolate* isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 711 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 712 | inline JavaScriptFrameIteratorTemp(Isolate* isolate, ThreadLocalTop* top); |
| 713 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 714 | // Skip frames until the frame with the given id is reached. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 715 | explicit JavaScriptFrameIteratorTemp(StackFrame::Id id) { AdvanceToId(id); } |
| 716 | |
| 717 | inline JavaScriptFrameIteratorTemp(Isolate* isolate, StackFrame::Id id); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 718 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 719 | JavaScriptFrameIteratorTemp(Address fp, |
| 720 | Address sp, |
| 721 | Address low_bound, |
| 722 | Address high_bound) : |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 723 | iterator_(fp, sp, low_bound, high_bound) { |
| 724 | if (!done()) Advance(); |
| 725 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 726 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 727 | JavaScriptFrameIteratorTemp(Isolate* isolate, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 728 | Address fp, |
| 729 | Address sp, |
| 730 | Address low_bound, |
| 731 | Address high_bound) : |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 732 | iterator_(isolate, fp, sp, low_bound, high_bound) { |
| 733 | if (!done()) Advance(); |
| 734 | } |
| 735 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 736 | inline JavaScriptFrame* frame() const; |
| 737 | |
| 738 | bool done() const { return iterator_.done(); } |
| 739 | void Advance(); |
| 740 | |
| 741 | // Advance to the frame holding the arguments for the current |
| 742 | // frame. This only affects the current frame if it has adapted |
| 743 | // arguments. |
| 744 | void AdvanceToArgumentsFrame(); |
| 745 | |
| 746 | // Go back to the first frame. |
| 747 | void Reset(); |
| 748 | |
| 749 | private: |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 750 | inline void AdvanceToId(StackFrame::Id id); |
| 751 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 752 | Iterator iterator_; |
| 753 | }; |
| 754 | |
| 755 | |
| 756 | typedef JavaScriptFrameIteratorTemp<StackFrameIterator> JavaScriptFrameIterator; |
| 757 | |
| 758 | |
| 759 | // NOTE: The stack trace frame iterator is an iterator that only |
| 760 | // traverse proper JavaScript frames; that is JavaScript frames that |
| 761 | // have proper JavaScript functions. This excludes the problematic |
| 762 | // functions in runtime.js. |
| 763 | class StackTraceFrameIterator: public JavaScriptFrameIterator { |
| 764 | public: |
| 765 | StackTraceFrameIterator(); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 766 | explicit StackTraceFrameIterator(Isolate* isolate); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 767 | void Advance(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 768 | |
| 769 | private: |
| 770 | bool IsValidFrame(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 771 | }; |
| 772 | |
| 773 | |
| 774 | class SafeStackFrameIterator BASE_EMBEDDED { |
| 775 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 776 | SafeStackFrameIterator(Isolate* isolate, |
| 777 | Address fp, Address sp, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 778 | Address low_bound, Address high_bound); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 779 | |
| 780 | StackFrame* frame() const { |
| 781 | ASSERT(is_working_iterator_); |
| 782 | return iterator_.frame(); |
| 783 | } |
| 784 | |
| 785 | bool done() const { return iteration_done_ ? true : iterator_.done(); } |
| 786 | |
| 787 | void Advance(); |
| 788 | void Reset(); |
| 789 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 790 | static bool is_active(Isolate* isolate); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 791 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 792 | static bool IsWithinBounds( |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 793 | Address low_bound, Address high_bound, Address addr) { |
| 794 | return low_bound <= addr && addr <= high_bound; |
| 795 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 796 | |
| 797 | private: |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 798 | class StackAddressValidator { |
| 799 | public: |
| 800 | StackAddressValidator(Address low_bound, Address high_bound) |
| 801 | : low_bound_(low_bound), high_bound_(high_bound) { } |
| 802 | bool IsValid(Address addr) const { |
| 803 | return IsWithinBounds(low_bound_, high_bound_, addr); |
| 804 | } |
| 805 | private: |
| 806 | Address low_bound_; |
| 807 | Address high_bound_; |
| 808 | }; |
| 809 | |
| 810 | class ExitFrameValidator { |
| 811 | public: |
| 812 | explicit ExitFrameValidator(const StackAddressValidator& validator) |
| 813 | : validator_(validator) { } |
| 814 | ExitFrameValidator(Address low_bound, Address high_bound) |
| 815 | : validator_(low_bound, high_bound) { } |
| 816 | bool IsValidFP(Address fp); |
| 817 | private: |
| 818 | StackAddressValidator validator_; |
| 819 | }; |
| 820 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 821 | bool IsValidStackAddress(Address addr) const { |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 822 | return stack_validator_.IsValid(addr); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 823 | } |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 824 | bool CanIterateHandles(StackFrame* frame, StackHandler* handler); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 825 | bool IsValidFrame(StackFrame* frame) const; |
| 826 | bool IsValidCaller(StackFrame* frame); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 827 | static bool IsValidTop(Isolate* isolate, |
| 828 | Address low_bound, Address high_bound); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 829 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 830 | // This is a nasty hack to make sure the active count is incremented |
| 831 | // before the constructor for the embedded iterator is invoked. This |
| 832 | // is needed because the constructor will start looking at frames |
| 833 | // right away and we need to make sure it doesn't start inspecting |
| 834 | // heap objects. |
| 835 | class ActiveCountMaintainer BASE_EMBEDDED { |
| 836 | public: |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 837 | explicit ActiveCountMaintainer(Isolate* isolate); |
| 838 | ~ActiveCountMaintainer(); |
| 839 | private: |
| 840 | Isolate* isolate_; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 841 | }; |
| 842 | |
| 843 | ActiveCountMaintainer maintainer_; |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 844 | StackAddressValidator stack_validator_; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 845 | const bool is_valid_top_; |
| 846 | const bool is_valid_fp_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 847 | const bool is_working_iterator_; |
| 848 | bool iteration_done_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 849 | StackFrameIterator iterator_; |
| 850 | }; |
| 851 | |
| 852 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 853 | typedef JavaScriptFrameIteratorTemp<SafeStackFrameIterator> |
| 854 | SafeJavaScriptFrameIterator; |
| 855 | |
| 856 | |
| 857 | class SafeStackTraceFrameIterator: public SafeJavaScriptFrameIterator { |
| 858 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 859 | explicit SafeStackTraceFrameIterator(Isolate* isolate, |
| 860 | Address fp, Address sp, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 861 | Address low_bound, Address high_bound); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 862 | void Advance(); |
| 863 | }; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 864 | |
| 865 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 866 | class StackFrameLocator BASE_EMBEDDED { |
| 867 | public: |
| 868 | // Find the nth JavaScript frame on the stack. The caller must |
| 869 | // guarantee that such a frame exists. |
| 870 | JavaScriptFrame* FindJavaScriptFrame(int n); |
| 871 | |
| 872 | private: |
| 873 | StackFrameIterator iterator_; |
| 874 | }; |
| 875 | |
| 876 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 877 | // Reads all frames on the current stack and copies them into the current |
| 878 | // zone memory. |
| 879 | Vector<StackFrame*> CreateStackMap(); |
| 880 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 881 | } } // namespace v8::internal |
| 882 | |
| 883 | #endif // V8_FRAMES_H_ |