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_IC_INL_H_ 00029 #define V8_IC_INL_H_ 00030 00031 #include "ic.h" 00032 #include "debug.h" 00033 #include "macro-assembler.h" 00034 00035 namespace v8 { namespace internal { 00036 00037 00038 Address IC::address() { 00039 // Get the address of the call. 00040 Address result = pc() - Assembler::kTargetAddrToReturnAddrDist; 00041 00042 // First check if any break points are active if not just return the address 00043 // of the call. 00044 if (!Debug::has_break_points()) return result; 00045 00046 // At least one break point is active perform additional test to ensure that 00047 // break point locations are updated correctly. 00048 if (Debug::IsDebugBreak(Assembler::target_address_at(result))) { 00049 // If the call site is a call to debug break then return the address in 00050 // the original code instead of the address in the running code. This will 00051 // cause the original code to be updated and keeps the breakpoint active in 00052 // the running code. 00053 return OriginalCodeAddress(); 00054 } else { 00055 // No break point here just return the address of the call. 00056 return result; 00057 } 00058 } 00059 00060 00061 Code* IC::GetTargetAtAddress(Address address) { 00062 Address target = Assembler::target_address_at(address); 00063 HeapObject* code = HeapObject::FromAddress(target - Code::kHeaderSize); 00064 // GetTargetAtAddress is called from IC::Clear which in turn is 00065 // called when marking objects during mark sweep. reinterpret_cast 00066 // is therefore used instead of the more appropriate 00067 // Code::cast. Code::cast does not work when the object's map is 00068 // marked. 00069 Code* result = reinterpret_cast<Code*>(code); 00070 ASSERT(result->is_inline_cache_stub()); 00071 return result; 00072 } 00073 00074 00075 void IC::SetTargetAtAddress(Address address, Code* target) { 00076 ASSERT(target->is_inline_cache_stub()); 00077 Assembler::set_target_address_at(address, target->instruction_start()); 00078 } 00079 00080 00081 Map* IC::GetCodeCacheMapForObject(Object* object) { 00082 if (object->IsJSObject()) return JSObject::cast(object)->map(); 00083 // If the object is a value, we use the prototype map for the cache. 00084 ASSERT(object->IsString() || object->IsNumber() || object->IsBoolean()); 00085 return JSObject::cast(object->GetPrototype())->map(); 00086 } 00087 00088 00089 } } // namespace v8::internal 00090 00091 #endif // V8_IC_INL_H_