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