00001 // Copyright 2006-2008 the V8 project authors. All rights reserved. 00002 // Redistribution and use in source and binary forms, with or without 00003 // modification, are permitted provided that the following conditions are 00004 // met: 00005 // 00006 // * Redistributions of source code must retain the above copyright 00007 // notice, this list of conditions and the following disclaimer. 00008 // * Redistributions in binary form must reproduce the above 00009 // copyright notice, this list of conditions and the following 00010 // disclaimer in the documentation and/or other materials provided 00011 // with the distribution. 00012 // * Neither the name of Google Inc. nor the names of its 00013 // contributors may be used to endorse or promote products derived 00014 // from this software without specific prior written permission. 00015 // 00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00017 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00018 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00019 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00020 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00021 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00026 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 00028 #ifndef V8_FRAMES_INL_H_ 00029 #define V8_FRAMES_INL_H_ 00030 00031 #include "frames.h" 00032 #if defined(ARM) || defined (__arm__) || defined(__thumb__) 00033 #include "frames-arm.h" 00034 #else 00035 #include "frames-ia32.h" 00036 #endif 00037 00038 00039 namespace v8 { namespace internal { 00040 00041 00042 inline Address StackHandler::address() const { 00043 // NOTE: There's an obvious problem with the address of the NULL 00044 // stack handler. Right now, it benefits us that the subtraction 00045 // leads to a very high address (above everything else on the 00046 // stack), but maybe we should stop relying on it? 00047 const int displacement = StackHandlerConstants::kAddressDisplacement; 00048 Address address = reinterpret_cast<Address>(const_cast<StackHandler*>(this)); 00049 return address + displacement; 00050 } 00051 00052 00053 inline StackHandler* StackHandler::next() const { 00054 const int offset = StackHandlerConstants::kNextOffset; 00055 return FromAddress(Memory::Address_at(address() + offset)); 00056 } 00057 00058 00059 inline bool StackHandler::includes(Address address) const { 00060 Address start = this->address(); 00061 Address end = start + StackHandlerConstants::kSize; 00062 return start <= address && address <= end; 00063 } 00064 00065 00066 inline void StackHandler::Iterate(ObjectVisitor* v) const { 00067 // Stack handlers do not contain any pointers that need to be 00068 // traversed. The only field that have to worry about is the code 00069 // field which is unused and should always be uninitialized. 00070 #ifdef DEBUG 00071 const int offset = StackHandlerConstants::kCodeOffset; 00072 Object* code = Memory::Object_at(address() + offset); 00073 ASSERT(Smi::cast(code)->value() == StackHandler::kCodeNotPresent); 00074 #endif 00075 } 00076 00077 00078 inline StackHandler* StackHandler::FromAddress(Address address) { 00079 return reinterpret_cast<StackHandler*>(address); 00080 } 00081 00082 00083 inline StackHandler::State StackHandler::state() const { 00084 const int offset = StackHandlerConstants::kStateOffset; 00085 return static_cast<State>(Memory::int_at(address() + offset)); 00086 } 00087 00088 00089 inline Address StackHandler::pc() const { 00090 const int offset = StackHandlerConstants::kPCOffset; 00091 return Memory::Address_at(address() + offset); 00092 } 00093 00094 00095 inline void StackHandler::set_pc(Address value) { 00096 const int offset = StackHandlerConstants::kPCOffset; 00097 Memory::Address_at(address() + offset) = value; 00098 } 00099 00100 00101 inline StackHandler* StackFrame::top_handler() const { 00102 return iterator_->handler(); 00103 } 00104 00105 00106 inline Object* StandardFrame::GetExpression(int index) const { 00107 return Memory::Object_at(GetExpressionAddress(index)); 00108 } 00109 00110 00111 inline void StandardFrame::SetExpression(int index, Object* value) { 00112 Memory::Object_at(GetExpressionAddress(index)) = value; 00113 } 00114 00115 00116 inline Object* StandardFrame::context() const { 00117 const int offset = StandardFrameConstants::kContextOffset; 00118 return Memory::Object_at(fp() + offset); 00119 } 00120 00121 00122 inline Address StandardFrame::caller_sp() const { 00123 return pp(); 00124 } 00125 00126 00127 inline Address StandardFrame::caller_fp() const { 00128 return Memory::Address_at(fp() + StandardFrameConstants::kCallerFPOffset); 00129 } 00130 00131 00132 inline Address StandardFrame::caller_pc() const { 00133 return Memory::Address_at(ComputePCAddress(fp())); 00134 } 00135 00136 00137 inline Address StandardFrame::ComputePCAddress(Address fp) { 00138 return fp + StandardFrameConstants::kCallerPCOffset; 00139 } 00140 00141 00142 inline bool StandardFrame::IsArgumentsAdaptorFrame(Address fp) { 00143 int context = Memory::int_at(fp + StandardFrameConstants::kContextOffset); 00144 return context == ArgumentsAdaptorFrame::SENTINEL; 00145 } 00146 00147 00148 inline bool StandardFrame::IsConstructFrame(Address fp) { 00149 Object* marker = 00150 Memory::Object_at(fp + StandardFrameConstants::kMarkerOffset); 00151 return marker == Smi::FromInt(CONSTRUCT); 00152 } 00153 00154 00155 inline Object* JavaScriptFrame::receiver() const { 00156 const int offset = JavaScriptFrameConstants::kReceiverOffset; 00157 return Memory::Object_at(pp() + offset); 00158 } 00159 00160 00161 inline void JavaScriptFrame::set_receiver(Object* value) { 00162 const int offset = JavaScriptFrameConstants::kReceiverOffset; 00163 Memory::Object_at(pp() + offset) = value; 00164 } 00165 00166 00167 inline bool JavaScriptFrame::has_adapted_arguments() const { 00168 return IsArgumentsAdaptorFrame(caller_fp()); 00169 } 00170 00171 00172 inline JavaScriptFrame* JavaScriptFrameIterator::frame() const { 00173 // TODO(1233797): The frame hierarchy needs to change. It's 00174 // problematic that we can't use the safe-cast operator to cast to 00175 // the JavaScript frame type, because we may encounter arguments 00176 // adaptor frames. 00177 StackFrame* frame = iterator_.frame(); 00178 ASSERT(frame->is_java_script() || frame->is_arguments_adaptor()); 00179 return static_cast<JavaScriptFrame*>(frame); 00180 } 00181 00182 00183 } } // namespace v8::internal 00184 00185 #endif // V8_FRAMES_INL_H_