yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +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 | #ifndef V8_FRAMES_INL_H_ |
| 29 | #define V8_FRAMES_INL_H_ |
| 30 | |
| 31 | #include "frames.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 32 | #include "isolate.h" |
| 33 | #include "v8memory.h" |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 34 | |
| 35 | #if V8_TARGET_ARCH_IA32 |
| 36 | #include "ia32/frames-ia32.h" |
| 37 | #elif V8_TARGET_ARCH_X64 |
| 38 | #include "x64/frames-x64.h" |
| 39 | #elif V8_TARGET_ARCH_ARM |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 40 | #include "arm/frames-arm.h" |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 41 | #elif V8_TARGET_ARCH_MIPS |
| 42 | #include "mips/frames-mips.h" |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 43 | #else |
| 44 | #error Unsupported target architecture. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 45 | #endif |
| 46 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 47 | namespace v8 { |
| 48 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | |
| 50 | |
| 51 | inline Address StackHandler::address() const { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 52 | return reinterpret_cast<Address>(const_cast<StackHandler*>(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
| 56 | inline StackHandler* StackHandler::next() const { |
| 57 | const int offset = StackHandlerConstants::kNextOffset; |
| 58 | return FromAddress(Memory::Address_at(address() + offset)); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | inline bool StackHandler::includes(Address address) const { |
| 63 | Address start = this->address(); |
| 64 | Address end = start + StackHandlerConstants::kSize; |
| 65 | return start <= address && address <= end; |
| 66 | } |
| 67 | |
| 68 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 69 | inline void StackHandler::Iterate(ObjectVisitor* v, Code* holder) const { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 70 | v->VisitPointer(context_address()); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 71 | v->VisitPointer(code_address()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | |
| 75 | inline StackHandler* StackHandler::FromAddress(Address address) { |
| 76 | return reinterpret_cast<StackHandler*>(address); |
| 77 | } |
| 78 | |
| 79 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame^] | 80 | inline bool StackHandler::is_js_entry() const { |
| 81 | return kind() == JS_ENTRY; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame^] | 85 | inline bool StackHandler::is_catch() const { |
| 86 | return kind() == CATCH; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame^] | 90 | inline bool StackHandler::is_finally() const { |
| 91 | return kind() == FINALLY; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 95 | inline StackHandler::Kind StackHandler::kind() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 96 | const int offset = StackHandlerConstants::kStateOffset; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 97 | return KindField::decode(Memory::unsigned_at(address() + offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 101 | inline Object** StackHandler::context_address() const { |
| 102 | const int offset = StackHandlerConstants::kContextOffset; |
| 103 | return reinterpret_cast<Object**>(address() + offset); |
| 104 | } |
| 105 | |
| 106 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 107 | inline Object** StackHandler::code_address() const { |
| 108 | const int offset = StackHandlerConstants::kCodeOffset; |
| 109 | return reinterpret_cast<Object**>(address() + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 113 | inline StackFrame::StackFrame(StackFrameIterator* iterator) |
| 114 | : iterator_(iterator), isolate_(iterator_->isolate()) { |
| 115 | } |
| 116 | |
| 117 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 118 | inline StackHandler* StackFrame::top_handler() const { |
| 119 | return iterator_->handler(); |
| 120 | } |
| 121 | |
| 122 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 123 | inline Code* StackFrame::LookupCode() const { |
| 124 | return GetContainingCode(isolate(), pc()); |
| 125 | } |
| 126 | |
| 127 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 128 | inline Code* StackFrame::GetContainingCode(Isolate* isolate, Address pc) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 129 | return isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; |
| 130 | } |
| 131 | |
| 132 | |
| 133 | inline EntryFrame::EntryFrame(StackFrameIterator* iterator) |
| 134 | : StackFrame(iterator) { |
| 135 | } |
| 136 | |
| 137 | |
| 138 | inline EntryConstructFrame::EntryConstructFrame(StackFrameIterator* iterator) |
| 139 | : EntryFrame(iterator) { |
| 140 | } |
| 141 | |
| 142 | |
| 143 | inline ExitFrame::ExitFrame(StackFrameIterator* iterator) |
| 144 | : StackFrame(iterator) { |
| 145 | } |
| 146 | |
| 147 | |
| 148 | inline StandardFrame::StandardFrame(StackFrameIterator* iterator) |
| 149 | : StackFrame(iterator) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | inline Object* StandardFrame::GetExpression(int index) const { |
| 154 | return Memory::Object_at(GetExpressionAddress(index)); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | inline void StandardFrame::SetExpression(int index, Object* value) { |
| 159 | Memory::Object_at(GetExpressionAddress(index)) = value; |
| 160 | } |
| 161 | |
| 162 | |
| 163 | inline Object* StandardFrame::context() const { |
| 164 | const int offset = StandardFrameConstants::kContextOffset; |
| 165 | return Memory::Object_at(fp() + offset); |
| 166 | } |
| 167 | |
| 168 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 169 | inline Address StandardFrame::caller_fp() const { |
| 170 | return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | inline Address StandardFrame::caller_pc() const { |
| 175 | return Memory::Address_at(ComputePCAddress(fp())); |
| 176 | } |
| 177 | |
| 178 | |
| 179 | inline Address StandardFrame::ComputePCAddress(Address fp) { |
| 180 | return fp + StandardFrameConstants::kCallerPCOffset; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 185 | Object* marker = |
| 186 | Memory::Object_at(fp + StandardFrameConstants::kContextOffset); |
| 187 | return marker == Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 191 | inline bool StandardFrame::IsConstructFrame(Address fp) { |
| 192 | Object* marker = |
| 193 | Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset); |
| 194 | return marker == Smi::FromInt(CONSTRUCT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 198 | inline JavaScriptFrame::JavaScriptFrame(StackFrameIterator* iterator) |
| 199 | : StandardFrame(iterator) { |
| 200 | } |
| 201 | |
| 202 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 203 | Address JavaScriptFrame::GetParameterSlot(int index) const { |
| 204 | int param_count = ComputeParametersCount(); |
| 205 | ASSERT(-1 <= index && index < param_count); |
| 206 | int parameter_offset = (param_count - index - 1) * kPointerSize; |
| 207 | return caller_sp() + parameter_offset; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | Object* JavaScriptFrame::GetParameter(int index) const { |
| 212 | return Memory::Object_at(GetParameterSlot(index)); |
| 213 | } |
| 214 | |
| 215 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | inline Object* JavaScriptFrame::receiver() const { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 217 | return GetParameter(-1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
| 221 | inline void JavaScriptFrame::set_receiver(Object* value) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 222 | Memory::Object_at(GetParameterSlot(-1)) = value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | |
| 226 | inline bool JavaScriptFrame::has_adapted_arguments() const { |
| 227 | return IsArgumentsAdaptorFrame(caller_fp()); |
| 228 | } |
| 229 | |
| 230 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 231 | inline Object* JavaScriptFrame::function() const { |
| 232 | Object* result = function_slot_object(); |
| 233 | ASSERT(result->IsJSFunction()); |
| 234 | return result; |
| 235 | } |
| 236 | |
| 237 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 238 | inline OptimizedFrame::OptimizedFrame(StackFrameIterator* iterator) |
| 239 | : JavaScriptFrame(iterator) { |
| 240 | } |
| 241 | |
| 242 | |
| 243 | inline ArgumentsAdaptorFrame::ArgumentsAdaptorFrame( |
| 244 | StackFrameIterator* iterator) : JavaScriptFrame(iterator) { |
| 245 | } |
| 246 | |
| 247 | |
| 248 | inline InternalFrame::InternalFrame(StackFrameIterator* iterator) |
| 249 | : StandardFrame(iterator) { |
| 250 | } |
| 251 | |
| 252 | |
| 253 | inline ConstructFrame::ConstructFrame(StackFrameIterator* iterator) |
| 254 | : InternalFrame(iterator) { |
| 255 | } |
| 256 | |
| 257 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 258 | template<typename Iterator> |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 259 | inline JavaScriptFrameIteratorTemp<Iterator>::JavaScriptFrameIteratorTemp( |
| 260 | Isolate* isolate) |
| 261 | : iterator_(isolate) { |
| 262 | if (!done()) Advance(); |
| 263 | } |
| 264 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 265 | |
| 266 | template<typename Iterator> |
| 267 | inline JavaScriptFrameIteratorTemp<Iterator>::JavaScriptFrameIteratorTemp( |
| 268 | Isolate* isolate, ThreadLocalTop* top) |
| 269 | : iterator_(isolate, top) { |
| 270 | if (!done()) Advance(); |
| 271 | } |
| 272 | |
| 273 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 274 | template<typename Iterator> |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 275 | inline JavaScriptFrame* JavaScriptFrameIteratorTemp<Iterator>::frame() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | // TODO(1233797): The frame hierarchy needs to change. It's |
| 277 | // problematic that we can't use the safe-cast operator to cast to |
| 278 | // the JavaScript frame type, because we may encounter arguments |
| 279 | // adaptor frames. |
| 280 | StackFrame* frame = iterator_.frame(); |
| 281 | ASSERT(frame->is_java_script() || frame->is_arguments_adaptor()); |
| 282 | return static_cast<JavaScriptFrame*>(frame); |
| 283 | } |
| 284 | |
| 285 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 286 | template<typename Iterator> |
| 287 | JavaScriptFrameIteratorTemp<Iterator>::JavaScriptFrameIteratorTemp( |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 288 | Isolate* isolate, StackFrame::Id id) |
| 289 | : iterator_(isolate) { |
| 290 | AdvanceToId(id); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
| 294 | template<typename Iterator> |
| 295 | void JavaScriptFrameIteratorTemp<Iterator>::Advance() { |
| 296 | do { |
| 297 | iterator_.Advance(); |
| 298 | } while (!iterator_.done() && !iterator_.frame()->is_java_script()); |
| 299 | } |
| 300 | |
| 301 | |
| 302 | template<typename Iterator> |
| 303 | void JavaScriptFrameIteratorTemp<Iterator>::AdvanceToArgumentsFrame() { |
| 304 | if (!frame()->has_adapted_arguments()) return; |
| 305 | iterator_.Advance(); |
| 306 | ASSERT(iterator_.frame()->is_arguments_adaptor()); |
| 307 | } |
| 308 | |
| 309 | |
| 310 | template<typename Iterator> |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 311 | void JavaScriptFrameIteratorTemp<Iterator>::AdvanceToId(StackFrame::Id id) { |
| 312 | while (!done()) { |
| 313 | Advance(); |
| 314 | if (frame()->id() == id) return; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | |
| 319 | template<typename Iterator> |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 320 | void JavaScriptFrameIteratorTemp<Iterator>::Reset() { |
| 321 | iterator_.Reset(); |
| 322 | if (!done()) Advance(); |
| 323 | } |
| 324 | |
| 325 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 326 | } } // namespace v8::internal |
| 327 | |
| 328 | #endif // V8_FRAMES_INL_H_ |