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" |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame^] | 39 | #else |
| 40 | #error Unsupported target architecture. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 41 | #endif |
| 42 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 43 | namespace v8 { |
| 44 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | inline Address StackHandler::address() const { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 48 | return reinterpret_cast<Address>(const_cast<StackHandler*>(this)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 67 | // traversed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | int context = Memory::int_at(fp + StandardFrameConstants::kContextOffset); |
| 132 | return context == ArgumentsAdaptorFrame::SENTINEL; |
| 133 | } |
| 134 | |
| 135 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 136 | inline bool StandardFrame::IsConstructFrame(Address fp) { |
| 137 | Object* marker = |
| 138 | Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset); |
| 139 | return marker == Smi::FromInt(CONSTRUCT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | |
| 143 | inline Object* JavaScriptFrame::receiver() const { |
| 144 | const int offset = JavaScriptFrameConstants::kReceiverOffset; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 145 | return Memory::Object_at(caller_sp() + offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | |
| 149 | inline void JavaScriptFrame::set_receiver(Object* value) { |
| 150 | const int offset = JavaScriptFrameConstants::kReceiverOffset; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 151 | Memory::Object_at(caller_sp() + offset) = value; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | |
| 155 | inline bool JavaScriptFrame::has_adapted_arguments() const { |
| 156 | return IsArgumentsAdaptorFrame(caller_fp()); |
| 157 | } |
| 158 | |
| 159 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 160 | inline Object* JavaScriptFrame::function() const { |
| 161 | Object* result = function_slot_object(); |
| 162 | ASSERT(result->IsJSFunction()); |
| 163 | return result; |
| 164 | } |
| 165 | |
| 166 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 167 | template<typename Iterator> |
| 168 | inline JavaScriptFrame* JavaScriptFrameIteratorTemp<Iterator>::frame() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 169 | // TODO(1233797): The frame hierarchy needs to change. It's |
| 170 | // problematic that we can't use the safe-cast operator to cast to |
| 171 | // the JavaScript frame type, because we may encounter arguments |
| 172 | // adaptor frames. |
| 173 | StackFrame* frame = iterator_.frame(); |
| 174 | ASSERT(frame->is_java_script() || frame->is_arguments_adaptor()); |
| 175 | return static_cast<JavaScriptFrame*>(frame); |
| 176 | } |
| 177 | |
| 178 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 179 | template<typename Iterator> |
| 180 | JavaScriptFrameIteratorTemp<Iterator>::JavaScriptFrameIteratorTemp( |
| 181 | StackFrame::Id id) { |
| 182 | while (!done()) { |
| 183 | Advance(); |
| 184 | if (frame()->id() == id) return; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | |
| 189 | template<typename Iterator> |
| 190 | void JavaScriptFrameIteratorTemp<Iterator>::Advance() { |
| 191 | do { |
| 192 | iterator_.Advance(); |
| 193 | } while (!iterator_.done() && !iterator_.frame()->is_java_script()); |
| 194 | } |
| 195 | |
| 196 | |
| 197 | template<typename Iterator> |
| 198 | void JavaScriptFrameIteratorTemp<Iterator>::AdvanceToArgumentsFrame() { |
| 199 | if (!frame()->has_adapted_arguments()) return; |
| 200 | iterator_.Advance(); |
| 201 | ASSERT(iterator_.frame()->is_arguments_adaptor()); |
| 202 | } |
| 203 | |
| 204 | |
| 205 | template<typename Iterator> |
| 206 | void JavaScriptFrameIteratorTemp<Iterator>::Reset() { |
| 207 | iterator_.Reset(); |
| 208 | if (!done()) Advance(); |
| 209 | } |
| 210 | |
| 211 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 212 | } } // namespace v8::internal |
| 213 | |
| 214 | #endif // V8_FRAMES_INL_H_ |