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