Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 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" |
| 32 | |
| 33 | #if V8_TARGET_ARCH_IA32 |
| 34 | #include "ia32/frames-ia32.h" |
| 35 | #elif V8_TARGET_ARCH_X64 |
| 36 | #include "x64/frames-x64.h" |
| 37 | #elif V8_TARGET_ARCH_ARM |
| 38 | #include "arm/frames-arm.h" |
| 39 | #else |
| 40 | #error Unsupported target architecture. |
| 41 | #endif |
| 42 | |
| 43 | namespace v8 { |
| 44 | namespace internal { |
| 45 | |
| 46 | |
| 47 | inline Address StackHandler::address() const { |
| 48 | return reinterpret_cast<Address>(const_cast<StackHandler*>(this)); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | inline StackHandler* StackHandler::next() const { |
| 53 | const int offset = StackHandlerConstants::kNextOffset; |
| 54 | return FromAddress(Memory::Address_at(address() + offset)); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | inline bool StackHandler::includes(Address address) const { |
| 59 | Address start = this->address(); |
| 60 | Address end = start + StackHandlerConstants::kSize; |
| 61 | return start <= address && address <= end; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | inline void StackHandler::Iterate(ObjectVisitor* v) const { |
| 66 | // Stack handlers do not contain any pointers that need to be |
| 67 | // traversed. |
| 68 | } |
| 69 | |
| 70 | |
| 71 | inline StackHandler* StackHandler::FromAddress(Address address) { |
| 72 | return reinterpret_cast<StackHandler*>(address); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | inline StackHandler::State StackHandler::state() const { |
| 77 | const int offset = StackHandlerConstants::kStateOffset; |
| 78 | return static_cast<State>(Memory::int_at(address() + offset)); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | inline Address StackHandler::pc() const { |
| 83 | const int offset = StackHandlerConstants::kPCOffset; |
| 84 | return Memory::Address_at(address() + offset); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | inline void StackHandler::set_pc(Address value) { |
| 89 | const int offset = StackHandlerConstants::kPCOffset; |
| 90 | Memory::Address_at(address() + offset) = value; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | inline StackHandler* StackFrame::top_handler() const { |
| 95 | return iterator_->handler(); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | inline Object* StandardFrame::GetExpression(int index) const { |
| 100 | return Memory::Object_at(GetExpressionAddress(index)); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | inline void StandardFrame::SetExpression(int index, Object* value) { |
| 105 | Memory::Object_at(GetExpressionAddress(index)) = value; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | inline Object* StandardFrame::context() const { |
| 110 | const int offset = StandardFrameConstants::kContextOffset; |
| 111 | return Memory::Object_at(fp() + offset); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | inline Address StandardFrame::caller_fp() const { |
| 116 | return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | inline Address StandardFrame::caller_pc() const { |
| 121 | return Memory::Address_at(ComputePCAddress(fp())); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | inline Address StandardFrame::ComputePCAddress(Address fp) { |
| 126 | return fp + StandardFrameConstants::kCallerPCOffset; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) { |
| 131 | Object* marker = |
| 132 | Memory::Object_at(fp + StandardFrameConstants::kContextOffset); |
| 133 | return marker == Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | inline bool StandardFrame::IsConstructFrame(Address fp) { |
| 138 | Object* marker = |
| 139 | Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset); |
| 140 | return marker == Smi::FromInt(CONSTRUCT); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | inline Object* JavaScriptFrame::receiver() const { |
| 145 | const int offset = JavaScriptFrameConstants::kReceiverOffset; |
| 146 | return Memory::Object_at(caller_sp() + offset); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | inline void JavaScriptFrame::set_receiver(Object* value) { |
| 151 | const int offset = JavaScriptFrameConstants::kReceiverOffset; |
| 152 | Memory::Object_at(caller_sp() + offset) = value; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | inline bool JavaScriptFrame::has_adapted_arguments() const { |
| 157 | return IsArgumentsAdaptorFrame(caller_fp()); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | inline Object* JavaScriptFrame::function() const { |
| 162 | Object* result = function_slot_object(); |
| 163 | ASSERT(result->IsJSFunction()); |
| 164 | return result; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | template<typename Iterator> |
| 169 | inline JavaScriptFrame* JavaScriptFrameIteratorTemp<Iterator>::frame() const { |
| 170 | // TODO(1233797): The frame hierarchy needs to change. It's |
| 171 | // problematic that we can't use the safe-cast operator to cast to |
| 172 | // the JavaScript frame type, because we may encounter arguments |
| 173 | // adaptor frames. |
| 174 | StackFrame* frame = iterator_.frame(); |
| 175 | ASSERT(frame->is_java_script() || frame->is_arguments_adaptor()); |
| 176 | return static_cast<JavaScriptFrame*>(frame); |
| 177 | } |
| 178 | |
| 179 | |
| 180 | template<typename Iterator> |
| 181 | JavaScriptFrameIteratorTemp<Iterator>::JavaScriptFrameIteratorTemp( |
| 182 | StackFrame::Id id) { |
| 183 | while (!done()) { |
| 184 | Advance(); |
| 185 | if (frame()->id() == id) return; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | |
| 190 | template<typename Iterator> |
| 191 | void JavaScriptFrameIteratorTemp<Iterator>::Advance() { |
| 192 | do { |
| 193 | iterator_.Advance(); |
| 194 | } while (!iterator_.done() && !iterator_.frame()->is_java_script()); |
| 195 | } |
| 196 | |
| 197 | |
| 198 | template<typename Iterator> |
| 199 | void JavaScriptFrameIteratorTemp<Iterator>::AdvanceToArgumentsFrame() { |
| 200 | if (!frame()->has_adapted_arguments()) return; |
| 201 | iterator_.Advance(); |
| 202 | ASSERT(iterator_.frame()->is_arguments_adaptor()); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | template<typename Iterator> |
| 207 | void JavaScriptFrameIteratorTemp<Iterator>::Reset() { |
| 208 | iterator_.Reset(); |
| 209 | if (!done()) Advance(); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | } } // namespace v8::internal |
| 214 | |
| 215 | #endif // V8_FRAMES_INL_H_ |