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" |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 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 |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 38 | #include "arm/frames-arm.h" |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 39 | #endif |
| 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 | |
| 44 | |
| 45 | inline Address StackHandler::address() const { |
| 46 | // NOTE: There's an obvious problem with the address of the NULL |
| 47 | // stack handler. Right now, it benefits us that the subtraction |
| 48 | // leads to a very high address (above everything else on the |
| 49 | // stack), but maybe we should stop relying on it? |
| 50 | const int displacement = StackHandlerConstants::kAddressDisplacement; |
| 51 | Address address = reinterpret_cast<Address>(const_cast<StackHandler*>(this)); |
| 52 | return address + displacement; |
| 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 | |
| 69 | inline void StackHandler::Iterate(ObjectVisitor* v) const { |
| 70 | // Stack handlers do not contain any pointers that need to be |
| 71 | // traversed. The only field that have to worry about is the code |
| 72 | // field which is unused and should always be uninitialized. |
| 73 | #ifdef DEBUG |
| 74 | const int offset = StackHandlerConstants::kCodeOffset; |
| 75 | Object* code = Memory::Object_at(address() + offset); |
| 76 | ASSERT(Smi::cast(code)->value() == StackHandler::kCodeNotPresent); |
| 77 | #endif |
| 78 | } |
| 79 | |
| 80 | |
| 81 | inline StackHandler* StackHandler::FromAddress(Address address) { |
| 82 | return reinterpret_cast<StackHandler*>(address); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | inline StackHandler::State StackHandler::state() const { |
| 87 | const int offset = StackHandlerConstants::kStateOffset; |
| 88 | return static_cast<State>(Memory::int_at(address() + offset)); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | inline Address StackHandler::pc() const { |
| 93 | const int offset = StackHandlerConstants::kPCOffset; |
| 94 | return Memory::Address_at(address() + offset); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | inline void StackHandler::set_pc(Address value) { |
| 99 | const int offset = StackHandlerConstants::kPCOffset; |
| 100 | Memory::Address_at(address() + offset) = value; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | inline StackHandler* StackFrame::top_handler() const { |
| 105 | return iterator_->handler(); |
| 106 | } |
| 107 | |
| 108 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 109 | inline Object* StandardFrame::GetExpression(int index) const { |
| 110 | return Memory::Object_at(GetExpressionAddress(index)); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | inline void StandardFrame::SetExpression(int index, Object* value) { |
| 115 | Memory::Object_at(GetExpressionAddress(index)) = value; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | inline Object* StandardFrame::context() const { |
| 120 | const int offset = StandardFrameConstants::kContextOffset; |
| 121 | return Memory::Object_at(fp() + offset); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | inline Address StandardFrame::caller_sp() const { |
| 126 | return pp(); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | inline Address StandardFrame::caller_fp() const { |
| 131 | return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset); |
| 132 | } |
| 133 | |
| 134 | |
| 135 | inline Address StandardFrame::caller_pc() const { |
| 136 | return Memory::Address_at(ComputePCAddress(fp())); |
| 137 | } |
| 138 | |
| 139 | |
| 140 | inline Address StandardFrame::ComputePCAddress(Address fp) { |
| 141 | return fp + StandardFrameConstants::kCallerPCOffset; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) { |
| 146 | int context = Memory::int_at(fp + StandardFrameConstants::kContextOffset); |
| 147 | return context == ArgumentsAdaptorFrame::SENTINEL; |
| 148 | } |
| 149 | |
| 150 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 151 | inline bool StandardFrame::IsConstructFrame(Address fp) { |
| 152 | Object* marker = |
| 153 | Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset); |
| 154 | return marker == Smi::FromInt(CONSTRUCT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | |
| 158 | inline Object* JavaScriptFrame::receiver() const { |
| 159 | const int offset = JavaScriptFrameConstants::kReceiverOffset; |
| 160 | return Memory::Object_at(pp() + offset); |
| 161 | } |
| 162 | |
| 163 | |
| 164 | inline void JavaScriptFrame::set_receiver(Object* value) { |
| 165 | const int offset = JavaScriptFrameConstants::kReceiverOffset; |
| 166 | Memory::Object_at(pp() + offset) = value; |
| 167 | } |
| 168 | |
| 169 | |
| 170 | inline bool JavaScriptFrame::has_adapted_arguments() const { |
| 171 | return IsArgumentsAdaptorFrame(caller_fp()); |
| 172 | } |
| 173 | |
| 174 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 175 | inline Object* JavaScriptFrame::function() const { |
| 176 | Object* result = function_slot_object(); |
| 177 | ASSERT(result->IsJSFunction()); |
| 178 | return result; |
| 179 | } |
| 180 | |
| 181 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 182 | template<typename Iterator> |
| 183 | inline JavaScriptFrame* JavaScriptFrameIteratorTemp<Iterator>::frame() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 184 | // TODO(1233797): The frame hierarchy needs to change. It's |
| 185 | // problematic that we can't use the safe-cast operator to cast to |
| 186 | // the JavaScript frame type, because we may encounter arguments |
| 187 | // adaptor frames. |
| 188 | StackFrame* frame = iterator_.frame(); |
| 189 | ASSERT(frame->is_java_script() || frame->is_arguments_adaptor()); |
| 190 | return static_cast<JavaScriptFrame*>(frame); |
| 191 | } |
| 192 | |
| 193 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 194 | template<typename Iterator> |
| 195 | JavaScriptFrameIteratorTemp<Iterator>::JavaScriptFrameIteratorTemp( |
| 196 | StackFrame::Id id) { |
| 197 | while (!done()) { |
| 198 | Advance(); |
| 199 | if (frame()->id() == id) return; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | |
| 204 | template<typename Iterator> |
| 205 | void JavaScriptFrameIteratorTemp<Iterator>::Advance() { |
| 206 | do { |
| 207 | iterator_.Advance(); |
| 208 | } while (!iterator_.done() && !iterator_.frame()->is_java_script()); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | template<typename Iterator> |
| 213 | void JavaScriptFrameIteratorTemp<Iterator>::AdvanceToArgumentsFrame() { |
| 214 | if (!frame()->has_adapted_arguments()) return; |
| 215 | iterator_.Advance(); |
| 216 | ASSERT(iterator_.frame()->is_arguments_adaptor()); |
| 217 | } |
| 218 | |
| 219 | |
| 220 | template<typename Iterator> |
| 221 | void JavaScriptFrameIteratorTemp<Iterator>::Reset() { |
| 222 | iterator_.Reset(); |
| 223 | if (!done()) Advance(); |
| 224 | } |
| 225 | |
| 226 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | } } // namespace v8::internal |
| 228 | |
| 229 | #endif // V8_FRAMES_INL_H_ |