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