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