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