1 // Copyright 2012 the V8 project authors. All rights reserved. 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_IC_INL_H_ 29 #define V8_IC_INL_H_ 30 31 #include "ic.h" 32 33 #include "compiler.h" 34 #include "debug.h" 35 #include "macro-assembler.h" 36 37 namespace v8 { 38 namespace internal { 39 40 41 Address IC::address() const { 42 // Get the address of the call. 43 Address result = Assembler::target_address_from_return_address(pc()); 44 45 #ifdef ENABLE_DEBUGGER_SUPPORT 46 ASSERT(Isolate::Current() == isolate()); 47 Debug* debug = isolate()->debug(); 48 // First check if any break points are active if not just return the address 49 // of the call. 50 if (!debug->has_break_points()) return result; 51 52 // At least one break point is active perform additional test to ensure that 53 // break point locations are updated correctly. 54 if (debug->IsDebugBreak(Assembler::target_address_at(result))) { 55 // If the call site is a call to debug break then return the address in 56 // the original code instead of the address in the running code. This will 57 // cause the original code to be updated and keeps the breakpoint active in 58 // the running code. 59 return OriginalCodeAddress(); 60 } else { 61 // No break point here just return the address of the call. 62 return result; 63 } 64 #else 65 return result; 66 #endif 67 } 68 69 70 Code* IC::GetTargetAtAddress(Address address) { 71 // Get the target address of the IC. 72 Address target = Assembler::target_address_at(address); 73 // Convert target address to the code object. Code::GetCodeFromTargetAddress 74 // is safe for use during GC where the map might be marked. 75 Code* result = Code::GetCodeFromTargetAddress(target); 76 ASSERT(result->is_inline_cache_stub()); 77 return result; 78 } 79 80 81 void IC::SetTargetAtAddress(Address address, Code* target) { 82 ASSERT(target->is_inline_cache_stub() || target->is_compare_ic_stub()); 83 Heap* heap = target->GetHeap(); 84 Code* old_target = GetTargetAtAddress(address); 85 #ifdef DEBUG 86 // STORE_IC and KEYED_STORE_IC use Code::extra_ic_state() to mark 87 // ICs as strict mode. The strict-ness of the IC must be preserved. 88 if (old_target->kind() == Code::STORE_IC || 89 old_target->kind() == Code::KEYED_STORE_IC) { 90 ASSERT(Code::GetStrictMode(old_target->extra_ic_state()) == 91 Code::GetStrictMode(target->extra_ic_state())); 92 } 93 #endif 94 Assembler::set_target_address_at(address, target->instruction_start()); 95 if (heap->gc_state() == Heap::MARK_COMPACT) { 96 heap->mark_compact_collector()->RecordCodeTargetPatch(address, target); 97 } else { 98 heap->incremental_marking()->RecordCodeTargetPatch(address, target); 99 } 100 PostPatching(address, target, old_target); 101 } 102 103 104 InlineCacheHolderFlag IC::GetCodeCacheForObject(Object* object, 105 JSObject* holder) { 106 if (object->IsJSObject()) { 107 return GetCodeCacheForObject(JSObject::cast(object), holder); 108 } 109 // If the object is a value, we use the prototype map for the cache. 110 ASSERT(object->IsString() || object->IsSymbol() || 111 object->IsNumber() || object->IsBoolean()); 112 return PROTOTYPE_MAP; 113 } 114 115 116 InlineCacheHolderFlag IC::GetCodeCacheForObject(JSObject* object, 117 JSObject* holder) { 118 // Fast-properties and global objects store stubs in their own maps. 119 // Slow properties objects use prototype's map (unless the property is its own 120 // when holder == object). It works because slow properties objects having 121 // the same prototype (or a prototype with the same map) and not having 122 // the property are interchangeable for such a stub. 123 if (holder != object && 124 !object->HasFastProperties() && 125 !object->IsJSGlobalProxy() && 126 !object->IsJSGlobalObject()) { 127 return PROTOTYPE_MAP; 128 } 129 return OWN_MAP; 130 } 131 132 133 JSObject* IC::GetCodeCacheHolder(Isolate* isolate, 134 Object* object, 135 InlineCacheHolderFlag holder) { 136 Object* map_owner = 137 holder == OWN_MAP ? object : object->GetPrototype(isolate); 138 ASSERT(map_owner->IsJSObject()); 139 return JSObject::cast(map_owner); 140 } 141 142 143 } } // namespace v8::internal 144 145 #endif // V8_IC_INL_H_ 146