yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1 | // Copyright 2012 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" |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 34 | #include "lazy-instance.h" |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 35 | #include "mark-compact.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 36 | #include "safepoint-table.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | #include "scopeinfo.h" |
| 38 | #include "string-stream.h" |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 39 | #include "vm-state-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 41 | namespace v8 { |
| 42 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 43 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 44 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 45 | ReturnAddressLocationResolver |
| 46 | StackFrame::return_address_location_resolver_ = NULL; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 47 | |
| 48 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | // Iterator that supports traversing the stack handlers of a |
| 50 | // particular frame. Needs to know the top of the handler chain. |
| 51 | class StackHandlerIterator BASE_EMBEDDED { |
| 52 | public: |
| 53 | StackHandlerIterator(const StackFrame* frame, StackHandler* handler) |
| 54 | : limit_(frame->fp()), handler_(handler) { |
| 55 | // Make sure the handler has already been unwound to this frame. |
| 56 | ASSERT(frame->sp() <= handler->address()); |
| 57 | } |
| 58 | |
| 59 | StackHandler* handler() const { return handler_; } |
| 60 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 61 | bool done() { |
| 62 | return handler_ == NULL || handler_->address() > limit_; |
| 63 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | void Advance() { |
| 65 | ASSERT(!done()); |
| 66 | handler_ = handler_->next(); |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | const Address limit_; |
| 71 | StackHandler* handler_; |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | // ------------------------------------------------------------------------- |
| 76 | |
| 77 | |
| 78 | #define INITIALIZE_SINGLETON(type, field) field##_(this), |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 79 | StackFrameIteratorBase::StackFrameIteratorBase(Isolate* isolate, |
| 80 | bool can_access_heap_objects) |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 81 | : isolate_(isolate), |
| 82 | STACK_FRAME_TYPE_LIST(INITIALIZE_SINGLETON) |
| 83 | frame_(NULL), handler_(NULL), |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 84 | can_access_heap_objects_(can_access_heap_objects) { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 85 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | #undef INITIALIZE_SINGLETON |
| 87 | |
| 88 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 89 | StackFrameIterator::StackFrameIterator(Isolate* isolate) |
| 90 | : StackFrameIteratorBase(isolate, true) { |
| 91 | Reset(isolate->thread_local_top()); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | StackFrameIterator::StackFrameIterator(Isolate* isolate, ThreadLocalTop* t) |
| 96 | : StackFrameIteratorBase(isolate, true) { |
| 97 | Reset(t); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void StackFrameIterator::Advance() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 102 | ASSERT(!done()); |
| 103 | // Compute the state of the calling frame before restoring |
| 104 | // callee-saved registers and unwinding handlers. This allows the |
| 105 | // frame code that computes the caller state to access the top |
| 106 | // handler and the value of any callee-saved register if needed. |
| 107 | StackFrame::State state; |
| 108 | StackFrame::Type type = frame_->GetCallerState(&state); |
| 109 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | // Unwind handlers corresponding to the current frame. |
| 111 | StackHandlerIterator it(frame_, handler_); |
| 112 | while (!it.done()) it.Advance(); |
| 113 | handler_ = it.handler(); |
| 114 | |
| 115 | // Advance to the calling frame. |
| 116 | frame_ = SingletonFor(type, &state); |
| 117 | |
| 118 | // When we're done iterating over the stack frames, the handler |
| 119 | // chain must have been completely unwound. |
| 120 | ASSERT(!done() || handler_ == NULL); |
| 121 | } |
| 122 | |
| 123 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 124 | void StackFrameIterator::Reset(ThreadLocalTop* top) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 125 | StackFrame::State state; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 126 | StackFrame::Type type = ExitFrame::GetStateForFramePointer( |
| 127 | Isolate::c_entry_fp(top), &state); |
| 128 | handler_ = StackHandler::FromAddress(Isolate::handler(top)); |
danno@chromium.org | d43f645 | 2013-04-30 16:42:35 +0000 | [diff] [blame] | 129 | if (SingletonFor(type) == NULL) return; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 130 | frame_ = SingletonFor(type, &state); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 134 | StackFrame* StackFrameIteratorBase::SingletonFor(StackFrame::Type type, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 135 | StackFrame::State* state) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 136 | if (type == StackFrame::NONE) return NULL; |
| 137 | StackFrame* result = SingletonFor(type); |
| 138 | ASSERT(result != NULL); |
| 139 | result->state_ = *state; |
| 140 | return result; |
| 141 | } |
| 142 | |
| 143 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 144 | StackFrame* StackFrameIteratorBase::SingletonFor(StackFrame::Type type) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | #define FRAME_TYPE_CASE(type, field) \ |
| 146 | case StackFrame::type: result = &field##_; break; |
| 147 | |
| 148 | StackFrame* result = NULL; |
| 149 | switch (type) { |
| 150 | case StackFrame::NONE: return NULL; |
| 151 | STACK_FRAME_TYPE_LIST(FRAME_TYPE_CASE) |
| 152 | default: break; |
| 153 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 154 | return result; |
| 155 | |
| 156 | #undef FRAME_TYPE_CASE |
| 157 | } |
| 158 | |
| 159 | |
| 160 | // ------------------------------------------------------------------------- |
| 161 | |
| 162 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 163 | JavaScriptFrameIterator::JavaScriptFrameIterator( |
| 164 | Isolate* isolate, StackFrame::Id id) |
| 165 | : iterator_(isolate) { |
| 166 | while (!done()) { |
| 167 | Advance(); |
| 168 | if (frame()->id() == id) return; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
| 173 | void JavaScriptFrameIterator::Advance() { |
| 174 | do { |
| 175 | iterator_.Advance(); |
| 176 | } while (!iterator_.done() && !iterator_.frame()->is_java_script()); |
| 177 | } |
| 178 | |
| 179 | |
| 180 | void JavaScriptFrameIterator::AdvanceToArgumentsFrame() { |
| 181 | if (!frame()->has_adapted_arguments()) return; |
| 182 | iterator_.Advance(); |
| 183 | ASSERT(iterator_.frame()->is_arguments_adaptor()); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | // ------------------------------------------------------------------------- |
| 188 | |
| 189 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 190 | StackTraceFrameIterator::StackTraceFrameIterator(Isolate* isolate) |
| 191 | : JavaScriptFrameIterator(isolate) { |
| 192 | if (!done() && !IsValidFrame()) Advance(); |
| 193 | } |
| 194 | |
| 195 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 196 | void StackTraceFrameIterator::Advance() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 197 | while (true) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 198 | JavaScriptFrameIterator::Advance(); |
| 199 | if (done()) return; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 200 | if (IsValidFrame()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 204 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 205 | bool StackTraceFrameIterator::IsValidFrame() { |
| 206 | if (!frame()->function()->IsJSFunction()) return false; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 207 | Object* script = frame()->function()->shared()->script(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 208 | // Don't show functions from native scripts to user. |
| 209 | return (script->IsScript() && |
| 210 | Script::TYPE_NATIVE != Script::cast(script)->type()->value()); |
| 211 | } |
| 212 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 213 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 214 | // ------------------------------------------------------------------------- |
| 215 | |
| 216 | |
| 217 | SafeStackFrameIterator::SafeStackFrameIterator( |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 218 | Isolate* isolate, |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 219 | Address fp, Address sp, Address js_entry_sp) |
| 220 | : StackFrameIteratorBase(isolate, false), |
| 221 | low_bound_(sp), |
| 222 | high_bound_(js_entry_sp), |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 223 | top_frame_type_(StackFrame::NONE), |
| 224 | external_callback_scope_(isolate->external_callback_scope()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 225 | StackFrame::State state; |
| 226 | StackFrame::Type type; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 227 | ThreadLocalTop* top = isolate->thread_local_top(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 228 | if (IsValidTop(top)) { |
| 229 | type = ExitFrame::GetStateForFramePointer(Isolate::c_entry_fp(top), &state); |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 230 | top_frame_type_ = type; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 231 | } else if (IsValidStackAddress(fp)) { |
| 232 | ASSERT(fp != NULL); |
| 233 | state.fp = fp; |
| 234 | state.sp = sp; |
| 235 | state.pc_address = StackFrame::ResolveReturnAddressLocation( |
| 236 | reinterpret_cast<Address*>(StandardFrame::ComputePCAddress(fp))); |
machenbach@chromium.org | c1789ee | 2013-07-05 07:09:57 +0000 | [diff] [blame] | 237 | // StackFrame::ComputeType will read both kContextOffset and kMarkerOffset, |
| 238 | // we check only that kMarkerOffset is within the stack bounds and do |
| 239 | // compile time check that kContextOffset slot is pushed on the stack before |
| 240 | // kMarkerOffset. |
| 241 | STATIC_ASSERT(StandardFrameConstants::kMarkerOffset < |
| 242 | StandardFrameConstants::kContextOffset); |
| 243 | Address frame_marker = fp + StandardFrameConstants::kMarkerOffset; |
| 244 | if (IsValidStackAddress(frame_marker)) { |
| 245 | type = StackFrame::ComputeType(this, &state); |
| 246 | top_frame_type_ = type; |
| 247 | } else { |
| 248 | // Mark the frame as JAVA_SCRIPT if we cannot determine its type. |
| 249 | // The frame anyways will be skipped. |
| 250 | type = StackFrame::JAVA_SCRIPT; |
| 251 | // Top frame is incomplete so we cannot reliably determine its type. |
| 252 | top_frame_type_ = StackFrame::NONE; |
| 253 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 254 | } else { |
| 255 | return; |
| 256 | } |
| 257 | if (SingletonFor(type) == NULL) return; |
| 258 | frame_ = SingletonFor(type, &state); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 259 | if (frame_ == NULL) return; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 260 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 261 | Advance(); |
| 262 | |
| 263 | if (frame_ != NULL && !frame_->is_exit() && |
| 264 | external_callback_scope_ != NULL && |
| 265 | external_callback_scope_->scope_address() < frame_->fp()) { |
| 266 | // Skip top ExternalCallbackScope if we already advanced to a JS frame |
| 267 | // under it. Sampler will anyways take this top external callback. |
| 268 | external_callback_scope_ = external_callback_scope_->previous(); |
| 269 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | |
| 273 | bool SafeStackFrameIterator::IsValidTop(ThreadLocalTop* top) const { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 274 | Address c_entry_fp = Isolate::c_entry_fp(top); |
| 275 | if (!IsValidExitFrame(c_entry_fp)) return false; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 276 | // There should be at least one JS_ENTRY stack handler. |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 277 | Address handler = Isolate::handler(top); |
| 278 | if (handler == NULL) return false; |
| 279 | // Check that there are no js frames on top of the native frames. |
| 280 | return c_entry_fp < handler; |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 284 | void SafeStackFrameIterator::AdvanceOneFrame() { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 285 | ASSERT(!done()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 286 | StackFrame* last_frame = frame_; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 287 | Address last_sp = last_frame->sp(), last_fp = last_frame->fp(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 288 | // Before advancing to the next stack frame, perform pointer validity tests. |
| 289 | if (!IsValidFrame(last_frame) || !IsValidCaller(last_frame)) { |
| 290 | frame_ = NULL; |
| 291 | return; |
| 292 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 293 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 294 | // Advance to the previous frame. |
| 295 | StackFrame::State state; |
| 296 | StackFrame::Type type = frame_->GetCallerState(&state); |
| 297 | frame_ = SingletonFor(type, &state); |
| 298 | if (frame_ == NULL) return; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 299 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 300 | // Check that we have actually moved to the previous frame in the stack. |
| 301 | if (frame_->sp() < last_sp || frame_->fp() < last_fp) { |
| 302 | frame_ = NULL; |
| 303 | } |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 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); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 320 | if (!IsValidExitFrame(caller_fp)) return false; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 321 | } else if (frame->is_arguments_adaptor()) { |
| 322 | // See ArgumentsAdaptorFrame::GetCallerStackPointer. It assumes that |
| 323 | // the number of arguments is stored on stack as Smi. We need to check |
| 324 | // that it really an Smi. |
| 325 | Object* number_of_args = reinterpret_cast<ArgumentsAdaptorFrame*>(frame)-> |
| 326 | GetExpression(0); |
| 327 | if (!number_of_args->IsSmi()) { |
| 328 | return false; |
| 329 | } |
| 330 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 331 | frame->ComputeCallerState(&state); |
| 332 | return IsValidStackAddress(state.sp) && IsValidStackAddress(state.fp) && |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 333 | SingletonFor(frame->GetCallerState(&state)) != NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 337 | bool SafeStackFrameIterator::IsValidExitFrame(Address fp) const { |
| 338 | if (!IsValidStackAddress(fp)) return false; |
| 339 | Address sp = ExitFrame::ComputeStackPointer(fp); |
| 340 | if (!IsValidStackAddress(sp)) return false; |
| 341 | StackFrame::State state; |
| 342 | ExitFrame::FillState(fp, sp, &state); |
| 343 | if (!IsValidStackAddress(reinterpret_cast<Address>(state.pc_address))) { |
| 344 | return false; |
| 345 | } |
| 346 | return *state.pc_address != NULL; |
| 347 | } |
| 348 | |
| 349 | |
| 350 | void SafeStackFrameIterator::Advance() { |
| 351 | while (true) { |
| 352 | AdvanceOneFrame(); |
| 353 | if (done()) return; |
| 354 | if (frame_->is_java_script()) return; |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 355 | if (frame_->is_exit() && external_callback_scope_) { |
| 356 | // Some of the EXIT frames may have ExternalCallbackScope allocated on |
| 357 | // top of them. In that case the scope corresponds to the first EXIT |
| 358 | // frame beneath it. There may be other EXIT frames on top of the |
| 359 | // ExternalCallbackScope, just skip them as we cannot collect any useful |
| 360 | // information about them. |
| 361 | if (external_callback_scope_->scope_address() < frame_->fp()) { |
| 362 | Address* callback_address = |
| 363 | external_callback_scope_->callback_address(); |
| 364 | if (*callback_address != NULL) { |
| 365 | frame_->state_.pc_address = callback_address; |
| 366 | } |
| 367 | external_callback_scope_ = external_callback_scope_->previous(); |
| 368 | ASSERT(external_callback_scope_ == NULL || |
| 369 | external_callback_scope_->scope_address() > frame_->fp()); |
| 370 | return; |
| 371 | } |
| 372 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 373 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 377 | // ------------------------------------------------------------------------- |
| 378 | |
| 379 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 380 | Code* StackFrame::GetSafepointData(Isolate* isolate, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 381 | Address inner_pointer, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 382 | SafepointEntry* safepoint_entry, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 383 | unsigned* stack_slots) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 384 | InnerPointerToCodeCache::InnerPointerToCodeCacheEntry* entry = |
| 385 | isolate->inner_pointer_to_code_cache()->GetCacheEntry(inner_pointer); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 386 | if (!entry->safepoint_entry.is_valid()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 387 | entry->safepoint_entry = entry->code->GetSafepointEntry(inner_pointer); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 388 | ASSERT(entry->safepoint_entry.is_valid()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 389 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 390 | ASSERT(entry->safepoint_entry.Equals( |
| 391 | entry->code->GetSafepointEntry(inner_pointer))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | // Fill in the results and return the code. |
| 395 | Code* code = entry->code; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 396 | *safepoint_entry = entry->safepoint_entry; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 397 | *stack_slots = code->stack_slots(); |
| 398 | return code; |
| 399 | } |
| 400 | |
| 401 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 402 | bool StackFrame::HasHandler() const { |
| 403 | StackHandlerIterator it(this, top_handler()); |
| 404 | return !it.done(); |
| 405 | } |
| 406 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 407 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 408 | #ifdef DEBUG |
| 409 | static bool GcSafeCodeContains(HeapObject* object, Address addr); |
| 410 | #endif |
| 411 | |
| 412 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 413 | void StackFrame::IteratePc(ObjectVisitor* v, |
| 414 | Address* pc_address, |
| 415 | Code* holder) { |
| 416 | Address pc = *pc_address; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 417 | ASSERT(GcSafeCodeContains(holder, pc)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 418 | unsigned pc_offset = static_cast<unsigned>(pc - holder->instruction_start()); |
| 419 | Object* code = holder; |
| 420 | v->VisitPointer(&code); |
| 421 | if (code != holder) { |
| 422 | holder = reinterpret_cast<Code*>(code); |
| 423 | pc = holder->instruction_start() + pc_offset; |
| 424 | *pc_address = pc; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 425 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 429 | void StackFrame::SetReturnAddressLocationResolver( |
| 430 | ReturnAddressLocationResolver resolver) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 431 | ASSERT(return_address_location_resolver_ == NULL); |
| 432 | return_address_location_resolver_ = resolver; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 436 | StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator, |
| 437 | State* state) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 438 | ASSERT(state->fp != NULL); |
| 439 | if (StandardFrame::IsArgumentsAdaptorFrame(state->fp)) { |
| 440 | return ARGUMENTS_ADAPTOR; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 441 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 442 | // The marker and function offsets overlap. If the marker isn't a |
| 443 | // smi then the frame is a JavaScript frame -- and the marker is |
| 444 | // really the function. |
| 445 | const int offset = StandardFrameConstants::kMarkerOffset; |
| 446 | Object* marker = Memory::Object_at(state->fp + offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 447 | if (!marker->IsSmi()) { |
| 448 | // If we're using a "safe" stack iterator, we treat optimized |
| 449 | // frames as normal JavaScript frames to avoid having to look |
| 450 | // into the heap to determine the state. This is safe as long |
| 451 | // as nobody tries to GC... |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 452 | if (!iterator->can_access_heap_objects_) return JAVA_SCRIPT; |
| 453 | Code::Kind kind = GetContainingCode(iterator->isolate(), |
| 454 | *(state->pc_address))->kind(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 455 | ASSERT(kind == Code::FUNCTION || kind == Code::OPTIMIZED_FUNCTION); |
| 456 | return (kind == Code::OPTIMIZED_FUNCTION) ? OPTIMIZED : JAVA_SCRIPT; |
| 457 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 458 | return static_cast<StackFrame::Type>(Smi::cast(marker)->value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 462 | #ifdef DEBUG |
| 463 | bool StackFrame::can_access_heap_objects() const { |
| 464 | return iterator_->can_access_heap_objects_; |
| 465 | } |
| 466 | #endif |
| 467 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 468 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 469 | StackFrame::Type StackFrame::GetCallerState(State* state) const { |
| 470 | ComputeCallerState(state); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 471 | return ComputeType(iterator_, state); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 475 | Address StackFrame::UnpaddedFP() const { |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 476 | #if V8_TARGET_ARCH_IA32 |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 477 | if (!is_optimized()) return fp(); |
| 478 | int32_t alignment_state = Memory::int32_at( |
| 479 | fp() + JavaScriptFrameConstants::kDynamicAlignmentStateOffset); |
| 480 | |
| 481 | return (alignment_state == kAlignmentPaddingPushed) ? |
| 482 | (fp() + kPointerSize) : fp(); |
| 483 | #else |
| 484 | return fp(); |
| 485 | #endif |
| 486 | } |
| 487 | |
| 488 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 489 | Code* EntryFrame::unchecked_code() const { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 490 | return isolate()->heap()->js_entry_code(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 494 | void EntryFrame::ComputeCallerState(State* state) const { |
| 495 | GetCallerState(state); |
| 496 | } |
| 497 | |
| 498 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 499 | void EntryFrame::SetCallerFp(Address caller_fp) { |
| 500 | const int offset = EntryFrameConstants::kCallerFPOffset; |
| 501 | Memory::Address_at(this->fp() + offset) = caller_fp; |
| 502 | } |
| 503 | |
| 504 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 505 | StackFrame::Type EntryFrame::GetCallerState(State* state) const { |
| 506 | const int offset = EntryFrameConstants::kCallerFPOffset; |
| 507 | Address fp = Memory::Address_at(this->fp() + offset); |
| 508 | return ExitFrame::GetStateForFramePointer(fp, state); |
| 509 | } |
| 510 | |
| 511 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 512 | Code* EntryConstructFrame::unchecked_code() const { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 513 | return isolate()->heap()->js_construct_entry_code(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 517 | Object*& ExitFrame::code_slot() const { |
| 518 | const int offset = ExitFrameConstants::kCodeOffset; |
| 519 | return Memory::Object_at(fp() + offset); |
| 520 | } |
| 521 | |
| 522 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 523 | Code* ExitFrame::unchecked_code() const { |
| 524 | return reinterpret_cast<Code*>(code_slot()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 528 | void ExitFrame::ComputeCallerState(State* state) const { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 529 | // Set up the caller state. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 530 | state->sp = caller_sp(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 531 | state->fp = Memory::Address_at(fp() + ExitFrameConstants::kCallerFPOffset); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 532 | state->pc_address = ResolveReturnAddressLocation( |
| 533 | reinterpret_cast<Address*>(fp() + ExitFrameConstants::kCallerPCOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 537 | void ExitFrame::SetCallerFp(Address caller_fp) { |
| 538 | Memory::Address_at(fp() + ExitFrameConstants::kCallerFPOffset) = caller_fp; |
| 539 | } |
| 540 | |
| 541 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 542 | void ExitFrame::Iterate(ObjectVisitor* v) const { |
| 543 | // The arguments are traversed as part of the expression stack of |
| 544 | // the calling frame. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 545 | IteratePc(v, pc_address(), LookupCode()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 546 | v->VisitPointer(&code_slot()); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame^] | 547 | if (FLAG_enable_ool_constant_pool) { |
| 548 | v->VisitPointer(&constant_pool_slot()); |
| 549 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 553 | Address ExitFrame::GetCallerStackPointer() const { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 554 | return fp() + ExitFrameConstants::kCallerSPDisplacement; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 558 | StackFrame::Type ExitFrame::GetStateForFramePointer(Address fp, State* state) { |
| 559 | if (fp == 0) return NONE; |
| 560 | Address sp = ComputeStackPointer(fp); |
| 561 | FillState(fp, sp, state); |
| 562 | ASSERT(*state->pc_address != NULL); |
| 563 | return EXIT; |
| 564 | } |
| 565 | |
| 566 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 567 | Address ExitFrame::ComputeStackPointer(Address fp) { |
| 568 | return Memory::Address_at(fp + ExitFrameConstants::kSPOffset); |
| 569 | } |
| 570 | |
| 571 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 572 | void ExitFrame::FillState(Address fp, Address sp, State* state) { |
| 573 | state->sp = sp; |
| 574 | state->fp = fp; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 575 | state->pc_address = ResolveReturnAddressLocation( |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 576 | reinterpret_cast<Address*>(sp - 1 * kPCOnStackSize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 580 | Address StandardFrame::GetExpressionAddress(int n) const { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 581 | const int offset = StandardFrameConstants::kExpressionsOffset; |
| 582 | return fp() + offset - n * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 586 | Object* StandardFrame::GetExpression(Address fp, int index) { |
| 587 | return Memory::Object_at(GetExpressionAddress(fp, index)); |
| 588 | } |
| 589 | |
| 590 | |
| 591 | Address StandardFrame::GetExpressionAddress(Address fp, int n) { |
| 592 | const int offset = StandardFrameConstants::kExpressionsOffset; |
| 593 | return fp + offset - n * kPointerSize; |
| 594 | } |
| 595 | |
| 596 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 597 | int StandardFrame::ComputeExpressionsCount() const { |
| 598 | const int offset = |
| 599 | StandardFrameConstants::kExpressionsOffset + kPointerSize; |
| 600 | Address base = fp() + offset; |
| 601 | Address limit = sp(); |
| 602 | ASSERT(base >= limit); // stack grows downwards |
| 603 | // Include register-allocated locals in number of expressions. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 604 | return static_cast<int>((base - limit) / kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 608 | void StandardFrame::ComputeCallerState(State* state) const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 609 | state->sp = caller_sp(); |
| 610 | state->fp = caller_fp(); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 611 | state->pc_address = ResolveReturnAddressLocation( |
| 612 | reinterpret_cast<Address*>(ComputePCAddress(fp()))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 616 | void StandardFrame::SetCallerFp(Address caller_fp) { |
| 617 | Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset) = |
| 618 | caller_fp; |
| 619 | } |
| 620 | |
| 621 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | bool StandardFrame::IsExpressionInsideHandler(int n) const { |
| 623 | Address address = GetExpressionAddress(n); |
| 624 | for (StackHandlerIterator it(this, top_handler()); !it.done(); it.Advance()) { |
| 625 | if (it.handler()->includes(address)) return true; |
| 626 | } |
| 627 | return false; |
| 628 | } |
| 629 | |
| 630 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 631 | void StandardFrame::IterateCompiledFrame(ObjectVisitor* v) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 632 | // Make sure that we're not doing "safe" stack frame iteration. We cannot |
| 633 | // possibly find pointers in optimized frames in that state. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 634 | ASSERT(can_access_heap_objects()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 635 | |
| 636 | // Compute the safepoint information. |
| 637 | unsigned stack_slots = 0; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 638 | SafepointEntry safepoint_entry; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 639 | Code* code = StackFrame::GetSafepointData( |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 640 | isolate(), pc(), &safepoint_entry, &stack_slots); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 641 | unsigned slot_space = stack_slots * kPointerSize; |
| 642 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 643 | // Visit the outgoing parameters. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 644 | Object** parameters_base = &Memory::Object_at(sp()); |
| 645 | Object** parameters_limit = &Memory::Object_at( |
| 646 | fp() + JavaScriptFrameConstants::kFunctionOffset - slot_space); |
| 647 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 648 | // Visit the parameters that may be on top of the saved registers. |
| 649 | if (safepoint_entry.argument_count() > 0) { |
| 650 | v->VisitPointers(parameters_base, |
| 651 | parameters_base + safepoint_entry.argument_count()); |
| 652 | parameters_base += safepoint_entry.argument_count(); |
| 653 | } |
| 654 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 655 | // Skip saved double registers. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 656 | if (safepoint_entry.has_doubles()) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 657 | // Number of doubles not known at snapshot time. |
| 658 | ASSERT(!Serializer::enabled()); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 659 | parameters_base += DoubleRegister::NumAllocatableRegisters() * |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 660 | kDoubleSize / kPointerSize; |
| 661 | } |
| 662 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 663 | // Visit the registers that contain pointers if any. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 664 | if (safepoint_entry.HasRegisters()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 665 | for (int i = kNumSafepointRegisters - 1; i >=0; i--) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 666 | if (safepoint_entry.HasRegisterAt(i)) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 667 | int reg_stack_index = MacroAssembler::SafepointRegisterStackIndex(i); |
| 668 | v->VisitPointer(parameters_base + reg_stack_index); |
| 669 | } |
| 670 | } |
| 671 | // Skip the words containing the register values. |
| 672 | parameters_base += kNumSafepointRegisters; |
| 673 | } |
| 674 | |
| 675 | // We're done dealing with the register bits. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 676 | uint8_t* safepoint_bits = safepoint_entry.bits(); |
| 677 | safepoint_bits += kNumSafepointRegisters >> kBitsPerByteLog2; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 678 | |
| 679 | // Visit the rest of the parameters. |
| 680 | v->VisitPointers(parameters_base, parameters_limit); |
| 681 | |
| 682 | // Visit pointer spill slots and locals. |
| 683 | for (unsigned index = 0; index < stack_slots; index++) { |
| 684 | int byte_index = index >> kBitsPerByteLog2; |
| 685 | int bit_index = index & (kBitsPerByte - 1); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 686 | if ((safepoint_bits[byte_index] & (1U << bit_index)) != 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 687 | v->VisitPointer(parameters_limit + index); |
| 688 | } |
| 689 | } |
| 690 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 691 | // Visit the return address in the callee and incoming arguments. |
| 692 | IteratePc(v, pc_address(), code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 693 | |
| 694 | // Visit the context in stub frame and JavaScript frame. |
| 695 | // Visit the function in JavaScript frame. |
| 696 | Object** fixed_base = &Memory::Object_at( |
| 697 | fp() + StandardFrameConstants::kMarkerOffset); |
| 698 | Object** fixed_limit = &Memory::Object_at(fp()); |
| 699 | v->VisitPointers(fixed_base, fixed_limit); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | |
| 703 | void StubFrame::Iterate(ObjectVisitor* v) const { |
| 704 | IterateCompiledFrame(v); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | Code* StubFrame::unchecked_code() const { |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 709 | return static_cast<Code*>(isolate()->FindCodeObject(pc())); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | |
| 713 | Address StubFrame::GetCallerStackPointer() const { |
| 714 | return fp() + ExitFrameConstants::kCallerSPDisplacement; |
| 715 | } |
| 716 | |
| 717 | |
| 718 | int StubFrame::GetNumberOfIncomingArguments() const { |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | |
| 723 | void OptimizedFrame::Iterate(ObjectVisitor* v) const { |
| 724 | #ifdef DEBUG |
| 725 | // Make sure that optimized frames do not contain any stack handlers. |
| 726 | StackHandlerIterator it(this, top_handler()); |
| 727 | ASSERT(it.done()); |
| 728 | #endif |
| 729 | |
| 730 | IterateCompiledFrame(v); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 731 | } |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 732 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 733 | |
| 734 | void JavaScriptFrame::SetParameterValue(int index, Object* value) const { |
| 735 | Memory::Object_at(GetParameterSlot(index)) = value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | |
| 739 | bool JavaScriptFrame::IsConstructor() const { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 740 | Address fp = caller_fp(); |
| 741 | if (has_adapted_arguments()) { |
| 742 | // Skip the arguments adaptor frame and look at the real caller. |
| 743 | fp = Memory::Address_at(fp + StandardFrameConstants::kCallerFPOffset); |
| 744 | } |
| 745 | return IsConstructFrame(fp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 749 | int JavaScriptFrame::GetArgumentsLength() const { |
| 750 | // If there is an arguments adaptor frame get the arguments length from it. |
| 751 | if (has_adapted_arguments()) { |
| 752 | return Smi::cast(GetExpression(caller_fp(), 0))->value(); |
| 753 | } else { |
| 754 | return GetNumberOfIncomingArguments(); |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 759 | Code* JavaScriptFrame::unchecked_code() const { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 760 | return function()->code(); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 764 | int JavaScriptFrame::GetNumberOfIncomingArguments() const { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 765 | ASSERT(can_access_heap_objects() && |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 766 | isolate()->heap()->gc_state() == Heap::NOT_IN_GC); |
| 767 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 768 | return function()->shared()->formal_parameter_count(); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 772 | Address JavaScriptFrame::GetCallerStackPointer() const { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 773 | return fp() + StandardFrameConstants::kCallerSPOffset; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 777 | void JavaScriptFrame::GetFunctions(List<JSFunction*>* functions) { |
| 778 | ASSERT(functions->length() == 0); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 779 | functions->Add(function()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | |
| 783 | void JavaScriptFrame::Summarize(List<FrameSummary>* functions) { |
| 784 | ASSERT(functions->length() == 0); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 785 | Code* code_pointer = LookupCode(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 786 | int offset = static_cast<int>(pc() - code_pointer->address()); |
| 787 | FrameSummary summary(receiver(), |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 788 | function(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 789 | code_pointer, |
| 790 | offset, |
| 791 | IsConstructor()); |
| 792 | functions->Add(summary); |
| 793 | } |
| 794 | |
| 795 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 796 | void JavaScriptFrame::PrintTop(Isolate* isolate, |
| 797 | FILE* file, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 798 | bool print_args, |
| 799 | bool print_line_number) { |
| 800 | // constructor calls |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 801 | HandleScope scope(isolate); |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 802 | DisallowHeapAllocation no_allocation; |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 803 | JavaScriptFrameIterator it(isolate); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 804 | while (!it.done()) { |
| 805 | if (it.frame()->is_java_script()) { |
| 806 | JavaScriptFrame* frame = it.frame(); |
| 807 | if (frame->IsConstructor()) PrintF(file, "new "); |
| 808 | // function name |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 809 | JSFunction* fun = frame->function(); |
| 810 | fun->PrintName(); |
| 811 | Code* js_code = frame->unchecked_code(); |
| 812 | Address pc = frame->pc(); |
| 813 | int code_offset = |
| 814 | static_cast<int>(pc - js_code->instruction_start()); |
| 815 | PrintF("+%d", code_offset); |
| 816 | SharedFunctionInfo* shared = fun->shared(); |
| 817 | if (print_line_number) { |
jkummerow@chromium.org | 3d00d0a | 2013-09-04 13:57:32 +0000 | [diff] [blame] | 818 | Code* code = Code::cast(isolate->FindCodeObject(pc)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 819 | int source_pos = code->SourcePosition(pc); |
| 820 | Object* maybe_script = shared->script(); |
| 821 | if (maybe_script->IsScript()) { |
| 822 | Handle<Script> script(Script::cast(maybe_script)); |
| 823 | int line = GetScriptLineNumberSafe(script, source_pos) + 1; |
| 824 | Object* script_name_raw = script->name(); |
| 825 | if (script_name_raw->IsString()) { |
| 826 | String* script_name = String::cast(script->name()); |
| 827 | SmartArrayPointer<char> c_script_name = |
| 828 | script_name->ToCString(DISALLOW_NULLS, |
| 829 | ROBUST_STRING_TRAVERSAL); |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 830 | PrintF(file, " at %s:%d", c_script_name.get(), line); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 831 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 832 | PrintF(file, " at <unknown>:%d", line); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 833 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 834 | } else { |
| 835 | PrintF(file, " at <unknown>:<unknown>"); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 836 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | if (print_args) { |
| 840 | // function arguments |
| 841 | // (we are intentionally only printing the actually |
| 842 | // supplied parameters, not all parameters required) |
| 843 | PrintF(file, "(this="); |
| 844 | frame->receiver()->ShortPrint(file); |
| 845 | const int length = frame->ComputeParametersCount(); |
| 846 | for (int i = 0; i < length; i++) { |
| 847 | PrintF(file, ", "); |
| 848 | frame->GetParameter(i)->ShortPrint(file); |
| 849 | } |
| 850 | PrintF(file, ")"); |
| 851 | } |
| 852 | break; |
| 853 | } |
| 854 | it.Advance(); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 859 | void JavaScriptFrame::SaveOperandStack(FixedArray* store, |
| 860 | int* stack_handler_index) const { |
| 861 | int operands_count = store->length(); |
| 862 | ASSERT_LE(operands_count, ComputeOperandsCount()); |
| 863 | |
| 864 | // Visit the stack in LIFO order, saving operands and stack handlers into the |
| 865 | // array. The saved stack handlers store a link to the next stack handler, |
| 866 | // which will allow RestoreOperandStack to rewind the handlers. |
| 867 | StackHandlerIterator it(this, top_handler()); |
| 868 | int i = operands_count - 1; |
| 869 | *stack_handler_index = -1; |
| 870 | for (; !it.done(); it.Advance()) { |
| 871 | StackHandler* handler = it.handler(); |
| 872 | // Save operands pushed after the handler was pushed. |
| 873 | for (; GetOperandSlot(i) < handler->address(); i--) { |
| 874 | store->set(i, GetOperand(i)); |
| 875 | } |
| 876 | ASSERT_GE(i + 1, StackHandlerConstants::kSlotCount); |
| 877 | ASSERT_EQ(handler->address(), GetOperandSlot(i)); |
| 878 | int next_stack_handler_index = i + 1 - StackHandlerConstants::kSlotCount; |
| 879 | handler->Unwind(isolate(), store, next_stack_handler_index, |
| 880 | *stack_handler_index); |
| 881 | *stack_handler_index = next_stack_handler_index; |
| 882 | i -= StackHandlerConstants::kSlotCount; |
| 883 | } |
| 884 | |
| 885 | // Save any remaining operands. |
| 886 | for (; i >= 0; i--) { |
| 887 | store->set(i, GetOperand(i)); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | |
| 892 | void JavaScriptFrame::RestoreOperandStack(FixedArray* store, |
| 893 | int stack_handler_index) { |
| 894 | int operands_count = store->length(); |
| 895 | ASSERT_LE(operands_count, ComputeOperandsCount()); |
| 896 | int i = 0; |
| 897 | while (i <= stack_handler_index) { |
| 898 | if (i < stack_handler_index) { |
| 899 | // An operand. |
| 900 | ASSERT_EQ(GetOperand(i), isolate()->heap()->the_hole_value()); |
| 901 | Memory::Object_at(GetOperandSlot(i)) = store->get(i); |
| 902 | i++; |
| 903 | } else { |
| 904 | // A stack handler. |
| 905 | ASSERT_EQ(i, stack_handler_index); |
| 906 | // The FixedArray store grows up. The stack grows down. So the operand |
| 907 | // slot for i actually points to the bottom of the top word in the |
| 908 | // handler. The base of the StackHandler* is the address of the bottom |
| 909 | // word, which will be the last slot that is in the handler. |
| 910 | int handler_slot_index = i + StackHandlerConstants::kSlotCount - 1; |
| 911 | StackHandler *handler = |
| 912 | StackHandler::FromAddress(GetOperandSlot(handler_slot_index)); |
| 913 | stack_handler_index = handler->Rewind(isolate(), store, i, fp()); |
| 914 | i += StackHandlerConstants::kSlotCount; |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | for (; i < operands_count; i++) { |
| 919 | ASSERT_EQ(GetOperand(i), isolate()->heap()->the_hole_value()); |
| 920 | Memory::Object_at(GetOperandSlot(i)) = store->get(i); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 925 | void FrameSummary::Print() { |
| 926 | PrintF("receiver: "); |
| 927 | receiver_->ShortPrint(); |
| 928 | PrintF("\nfunction: "); |
| 929 | function_->shared()->DebugName()->ShortPrint(); |
| 930 | PrintF("\ncode: "); |
| 931 | code_->ShortPrint(); |
| 932 | if (code_->kind() == Code::FUNCTION) PrintF(" NON-OPT"); |
| 933 | if (code_->kind() == Code::OPTIMIZED_FUNCTION) PrintF(" OPT"); |
| 934 | PrintF("\npc: %d\n", offset_); |
| 935 | } |
| 936 | |
| 937 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 938 | JSFunction* OptimizedFrame::LiteralAt(FixedArray* literal_array, |
| 939 | int literal_id) { |
| 940 | if (literal_id == Translation::kSelfLiteralId) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 941 | return function(); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | return JSFunction::cast(literal_array->get(literal_id)); |
| 945 | } |
| 946 | |
| 947 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 948 | void OptimizedFrame::Summarize(List<FrameSummary>* frames) { |
| 949 | ASSERT(frames->length() == 0); |
| 950 | ASSERT(is_optimized()); |
| 951 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 952 | int deopt_index = Safepoint::kNoDeoptimizationIndex; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 953 | DeoptimizationInputData* data = GetDeoptimizationData(&deopt_index); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 954 | FixedArray* literal_array = data->LiteralArray(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 955 | |
| 956 | // BUG(3243555): Since we don't have a lazy-deopt registered at |
| 957 | // throw-statements, we can't use the translation at the call-site of |
| 958 | // throw. An entry with no deoptimization index indicates a call-site |
| 959 | // without a lazy-deopt. As a consequence we are not allowed to inline |
| 960 | // functions containing throw. |
| 961 | if (deopt_index == Safepoint::kNoDeoptimizationIndex) { |
| 962 | JavaScriptFrame::Summarize(frames); |
| 963 | return; |
| 964 | } |
| 965 | |
| 966 | TranslationIterator it(data->TranslationByteArray(), |
| 967 | data->TranslationIndex(deopt_index)->value()); |
| 968 | Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); |
| 969 | ASSERT(opcode == Translation::BEGIN); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 970 | it.Next(); // Drop frame count. |
| 971 | int jsframe_count = it.Next(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 972 | |
| 973 | // We create the summary in reverse order because the frames |
| 974 | // in the deoptimization translation are ordered bottom-to-top. |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 975 | bool is_constructor = IsConstructor(); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 976 | int i = jsframe_count; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 977 | while (i > 0) { |
| 978 | opcode = static_cast<Translation::Opcode>(it.Next()); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 979 | if (opcode == Translation::JS_FRAME) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 980 | i--; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 981 | BailoutId ast_id = BailoutId(it.Next()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 982 | JSFunction* function = LiteralAt(literal_array, it.Next()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 983 | it.Next(); // Skip height. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 984 | |
| 985 | // The translation commands are ordered and the receiver is always |
| 986 | // at the first position. Since we are always at a call when we need |
| 987 | // to construct a stack trace, the receiver is always in a stack slot. |
| 988 | opcode = static_cast<Translation::Opcode>(it.Next()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 989 | ASSERT(opcode == Translation::STACK_SLOT || |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 990 | opcode == Translation::LITERAL || |
| 991 | opcode == Translation::CAPTURED_OBJECT || |
| 992 | opcode == Translation::DUPLICATED_OBJECT); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 993 | int index = it.Next(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 994 | |
| 995 | // Get the correct receiver in the optimized frame. |
| 996 | Object* receiver = NULL; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 997 | if (opcode == Translation::LITERAL) { |
| 998 | receiver = data->LiteralArray()->get(index); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 999 | } else if (opcode == Translation::STACK_SLOT) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1000 | // Positive index means the value is spilled to the locals |
| 1001 | // area. Negative means it is stored in the incoming parameter |
| 1002 | // area. |
| 1003 | if (index >= 0) { |
| 1004 | receiver = GetExpression(index); |
| 1005 | } else { |
| 1006 | // Index -1 overlaps with last parameter, -n with the first parameter, |
| 1007 | // (-n - 1) with the receiver with n being the number of parameters |
| 1008 | // of the outermost, optimized frame. |
| 1009 | int parameter_count = ComputeParametersCount(); |
| 1010 | int parameter_index = index + parameter_count; |
| 1011 | receiver = (parameter_index == -1) |
| 1012 | ? this->receiver() |
| 1013 | : this->GetParameter(parameter_index); |
| 1014 | } |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 1015 | } else { |
| 1016 | // TODO(3029): Materializing a captured object (or duplicated |
| 1017 | // object) is hard, we return undefined for now. This breaks the |
| 1018 | // produced stack trace, as constructor frames aren't marked as |
| 1019 | // such anymore. |
| 1020 | receiver = isolate()->heap()->undefined_value(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | Code* code = function->shared()->code(); |
| 1024 | DeoptimizationOutputData* output_data = |
| 1025 | DeoptimizationOutputData::cast(code->deoptimization_data()); |
| 1026 | unsigned entry = Deoptimizer::GetOutputInfo(output_data, |
| 1027 | ast_id, |
| 1028 | function->shared()); |
| 1029 | unsigned pc_offset = |
| 1030 | FullCodeGenerator::PcField::decode(entry) + Code::kHeaderSize; |
| 1031 | ASSERT(pc_offset > 0); |
| 1032 | |
| 1033 | FrameSummary summary(receiver, function, code, pc_offset, is_constructor); |
| 1034 | frames->Add(summary); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1035 | is_constructor = false; |
| 1036 | } else if (opcode == Translation::CONSTRUCT_STUB_FRAME) { |
| 1037 | // The next encountered JS_FRAME will be marked as a constructor call. |
| 1038 | it.Skip(Translation::NumberOfOperandsFor(opcode)); |
| 1039 | ASSERT(!is_constructor); |
| 1040 | is_constructor = true; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1041 | } else { |
| 1042 | // Skip over operands to advance to the next opcode. |
| 1043 | it.Skip(Translation::NumberOfOperandsFor(opcode)); |
| 1044 | } |
| 1045 | } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1046 | ASSERT(!is_constructor); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | |
| 1050 | DeoptimizationInputData* OptimizedFrame::GetDeoptimizationData( |
| 1051 | int* deopt_index) { |
| 1052 | ASSERT(is_optimized()); |
| 1053 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1054 | JSFunction* opt_function = function(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1055 | Code* code = opt_function->code(); |
| 1056 | |
| 1057 | // The code object may have been replaced by lazy deoptimization. Fall |
| 1058 | // back to a slow search in this case to find the original optimized |
| 1059 | // code object. |
| 1060 | if (!code->contains(pc())) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1061 | code = isolate()->inner_pointer_to_code_cache()-> |
| 1062 | GcSafeFindCodeForInnerPointer(pc()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1063 | } |
| 1064 | ASSERT(code != NULL); |
| 1065 | ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); |
| 1066 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1067 | SafepointEntry safepoint_entry = code->GetSafepointEntry(pc()); |
| 1068 | *deopt_index = safepoint_entry.deoptimization_index(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1069 | ASSERT(*deopt_index != Safepoint::kNoDeoptimizationIndex); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1070 | |
| 1071 | return DeoptimizationInputData::cast(code->deoptimization_data()); |
| 1072 | } |
| 1073 | |
| 1074 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1075 | int OptimizedFrame::GetInlineCount() { |
| 1076 | ASSERT(is_optimized()); |
| 1077 | |
| 1078 | int deopt_index = Safepoint::kNoDeoptimizationIndex; |
| 1079 | DeoptimizationInputData* data = GetDeoptimizationData(&deopt_index); |
| 1080 | |
| 1081 | TranslationIterator it(data->TranslationByteArray(), |
| 1082 | data->TranslationIndex(deopt_index)->value()); |
| 1083 | Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); |
| 1084 | ASSERT(opcode == Translation::BEGIN); |
| 1085 | USE(opcode); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1086 | it.Next(); // Drop frame count. |
| 1087 | int jsframe_count = it.Next(); |
| 1088 | return jsframe_count; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1092 | void OptimizedFrame::GetFunctions(List<JSFunction*>* functions) { |
| 1093 | ASSERT(functions->length() == 0); |
| 1094 | ASSERT(is_optimized()); |
| 1095 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1096 | int deopt_index = Safepoint::kNoDeoptimizationIndex; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1097 | DeoptimizationInputData* data = GetDeoptimizationData(&deopt_index); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1098 | FixedArray* literal_array = data->LiteralArray(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1099 | |
| 1100 | TranslationIterator it(data->TranslationByteArray(), |
| 1101 | data->TranslationIndex(deopt_index)->value()); |
| 1102 | Translation::Opcode opcode = static_cast<Translation::Opcode>(it.Next()); |
| 1103 | ASSERT(opcode == Translation::BEGIN); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1104 | it.Next(); // Drop frame count. |
| 1105 | int jsframe_count = it.Next(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1106 | |
| 1107 | // We insert the frames in reverse order because the frames |
| 1108 | // in the deoptimization translation are ordered bottom-to-top. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1109 | while (jsframe_count > 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1110 | opcode = static_cast<Translation::Opcode>(it.Next()); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1111 | if (opcode == Translation::JS_FRAME) { |
| 1112 | jsframe_count--; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1113 | it.Next(); // Skip ast id. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1114 | JSFunction* function = LiteralAt(literal_array, it.Next()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1115 | it.Next(); // Skip height. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1116 | functions->Add(function); |
| 1117 | } else { |
| 1118 | // Skip over operands to advance to the next opcode. |
| 1119 | it.Skip(Translation::NumberOfOperandsFor(opcode)); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1125 | int ArgumentsAdaptorFrame::GetNumberOfIncomingArguments() const { |
| 1126 | return Smi::cast(GetExpression(0))->value(); |
| 1127 | } |
| 1128 | |
| 1129 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1130 | Address ArgumentsAdaptorFrame::GetCallerStackPointer() const { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1131 | return fp() + StandardFrameConstants::kCallerSPOffset; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | |
| 1135 | Address InternalFrame::GetCallerStackPointer() const { |
| 1136 | // Internal frames have no arguments. The stack pointer of the |
| 1137 | // caller is at a fixed offset from the frame pointer. |
| 1138 | return fp() + StandardFrameConstants::kCallerSPOffset; |
| 1139 | } |
| 1140 | |
| 1141 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1142 | Code* ArgumentsAdaptorFrame::unchecked_code() const { |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1143 | return isolate()->builtins()->builtin( |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1144 | Builtins::kArgumentsAdaptorTrampoline); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1148 | Code* InternalFrame::unchecked_code() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1149 | const int offset = InternalFrameConstants::kCodeOffset; |
| 1150 | Object* code = Memory::Object_at(fp() + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1151 | ASSERT(code != NULL); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1152 | return reinterpret_cast<Code*>(code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | |
| 1156 | void StackFrame::PrintIndex(StringStream* accumulator, |
| 1157 | PrintMode mode, |
| 1158 | int index) { |
| 1159 | accumulator->Add((mode == OVERVIEW) ? "%5d: " : "[%d]: ", index); |
| 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | void JavaScriptFrame::Print(StringStream* accumulator, |
| 1164 | PrintMode mode, |
| 1165 | int index) const { |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1166 | HandleScope scope(isolate()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1167 | Object* receiver = this->receiver(); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1168 | JSFunction* function = this->function(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1169 | |
| 1170 | accumulator->PrintSecurityTokenIfChanged(function); |
| 1171 | PrintIndex(accumulator, mode, index); |
| 1172 | Code* code = NULL; |
| 1173 | if (IsConstructor()) accumulator->Add("new "); |
| 1174 | accumulator->PrintFunction(function, receiver, &code); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1175 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1176 | // Get scope information for nicer output, if possible. If code is NULL, or |
| 1177 | // doesn't contain scope info, scope_info will return 0 for the number of |
| 1178 | // parameters, stack local variables, context local variables, stack slots, |
| 1179 | // or context slots. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1180 | Handle<ScopeInfo> scope_info(ScopeInfo::Empty(isolate())); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1181 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1182 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 1183 | scope_info = Handle<ScopeInfo>(shared->scope_info()); |
| 1184 | Object* script_obj = shared->script(); |
| 1185 | if (script_obj->IsScript()) { |
| 1186 | Handle<Script> script(Script::cast(script_obj)); |
| 1187 | accumulator->Add(" ["); |
| 1188 | accumulator->PrintName(script->name()); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1189 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1190 | Address pc = this->pc(); |
| 1191 | if (code != NULL && code->kind() == Code::FUNCTION && |
| 1192 | pc >= code->instruction_start() && pc < code->instruction_end()) { |
| 1193 | int source_pos = code->SourcePosition(pc); |
| 1194 | int line = GetScriptLineNumberSafe(script, source_pos) + 1; |
| 1195 | accumulator->Add(":%d", line); |
| 1196 | } else { |
| 1197 | int function_start_pos = shared->start_position(); |
| 1198 | int line = GetScriptLineNumberSafe(script, function_start_pos) + 1; |
| 1199 | accumulator->Add(":~%d", line); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1200 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1201 | |
| 1202 | accumulator->Add("] "); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1205 | accumulator->Add("(this=%o", receiver); |
| 1206 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1207 | // Print the parameters. |
| 1208 | int parameters_count = ComputeParametersCount(); |
| 1209 | for (int i = 0; i < parameters_count; i++) { |
| 1210 | accumulator->Add(","); |
| 1211 | // If we have a name for the parameter we print it. Nameless |
| 1212 | // parameters are either because we have more actual parameters |
| 1213 | // than formal parameters or because we have no scope information. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1214 | if (i < scope_info->ParameterCount()) { |
| 1215 | accumulator->PrintName(scope_info->ParameterName(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1216 | accumulator->Add("="); |
| 1217 | } |
| 1218 | accumulator->Add("%o", GetParameter(i)); |
| 1219 | } |
| 1220 | |
| 1221 | accumulator->Add(")"); |
| 1222 | if (mode == OVERVIEW) { |
| 1223 | accumulator->Add("\n"); |
| 1224 | return; |
| 1225 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1226 | if (is_optimized()) { |
| 1227 | accumulator->Add(" {\n// optimized frame\n}\n"); |
| 1228 | return; |
| 1229 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1230 | accumulator->Add(" {\n"); |
| 1231 | |
| 1232 | // Compute the number of locals and expression stack elements. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1233 | int stack_locals_count = scope_info->StackLocalCount(); |
| 1234 | int heap_locals_count = scope_info->ContextLocalCount(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1235 | int expressions_count = ComputeExpressionsCount(); |
| 1236 | |
| 1237 | // Print stack-allocated local variables. |
| 1238 | if (stack_locals_count > 0) { |
| 1239 | accumulator->Add(" // stack-allocated locals\n"); |
| 1240 | } |
| 1241 | for (int i = 0; i < stack_locals_count; i++) { |
| 1242 | accumulator->Add(" var "); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1243 | accumulator->PrintName(scope_info->StackLocalName(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1244 | accumulator->Add(" = "); |
| 1245 | if (i < expressions_count) { |
| 1246 | accumulator->Add("%o", GetExpression(i)); |
| 1247 | } else { |
| 1248 | accumulator->Add("// no expression found - inconsistent frame?"); |
| 1249 | } |
| 1250 | accumulator->Add("\n"); |
| 1251 | } |
| 1252 | |
| 1253 | // Try to get hold of the context of this frame. |
| 1254 | Context* context = NULL; |
| 1255 | if (this->context() != NULL && this->context()->IsContext()) { |
| 1256 | context = Context::cast(this->context()); |
| 1257 | } |
| 1258 | |
| 1259 | // Print heap-allocated local variables. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1260 | if (heap_locals_count > 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1261 | accumulator->Add(" // heap-allocated locals\n"); |
| 1262 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1263 | for (int i = 0; i < heap_locals_count; i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1264 | accumulator->Add(" var "); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1265 | accumulator->PrintName(scope_info->ContextLocalName(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1266 | accumulator->Add(" = "); |
| 1267 | if (context != NULL) { |
| 1268 | if (i < context->length()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1269 | accumulator->Add("%o", context->get(Context::MIN_CONTEXT_SLOTS + i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1270 | } else { |
| 1271 | accumulator->Add( |
| 1272 | "// warning: missing context slot - inconsistent frame?"); |
| 1273 | } |
| 1274 | } else { |
| 1275 | accumulator->Add("// warning: no context found - inconsistent frame?"); |
| 1276 | } |
| 1277 | accumulator->Add("\n"); |
| 1278 | } |
| 1279 | |
| 1280 | // Print the expression stack. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1281 | int expressions_start = stack_locals_count; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1282 | if (expressions_start < expressions_count) { |
| 1283 | accumulator->Add(" // expression stack (top to bottom)\n"); |
| 1284 | } |
| 1285 | for (int i = expressions_count - 1; i >= expressions_start; i--) { |
| 1286 | if (IsExpressionInsideHandler(i)) continue; |
| 1287 | accumulator->Add(" [%02d] : %o\n", i, GetExpression(i)); |
| 1288 | } |
| 1289 | |
| 1290 | // Print details about the function. |
| 1291 | if (FLAG_max_stack_trace_source_length != 0 && code != NULL) { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1292 | SharedFunctionInfo* shared = function->shared(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1293 | accumulator->Add("--------- s o u r c e c o d e ---------\n"); |
| 1294 | shared->SourceCodePrint(accumulator, FLAG_max_stack_trace_source_length); |
| 1295 | accumulator->Add("\n-----------------------------------------\n"); |
| 1296 | } |
| 1297 | |
| 1298 | accumulator->Add("}\n\n"); |
| 1299 | } |
| 1300 | |
| 1301 | |
| 1302 | void ArgumentsAdaptorFrame::Print(StringStream* accumulator, |
| 1303 | PrintMode mode, |
| 1304 | int index) const { |
| 1305 | int actual = ComputeParametersCount(); |
| 1306 | int expected = -1; |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 1307 | JSFunction* function = this->function(); |
| 1308 | expected = function->shared()->formal_parameter_count(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1309 | |
| 1310 | PrintIndex(accumulator, mode, index); |
| 1311 | accumulator->Add("arguments adaptor frame: %d->%d", actual, expected); |
| 1312 | if (mode == OVERVIEW) { |
| 1313 | accumulator->Add("\n"); |
| 1314 | return; |
| 1315 | } |
| 1316 | accumulator->Add(" {\n"); |
| 1317 | |
| 1318 | // Print actual arguments. |
| 1319 | if (actual > 0) accumulator->Add(" // actual arguments\n"); |
| 1320 | for (int i = 0; i < actual; i++) { |
| 1321 | accumulator->Add(" [%02d] : %o", i, GetParameter(i)); |
| 1322 | if (expected != -1 && i >= expected) { |
| 1323 | accumulator->Add(" // not passed to callee"); |
| 1324 | } |
| 1325 | accumulator->Add("\n"); |
| 1326 | } |
| 1327 | |
| 1328 | accumulator->Add("}\n\n"); |
| 1329 | } |
| 1330 | |
| 1331 | |
| 1332 | void EntryFrame::Iterate(ObjectVisitor* v) const { |
| 1333 | StackHandlerIterator it(this, top_handler()); |
| 1334 | ASSERT(!it.done()); |
| 1335 | StackHandler* handler = it.handler(); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1336 | ASSERT(handler->is_js_entry()); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1337 | handler->Iterate(v, LookupCode()); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1338 | #ifdef DEBUG |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1339 | // Make sure that the entry frame does not contain more than one |
| 1340 | // stack handler. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1341 | it.Advance(); |
| 1342 | ASSERT(it.done()); |
| 1343 | #endif |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1344 | IteratePc(v, pc_address(), LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | |
| 1348 | void StandardFrame::IterateExpressions(ObjectVisitor* v) const { |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame^] | 1349 | const int offset = StandardFrameConstants::kLastObjectOffset; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1350 | Object** base = &Memory::Object_at(sp()); |
| 1351 | Object** limit = &Memory::Object_at(fp() + offset) + 1; |
| 1352 | for (StackHandlerIterator it(this, top_handler()); !it.done(); it.Advance()) { |
| 1353 | StackHandler* handler = it.handler(); |
| 1354 | // Traverse pointers down to - but not including - the next |
| 1355 | // handler in the handler chain. Update the base to skip the |
| 1356 | // handler and allow the handler to traverse its own pointers. |
| 1357 | const Address address = handler->address(); |
| 1358 | v->VisitPointers(base, reinterpret_cast<Object**>(address)); |
| 1359 | base = reinterpret_cast<Object**>(address + StackHandlerConstants::kSize); |
| 1360 | // Traverse the pointers in the handler itself. |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1361 | handler->Iterate(v, LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1362 | } |
| 1363 | v->VisitPointers(base, limit); |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | void JavaScriptFrame::Iterate(ObjectVisitor* v) const { |
| 1368 | IterateExpressions(v); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1369 | IteratePc(v, pc_address(), LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | void InternalFrame::Iterate(ObjectVisitor* v) const { |
| 1374 | // Internal frames only have object pointers on the expression stack |
| 1375 | // as they never have any arguments. |
| 1376 | IterateExpressions(v); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1377 | IteratePc(v, pc_address(), LookupCode()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1381 | void StubFailureTrampolineFrame::Iterate(ObjectVisitor* v) const { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1382 | Object** base = &Memory::Object_at(sp()); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1383 | Object** limit = &Memory::Object_at(fp() + |
| 1384 | kFirstRegisterParameterFrameOffset); |
| 1385 | v->VisitPointers(base, limit); |
| 1386 | base = &Memory::Object_at(fp() + StandardFrameConstants::kMarkerOffset); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame^] | 1387 | const int offset = StandardFrameConstants::kLastObjectOffset; |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1388 | limit = &Memory::Object_at(fp() + offset) + 1; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1389 | v->VisitPointers(base, limit); |
| 1390 | IteratePc(v, pc_address(), LookupCode()); |
| 1391 | } |
| 1392 | |
| 1393 | |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1394 | Address StubFailureTrampolineFrame::GetCallerStackPointer() const { |
| 1395 | return fp() + StandardFrameConstants::kCallerSPOffset; |
| 1396 | } |
| 1397 | |
| 1398 | |
| 1399 | Code* StubFailureTrampolineFrame::unchecked_code() const { |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1400 | Code* trampoline; |
| 1401 | StubFailureTrampolineStub(NOT_JS_FUNCTION_STUB_MODE). |
| 1402 | FindCodeInCache(&trampoline, isolate()); |
| 1403 | if (trampoline->contains(pc())) { |
| 1404 | return trampoline; |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1405 | } |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1406 | |
| 1407 | StubFailureTrampolineStub(JS_FUNCTION_STUB_MODE). |
| 1408 | FindCodeInCache(&trampoline, isolate()); |
| 1409 | if (trampoline->contains(pc())) { |
| 1410 | return trampoline; |
| 1411 | } |
| 1412 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 1413 | StubFailureTailCallTrampolineStub().FindCodeInCache(&trampoline, isolate()); |
| 1414 | if (trampoline->contains(pc())) { |
| 1415 | return trampoline; |
| 1416 | } |
| 1417 | |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 1418 | UNREACHABLE(); |
| 1419 | return NULL; |
| 1420 | } |
| 1421 | |
| 1422 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1423 | // ------------------------------------------------------------------------- |
| 1424 | |
| 1425 | |
| 1426 | JavaScriptFrame* StackFrameLocator::FindJavaScriptFrame(int n) { |
| 1427 | ASSERT(n >= 0); |
| 1428 | for (int i = 0; i <= n; i++) { |
| 1429 | while (!iterator_.frame()->is_java_script()) iterator_.Advance(); |
| 1430 | if (i == n) return JavaScriptFrame::cast(iterator_.frame()); |
| 1431 | iterator_.Advance(); |
| 1432 | } |
| 1433 | UNREACHABLE(); |
| 1434 | return NULL; |
| 1435 | } |
| 1436 | |
| 1437 | |
| 1438 | // ------------------------------------------------------------------------- |
| 1439 | |
| 1440 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1441 | static Map* GcSafeMapOfCodeSpaceObject(HeapObject* object) { |
| 1442 | MapWord map_word = object->map_word(); |
| 1443 | return map_word.IsForwardingAddress() ? |
| 1444 | map_word.ToForwardingAddress()->map() : map_word.ToMap(); |
| 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | static int GcSafeSizeOfCodeSpaceObject(HeapObject* object) { |
| 1449 | return object->SizeFromMap(GcSafeMapOfCodeSpaceObject(object)); |
| 1450 | } |
| 1451 | |
| 1452 | |
| 1453 | #ifdef DEBUG |
| 1454 | static bool GcSafeCodeContains(HeapObject* code, Address addr) { |
| 1455 | Map* map = GcSafeMapOfCodeSpaceObject(code); |
| 1456 | ASSERT(map == code->GetHeap()->code_map()); |
| 1457 | Address start = code->address(); |
| 1458 | Address end = code->address() + code->SizeFromMap(map); |
| 1459 | return start <= addr && addr < end; |
| 1460 | } |
| 1461 | #endif |
| 1462 | |
| 1463 | |
| 1464 | Code* InnerPointerToCodeCache::GcSafeCastToCode(HeapObject* object, |
| 1465 | Address inner_pointer) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1466 | Code* code = reinterpret_cast<Code*>(object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1467 | ASSERT(code != NULL && GcSafeCodeContains(code, inner_pointer)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1468 | return code; |
| 1469 | } |
| 1470 | |
| 1471 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1472 | Code* InnerPointerToCodeCache::GcSafeFindCodeForInnerPointer( |
| 1473 | Address inner_pointer) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1474 | Heap* heap = isolate_->heap(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1475 | // Check if the inner pointer points into a large object chunk. |
jkummerow@chromium.org | 531dfe8 | 2012-03-20 13:01:16 +0000 | [diff] [blame] | 1476 | LargePage* large_page = heap->lo_space()->FindPage(inner_pointer); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1477 | if (large_page != NULL) { |
| 1478 | return GcSafeCastToCode(large_page->GetObject(), inner_pointer); |
| 1479 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1480 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1481 | // Iterate through the page until we reach the end or find an object starting |
| 1482 | // after the inner pointer. |
| 1483 | Page* page = Page::FromAddress(inner_pointer); |
| 1484 | |
| 1485 | Address addr = page->skip_list()->StartFor(inner_pointer); |
| 1486 | |
| 1487 | Address top = heap->code_space()->top(); |
| 1488 | Address limit = heap->code_space()->limit(); |
| 1489 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1490 | while (true) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1491 | if (addr == top && addr != limit) { |
| 1492 | addr = limit; |
| 1493 | continue; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1494 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1495 | |
| 1496 | HeapObject* obj = HeapObject::FromAddress(addr); |
| 1497 | int obj_size = GcSafeSizeOfCodeSpaceObject(obj); |
| 1498 | Address next_addr = addr + obj_size; |
| 1499 | if (next_addr > inner_pointer) return GcSafeCastToCode(obj, inner_pointer); |
| 1500 | addr = next_addr; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1504 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1505 | InnerPointerToCodeCache::InnerPointerToCodeCacheEntry* |
| 1506 | InnerPointerToCodeCache::GetCacheEntry(Address inner_pointer) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1507 | isolate_->counters()->pc_to_code()->Increment(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1508 | ASSERT(IsPowerOf2(kInnerPointerToCodeCacheSize)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1509 | uint32_t hash = ComputeIntegerHash( |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1510 | static_cast<uint32_t>(reinterpret_cast<uintptr_t>(inner_pointer)), |
| 1511 | v8::internal::kZeroHashSeed); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1512 | uint32_t index = hash & (kInnerPointerToCodeCacheSize - 1); |
| 1513 | InnerPointerToCodeCacheEntry* entry = cache(index); |
| 1514 | if (entry->inner_pointer == inner_pointer) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1515 | isolate_->counters()->pc_to_code_cached()->Increment(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1516 | ASSERT(entry->code == GcSafeFindCodeForInnerPointer(inner_pointer)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1517 | } else { |
| 1518 | // Because this code may be interrupted by a profiling signal that |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1519 | // also queries the cache, we cannot update inner_pointer before the code |
| 1520 | // has been set. Otherwise, we risk trying to use a cache entry before |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1521 | // the code has been computed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1522 | entry->code = GcSafeFindCodeForInnerPointer(inner_pointer); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1523 | entry->safepoint_entry.Reset(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1524 | entry->inner_pointer = inner_pointer; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1525 | } |
| 1526 | return entry; |
| 1527 | } |
| 1528 | |
| 1529 | |
| 1530 | // ------------------------------------------------------------------------- |
| 1531 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1532 | |
| 1533 | void StackHandler::Unwind(Isolate* isolate, |
| 1534 | FixedArray* array, |
| 1535 | int offset, |
| 1536 | int previous_handler_offset) const { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1537 | STATIC_ASSERT(StackHandlerConstants::kSlotCount >= 5); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1538 | ASSERT_LE(0, offset); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1539 | ASSERT_GE(array->length(), offset + StackHandlerConstants::kSlotCount); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1540 | // Unwinding a stack handler into an array chains it in the opposite |
| 1541 | // direction, re-using the "next" slot as a "previous" link, so that stack |
| 1542 | // handlers can be later re-wound in the correct order. Decode the "state" |
| 1543 | // slot into "index" and "kind" and store them separately, using the fp slot. |
| 1544 | array->set(offset, Smi::FromInt(previous_handler_offset)); // next |
| 1545 | array->set(offset + 1, *code_address()); // code |
| 1546 | array->set(offset + 2, Smi::FromInt(static_cast<int>(index()))); // state |
| 1547 | array->set(offset + 3, *context_address()); // context |
| 1548 | array->set(offset + 4, Smi::FromInt(static_cast<int>(kind()))); // fp |
| 1549 | |
| 1550 | *isolate->handler_address() = next()->address(); |
| 1551 | } |
| 1552 | |
| 1553 | |
| 1554 | int StackHandler::Rewind(Isolate* isolate, |
| 1555 | FixedArray* array, |
| 1556 | int offset, |
| 1557 | Address fp) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1558 | STATIC_ASSERT(StackHandlerConstants::kSlotCount >= 5); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1559 | ASSERT_LE(0, offset); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1560 | ASSERT_GE(array->length(), offset + StackHandlerConstants::kSlotCount); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1561 | Smi* prev_handler_offset = Smi::cast(array->get(offset)); |
| 1562 | Code* code = Code::cast(array->get(offset + 1)); |
| 1563 | Smi* smi_index = Smi::cast(array->get(offset + 2)); |
| 1564 | Object* context = array->get(offset + 3); |
| 1565 | Smi* smi_kind = Smi::cast(array->get(offset + 4)); |
| 1566 | |
| 1567 | unsigned state = KindField::encode(static_cast<Kind>(smi_kind->value())) | |
| 1568 | IndexField::encode(static_cast<unsigned>(smi_index->value())); |
| 1569 | |
| 1570 | Memory::Address_at(address() + StackHandlerConstants::kNextOffset) = |
| 1571 | *isolate->handler_address(); |
| 1572 | Memory::Object_at(address() + StackHandlerConstants::kCodeOffset) = code; |
| 1573 | Memory::uintptr_at(address() + StackHandlerConstants::kStateOffset) = state; |
| 1574 | Memory::Object_at(address() + StackHandlerConstants::kContextOffset) = |
| 1575 | context; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1576 | SetFp(address() + StackHandlerConstants::kFPOffset, fp); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1577 | |
| 1578 | *isolate->handler_address() = address(); |
| 1579 | |
| 1580 | return prev_handler_offset->value(); |
| 1581 | } |
| 1582 | |
| 1583 | |
| 1584 | // ------------------------------------------------------------------------- |
| 1585 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1586 | int NumRegs(RegList reglist) { |
yangguo@chromium.org | efdb9d7 | 2012-04-26 08:21:05 +0000 | [diff] [blame] | 1587 | return CompilerIntrinsics::CountSetBits(reglist); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1591 | struct JSCallerSavedCodeData { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1592 | int reg_code[kNumJSCallerSaved]; |
| 1593 | }; |
| 1594 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 1595 | JSCallerSavedCodeData caller_saved_code_data; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1596 | |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 1597 | void SetUpJSCallerSavedCodeData() { |
| 1598 | int i = 0; |
| 1599 | for (int r = 0; r < kNumRegs; r++) |
| 1600 | if ((kJSCallerSaved & (1 << r)) != 0) |
| 1601 | caller_saved_code_data.reg_code[i++] = r; |
| 1602 | |
| 1603 | ASSERT(i == kNumJSCallerSaved); |
| 1604 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1605 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1606 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1607 | int JSCallerSavedCode(int n) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1608 | ASSERT(0 <= n && n < kNumJSCallerSaved); |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 1609 | return caller_saved_code_data.reg_code[n]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1613 | #define DEFINE_WRAPPER(type, field) \ |
| 1614 | class field##_Wrapper : public ZoneObject { \ |
| 1615 | public: /* NOLINT */ \ |
| 1616 | field##_Wrapper(const field& original) : frame_(original) { \ |
| 1617 | } \ |
| 1618 | field frame_; \ |
| 1619 | }; |
| 1620 | STACK_FRAME_TYPE_LIST(DEFINE_WRAPPER) |
| 1621 | #undef DEFINE_WRAPPER |
| 1622 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1623 | static StackFrame* AllocateFrameCopy(StackFrame* frame, Zone* zone) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1624 | #define FRAME_TYPE_CASE(type, field) \ |
| 1625 | case StackFrame::type: { \ |
| 1626 | field##_Wrapper* wrapper = \ |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1627 | new(zone) field##_Wrapper(*(reinterpret_cast<field*>(frame))); \ |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1628 | return &wrapper->frame_; \ |
| 1629 | } |
| 1630 | |
| 1631 | switch (frame->type()) { |
| 1632 | STACK_FRAME_TYPE_LIST(FRAME_TYPE_CASE) |
| 1633 | default: UNREACHABLE(); |
| 1634 | } |
| 1635 | #undef FRAME_TYPE_CASE |
| 1636 | return NULL; |
| 1637 | } |
| 1638 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1639 | |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1640 | Vector<StackFrame*> CreateStackMap(Isolate* isolate, Zone* zone) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1641 | ZoneList<StackFrame*> list(10, zone); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 1642 | for (StackFrameIterator it(isolate); !it.done(); it.Advance()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1643 | StackFrame* frame = AllocateFrameCopy(it.frame(), zone); |
| 1644 | list.Add(frame, zone); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1645 | } |
| 1646 | return list.ToVector(); |
| 1647 | } |
| 1648 | |
| 1649 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1650 | } } // namespace v8::internal |