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