danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +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 | #include "v8.h" |
| 29 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 30 | #include "ast.h" |
| 31 | #include "deoptimizer.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "frames-inl.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 33 | #include "full-codegen.h" |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 34 | #include "mark-compact.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 35 | #include "safepoint-table.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | #include "scopeinfo.h" |
| 37 | #include "string-stream.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 38 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 39 | namespace v8 { |
| 40 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | // Iterator that supports traversing the stack handlers of a |
| 43 | // particular frame. Needs to know the top of the handler chain. |
| 44 | class StackHandlerIterator BASE_EMBEDDED { |
| 45 | public: |
| 46 | StackHandlerIterator(const StackFrame* frame, StackHandler* handler) |
| 47 | : limit_(frame->fp()), handler_(handler) { |
| 48 | // Make sure the handler has already been unwound to this frame. |
| 49 | ASSERT(frame->sp() <= handler->address()); |
| 50 | } |
| 51 | |
| 52 | StackHandler* handler() const { return handler_; } |
| 53 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 54 | bool done() { |
| 55 | return handler_ == NULL || handler_->address() > limit_; |
| 56 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | void Advance() { |
| 58 | ASSERT(!done()); |
| 59 | handler_ = handler_->next(); |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | const Address limit_; |
| 64 | StackHandler* handler_; |
| 65 | }; |
| 66 | |
| 67 | |
| 68 | // ------------------------------------------------------------------------- |
| 69 | |
| 70 | |
| 71 | #define INITIALIZE_SINGLETON(type, field) field##_(this), |
| 72 | StackFrameIterator::StackFrameIterator() |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 73 | : isolate_(Isolate::Current()), |
| 74 | STACK_FRAME_TYPE_LIST(INITIALIZE_SINGLETON) |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 75 | frame_(NULL), handler_(NULL), |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 76 | thread_(isolate_->thread_local_top()), |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 77 | fp_(NULL), sp_(NULL), advance_(&StackFrameIterator::AdvanceWithHandler) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | Reset(); |
| 79 | } |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 80 | StackFrameIterator::StackFrameIterator(Isolate* isolate) |
| 81 | : isolate_(isolate), |
| 82 | STACK_FRAME_TYPE_LIST(INITIALIZE_SINGLETON) |
| 83 | frame_(NULL), handler_(NULL), |
| 84 | thread_(isolate_->thread_local_top()), |
| 85 | fp_(NULL), sp_(NULL), advance_(&StackFrameIterator::AdvanceWithHandler) { |
| 86 | Reset(); |
| 87 | } |
| 88 | StackFrameIterator::StackFrameIterator(Isolate* isolate, ThreadLocalTop* t) |
| 89 | : isolate_(isolate), |
| 90 | STACK_FRAME_TYPE_LIST(INITIALIZE_SINGLETON) |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 91 | frame_(NULL), handler_(NULL), thread_(t), |
| 92 | fp_(NULL), sp_(NULL), advance_(&StackFrameIterator::AdvanceWithHandler) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 93 | Reset(); |
| 94 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 95 | StackFrameIterator::StackFrameIterator(Isolate* isolate, |
| 96 | bool use_top, Address fp, Address sp) |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 97 | : isolate_(isolate), |
| 98 | STACK_FRAME_TYPE_LIST(INITIALIZE_SINGLETON) |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 99 | frame_(NULL), handler_(NULL), |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 100 | thread_(use_top ? isolate_->thread_local_top() : NULL), |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 101 | fp_(use_top ? NULL : fp), sp_(sp), |
| 102 | advance_(use_top ? &StackFrameIterator::AdvanceWithHandler : |
| 103 | &StackFrameIterator::AdvanceWithoutHandler) { |
| 104 | if (use_top || fp != NULL) { |
| 105 | Reset(); |
| 106 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 107 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 108 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 109 | #undef INITIALIZE_SINGLETON |
| 110 | |
| 111 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 112 | void StackFrameIterator::AdvanceWithHandler() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | ASSERT(!done()); |
| 114 | // Compute the state of the calling frame before restoring |
| 115 | // callee-saved registers and unwinding handlers. This allows the |
| 116 | // frame code that computes the caller state to access the top |
| 117 | // handler and the value of any callee-saved register if needed. |
| 118 | StackFrame::State state; |
| 119 | StackFrame::Type type = frame_->GetCallerState(&state); |
| 120 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 121 | // Unwind handlers corresponding to the current frame. |
| 122 | StackHandlerIterator it(frame_, handler_); |
| 123 | while (!it.done()) it.Advance(); |
| 124 | handler_ = it.handler(); |
| 125 | |
| 126 | // Advance to the calling frame. |
| 127 | frame_ = SingletonFor(type, &state); |
| 128 | |
| 129 | // When we're done iterating over the stack frames, the handler |
| 130 | // chain must have been completely unwound. |
| 131 | ASSERT(!done() || handler_ == NULL); |
| 132 | } |
| 133 | |
| 134 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 135 | void StackFrameIterator::AdvanceWithoutHandler() { |
| 136 | // A simpler version of Advance which doesn't care about handler. |
| 137 | ASSERT(!done()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | StackFrame::State state; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 139 | StackFrame::Type type = frame_->GetCallerState(&state); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 140 | frame_ = SingletonFor(type, &state); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | void StackFrameIterator::Reset() { |
| 145 | StackFrame::State state; |
| 146 | StackFrame::Type type; |
| 147 | if (thread_ != NULL) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 148 | type = ExitFrame::GetStateForFramePointer( |
| 149 | Isolate::c_entry_fp(thread_), &state); |
| 150 | handler_ = StackHandler::FromAddress( |
| 151 | Isolate::handler(thread_)); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 152 | } else { |
| 153 | ASSERT(fp_ != NULL); |
| 154 | state.fp = fp_; |
| 155 | state.sp = sp_; |
| 156 | state.pc_address = |
| 157 | reinterpret_cast<Address*>(StandardFrame::ComputePCAddress(fp_)); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 158 | type = StackFrame::ComputeType(isolate(), &state); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 159 | } |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 160 | if (SingletonFor(type) == NULL) return; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 161 | frame_ = SingletonFor(type, &state); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | |
| 165 | StackFrame* StackFrameIterator::SingletonFor(StackFrame::Type type, |
| 166 | StackFrame::State* state) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 167 | if (type == StackFrame::NONE) return NULL; |
| 168 | StackFrame* result = SingletonFor(type); |
| 169 | ASSERT(result != NULL); |
| 170 | result->state_ = *state; |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | StackFrame* StackFrameIterator::SingletonFor(StackFrame::Type type) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 176 | #define FRAME_TYPE_CASE(type, field) \ |
| 177 | case StackFrame::type: result = &field##_; break; |
| 178 | |
| 179 | StackFrame* result = NULL; |
| 180 | switch (type) { |
| 181 | case StackFrame::NONE: return NULL; |
| 182 | STACK_FRAME_TYPE_LIST(FRAME_TYPE_CASE) |
| 183 | default: break; |
| 184 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 185 | return result; |
| 186 | |
| 187 | #undef FRAME_TYPE_CASE |
| 188 | } |
| 189 | |
| 190 | |
| 191 | // ------------------------------------------------------------------------- |
| 192 | |
| 193 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 194 | StackTraceFrameIterator::StackTraceFrameIterator() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 195 | if (!done() && !IsValidFrame()) Advance(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 199 | StackTraceFrameIterator::StackTraceFrameIterator(Isolate* isolate) |
| 200 | : JavaScriptFrameIterator(isolate) { |
| 201 | if (!done() && !IsValidFrame()) Advance(); |
| 202 | } |
| 203 | |
| 204 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 205 | void StackTraceFrameIterator::Advance() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | while (true) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 207 | JavaScriptFrameIterator::Advance(); |
| 208 | if (done()) return; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 209 | if (IsValidFrame()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 213 | bool StackTraceFrameIterator::IsValidFrame() { |
| 214 | if (!frame()->function()->IsJSFunction()) return false; |
| 215 | Object* script = JSFunction::cast(frame()->function())->shared()->script(); |
| 216 | // Don't show functions from native scripts to user. |
| 217 | return (script->IsScript() && |
| 218 | Script::TYPE_NATIVE != Script::cast(script)->type()->value()); |
| 219 | } |
| 220 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 221 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 222 | // ------------------------------------------------------------------------- |
| 223 | |
| 224 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 225 | bool SafeStackFrameIterator::ExitFrameValidator::IsValidFP(Address fp) { |
| 226 | if (!validator_.IsValid(fp)) return false; |
| 227 | Address sp = ExitFrame::ComputeStackPointer(fp); |
| 228 | if (!validator_.IsValid(sp)) return false; |
| 229 | StackFrame::State state; |
| 230 | ExitFrame::FillState(fp, sp, &state); |
| 231 | if (!validator_.IsValid(reinterpret_cast<Address>(state.pc_address))) { |
| 232 | return false; |
| 233 | } |
| 234 | return *state.pc_address != NULL; |
| 235 | } |
| 236 | |
| 237 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 238 | SafeStackFrameIterator::ActiveCountMaintainer::ActiveCountMaintainer( |
| 239 | Isolate* isolate) |
| 240 | : isolate_(isolate) { |
| 241 | isolate_->set_safe_stack_iterator_counter( |
| 242 | isolate_->safe_stack_iterator_counter() + 1); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | SafeStackFrameIterator::ActiveCountMaintainer::~ActiveCountMaintainer() { |
| 247 | isolate_->set_safe_stack_iterator_counter( |
| 248 | isolate_->safe_stack_iterator_counter() - 1); |
| 249 | } |
| 250 | |
| 251 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 252 | SafeStackFrameIterator::SafeStackFrameIterator( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 253 | Isolate* isolate, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 254 | Address fp, Address sp, Address low_bound, Address high_bound) : |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 255 | maintainer_(isolate), |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 256 | stack_validator_(low_bound, high_bound), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 257 | is_valid_top_(IsValidTop(isolate, low_bound, high_bound)), |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 258 | is_valid_fp_(IsWithinBounds(low_bound, high_bound, fp)), |
| 259 | is_working_iterator_(is_valid_top_ || is_valid_fp_), |
| 260 | iteration_done_(!is_working_iterator_), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 261 | iterator_(isolate, is_valid_top_, is_valid_fp_ ? fp : NULL, sp) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 262 | } |
| 263 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 264 | bool SafeStackFrameIterator::is_active(Isolate* isolate) { |
| 265 | return isolate->safe_stack_iterator_counter() > 0; |
| 266 | } |
| 267 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 268 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 269 | bool SafeStackFrameIterator::IsValidTop(Isolate* isolate, |
| 270 | Address low_bound, Address high_bound) { |
| 271 | ThreadLocalTop* top = isolate->thread_local_top(); |
| 272 | Address fp = Isolate::c_entry_fp(top); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 273 | ExitFrameValidator validator(low_bound, high_bound); |
| 274 | if (!validator.IsValidFP(fp)) return false; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 275 | return Isolate::handler(top) != NULL; |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 279 | void SafeStackFrameIterator::Advance() { |
| 280 | ASSERT(is_working_iterator_); |
| 281 | ASSERT(!done()); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 282 | StackFrame* last_frame = iterator_.frame(); |
| 283 | Address last_sp = last_frame->sp(), last_fp = last_frame->fp(); |
| 284 | // Before advancing to the next stack frame, perform pointer validity tests |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 285 | iteration_done_ = !IsValidFrame(last_frame) || |
| 286 | !CanIterateHandles(last_frame, iterator_.handler()) || |
| 287 | !IsValidCaller(last_frame); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 288 | if (iteration_done_) return; |
| 289 | |
| 290 | iterator_.Advance(); |
| 291 | if (iterator_.done()) return; |
| 292 | // Check that we have actually moved to the previous frame in the stack |
| 293 | StackFrame* prev_frame = iterator_.frame(); |
| 294 | iteration_done_ = prev_frame->sp() < last_sp || prev_frame->fp() < last_fp; |
| 295 | } |
| 296 | |
| 297 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 298 | bool SafeStackFrameIterator::CanIterateHandles(StackFrame* frame, |
| 299 | StackHandler* handler) { |
| 300 | // If StackIterator iterates over StackHandles, verify that |
| 301 | // StackHandlerIterator can be instantiated (see StackHandlerIterator |
| 302 | // constructor.) |
| 303 | return !is_valid_top_ || (frame->sp() <= handler->address()); |
| 304 | } |
| 305 | |
| 306 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 307 | bool SafeStackFrameIterator::IsValidFrame(StackFrame* frame) const { |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 308 | return IsValidStackAddress(frame->sp()) && IsValidStackAddress(frame->fp()); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | |
| 312 | bool SafeStackFrameIterator::IsValidCaller(StackFrame* frame) { |
| 313 | StackFrame::State state; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 314 | if (frame->is_entry() || frame->is_entry_construct()) { |
| 315 | // See EntryFrame::GetCallerState. It computes the caller FP address |
| 316 | // and calls ExitFrame::GetStateForFramePointer on it. We need to be |
| 317 | // sure that caller FP address is valid. |
| 318 | Address caller_fp = Memory::Address_at( |
| 319 | frame->fp() + EntryFrameConstants::kCallerFPOffset); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 320 | ExitFrameValidator validator(stack_validator_); |
| 321 | if (!validator.IsValidFP(caller_fp)) return false; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 322 | } else if (frame->is_arguments_adaptor()) { |
| 323 | // See ArgumentsAdaptorFrame::GetCallerStackPointer. It assumes that |
| 324 | // the number of arguments is stored on stack as Smi. We need to check |
| 325 | // that it really an Smi. |
| 326 | Object* number_of_args = reinterpret_cast<ArgumentsAdaptorFrame*>(frame)-> |
| 327 | GetExpression(0); |
| 328 | if (!number_of_args->IsSmi()) { |
| 329 | return false; |
| 330 | } |
| 331 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 332 | frame->ComputeCallerState(&state); |
| 333 | return IsValidStackAddress(state.sp) && IsValidStackAddress(state.fp) && |
| 334 | iterator_.SingletonFor(frame->GetCallerState(&state)) != NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 338 | void SafeStackFrameIterator::Reset() { |
| 339 | if (is_working_iterator_) { |
| 340 | iterator_.Reset(); |
| 341 | iteration_done_ = false; |
| 342 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 346 | // ------------------------------------------------------------------------- |
| 347 | |
| 348 | |
| 349 | #ifdef ENABLE_LOGGING_AND_PROFILING |
| 350 | SafeStackTraceFrameIterator::SafeStackTraceFrameIterator( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 351 | Isolate* isolate, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 352 | Address fp, Address sp, Address low_bound, Address high_bound) : |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 353 | SafeJavaScriptFrameIterator(isolate, fp, sp, low_bound, high_bound) { |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 354 | if (!done() && !frame()->is_java_script()) Advance(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 358 | void SafeStackTraceFrameIterator::Advance() { |
| 359 | while (true) { |
| 360 | SafeJavaScriptFrameIterator::Advance(); |
| 361 | if (done()) return; |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 362 | if (frame()->is_java_script()) return; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | #endif |
| 366 | |
| 367 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 368 | Code* StackFrame::GetSafepointData(Isolate* isolate, |
| 369 | Address pc, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 370 | SafepointEntry* safepoint_entry, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 371 | unsigned* stack_slots) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 372 | PcToCodeCache::PcToCodeCacheEntry* entry = |
| 373 | isolate->pc_to_code_cache()->GetCacheEntry(pc); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 374 | SafepointEntry cached_safepoint_entry = entry->safepoint_entry; |
| 375 | if (!entry->safepoint_entry.is_valid()) { |
| 376 | entry->safepoint_entry = entry->code->GetSafepointEntry(pc); |
| 377 | ASSERT(entry->safepoint_entry.is_valid()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 378 | } else { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 379 | ASSERT(entry->safepoint_entry.Equals(entry->code->GetSafepointEntry(pc))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | // Fill in the results and return the code. |
| 383 | Code* code = entry->code; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 384 | *safepoint_entry = entry->safepoint_entry; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 385 | *stack_slots = code->stack_slots(); |
| 386 | return code; |
| 387 | } |
| 388 | |
| 389 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 390 | bool StackFrame::HasHandler() const { |
| 391 | StackHandlerIterator it(this, top_handler()); |
| 392 | return !it.done(); |
| 393 | } |
| 394 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 395 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 396 | void StackFrame::IteratePc(ObjectVisitor* v, |
| 397 | Address* pc_address, |
| 398 | Code* holder) { |
| 399 | Address pc = *pc_address; |
| 400 | ASSERT(holder->contains(pc)); |
| 401 | unsigned pc_offset = static_cast<unsigned>(pc - holder->instruction_start()); |
| 402 | Object* code = holder; |
| 403 | v->VisitPointer(&code); |
| 404 | if (code != holder) { |
| 405 | holder = reinterpret_cast<Code*>(code); |
| 406 | pc = holder->instruction_start() + pc_offset; |
| 407 | *pc_address = pc; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 408 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 412 | StackFrame::Type StackFrame::ComputeType(Isolate* isolate, State* state) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 413 | ASSERT(state->fp != NULL); |
| 414 | if (StandardFrame::IsArgumentsAdaptorFrame(state->fp)) { |
| 415 | return ARGUMENTS_ADAPTOR; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 416 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 417 | // The marker and function offsets overlap. If the marker isn't a |
| 418 | // smi then the frame is a JavaScript frame -- and the marker is |
| 419 | // really the function. |
| 420 | const int offset = StandardFrameConstants::kMarkerOffset; |
| 421 | Object* marker = Memory::Object_at(state->fp + offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 422 | if (!marker->IsSmi()) { |
| 423 | // If we're using a "safe" stack iterator, we treat optimized |
| 424 | // frames as normal JavaScript frames to avoid having to look |
| 425 | // into the heap to determine the state. This is safe as long |
| 426 | // as nobody tries to GC... |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 427 | if (SafeStackFrameIterator::is_active(isolate)) return JAVA_SCRIPT; |
| 428 | Code::Kind kind = GetContainingCode(isolate, *(state->pc_address))->kind(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 429 | ASSERT(kind == Code::FUNCTION || kind == Code::OPTIMIZED_FUNCTION); |
| 430 | return (kind == Code::OPTIMIZED_FUNCTION) ? OPTIMIZED : JAVA_SCRIPT; |
| 431 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 432 | return static_cast<StackFrame::Type>(Smi::cast(marker)->value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 436 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 437 | StackFrame::Type StackFrame::GetCallerState(State* state) const { |
| 438 | ComputeCallerState(state); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 439 | return ComputeType(isolate(), state); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 443 | Code* EntryFrame::unchecked_code() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 444 | return HEAP->raw_unchecked_js_entry_code(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 448 | void EntryFrame::ComputeCallerState(State* state) const { |
| 449 | GetCallerState(state); |
| 450 | } |
| 451 | |
| 452 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 453 | void EntryFrame::SetCallerFp(Address caller_fp) { |
| 454 | const int offset = EntryFrameConstants::kCallerFPOffset; |
| 455 | Memory::Address_at(this->fp() + offset) = caller_fp; |
| 456 | } |
| 457 | |
| 458 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 459 | StackFrame::Type EntryFrame::GetCallerState(State* state) const { |
| 460 | const int offset = EntryFrameConstants::kCallerFPOffset; |
| 461 | Address fp = Memory::Address_at(this->fp() + offset); |
| 462 | return ExitFrame::GetStateForFramePointer(fp, state); |
| 463 | } |
| 464 | |
| 465 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 466 | Code* EntryConstructFrame::unchecked_code() const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 467 | return HEAP->raw_unchecked_js_construct_entry_code(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 471 | Object*& ExitFrame::code_slot() const { |
| 472 | const int offset = ExitFrameConstants::kCodeOffset; |
| 473 | return Memory::Object_at(fp() + offset); |
| 474 | } |
| 475 | |
| 476 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 477 | Code* ExitFrame::unchecked_code() const { |
| 478 | return reinterpret_cast<Code*>(code_slot()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 482 | void ExitFrame::ComputeCallerState(State* state) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 483 | // Setup the caller state. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 484 | state->sp = caller_sp(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 485 | state->fp = Memory::Address_at(fp() + ExitFrameConstants::kCallerFPOffset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 486 | state->pc_address |
| 487 | = reinterpret_cast<Address*>(fp() + ExitFrameConstants::kCallerPCOffset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 491 | void ExitFrame::SetCallerFp(Address caller_fp) { |
| 492 | Memory::Address_at(fp() + ExitFrameConstants::kCallerFPOffset) = caller_fp; |
| 493 | } |
| 494 | |
| 495 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 496 | void ExitFrame::Iterate(ObjectVisitor* v) const { |
| 497 | // The arguments are traversed as part of the expression stack of |
| 498 | // the calling frame. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 499 | IteratePc(v, pc_address(), LookupCode()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 500 | v->VisitPointer(&code_slot()); |
| 501 | } |
| 502 | |
| 503 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 504 | Address ExitFrame::GetCallerStackPointer() const { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 505 | return fp() + ExitFrameConstants::kCallerSPDisplacement; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 509 | StackFrame::Type ExitFrame::GetStateForFramePointer(Address fp, State* state) { |
| 510 | if (fp == 0) return NONE; |
| 511 | Address sp = ComputeStackPointer(fp); |
| 512 | FillState(fp, sp, state); |
| 513 | ASSERT(*state->pc_address != NULL); |
| 514 | return EXIT; |
| 515 | } |
| 516 | |
| 517 | |
| 518 | void ExitFrame::FillState(Address fp, Address sp, State* state) { |
| 519 | state->sp = sp; |
| 520 | state->fp = fp; |
| 521 | state->pc_address = reinterpret_cast<Address*>(sp - 1 * kPointerSize); |
| 522 | } |
| 523 | |
| 524 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | Address StandardFrame::GetExpressionAddress(int n) const { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 526 | const int offset = StandardFrameConstants::kExpressionsOffset; |
| 527 | return fp() + offset - n * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | |
| 531 | int StandardFrame::ComputeExpressionsCount() const { |
| 532 | const int offset = |
| 533 | StandardFrameConstants::kExpressionsOffset + kPointerSize; |
| 534 | Address base = fp() + offset; |
| 535 | Address limit = sp(); |
| 536 | ASSERT(base >= limit); // stack grows downwards |
| 537 | // Include register-allocated locals in number of expressions. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 538 | return static_cast<int>((base - limit) / kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 542 | void StandardFrame::ComputeCallerState(State* state) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | state->sp = caller_sp(); |
| 544 | state->fp = caller_fp(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | state->pc_address = reinterpret_cast<Address*>(ComputePCAddress(fp())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 549 | void StandardFrame::SetCallerFp(Address caller_fp) { |
| 550 | Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset) = |
| 551 | caller_fp; |
| 552 | } |
| 553 | |
| 554 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | bool StandardFrame::IsExpressionInsideHandler(int n) const { |
| 556 | Address address = GetExpressionAddress(n); |
| 557 | for (StackHandlerIterator it(this, top_handler()); !it.done(); it.Advance()) { |
| 558 | if (it.handler()->includes(address)) return true; |
| 559 | } |
| 560 | return false; |
| 561 | } |
| 562 | |
| 563 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 564 | void OptimizedFrame::Iterate(ObjectVisitor* v) const { |
| 565 | #ifdef DEBUG |
| 566 | // Make sure that optimized frames do not contain any stack handlers. |
| 567 | StackHandlerIterator it(this, top_handler()); |
| 568 | ASSERT(it.done()); |
| 569 | #endif |
| 570 | |
| 571 | // Make sure that we're not doing "safe" stack frame iteration. We cannot |
| 572 | // possibly find pointers in optimized frames in that state. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 573 | ASSERT(!SafeStackFrameIterator::is_active(isolate())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 574 | |
| 575 | // Compute the safepoint information. |
| 576 | unsigned stack_slots = 0; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 577 | SafepointEntry safepoint_entry; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 578 | Code* code = StackFrame::GetSafepointData( |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 579 | isolate(), pc(), &safepoint_entry, &stack_slots); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 580 | unsigned slot_space = stack_slots * kPointerSize; |
| 581 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 582 | // Visit the outgoing parameters. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 583 | Object** parameters_base = &Memory::Object_at(sp()); |
| 584 | Object** parameters_limit = &Memory::Object_at( |
| 585 | fp() + JavaScriptFrameConstants::kFunctionOffset - slot_space); |
| 586 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 587 | // Visit the parameters that may be on top of the saved registers. |
| 588 | if (safepoint_entry.argument_count() > 0) { |
| 589 | v->VisitPointers(parameters_base, |
| 590 | parameters_base + safepoint_entry.argument_count()); |
| 591 | parameters_base += safepoint_entry.argument_count(); |
| 592 | } |
| 593 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 594 | // Skip saved double registers. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 595 | if (safepoint_entry.has_doubles()) { |
| 596 | parameters_base += DoubleRegister::kNumAllocatableRegisters * |
| 597 | kDoubleSize / kPointerSize; |
| 598 | } |
| 599 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 600 | // Visit the registers that contain pointers if any. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 601 | if (safepoint_entry.HasRegisters()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 602 | for (int i = kNumSafepointRegisters - 1; i >=0; i--) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 603 | if (safepoint_entry.HasRegisterAt(i)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 604 | int reg_stack_index = MacroAssembler::SafepointRegisterStackIndex(i); |
| 605 | v->VisitPointer(parameters_base + reg_stack_index); |
| 606 | } |
| 607 | } |
| 608 | // Skip the words containing the register values. |
| 609 | parameters_base += kNumSafepointRegisters; |
| 610 | } |
| 611 | |
| 612 | // We're done dealing with the register bits. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 613 | uint8_t* safepoint_bits = safepoint_entry.bits(); |
| 614 | safepoint_bits += kNumSafepointRegisters >> kBitsPerByteLog2; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 615 | |
| 616 | // Visit the rest of the parameters. |
| 617 | v->VisitPointers(parameters_base, parameters_limit); |
| 618 | |
| 619 | // Visit pointer spill slots and locals. |
| 620 | for (unsigned index = 0; index < stack_slots; index++) { |
| 621 | int byte_index = index >> kBitsPerByteLog2; |
| 622 | int bit_index = index & (kBitsPerByte - 1); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 623 | if ((safepoint_bits[byte_index] & (1U << bit_index)) != 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 624 | v->VisitPointer(parameters_limit + index); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | // Visit the context and the function. |
| 629 | Object** fixed_base = &Memory::Object_at( |
| 630 | fp() + JavaScriptFrameConstants::kFunctionOffset); |
| 631 | Object** fixed_limit = &Memory::Object_at(fp()); |
| 632 | v->VisitPointers(fixed_base, fixed_limit); |
| 633 | |
| 634 | // Visit the return address in the callee and incoming arguments. |
| 635 | IteratePc(v, pc_address(), code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | |
| 639 | bool JavaScriptFrame::IsConstructor() const { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 640 | Address fp = caller_fp(); |
| 641 | if (has_adapted_arguments()) { |
| 642 | // Skip the arguments adaptor frame and look at the real caller. |
| 643 | fp = Memory::Address_at(fp + StandardFrameConstants::kCallerFPOffset); |
| 644 | } |
| 645 | return IsConstructFrame(fp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 649 | Code* JavaScriptFrame::unchecked_code() const { |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 650 | JSFunction* function = JSFunction::cast(this->function()); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 651 | return function->unchecked_code(); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 655 | int JavaScriptFrame::GetNumberOfIncomingArguments() const { |
| 656 | ASSERT(!SafeStackFrameIterator::is_active(isolate()) && |
| 657 | isolate()->heap()->gc_state() == Heap::NOT_IN_GC); |
| 658 | |
| 659 | JSFunction* function = JSFunction::cast(this->function()); |
| 660 | return function->shared()->formal_parameter_count(); |
| 661 | } |
| 662 | |
| 663 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 664 | Address JavaScriptFrame::GetCallerStackPointer() const { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 665 | return fp() + StandardFrameConstants::kCallerSPOffset; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 669 | void JavaScriptFrame::GetFunctions(List<JSFunction*>* functions) { |
| 670 | ASSERT(functions->length() == 0); |
| 671 | functions->Add(JSFunction::cast(function())); |
| 672 | } |
| 673 | |
| 674 | |
| 675 | void JavaScriptFrame::Summarize(List<FrameSummary>* functions) { |
| 676 | ASSERT(functions->length() == 0); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 677 | Code* code_pointer = LookupCode(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 678 | int offset = static_cast<int>(pc() - code_pointer->address()); |
| 679 | FrameSummary summary(receiver(), |
| 680 | JSFunction::cast(function()), |
| 681 | code_pointer, |
| 682 | offset, |
| 683 | IsConstructor()); |
| 684 | functions->Add(summary); |
| 685 | } |
| 686 | |
| 687 | |
| 688 | void FrameSummary::Print() { |
| 689 | PrintF("receiver: "); |
| 690 | receiver_->ShortPrint(); |
| 691 | PrintF("\nfunction: "); |
| 692 | function_->shared()->DebugName()->ShortPrint(); |
| 693 | PrintF("\ncode: "); |
| 694 | code_->ShortPrint(); |
| 695 | if (code_->kind() == Code::FUNCTION) PrintF(" NON-OPT"); |
| 696 | if (code_->kind() == Code::OPTIMIZED_FUNCTION) PrintF(" OPT"); |
| 697 | PrintF("\npc: %d\n", offset_); |
| 698 | } |
| 699 | |
| 700 | |
| 701 | void OptimizedFrame::Summarize(List<FrameSummary>* frames) { |
| 702 | ASSERT(frames->length() == 0); |
| 703 | ASSERT(is_optimized()); |
| 704 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 705 | int deopt_index = Safepoint::kNoDeoptimizationIndex; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 706 | DeoptimizationInputData* data = GetDeoptimizationData(&deopt_index); |
| 707 | |
| 708 | // BUG(3243555): Since we don't have a lazy-deopt registered at |
| 709 | // throw-statements, we can't use the translation at the call-site of |
| 710 | // throw. An entry with no deoptimization index indicates a call-site |
| 711 | // without a lazy-deopt. As a consequence we are not allowed to inline |
| 712 | // functions containing throw. |
| 713 | if (deopt_index == Safepoint::kNoDeoptimizationIndex) { |
| 714 | JavaScriptFrame::Summarize(frames); |
| 715 | return; |
| 716 | } |
| 717 | |
| 718 | TranslationIterator it(data->TranslationByteArray(), |
| 719 | data->TranslationIndex(deopt_index)->value()); |
| 720 | Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); |
| 721 | ASSERT(opcode == Translation::BEGIN); |
| 722 | int frame_count = it.Next(); |
| 723 | |
| 724 | // We create the summary in reverse order because the frames |
| 725 | // in the deoptimization translation are ordered bottom-to-top. |
| 726 | int i = frame_count; |
| 727 | while (i > 0) { |
| 728 | opcode = static_cast<Translation::Opcode>(it.Next()); |
| 729 | if (opcode == Translation::FRAME) { |
| 730 | // We don't inline constructor calls, so only the first, outermost |
| 731 | // frame can be a constructor frame in case of inlining. |
| 732 | bool is_constructor = (i == frame_count) && IsConstructor(); |
| 733 | |
| 734 | i--; |
| 735 | int ast_id = it.Next(); |
| 736 | int function_id = it.Next(); |
| 737 | it.Next(); // Skip height. |
| 738 | JSFunction* function = |
| 739 | JSFunction::cast(data->LiteralArray()->get(function_id)); |
| 740 | |
| 741 | // The translation commands are ordered and the receiver is always |
| 742 | // at the first position. Since we are always at a call when we need |
| 743 | // to construct a stack trace, the receiver is always in a stack slot. |
| 744 | opcode = static_cast<Translation::Opcode>(it.Next()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame^] | 745 | ASSERT(opcode == Translation::STACK_SLOT || |
| 746 | opcode == Translation::LITERAL); |
| 747 | int index = it.Next(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 748 | |
| 749 | // Get the correct receiver in the optimized frame. |
| 750 | Object* receiver = NULL; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame^] | 751 | if (opcode == Translation::LITERAL) { |
| 752 | receiver = data->LiteralArray()->get(index); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 753 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame^] | 754 | // Positive index means the value is spilled to the locals |
| 755 | // area. Negative means it is stored in the incoming parameter |
| 756 | // area. |
| 757 | if (index >= 0) { |
| 758 | receiver = GetExpression(index); |
| 759 | } else { |
| 760 | // Index -1 overlaps with last parameter, -n with the first parameter, |
| 761 | // (-n - 1) with the receiver with n being the number of parameters |
| 762 | // of the outermost, optimized frame. |
| 763 | int parameter_count = ComputeParametersCount(); |
| 764 | int parameter_index = index + parameter_count; |
| 765 | receiver = (parameter_index == -1) |
| 766 | ? this->receiver() |
| 767 | : this->GetParameter(parameter_index); |
| 768 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | Code* code = function->shared()->code(); |
| 772 | DeoptimizationOutputData* output_data = |
| 773 | DeoptimizationOutputData::cast(code->deoptimization_data()); |
| 774 | unsigned entry = Deoptimizer::GetOutputInfo(output_data, |
| 775 | ast_id, |
| 776 | function->shared()); |
| 777 | unsigned pc_offset = |
| 778 | FullCodeGenerator::PcField::decode(entry) + Code::kHeaderSize; |
| 779 | ASSERT(pc_offset > 0); |
| 780 | |
| 781 | FrameSummary summary(receiver, function, code, pc_offset, is_constructor); |
| 782 | frames->Add(summary); |
| 783 | } else { |
| 784 | // Skip over operands to advance to the next opcode. |
| 785 | it.Skip(Translation::NumberOfOperandsFor(opcode)); |
| 786 | } |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | |
| 791 | DeoptimizationInputData* OptimizedFrame::GetDeoptimizationData( |
| 792 | int* deopt_index) { |
| 793 | ASSERT(is_optimized()); |
| 794 | |
| 795 | JSFunction* opt_function = JSFunction::cast(function()); |
| 796 | Code* code = opt_function->code(); |
| 797 | |
| 798 | // The code object may have been replaced by lazy deoptimization. Fall |
| 799 | // back to a slow search in this case to find the original optimized |
| 800 | // code object. |
| 801 | if (!code->contains(pc())) { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 802 | code = isolate()->pc_to_code_cache()->GcSafeFindCodeForPc(pc()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 803 | } |
| 804 | ASSERT(code != NULL); |
| 805 | ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); |
| 806 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 807 | SafepointEntry safepoint_entry = code->GetSafepointEntry(pc()); |
| 808 | *deopt_index = safepoint_entry.deoptimization_index(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 809 | ASSERT(*deopt_index != Safepoint::kNoDeoptimizationIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 810 | |
| 811 | return DeoptimizationInputData::cast(code->deoptimization_data()); |
| 812 | } |
| 813 | |
| 814 | |
| 815 | void OptimizedFrame::GetFunctions(List<JSFunction*>* functions) { |
| 816 | ASSERT(functions->length() == 0); |
| 817 | ASSERT(is_optimized()); |
| 818 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 819 | int deopt_index = Safepoint::kNoDeoptimizationIndex; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 820 | DeoptimizationInputData* data = GetDeoptimizationData(&deopt_index); |
| 821 | |
| 822 | TranslationIterator it(data->TranslationByteArray(), |
| 823 | data->TranslationIndex(deopt_index)->value()); |
| 824 | Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); |
| 825 | ASSERT(opcode == Translation::BEGIN); |
| 826 | int frame_count = it.Next(); |
| 827 | |
| 828 | // We insert the frames in reverse order because the frames |
| 829 | // in the deoptimization translation are ordered bottom-to-top. |
| 830 | while (frame_count > 0) { |
| 831 | opcode = static_cast<Translation::Opcode>(it.Next()); |
| 832 | if (opcode == Translation::FRAME) { |
| 833 | frame_count--; |
| 834 | it.Next(); // Skip ast id. |
| 835 | int function_id = it.Next(); |
| 836 | it.Next(); // Skip height. |
| 837 | JSFunction* function = |
| 838 | JSFunction::cast(data->LiteralArray()->get(function_id)); |
| 839 | functions->Add(function); |
| 840 | } else { |
| 841 | // Skip over operands to advance to the next opcode. |
| 842 | it.Skip(Translation::NumberOfOperandsFor(opcode)); |
| 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 848 | Address ArgumentsAdaptorFrame::GetCallerStackPointer() const { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 849 | return fp() + StandardFrameConstants::kCallerSPOffset; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | |
| 853 | Address InternalFrame::GetCallerStackPointer() const { |
| 854 | // Internal frames have no arguments. The stack pointer of the |
| 855 | // caller is at a fixed offset from the frame pointer. |
| 856 | return fp() + StandardFrameConstants::kCallerSPOffset; |
| 857 | } |
| 858 | |
| 859 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 860 | Code* ArgumentsAdaptorFrame::unchecked_code() const { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 861 | return isolate()->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 862 | Builtins::kArgumentsAdaptorTrampoline); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 866 | Code* InternalFrame::unchecked_code() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 867 | const int offset = InternalFrameConstants::kCodeOffset; |
| 868 | Object* code = Memory::Object_at(fp() + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 869 | ASSERT(code != NULL); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 870 | return reinterpret_cast<Code*>(code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | |
| 874 | void StackFrame::PrintIndex(StringStream* accumulator, |
| 875 | PrintMode mode, |
| 876 | int index) { |
| 877 | accumulator->Add((mode == OVERVIEW) ? "%5d: " : "[%d]: ", index); |
| 878 | } |
| 879 | |
| 880 | |
| 881 | void JavaScriptFrame::Print(StringStream* accumulator, |
| 882 | PrintMode mode, |
| 883 | int index) const { |
| 884 | HandleScope scope; |
| 885 | Object* receiver = this->receiver(); |
| 886 | Object* function = this->function(); |
| 887 | |
| 888 | accumulator->PrintSecurityTokenIfChanged(function); |
| 889 | PrintIndex(accumulator, mode, index); |
| 890 | Code* code = NULL; |
| 891 | if (IsConstructor()) accumulator->Add("new "); |
| 892 | accumulator->PrintFunction(function, receiver, &code); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 893 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 894 | Handle<SerializedScopeInfo> scope_info(SerializedScopeInfo::Empty()); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 895 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 896 | if (function->IsJSFunction()) { |
| 897 | Handle<SharedFunctionInfo> shared(JSFunction::cast(function)->shared()); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 898 | scope_info = Handle<SerializedScopeInfo>(shared->scope_info()); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 899 | Object* script_obj = shared->script(); |
| 900 | if (script_obj->IsScript()) { |
| 901 | Handle<Script> script(Script::cast(script_obj)); |
| 902 | accumulator->Add(" ["); |
| 903 | accumulator->PrintName(script->name()); |
| 904 | |
| 905 | Address pc = this->pc(); |
| 906 | if (code != NULL && code->kind() == Code::FUNCTION && |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 907 | pc >= code->instruction_start() && pc < code->instruction_end()) { |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 908 | int source_pos = code->SourcePosition(pc); |
| 909 | int line = GetScriptLineNumberSafe(script, source_pos) + 1; |
| 910 | accumulator->Add(":%d", line); |
| 911 | } else { |
| 912 | int function_start_pos = shared->start_position(); |
| 913 | int line = GetScriptLineNumberSafe(script, function_start_pos) + 1; |
| 914 | accumulator->Add(":~%d", line); |
| 915 | } |
| 916 | |
| 917 | accumulator->Add("] "); |
| 918 | } |
| 919 | } |
| 920 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | accumulator->Add("(this=%o", receiver); |
| 922 | |
| 923 | // Get scope information for nicer output, if possible. If code is |
| 924 | // NULL, or doesn't contain scope info, info will return 0 for the |
| 925 | // number of parameters, stack slots, or context slots. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 926 | ScopeInfo<PreallocatedStorage> info(*scope_info); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 927 | |
| 928 | // Print the parameters. |
| 929 | int parameters_count = ComputeParametersCount(); |
| 930 | for (int i = 0; i < parameters_count; i++) { |
| 931 | accumulator->Add(","); |
| 932 | // If we have a name for the parameter we print it. Nameless |
| 933 | // parameters are either because we have more actual parameters |
| 934 | // than formal parameters or because we have no scope information. |
| 935 | if (i < info.number_of_parameters()) { |
| 936 | accumulator->PrintName(*info.parameter_name(i)); |
| 937 | accumulator->Add("="); |
| 938 | } |
| 939 | accumulator->Add("%o", GetParameter(i)); |
| 940 | } |
| 941 | |
| 942 | accumulator->Add(")"); |
| 943 | if (mode == OVERVIEW) { |
| 944 | accumulator->Add("\n"); |
| 945 | return; |
| 946 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 947 | if (is_optimized()) { |
| 948 | accumulator->Add(" {\n// optimized frame\n}\n"); |
| 949 | return; |
| 950 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 951 | accumulator->Add(" {\n"); |
| 952 | |
| 953 | // Compute the number of locals and expression stack elements. |
| 954 | int stack_locals_count = info.number_of_stack_slots(); |
| 955 | int heap_locals_count = info.number_of_context_slots(); |
| 956 | int expressions_count = ComputeExpressionsCount(); |
| 957 | |
| 958 | // Print stack-allocated local variables. |
| 959 | if (stack_locals_count > 0) { |
| 960 | accumulator->Add(" // stack-allocated locals\n"); |
| 961 | } |
| 962 | for (int i = 0; i < stack_locals_count; i++) { |
| 963 | accumulator->Add(" var "); |
| 964 | accumulator->PrintName(*info.stack_slot_name(i)); |
| 965 | accumulator->Add(" = "); |
| 966 | if (i < expressions_count) { |
| 967 | accumulator->Add("%o", GetExpression(i)); |
| 968 | } else { |
| 969 | accumulator->Add("// no expression found - inconsistent frame?"); |
| 970 | } |
| 971 | accumulator->Add("\n"); |
| 972 | } |
| 973 | |
| 974 | // Try to get hold of the context of this frame. |
| 975 | Context* context = NULL; |
| 976 | if (this->context() != NULL && this->context()->IsContext()) { |
| 977 | context = Context::cast(this->context()); |
| 978 | } |
| 979 | |
| 980 | // Print heap-allocated local variables. |
| 981 | if (heap_locals_count > Context::MIN_CONTEXT_SLOTS) { |
| 982 | accumulator->Add(" // heap-allocated locals\n"); |
| 983 | } |
| 984 | for (int i = Context::MIN_CONTEXT_SLOTS; i < heap_locals_count; i++) { |
| 985 | accumulator->Add(" var "); |
| 986 | accumulator->PrintName(*info.context_slot_name(i)); |
| 987 | accumulator->Add(" = "); |
| 988 | if (context != NULL) { |
| 989 | if (i < context->length()) { |
| 990 | accumulator->Add("%o", context->get(i)); |
| 991 | } else { |
| 992 | accumulator->Add( |
| 993 | "// warning: missing context slot - inconsistent frame?"); |
| 994 | } |
| 995 | } else { |
| 996 | accumulator->Add("// warning: no context found - inconsistent frame?"); |
| 997 | } |
| 998 | accumulator->Add("\n"); |
| 999 | } |
| 1000 | |
| 1001 | // Print the expression stack. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1002 | int expressions_start = stack_locals_count; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1003 | if (expressions_start < expressions_count) { |
| 1004 | accumulator->Add(" // expression stack (top to bottom)\n"); |
| 1005 | } |
| 1006 | for (int i = expressions_count - 1; i >= expressions_start; i--) { |
| 1007 | if (IsExpressionInsideHandler(i)) continue; |
| 1008 | accumulator->Add(" [%02d] : %o\n", i, GetExpression(i)); |
| 1009 | } |
| 1010 | |
| 1011 | // Print details about the function. |
| 1012 | if (FLAG_max_stack_trace_source_length != 0 && code != NULL) { |
| 1013 | SharedFunctionInfo* shared = JSFunction::cast(function)->shared(); |
| 1014 | accumulator->Add("--------- s o u r c e c o d e ---------\n"); |
| 1015 | shared->SourceCodePrint(accumulator, FLAG_max_stack_trace_source_length); |
| 1016 | accumulator->Add("\n-----------------------------------------\n"); |
| 1017 | } |
| 1018 | |
| 1019 | accumulator->Add("}\n\n"); |
| 1020 | } |
| 1021 | |
| 1022 | |
| 1023 | void ArgumentsAdaptorFrame::Print(StringStream* accumulator, |
| 1024 | PrintMode mode, |
| 1025 | int index) const { |
| 1026 | int actual = ComputeParametersCount(); |
| 1027 | int expected = -1; |
| 1028 | Object* function = this->function(); |
| 1029 | if (function->IsJSFunction()) { |
| 1030 | expected = JSFunction::cast(function)->shared()->formal_parameter_count(); |
| 1031 | } |
| 1032 | |
| 1033 | PrintIndex(accumulator, mode, index); |
| 1034 | accumulator->Add("arguments adaptor frame: %d->%d", actual, expected); |
| 1035 | if (mode == OVERVIEW) { |
| 1036 | accumulator->Add("\n"); |
| 1037 | return; |
| 1038 | } |
| 1039 | accumulator->Add(" {\n"); |
| 1040 | |
| 1041 | // Print actual arguments. |
| 1042 | if (actual > 0) accumulator->Add(" // actual arguments\n"); |
| 1043 | for (int i = 0; i < actual; i++) { |
| 1044 | accumulator->Add(" [%02d] : %o", i, GetParameter(i)); |
| 1045 | if (expected != -1 && i >= expected) { |
| 1046 | accumulator->Add(" // not passed to callee"); |
| 1047 | } |
| 1048 | accumulator->Add("\n"); |
| 1049 | } |
| 1050 | |
| 1051 | accumulator->Add("}\n\n"); |
| 1052 | } |
| 1053 | |
| 1054 | |
| 1055 | void EntryFrame::Iterate(ObjectVisitor* v) const { |
| 1056 | StackHandlerIterator it(this, top_handler()); |
| 1057 | ASSERT(!it.done()); |
| 1058 | StackHandler* handler = it.handler(); |
| 1059 | ASSERT(handler->is_entry()); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1060 | handler->Iterate(v, LookupCode()); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1061 | #ifdef DEBUG |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1062 | // Make sure that the entry frame does not contain more than one |
| 1063 | // stack handler. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1064 | it.Advance(); |
| 1065 | ASSERT(it.done()); |
| 1066 | #endif |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1067 | IteratePc(v, pc_address(), LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | void StandardFrame::IterateExpressions(ObjectVisitor* v) const { |
| 1072 | const int offset = StandardFrameConstants::kContextOffset; |
| 1073 | Object** base = &Memory::Object_at(sp()); |
| 1074 | Object** limit = &Memory::Object_at(fp() + offset) + 1; |
| 1075 | for (StackHandlerIterator it(this, top_handler()); !it.done(); it.Advance()) { |
| 1076 | StackHandler* handler = it.handler(); |
| 1077 | // Traverse pointers down to - but not including - the next |
| 1078 | // handler in the handler chain. Update the base to skip the |
| 1079 | // handler and allow the handler to traverse its own pointers. |
| 1080 | const Address address = handler->address(); |
| 1081 | v->VisitPointers(base, reinterpret_cast<Object**>(address)); |
| 1082 | base = reinterpret_cast<Object**>(address + StackHandlerConstants::kSize); |
| 1083 | // Traverse the pointers in the handler itself. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1084 | handler->Iterate(v, LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1085 | } |
| 1086 | v->VisitPointers(base, limit); |
| 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | void JavaScriptFrame::Iterate(ObjectVisitor* v) const { |
| 1091 | IterateExpressions(v); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1092 | IteratePc(v, pc_address(), LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | |
| 1096 | void InternalFrame::Iterate(ObjectVisitor* v) const { |
| 1097 | // Internal frames only have object pointers on the expression stack |
| 1098 | // as they never have any arguments. |
| 1099 | IterateExpressions(v); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1100 | IteratePc(v, pc_address(), LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | // ------------------------------------------------------------------------- |
| 1105 | |
| 1106 | |
| 1107 | JavaScriptFrame* StackFrameLocator::FindJavaScriptFrame(int n) { |
| 1108 | ASSERT(n >= 0); |
| 1109 | for (int i = 0; i <= n; i++) { |
| 1110 | while (!iterator_.frame()->is_java_script()) iterator_.Advance(); |
| 1111 | if (i == n) return JavaScriptFrame::cast(iterator_.frame()); |
| 1112 | iterator_.Advance(); |
| 1113 | } |
| 1114 | UNREACHABLE(); |
| 1115 | return NULL; |
| 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | // ------------------------------------------------------------------------- |
| 1120 | |
| 1121 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1122 | Code* PcToCodeCache::GcSafeCastToCode(HeapObject* object, Address pc) { |
| 1123 | Code* code = reinterpret_cast<Code*>(object); |
| 1124 | ASSERT(code != NULL && code->contains(pc)); |
| 1125 | return code; |
| 1126 | } |
| 1127 | |
| 1128 | |
| 1129 | Code* PcToCodeCache::GcSafeFindCodeForPc(Address pc) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1130 | Heap* heap = isolate_->heap(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1131 | // Check if the pc points into a large object chunk. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1132 | LargeObjectChunk* chunk = heap->lo_space()->FindChunkContainingPc(pc); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1133 | if (chunk != NULL) return GcSafeCastToCode(chunk->GetObject(), pc); |
| 1134 | |
| 1135 | // Iterate through the 8K page until we reach the end or find an |
| 1136 | // object starting after the pc. |
| 1137 | Page* page = Page::FromAddress(pc); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1138 | HeapObjectIterator iterator(page, heap->GcSafeSizeOfOldObjectFunction()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1139 | HeapObject* previous = NULL; |
| 1140 | while (true) { |
| 1141 | HeapObject* next = iterator.next(); |
| 1142 | if (next == NULL || next->address() >= pc) { |
| 1143 | return GcSafeCastToCode(previous, pc); |
| 1144 | } |
| 1145 | previous = next; |
| 1146 | } |
| 1147 | } |
| 1148 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1149 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1150 | PcToCodeCache::PcToCodeCacheEntry* PcToCodeCache::GetCacheEntry(Address pc) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1151 | isolate_->counters()->pc_to_code()->Increment(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1152 | ASSERT(IsPowerOf2(kPcToCodeCacheSize)); |
| 1153 | uint32_t hash = ComputeIntegerHash( |
| 1154 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(pc))); |
| 1155 | uint32_t index = hash & (kPcToCodeCacheSize - 1); |
| 1156 | PcToCodeCacheEntry* entry = cache(index); |
| 1157 | if (entry->pc == pc) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1158 | isolate_->counters()->pc_to_code_cached()->Increment(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1159 | ASSERT(entry->code == GcSafeFindCodeForPc(pc)); |
| 1160 | } else { |
| 1161 | // Because this code may be interrupted by a profiling signal that |
| 1162 | // also queries the cache, we cannot update pc before the code has |
| 1163 | // been set. Otherwise, we risk trying to use a cache entry before |
| 1164 | // the code has been computed. |
| 1165 | entry->code = GcSafeFindCodeForPc(pc); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1166 | entry->safepoint_entry.Reset(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1167 | entry->pc = pc; |
| 1168 | } |
| 1169 | return entry; |
| 1170 | } |
| 1171 | |
| 1172 | |
| 1173 | // ------------------------------------------------------------------------- |
| 1174 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1175 | int NumRegs(RegList reglist) { |
| 1176 | int n = 0; |
| 1177 | while (reglist != 0) { |
| 1178 | n++; |
| 1179 | reglist &= reglist - 1; // clear one bit |
| 1180 | } |
| 1181 | return n; |
| 1182 | } |
| 1183 | |
| 1184 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1185 | struct JSCallerSavedCodeData { |
| 1186 | JSCallerSavedCodeData() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1187 | int i = 0; |
| 1188 | for (int r = 0; r < kNumRegs; r++) |
| 1189 | if ((kJSCallerSaved & (1 << r)) != 0) |
| 1190 | reg_code[i++] = r; |
| 1191 | |
| 1192 | ASSERT(i == kNumJSCallerSaved); |
| 1193 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1194 | int reg_code[kNumJSCallerSaved]; |
| 1195 | }; |
| 1196 | |
| 1197 | |
| 1198 | static const JSCallerSavedCodeData kCallerSavedCodeData; |
| 1199 | |
| 1200 | |
| 1201 | int JSCallerSavedCode(int n) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1202 | ASSERT(0 <= n && n < kNumJSCallerSaved); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1203 | return kCallerSavedCodeData.reg_code[n]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1207 | #define DEFINE_WRAPPER(type, field) \ |
| 1208 | class field##_Wrapper : public ZoneObject { \ |
| 1209 | public: /* NOLINT */ \ |
| 1210 | field##_Wrapper(const field& original) : frame_(original) { \ |
| 1211 | } \ |
| 1212 | field frame_; \ |
| 1213 | }; |
| 1214 | STACK_FRAME_TYPE_LIST(DEFINE_WRAPPER) |
| 1215 | #undef DEFINE_WRAPPER |
| 1216 | |
| 1217 | static StackFrame* AllocateFrameCopy(StackFrame* frame) { |
| 1218 | #define FRAME_TYPE_CASE(type, field) \ |
| 1219 | case StackFrame::type: { \ |
| 1220 | field##_Wrapper* wrapper = \ |
| 1221 | new field##_Wrapper(*(reinterpret_cast<field*>(frame))); \ |
| 1222 | return &wrapper->frame_; \ |
| 1223 | } |
| 1224 | |
| 1225 | switch (frame->type()) { |
| 1226 | STACK_FRAME_TYPE_LIST(FRAME_TYPE_CASE) |
| 1227 | default: UNREACHABLE(); |
| 1228 | } |
| 1229 | #undef FRAME_TYPE_CASE |
| 1230 | return NULL; |
| 1231 | } |
| 1232 | |
| 1233 | Vector<StackFrame*> CreateStackMap() { |
| 1234 | ZoneList<StackFrame*> list(10); |
| 1235 | for (StackFrameIterator it; !it.done(); it.Advance()) { |
| 1236 | StackFrame* frame = AllocateFrameCopy(it.frame()); |
| 1237 | list.Add(frame); |
| 1238 | } |
| 1239 | return list.ToVector(); |
| 1240 | } |
| 1241 | |
| 1242 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1243 | } } // namespace v8::internal |