ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 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 { |
| 70 | StackFrame::IteratePc(v, pc_address(), holder); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | |
| 74 | inline StackHandler* StackHandler::FromAddress(Address address) { |
| 75 | return reinterpret_cast<StackHandler*>(address); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | inline StackHandler::State StackHandler::state() const { |
| 80 | const int offset = StackHandlerConstants::kStateOffset; |
| 81 | return static_cast<State>(Memory::int_at(address() + offset)); |
| 82 | } |
| 83 | |
| 84 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 85 | inline Address* StackHandler::pc_address() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | const int offset = StackHandlerConstants::kPCOffset; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 87 | return reinterpret_cast<Address*>(address() + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | |
| 91 | inline StackHandler* StackFrame::top_handler() const { |
| 92 | return iterator_->handler(); |
| 93 | } |
| 94 | |
| 95 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame^] | 96 | inline Code* StackFrame::GetContainingCode(Isolate* isolate, Address pc) { |
| 97 | return isolate->pc_to_code_cache()->GetCacheEntry(pc)->code; |
| 98 | } |
| 99 | |
| 100 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | inline Object* StandardFrame::GetExpression(int index) const { |
| 102 | return Memory::Object_at(GetExpressionAddress(index)); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | inline void StandardFrame::SetExpression(int index, Object* value) { |
| 107 | Memory::Object_at(GetExpressionAddress(index)) = value; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | inline Object* StandardFrame::context() const { |
| 112 | const int offset = StandardFrameConstants::kContextOffset; |
| 113 | return Memory::Object_at(fp() + offset); |
| 114 | } |
| 115 | |
| 116 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | inline Address StandardFrame::caller_fp() const { |
| 118 | return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | inline Address StandardFrame::caller_pc() const { |
| 123 | return Memory::Address_at(ComputePCAddress(fp())); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | inline Address StandardFrame::ComputePCAddress(Address fp) { |
| 128 | return fp + StandardFrameConstants::kCallerPCOffset; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 133 | Object* marker = |
| 134 | Memory::Object_at(fp + StandardFrameConstants::kContextOffset); |
| 135 | return marker == Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 139 | inline bool StandardFrame::IsConstructFrame(Address fp) { |
| 140 | Object* marker = |
| 141 | Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset); |
| 142 | return marker == Smi::FromInt(CONSTRUCT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | |
| 146 | inline Object* JavaScriptFrame::receiver() const { |
| 147 | const int offset = JavaScriptFrameConstants::kReceiverOffset; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 148 | return Memory::Object_at(caller_sp() + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | |
| 152 | inline void JavaScriptFrame::set_receiver(Object* value) { |
| 153 | const int offset = JavaScriptFrameConstants::kReceiverOffset; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 154 | Memory::Object_at(caller_sp() + offset) = value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | |
| 158 | inline bool JavaScriptFrame::has_adapted_arguments() const { |
| 159 | return IsArgumentsAdaptorFrame(caller_fp()); |
| 160 | } |
| 161 | |
| 162 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 163 | inline Object* JavaScriptFrame::function() const { |
| 164 | Object* result = function_slot_object(); |
| 165 | ASSERT(result->IsJSFunction()); |
| 166 | return result; |
| 167 | } |
| 168 | |
| 169 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 170 | template<typename Iterator> |
| 171 | inline JavaScriptFrame* JavaScriptFrameIteratorTemp<Iterator>::frame() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 172 | // TODO(1233797): The frame hierarchy needs to change. It's |
| 173 | // problematic that we can't use the safe-cast operator to cast to |
| 174 | // the JavaScript frame type, because we may encounter arguments |
| 175 | // adaptor frames. |
| 176 | StackFrame* frame = iterator_.frame(); |
| 177 | ASSERT(frame->is_java_script() || frame->is_arguments_adaptor()); |
| 178 | return static_cast<JavaScriptFrame*>(frame); |
| 179 | } |
| 180 | |
| 181 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 182 | template<typename Iterator> |
| 183 | JavaScriptFrameIteratorTemp<Iterator>::JavaScriptFrameIteratorTemp( |
| 184 | StackFrame::Id id) { |
| 185 | while (!done()) { |
| 186 | Advance(); |
| 187 | if (frame()->id() == id) return; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | |
| 192 | template<typename Iterator> |
| 193 | void JavaScriptFrameIteratorTemp<Iterator>::Advance() { |
| 194 | do { |
| 195 | iterator_.Advance(); |
| 196 | } while (!iterator_.done() && !iterator_.frame()->is_java_script()); |
| 197 | } |
| 198 | |
| 199 | |
| 200 | template<typename Iterator> |
| 201 | void JavaScriptFrameIteratorTemp<Iterator>::AdvanceToArgumentsFrame() { |
| 202 | if (!frame()->has_adapted_arguments()) return; |
| 203 | iterator_.Advance(); |
| 204 | ASSERT(iterator_.frame()->is_arguments_adaptor()); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | template<typename Iterator> |
| 209 | void JavaScriptFrameIteratorTemp<Iterator>::Reset() { |
| 210 | iterator_.Reset(); |
| 211 | if (!done()) Advance(); |
| 212 | } |
| 213 | |
| 214 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 215 | } } // namespace v8::internal |
| 216 | |
| 217 | #endif // V8_FRAMES_INL_H_ |