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