ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1 | // Copyright 2012 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 | #include "v8.h" |
| 29 | |
| 30 | #include "accessors.h" |
| 31 | #include "api.h" |
| 32 | #include "arguments.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "execution.h" |
| 35 | #include "ic-inl.h" |
| 36 | #include "runtime.h" |
| 37 | #include "stub-cache.h" |
| 38 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 39 | namespace v8 { |
| 40 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | |
| 42 | #ifdef DEBUG |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 43 | char IC::TransitionMarkFromState(IC::State state) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | switch (state) { |
| 45 | case UNINITIALIZED: return '0'; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 46 | case PREMONOMORPHIC: return '.'; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | case MONOMORPHIC: return '1'; |
| 48 | case MONOMORPHIC_PROTOTYPE_FAILURE: return '^'; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 49 | case POLYMORPHIC: return 'P'; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 50 | case MEGAMORPHIC: return 'N'; |
| 51 | case GENERIC: return 'G'; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | |
| 53 | // We never see the debugger states here, because the state is |
| 54 | // computed from the original code - not the patched code. Let |
| 55 | // these cases fall through to the unreachable code below. |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 56 | case DEBUG_STUB: break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | } |
| 58 | UNREACHABLE(); |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | void IC::TraceIC(const char* type, |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 63 | Handle<Object> name, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 64 | State old_state, |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 65 | Code* new_target) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 66 | if (FLAG_trace_ic) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 67 | State new_state = StateFrom(new_target, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 68 | HEAP->undefined_value(), |
| 69 | HEAP->undefined_value()); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 70 | PrintF("[%s in ", type); |
| 71 | StackFrameIterator it; |
| 72 | while (it.frame()->fp() != this->fp()) it.Advance(); |
| 73 | StackFrame* raw_frame = it.frame(); |
| 74 | if (raw_frame->is_internal()) { |
| 75 | Isolate* isolate = new_target->GetIsolate(); |
| 76 | Code* apply_builtin = isolate->builtins()->builtin( |
| 77 | Builtins::kFunctionApply); |
| 78 | if (raw_frame->unchecked_code() == apply_builtin) { |
| 79 | PrintF("apply from "); |
| 80 | it.Advance(); |
| 81 | raw_frame = it.frame(); |
| 82 | } |
| 83 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 84 | JavaScriptFrame::PrintTop(stdout, false, true); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 85 | bool new_can_grow = |
| 86 | Code::GetKeyedAccessGrowMode(new_target->extra_ic_state()) == |
| 87 | ALLOW_JSARRAY_GROWTH; |
| 88 | PrintF(" (%c->%c%s)", |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | TransitionMarkFromState(old_state), |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 90 | TransitionMarkFromState(new_state), |
| 91 | new_can_grow ? ".GROW" : ""); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | name->Print(); |
| 93 | PrintF("]\n"); |
| 94 | } |
| 95 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 96 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 97 | #define TRACE_GENERIC_IC(type, reason) \ |
| 98 | do { \ |
| 99 | if (FLAG_trace_ic) { \ |
| 100 | PrintF("[%s patching generic stub in ", type); \ |
| 101 | JavaScriptFrame::PrintTop(stdout, false, true); \ |
| 102 | PrintF(" (%s)]\n", reason); \ |
| 103 | } \ |
| 104 | } while (false) |
| 105 | |
| 106 | #else |
| 107 | #define TRACE_GENERIC_IC(type, reason) |
| 108 | #endif // DEBUG |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 109 | |
| 110 | #define TRACE_IC(type, name, old_state, new_target) \ |
| 111 | ASSERT((TraceIC(type, name, old_state, new_target), true)) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 112 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 113 | IC::IC(FrameDepth depth, Isolate* isolate) : isolate_(isolate) { |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame^] | 114 | // To improve the performance of the (much used) IC code, we unfold a few |
| 115 | // levels of the stack frame iteration code. This yields a ~35% speedup when |
| 116 | // running DeltaBlue and a ~25% speedup of gbemu with the '--nouse-ic' flag. |
| 117 | const Address entry = |
| 118 | Isolate::c_entry_fp(isolate->thread_local_top()); |
| 119 | Address* pc_address = |
| 120 | reinterpret_cast<Address*>(entry + ExitFrameConstants::kCallerPCOffset); |
| 121 | Address fp = Memory::Address_at(entry + ExitFrameConstants::kCallerFPOffset); |
| 122 | // If there's another JavaScript frame on the stack or a |
| 123 | // StubFailureTrampoline, we need to look one frame further down the stack to |
| 124 | // find the frame pointer and the return address stack slot. |
| 125 | if (depth == EXTRA_CALL_FRAME) { |
| 126 | const int kCallerPCOffset = StandardFrameConstants::kCallerPCOffset; |
| 127 | pc_address = reinterpret_cast<Address*>(fp + kCallerPCOffset); |
| 128 | fp = Memory::Address_at(fp + StandardFrameConstants::kCallerFPOffset); |
| 129 | } |
| 130 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 131 | StackFrameIterator it; |
| 132 | for (int i = 0; i < depth + 1; i++) it.Advance(); |
| 133 | StackFrame* frame = it.frame(); |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame^] | 134 | ASSERT(fp == frame->fp() && pc_address == frame->pc_address()); |
| 135 | #endif |
| 136 | fp_ = fp; |
| 137 | pc_address_ = pc_address; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 141 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 142 | Address IC::OriginalCodeAddress() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | HandleScope scope; |
| 144 | // Compute the JavaScript frame for the frame pointer of this IC |
| 145 | // structure. We need this to be able to find the function |
| 146 | // corresponding to the frame. |
| 147 | StackFrameIterator it; |
| 148 | while (it.frame()->fp() != this->fp()) it.Advance(); |
| 149 | JavaScriptFrame* frame = JavaScriptFrame::cast(it.frame()); |
| 150 | // Find the function on the stack and both the active code for the |
| 151 | // function and the original code. |
| 152 | JSFunction* function = JSFunction::cast(frame->function()); |
| 153 | Handle<SharedFunctionInfo> shared(function->shared()); |
| 154 | Code* code = shared->code(); |
| 155 | ASSERT(Debug::HasDebugInfo(shared)); |
| 156 | Code* original_code = Debug::GetDebugInfo(shared)->original_code(); |
| 157 | ASSERT(original_code->IsCode()); |
| 158 | // Get the address of the call site in the active code. This is the |
| 159 | // place where the call to DebugBreakXXX is and where the IC |
| 160 | // normally would be. |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 161 | Address addr = Assembler::target_address_from_return_address(pc()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 162 | // Return the address in the original code. This is the place where |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 163 | // the call which has been overwritten by the DebugBreakXXX resides |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 164 | // and the place where the inline cache system should look. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 165 | intptr_t delta = |
| 166 | original_code->instruction_start() - code->instruction_start(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 167 | return addr + delta; |
| 168 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 169 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 170 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 171 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 172 | static bool TryRemoveInvalidPrototypeDependentStub(Code* target, |
| 173 | Object* receiver, |
| 174 | Object* name) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 175 | InlineCacheHolderFlag cache_holder = |
| 176 | Code::ExtractCacheHolderFromFlags(target->flags()); |
| 177 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 178 | if (cache_holder == OWN_MAP && !receiver->IsJSObject()) { |
| 179 | // The stub was generated for JSObject but called for non-JSObject. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 180 | // IC::GetCodeCacheHolder is not applicable. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 181 | return false; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 182 | } else if (cache_holder == PROTOTYPE_MAP && |
| 183 | receiver->GetPrototype()->IsNull()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 184 | // IC::GetCodeCacheHolder is not applicable. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 185 | return false; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 186 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 187 | Map* map = IC::GetCodeCacheHolder(receiver, cache_holder)->map(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 188 | |
| 189 | // Decide whether the inline cache failed because of changes to the |
| 190 | // receiver itself or changes to one of its prototypes. |
| 191 | // |
| 192 | // If there are changes to the receiver itself, the map of the |
| 193 | // receiver will have changed and the current target will not be in |
| 194 | // the receiver map's code cache. Therefore, if the current target |
| 195 | // is in the receiver map's code cache, the inline cache failed due |
| 196 | // to prototype check failure. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 197 | int index = map->IndexInCodeCache(name, target); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 198 | if (index >= 0) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 199 | map->RemoveFromCodeCache(String::cast(name), target, index); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 200 | return true; |
| 201 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 202 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 203 | return false; |
| 204 | } |
| 205 | |
| 206 | |
| 207 | IC::State IC::StateFrom(Code* target, Object* receiver, Object* name) { |
| 208 | IC::State state = target->ic_state(); |
| 209 | |
| 210 | if (state != MONOMORPHIC || !name->IsString()) return state; |
| 211 | if (receiver->IsUndefined() || receiver->IsNull()) return state; |
| 212 | |
| 213 | // For keyed load/store/call, the most likely cause of cache failure is |
| 214 | // that the key has changed. We do not distinguish between |
| 215 | // prototype and non-prototype failures for keyed access. |
| 216 | Code::Kind kind = target->kind(); |
| 217 | if (kind == Code::KEYED_LOAD_IC || |
| 218 | kind == Code::KEYED_STORE_IC || |
| 219 | kind == Code::KEYED_CALL_IC) { |
| 220 | return MONOMORPHIC; |
| 221 | } |
| 222 | |
| 223 | // Remove the target from the code cache if it became invalid |
| 224 | // because of changes in the prototype chain to avoid hitting it |
| 225 | // again. |
| 226 | // Call stubs handle this later to allow extra IC state |
| 227 | // transitions. |
| 228 | if (kind != Code::CALL_IC && |
| 229 | TryRemoveInvalidPrototypeDependentStub(target, receiver, name)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 230 | return MONOMORPHIC_PROTOTYPE_FAILURE; |
| 231 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 232 | |
| 233 | // The builtins object is special. It only changes when JavaScript |
| 234 | // builtins are loaded lazily. It is important to keep inline |
| 235 | // caches for the builtins object monomorphic. Therefore, if we get |
| 236 | // an inline cache miss for the builtins object after lazily loading |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 237 | // JavaScript builtins, we return uninitialized as the state to |
| 238 | // force the inline cache back to monomorphic state. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 239 | if (receiver->IsJSBuiltinsObject()) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 240 | return UNINITIALIZED; |
| 241 | } |
| 242 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | return MONOMORPHIC; |
| 244 | } |
| 245 | |
| 246 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 247 | RelocInfo::Mode IC::ComputeMode() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 248 | Address addr = address(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 249 | Code* code = Code::cast(isolate()->heap()->FindCodeObject(addr)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 250 | for (RelocIterator it(code, RelocInfo::kCodeTargetMask); |
| 251 | !it.done(); it.next()) { |
| 252 | RelocInfo* info = it.rinfo(); |
| 253 | if (info->pc() == addr) return info->rmode(); |
| 254 | } |
| 255 | UNREACHABLE(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 256 | return RelocInfo::NONE32; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | |
| 260 | Failure* IC::TypeError(const char* type, |
| 261 | Handle<Object> object, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 262 | Handle<Object> key) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 263 | HandleScope scope(isolate()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 264 | Handle<Object> args[2] = { key, object }; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 265 | Handle<Object> error = isolate()->factory()->NewTypeError( |
| 266 | type, HandleVector(args, 2)); |
| 267 | return isolate()->Throw(*error); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | |
| 271 | Failure* IC::ReferenceError(const char* type, Handle<String> name) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 272 | HandleScope scope(isolate()); |
| 273 | Handle<Object> error = isolate()->factory()->NewReferenceError( |
| 274 | type, HandleVector(&name, 1)); |
| 275 | return isolate()->Throw(*error); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 279 | static int ComputeTypeInfoCountDelta(IC::State old_state, IC::State new_state) { |
| 280 | bool was_uninitialized = |
| 281 | old_state == UNINITIALIZED || old_state == PREMONOMORPHIC; |
| 282 | bool is_uninitialized = |
| 283 | new_state == UNINITIALIZED || new_state == PREMONOMORPHIC; |
| 284 | return (was_uninitialized && !is_uninitialized) ? 1 : |
| 285 | (!was_uninitialized && is_uninitialized) ? -1 : 0; |
| 286 | } |
| 287 | |
| 288 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 289 | void IC::PostPatching(Address address, Code* target, Code* old_target) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 290 | if (FLAG_type_info_threshold == 0 && !FLAG_watch_ic_patching) { |
| 291 | return; |
| 292 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 293 | Isolate* isolate = target->GetHeap()->isolate(); |
| 294 | Code* host = isolate-> |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 295 | inner_pointer_to_code_cache()->GetCacheEntry(address)->code; |
| 296 | if (host->kind() != Code::FUNCTION) return; |
| 297 | |
| 298 | if (FLAG_type_info_threshold > 0 && |
| 299 | old_target->is_inline_cache_stub() && |
| 300 | target->is_inline_cache_stub()) { |
| 301 | int delta = ComputeTypeInfoCountDelta(old_target->ic_state(), |
| 302 | target->ic_state()); |
| 303 | // Not all Code objects have TypeFeedbackInfo. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 304 | if (host->type_feedback_info()->IsTypeFeedbackInfo() && delta != 0) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 305 | TypeFeedbackInfo* info = |
| 306 | TypeFeedbackInfo::cast(host->type_feedback_info()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 307 | info->change_ic_with_type_info_count(delta); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 310 | if (host->type_feedback_info()->IsTypeFeedbackInfo()) { |
| 311 | TypeFeedbackInfo* info = |
| 312 | TypeFeedbackInfo::cast(host->type_feedback_info()); |
| 313 | info->change_own_type_change_checksum(); |
| 314 | } |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 315 | if (FLAG_watch_ic_patching) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 316 | host->set_profiler_ticks(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 317 | isolate->runtime_profiler()->NotifyICChanged(); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 318 | } |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 319 | // TODO(2029): When an optimized function is patched, it would |
| 320 | // be nice to propagate the corresponding type information to its |
| 321 | // unoptimized version for the benefit of later inlining. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 325 | void IC::Clear(Address address) { |
| 326 | Code* target = GetTargetAtAddress(address); |
| 327 | |
| 328 | // Don't clear debug break inline cache as it will remove the break point. |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 329 | if (target->is_debug_break()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | |
| 331 | switch (target->kind()) { |
| 332 | case Code::LOAD_IC: return LoadIC::Clear(address, target); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 333 | case Code::KEYED_LOAD_IC: return KeyedLoadIC::Clear(address, target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 334 | case Code::STORE_IC: return StoreIC::Clear(address, target); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 335 | case Code::KEYED_STORE_IC: return KeyedStoreIC::Clear(address, target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 336 | case Code::CALL_IC: return CallIC::Clear(address, target); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 337 | case Code::KEYED_CALL_IC: return KeyedCallIC::Clear(address, target); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 338 | case Code::COMPARE_IC: return CompareIC::Clear(address, target); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 339 | case Code::UNARY_OP_IC: |
| 340 | case Code::BINARY_OP_IC: |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 341 | case Code::TO_BOOLEAN_IC: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 342 | // Clearing these is tricky and does not |
| 343 | // make any performance difference. |
| 344 | return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 345 | default: UNREACHABLE(); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 350 | void CallICBase::Clear(Address address, Code* target) { |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 351 | if (target->ic_state() == UNINITIALIZED) return; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 352 | bool contextual = CallICBase::Contextual::decode(target->extra_ic_state()); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 353 | Code* code = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 354 | Isolate::Current()->stub_cache()->FindCallInitialize( |
| 355 | target->arguments_count(), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 356 | contextual ? RelocInfo::CODE_TARGET_CONTEXT : RelocInfo::CODE_TARGET, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 357 | target->kind()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 358 | SetTargetAtAddress(address, code); |
| 359 | } |
| 360 | |
| 361 | |
| 362 | void KeyedLoadIC::Clear(Address address, Code* target) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 363 | if (target->ic_state() == UNINITIALIZED) return; |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 364 | // Make sure to also clear the map used in inline fast cases. If we |
| 365 | // do not clear these maps, cached code can keep objects alive |
| 366 | // through the embedded maps. |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 367 | SetTargetAtAddress(address, *initialize_stub()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | |
| 371 | void LoadIC::Clear(Address address, Code* target) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 372 | if (target->ic_state() == UNINITIALIZED) return; |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 373 | SetTargetAtAddress(address, *initialize_stub()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | |
| 377 | void StoreIC::Clear(Address address, Code* target) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 378 | if (target->ic_state() == UNINITIALIZED) return; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 379 | SetTargetAtAddress(address, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 380 | (Code::GetStrictMode(target->extra_ic_state()) == kStrictMode) |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 381 | ? *initialize_stub_strict() |
| 382 | : *initialize_stub()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | |
| 386 | void KeyedStoreIC::Clear(Address address, Code* target) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 387 | if (target->ic_state() == UNINITIALIZED) return; |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 388 | SetTargetAtAddress(address, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 389 | (Code::GetStrictMode(target->extra_ic_state()) == kStrictMode) |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 390 | ? *initialize_stub_strict() |
| 391 | : *initialize_stub()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 395 | void CompareIC::Clear(Address address, Code* target) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 396 | ASSERT(target->major_key() == CodeStub::CompareIC); |
| 397 | CompareIC::State handler_state; |
| 398 | Token::Value op; |
| 399 | ICCompareStub::DecodeMinorKey(target->stub_info(), NULL, NULL, |
| 400 | &handler_state, &op); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 401 | // Only clear CompareICs that can retain objects. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 402 | if (handler_state != KNOWN_OBJECTS) return; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 403 | SetTargetAtAddress(address, GetRawUninitialized(op)); |
| 404 | PatchInlinedSmiCode(address, DISABLE_INLINED_SMI_CHECK); |
| 405 | } |
| 406 | |
| 407 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 408 | static bool HasInterceptorGetter(JSObject* object) { |
| 409 | return !object->GetNamedInterceptor()->getter()->IsUndefined(); |
| 410 | } |
| 411 | |
| 412 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 413 | static void LookupForRead(Handle<Object> object, |
| 414 | Handle<String> name, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 415 | LookupResult* lookup) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 416 | // Skip all the objects with named interceptors, but |
| 417 | // without actual getter. |
| 418 | while (true) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 419 | object->Lookup(*name, lookup); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 420 | // Besides normal conditions (property not found or it's not |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 421 | // an interceptor), bail out if lookup is not cacheable: we won't |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 422 | // be able to IC it anyway and regular lookup should work fine. |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 423 | if (!lookup->IsInterceptor() || !lookup->IsCacheable()) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 424 | return; |
| 425 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 426 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 427 | Handle<JSObject> holder(lookup->holder()); |
| 428 | if (HasInterceptorGetter(*holder)) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 429 | return; |
| 430 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 431 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 432 | holder->LocalLookupRealNamedProperty(*name, lookup); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 433 | if (lookup->IsFound()) { |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 434 | ASSERT(!lookup->IsInterceptor()); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 435 | return; |
| 436 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 437 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 438 | Handle<Object> proto(holder->GetPrototype()); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 439 | if (proto->IsNull()) { |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 440 | ASSERT(!lookup->IsFound()); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 441 | return; |
| 442 | } |
| 443 | |
| 444 | object = proto; |
| 445 | } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 449 | Handle<Object> CallICBase::TryCallAsFunction(Handle<Object> object) { |
| 450 | Handle<Object> delegate = Execution::GetFunctionDelegate(object); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 451 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 452 | if (delegate->IsJSFunction() && !object->IsJSFunctionProxy()) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 453 | // Patch the receiver and use the delegate as the function to |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 454 | // invoke. This is used for invoking objects as if they were functions. |
| 455 | const int argc = target()->arguments_count(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 456 | StackFrameLocator locator; |
| 457 | JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); |
| 458 | int index = frame->ComputeExpressionsCount() - (argc + 1); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 459 | frame->SetExpression(index, *object); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 460 | } |
| 461 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 462 | return delegate; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 463 | } |
| 464 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 465 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 466 | void CallICBase::ReceiverToObjectIfRequired(Handle<Object> callee, |
| 467 | Handle<Object> object) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 468 | while (callee->IsJSFunctionProxy()) { |
| 469 | callee = Handle<Object>(JSFunctionProxy::cast(*callee)->call_trap()); |
| 470 | } |
| 471 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 472 | if (callee->IsJSFunction()) { |
| 473 | Handle<JSFunction> function = Handle<JSFunction>::cast(callee); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 474 | if (!function->shared()->is_classic_mode() || function->IsBuiltin()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 475 | // Do not wrap receiver for strict mode functions or for builtins. |
| 476 | return; |
| 477 | } |
| 478 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 479 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 480 | // And only wrap string, number or boolean. |
| 481 | if (object->IsString() || object->IsNumber() || object->IsBoolean()) { |
| 482 | // Change the receiver to the result of calling ToObject on it. |
| 483 | const int argc = this->target()->arguments_count(); |
| 484 | StackFrameLocator locator; |
| 485 | JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); |
| 486 | int index = frame->ComputeExpressionsCount() - (argc + 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 487 | frame->SetExpression(index, *isolate()->factory()->ToObject(object)); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 488 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 489 | } |
| 490 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 491 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 492 | MaybeObject* CallICBase::LoadFunction(State state, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 493 | Code::ExtraICState extra_ic_state, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 494 | Handle<Object> object, |
| 495 | Handle<String> name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 496 | // If the object is undefined or null it's illegal to try to get any |
| 497 | // of its properties; throw a TypeError in that case. |
| 498 | if (object->IsUndefined() || object->IsNull()) { |
| 499 | return TypeError("non_object_property_call", object, name); |
| 500 | } |
| 501 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 502 | // Check if the name is trivially convertible to an index and get |
| 503 | // the element if so. |
| 504 | uint32_t index; |
| 505 | if (name->AsArrayIndex(&index)) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 506 | Handle<Object> result = Object::GetElement(object, index); |
| 507 | RETURN_IF_EMPTY_HANDLE(isolate(), result); |
| 508 | if (result->IsJSFunction()) return *result; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 509 | |
| 510 | // Try to find a suitable function delegate for the object at hand. |
| 511 | result = TryCallAsFunction(result); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 512 | if (result->IsJSFunction()) return *result; |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 513 | |
| 514 | // Otherwise, it will fail in the lookup step. |
| 515 | } |
| 516 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 517 | // Lookup the property in the object. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 518 | LookupResult lookup(isolate()); |
| 519 | LookupForRead(object, name, &lookup); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 520 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 521 | if (!lookup.IsFound()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 522 | // If the object does not have the requested property, check which |
| 523 | // exception we need to throw. |
mvstanton@chromium.org | c47dff5 | 2013-01-23 16:28:41 +0000 | [diff] [blame] | 524 | return IsUndeclaredGlobal(object) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 525 | ? ReferenceError("not_defined", name) |
| 526 | : TypeError("undefined_method", object, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | // Lookup is valid: Update inline cache and stub cache. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 530 | if (FLAG_use_ic) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 531 | UpdateCaches(&lookup, state, extra_ic_state, object, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 532 | } |
| 533 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 534 | // Get the property. |
| 535 | PropertyAttributes attr; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 536 | Handle<Object> result = |
| 537 | Object::GetProperty(object, object, &lookup, name, &attr); |
| 538 | RETURN_IF_EMPTY_HANDLE(isolate(), result); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 539 | |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 540 | if (lookup.IsInterceptor() && attr == ABSENT) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 541 | // If the object does not have the requested property, check which |
| 542 | // exception we need to throw. |
mvstanton@chromium.org | c47dff5 | 2013-01-23 16:28:41 +0000 | [diff] [blame] | 543 | return IsUndeclaredGlobal(object) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 544 | ? ReferenceError("not_defined", name) |
| 545 | : TypeError("undefined_method", object, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 546 | } |
| 547 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 548 | ASSERT(!result->IsTheHole()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 549 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 550 | // Make receiver an object if the callee requires it. Strict mode or builtin |
| 551 | // functions do not wrap the receiver, non-strict functions and objects |
| 552 | // called as functions do. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 553 | ReceiverToObjectIfRequired(result, object); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 554 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 555 | if (result->IsJSFunction()) { |
| 556 | Handle<JSFunction> function = Handle<JSFunction>::cast(result); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 557 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 558 | // Handle stepping into a function if step into is active. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 559 | Debug* debug = isolate()->debug(); |
| 560 | if (debug->StepInActive()) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 561 | // Protect the result in a handle as the debugger can allocate and might |
| 562 | // cause GC. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 563 | debug->HandleStepIn(function, object, fp(), false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 564 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 565 | #endif |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 566 | return *function; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | // Try to find a suitable function delegate for the object at hand. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 570 | result = TryCallAsFunction(result); |
| 571 | if (result->IsJSFunction()) return *result; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 572 | |
| 573 | return TypeError("property_not_function", object, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 577 | bool CallICBase::TryUpdateExtraICState(LookupResult* lookup, |
| 578 | Handle<Object> object, |
| 579 | Code::ExtraICState* extra_ic_state) { |
| 580 | ASSERT(kind_ == Code::CALL_IC); |
| 581 | if (lookup->type() != CONSTANT_FUNCTION) return false; |
| 582 | JSFunction* function = lookup->GetConstantFunction(); |
| 583 | if (!function->shared()->HasBuiltinFunctionId()) return false; |
| 584 | |
| 585 | // Fetch the arguments passed to the called function. |
| 586 | const int argc = target()->arguments_count(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 587 | Address entry = isolate()->c_entry_fp(isolate()->thread_local_top()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 588 | Address fp = Memory::Address_at(entry + ExitFrameConstants::kCallerFPOffset); |
| 589 | Arguments args(argc + 1, |
| 590 | &Memory::Object_at(fp + |
| 591 | StandardFrameConstants::kCallerSPOffset + |
| 592 | argc * kPointerSize)); |
| 593 | switch (function->shared()->builtin_function_id()) { |
| 594 | case kStringCharCodeAt: |
| 595 | case kStringCharAt: |
| 596 | if (object->IsString()) { |
| 597 | String* string = String::cast(*object); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 598 | // Check there's the right string value or wrapper in the receiver slot. |
| 599 | ASSERT(string == args[0] || string == JSValue::cast(args[0])->value()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 600 | // If we're in the default (fastest) state and the index is |
| 601 | // out of bounds, update the state to record this fact. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 602 | if (StringStubState::decode(*extra_ic_state) == DEFAULT_STRING_STUB && |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 603 | argc >= 1 && args[1]->IsNumber()) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 604 | double index = DoubleToInteger(args.number_at(1)); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 605 | if (index < 0 || index >= string->length()) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 606 | *extra_ic_state = |
| 607 | StringStubState::update(*extra_ic_state, |
| 608 | STRING_INDEX_OUT_OF_BOUNDS); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 609 | return true; |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | break; |
| 614 | default: |
| 615 | return false; |
| 616 | } |
| 617 | return false; |
| 618 | } |
| 619 | |
| 620 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 621 | Handle<Code> CallICBase::ComputeMonomorphicStub(LookupResult* lookup, |
| 622 | State state, |
| 623 | Code::ExtraICState extra_state, |
| 624 | Handle<Object> object, |
| 625 | Handle<String> name) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 626 | int argc = target()->arguments_count(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 627 | Handle<JSObject> holder(lookup->holder()); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 628 | switch (lookup->type()) { |
| 629 | case FIELD: { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 630 | PropertyIndex index = lookup->GetFieldIndex(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 631 | return isolate()->stub_cache()->ComputeCallField( |
| 632 | argc, kind_, extra_state, name, object, holder, index); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 633 | } |
| 634 | case CONSTANT_FUNCTION: { |
| 635 | // Get the constant function and compute the code stub for this |
| 636 | // call; used for rewriting to monomorphic state and making sure |
| 637 | // that the code stub is in the stub cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 638 | Handle<JSFunction> function(lookup->GetConstantFunction()); |
| 639 | return isolate()->stub_cache()->ComputeCallConstant( |
| 640 | argc, kind_, extra_state, name, object, holder, function); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 641 | } |
| 642 | case NORMAL: { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 643 | // If we return a null handle, the IC will not be patched. |
| 644 | if (!object->IsJSObject()) return Handle<Code>::null(); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 645 | Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
| 646 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 647 | if (holder->IsGlobalObject()) { |
| 648 | Handle<GlobalObject> global = Handle<GlobalObject>::cast(holder); |
| 649 | Handle<JSGlobalPropertyCell> cell(global->GetPropertyCell(lookup)); |
| 650 | if (!cell->value()->IsJSFunction()) return Handle<Code>::null(); |
| 651 | Handle<JSFunction> function(JSFunction::cast(cell->value())); |
| 652 | return isolate()->stub_cache()->ComputeCallGlobal( |
| 653 | argc, kind_, extra_state, name, receiver, global, cell, function); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 654 | } else { |
| 655 | // There is only one shared stub for calling normalized |
| 656 | // properties. It does not traverse the prototype chain, so the |
| 657 | // property must be found in the receiver for the stub to be |
| 658 | // applicable. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 659 | if (!holder.is_identical_to(receiver)) return Handle<Code>::null(); |
| 660 | return isolate()->stub_cache()->ComputeCallNormal( |
| 661 | argc, kind_, extra_state); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 662 | } |
| 663 | break; |
| 664 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 665 | case INTERCEPTOR: |
| 666 | ASSERT(HasInterceptorGetter(*holder)); |
| 667 | return isolate()->stub_cache()->ComputeCallInterceptor( |
| 668 | argc, kind_, extra_state, name, object, holder); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 669 | default: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 670 | return Handle<Code>::null(); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 671 | } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 675 | void CallICBase::UpdateCaches(LookupResult* lookup, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 676 | State state, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 677 | Code::ExtraICState extra_ic_state, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 678 | Handle<Object> object, |
| 679 | Handle<String> name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 680 | // Bail out if we didn't find a result. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 681 | if (!lookup->IsProperty() || !lookup->IsCacheable()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 682 | |
| 683 | // Compute the number of arguments. |
| 684 | int argc = target()->arguments_count(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 685 | Handle<Code> code; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 686 | if (state == UNINITIALIZED) { |
| 687 | // This is the first time we execute this inline cache. |
| 688 | // Set the target to the pre monomorphic stub to delay |
| 689 | // setting the monomorphic state. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 690 | code = isolate()->stub_cache()->ComputeCallPreMonomorphic( |
| 691 | argc, kind_, extra_ic_state); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 692 | } else if (state == MONOMORPHIC) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 693 | if (kind_ == Code::CALL_IC && |
| 694 | TryUpdateExtraICState(lookup, object, &extra_ic_state)) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 695 | code = ComputeMonomorphicStub(lookup, state, extra_ic_state, |
| 696 | object, name); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 697 | } else if (kind_ == Code::CALL_IC && |
| 698 | TryRemoveInvalidPrototypeDependentStub(target(), |
| 699 | *object, |
| 700 | *name)) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 701 | state = MONOMORPHIC_PROTOTYPE_FAILURE; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 702 | code = ComputeMonomorphicStub(lookup, state, extra_ic_state, |
| 703 | object, name); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 704 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 705 | code = isolate()->stub_cache()->ComputeCallMegamorphic( |
| 706 | argc, kind_, extra_ic_state); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 707 | } |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 708 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 709 | code = ComputeMonomorphicStub(lookup, state, extra_ic_state, |
| 710 | object, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 711 | } |
| 712 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 713 | // If there's no appropriate stub we simply avoid updating the caches. |
| 714 | if (code.is_null()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 715 | |
| 716 | // Patch the call site depending on the state of the cache. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 717 | switch (state) { |
| 718 | case UNINITIALIZED: |
| 719 | case MONOMORPHIC_PROTOTYPE_FAILURE: |
| 720 | case PREMONOMORPHIC: |
| 721 | set_target(*code); |
| 722 | break; |
| 723 | case MONOMORPHIC: |
| 724 | if (code->ic_state() != MONOMORPHIC) { |
| 725 | Map* map = target()->FindFirstMap(); |
| 726 | if (map != NULL) { |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 727 | UpdateMegamorphicCache(map, *name, target()); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | set_target(*code); |
| 731 | break; |
| 732 | case MEGAMORPHIC: { |
| 733 | // Cache code holding map should be consistent with |
| 734 | // GenerateMonomorphicCacheProbe. It is not the map which holds the stub. |
| 735 | Handle<JSObject> cache_object = object->IsJSObject() |
| 736 | ? Handle<JSObject>::cast(object) |
| 737 | : Handle<JSObject>(JSObject::cast(object->GetPrototype())); |
| 738 | // Update the stub cache. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 739 | UpdateMegamorphicCache(cache_object->map(), *name, *code); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 740 | break; |
| 741 | } |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 742 | case DEBUG_STUB: |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 743 | break; |
| 744 | case POLYMORPHIC: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 745 | case GENERIC: |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 746 | UNREACHABLE(); |
| 747 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 748 | } |
| 749 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 750 | TRACE_IC(kind_ == Code::CALL_IC ? "CallIC" : "KeyedCallIC", |
| 751 | name, state, target()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 755 | MaybeObject* KeyedCallIC::LoadFunction(State state, |
| 756 | Handle<Object> object, |
| 757 | Handle<Object> key) { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 758 | if (key->IsSymbol()) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 759 | return CallICBase::LoadFunction(state, |
| 760 | Code::kNoExtraICState, |
| 761 | object, |
| 762 | Handle<String>::cast(key)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | if (object->IsUndefined() || object->IsNull()) { |
| 766 | return TypeError("non_object_property_call", object, key); |
| 767 | } |
| 768 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 769 | bool use_ic = FLAG_use_ic && !object->IsAccessCheckNeeded(); |
| 770 | ASSERT(!(use_ic && object->IsJSGlobalProxy())); |
| 771 | |
| 772 | if (use_ic && state != MEGAMORPHIC) { |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 773 | int argc = target()->arguments_count(); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 774 | Handle<Code> stub = isolate()->stub_cache()->ComputeCallMegamorphic( |
| 775 | argc, Code::KEYED_CALL_IC, Code::kNoExtraICState); |
| 776 | if (object->IsJSObject()) { |
| 777 | Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
| 778 | if (receiver->elements()->map() == |
| 779 | isolate()->heap()->non_strict_arguments_elements_map()) { |
| 780 | stub = isolate()->stub_cache()->ComputeCallArguments(argc); |
| 781 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 782 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 783 | ASSERT(!stub.is_null()); |
| 784 | set_target(*stub); |
| 785 | TRACE_IC("KeyedCallIC", key, state, target()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 786 | } |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 787 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 788 | Handle<Object> result = GetProperty(object, key); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 789 | RETURN_IF_EMPTY_HANDLE(isolate(), result); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 790 | |
| 791 | // Make receiver an object if the callee requires it. Strict mode or builtin |
| 792 | // functions do not wrap the receiver, non-strict functions and objects |
| 793 | // called as functions do. |
| 794 | ReceiverToObjectIfRequired(result, object); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 795 | if (result->IsJSFunction()) return *result; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 796 | |
| 797 | result = TryCallAsFunction(result); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 798 | if (result->IsJSFunction()) return *result; |
| 799 | |
| 800 | return TypeError("property_not_function", object, key); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 804 | MaybeObject* LoadIC::Load(State state, |
| 805 | Handle<Object> object, |
| 806 | Handle<String> name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 807 | // If the object is undefined or null it's illegal to try to get any |
| 808 | // of its properties; throw a TypeError in that case. |
| 809 | if (object->IsUndefined() || object->IsNull()) { |
| 810 | return TypeError("non_object_property_load", object, name); |
| 811 | } |
| 812 | |
| 813 | if (FLAG_use_ic) { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 814 | // Use specialized code for getting the length of strings and |
| 815 | // string wrapper objects. The length property of string wrapper |
| 816 | // objects is read-only and therefore always returns the length of |
| 817 | // the underlying string value. See ECMA-262 15.5.5.1. |
| 818 | if ((object->IsString() || object->IsStringWrapper()) && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 819 | name->Equals(isolate()->heap()->length_symbol())) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 820 | Handle<Code> stub; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 821 | if (state == UNINITIALIZED) { |
| 822 | stub = pre_monomorphic_stub(); |
| 823 | } else if (state == PREMONOMORPHIC) { |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 824 | StringLengthStub string_length_stub(kind(), !object->IsString()); |
| 825 | stub = string_length_stub.GetCode(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 826 | } else if (state == MONOMORPHIC && object->IsStringWrapper()) { |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 827 | StringLengthStub string_length_stub(kind(), true); |
| 828 | stub = string_length_stub.GetCode(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 829 | } else if (state != MEGAMORPHIC) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 830 | ASSERT(state != GENERIC); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 831 | stub = megamorphic_stub(); |
| 832 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 833 | if (!stub.is_null()) { |
| 834 | set_target(*stub); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 835 | #ifdef DEBUG |
| 836 | if (FLAG_trace_ic) PrintF("[LoadIC : +#length /string]\n"); |
| 837 | #endif |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 838 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 839 | // Get the string if we have a string wrapper object. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 840 | Handle<Object> string = object->IsJSValue() |
| 841 | ? Handle<Object>(Handle<JSValue>::cast(object)->value()) |
| 842 | : object; |
| 843 | return Smi::FromInt(String::cast(*string)->length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | // Use specialized code for getting the length of arrays. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 847 | if (object->IsJSArray() && |
| 848 | name->Equals(isolate()->heap()->length_symbol())) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 849 | Handle<Code> stub; |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 850 | if (state == UNINITIALIZED) { |
| 851 | stub = pre_monomorphic_stub(); |
| 852 | } else if (state == PREMONOMORPHIC) { |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 853 | ArrayLengthStub array_length_stub(kind()); |
| 854 | stub = array_length_stub.GetCode(); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 855 | } else if (state != MEGAMORPHIC) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 856 | ASSERT(state != GENERIC); |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 857 | stub = megamorphic_stub(); |
| 858 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 859 | if (!stub.is_null()) { |
| 860 | set_target(*stub); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 861 | #ifdef DEBUG |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 862 | if (FLAG_trace_ic) PrintF("[LoadIC : +#length /array]\n"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | #endif |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 864 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 865 | return JSArray::cast(*object)->length(); |
| 866 | } |
| 867 | |
| 868 | // Use specialized code for getting prototype of functions. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 869 | if (object->IsJSFunction() && |
| 870 | name->Equals(isolate()->heap()->prototype_symbol()) && |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 871 | Handle<JSFunction>::cast(object)->should_have_prototype()) { |
| 872 | Handle<Code> stub; |
| 873 | if (state == UNINITIALIZED) { |
| 874 | stub = pre_monomorphic_stub(); |
| 875 | } else if (state == PREMONOMORPHIC) { |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 876 | FunctionPrototypeStub function_prototype_stub(kind()); |
| 877 | stub = function_prototype_stub.GetCode(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 878 | } else if (state != MEGAMORPHIC) { |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 879 | ASSERT(state != GENERIC); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 880 | stub = megamorphic_stub(); |
| 881 | } |
| 882 | if (!stub.is_null()) { |
| 883 | set_target(*stub); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | #ifdef DEBUG |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 885 | if (FLAG_trace_ic) PrintF("[LoadIC : +#prototype /function]\n"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 886 | #endif |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 887 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 888 | return Accessors::FunctionGetPrototype(*object, 0); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | // Check if the name is trivially convertible to an index and get |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 893 | // the element or char if so. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 894 | uint32_t index; |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 895 | if (kind() == Code::KEYED_LOAD_IC && name->AsArrayIndex(&index)) { |
| 896 | // Rewrite to the generic keyed load stub. |
| 897 | if (FLAG_use_ic) set_target(*generic_stub()); |
| 898 | return Runtime::GetElementOrCharAt(isolate(), object, index); |
| 899 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 900 | |
| 901 | // Named lookup in the object. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 902 | LookupResult lookup(isolate()); |
| 903 | LookupForRead(object, name, &lookup); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 904 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 905 | // If we did not find a property, check if we need to throw an exception. |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 906 | if (!lookup.IsFound()) { |
mvstanton@chromium.org | c47dff5 | 2013-01-23 16:28:41 +0000 | [diff] [blame] | 907 | if (IsUndeclaredGlobal(object)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 908 | return ReferenceError("not_defined", name); |
| 909 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 910 | LOG(isolate(), SuspectReadEvent(*name, *object)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | // Update inline cache and stub cache. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 914 | if (FLAG_use_ic) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 915 | UpdateCaches(&lookup, state, object, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | PropertyAttributes attr; |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 919 | if (lookup.IsInterceptor() || lookup.IsHandler()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 920 | // Get the property. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 921 | Handle<Object> result = |
| 922 | Object::GetProperty(object, object, &lookup, name, &attr); |
| 923 | RETURN_IF_EMPTY_HANDLE(isolate(), result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 924 | // If the property is not present, check if we need to throw an |
| 925 | // exception. |
mvstanton@chromium.org | c47dff5 | 2013-01-23 16:28:41 +0000 | [diff] [blame] | 926 | if (attr == ABSENT && IsUndeclaredGlobal(object)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 927 | return ReferenceError("not_defined", name); |
| 928 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 929 | return *result; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | // Get the property. |
| 933 | return object->GetProperty(*object, &lookup, *name, &attr); |
| 934 | } |
| 935 | |
| 936 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 937 | void IC::PatchCache(State state, |
| 938 | StrictModeFlag strict_mode, |
| 939 | Handle<JSObject> receiver, |
| 940 | Handle<String> name, |
| 941 | Handle<Code> code) { |
| 942 | switch (state) { |
| 943 | case UNINITIALIZED: |
| 944 | case PREMONOMORPHIC: |
| 945 | case MONOMORPHIC_PROTOTYPE_FAILURE: |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 946 | set_target(*code); |
| 947 | break; |
| 948 | case MONOMORPHIC: |
| 949 | // Only move to megamorphic if the target changes. |
| 950 | if (target() != *code) { |
| 951 | // We are transitioning from monomorphic to megamorphic case. |
| 952 | // Place the current monomorphic stub and stub compiled for |
| 953 | // the receiver into stub cache. |
| 954 | Map* map = target()->FindFirstMap(); |
| 955 | if (map != NULL) { |
| 956 | UpdateMegamorphicCache(map, *name, target()); |
| 957 | } |
| 958 | UpdateMegamorphicCache(receiver->map(), *name, *code); |
| 959 | set_target((strict_mode == kStrictMode) |
| 960 | ? *megamorphic_stub_strict() |
| 961 | : *megamorphic_stub()); |
| 962 | } |
| 963 | break; |
| 964 | case MEGAMORPHIC: |
| 965 | // Update the stub cache. |
| 966 | UpdateMegamorphicCache(receiver->map(), *name, *code); |
| 967 | break; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 968 | case POLYMORPHIC: |
| 969 | // When trying to patch a polymorphic stub with anything other than |
| 970 | // another polymorphic stub, go generic. |
| 971 | // TODO(verwaest): Currently we always go generic since no polymorphic |
| 972 | // stubs enter this code path. Replace with proper updating once named |
| 973 | // load/store can also be polymorphic. |
| 974 | set_target((strict_mode == kStrictMode) |
| 975 | ? *generic_stub_strict() |
| 976 | : *generic_stub()); |
| 977 | break; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 978 | case DEBUG_STUB: |
| 979 | break; |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 980 | case GENERIC: |
| 981 | UNREACHABLE(); |
| 982 | break; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
| 986 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 987 | void LoadIC::UpdateCaches(LookupResult* lookup, |
| 988 | State state, |
| 989 | Handle<Object> object, |
| 990 | Handle<String> name) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 991 | // Bail out if the result is not cacheable. |
| 992 | if (!lookup->IsCacheable()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 993 | |
| 994 | // Loading properties from values is not common, so don't try to |
| 995 | // deal with non-JS objects here. |
| 996 | if (!object->IsJSObject()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 997 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 998 | Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 999 | Handle<Code> code; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1000 | if (state == UNINITIALIZED) { |
| 1001 | // This is the first time we execute this inline cache. |
| 1002 | // Set the target to the pre monomorphic stub to delay |
| 1003 | // setting the monomorphic state. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1004 | code = pre_monomorphic_stub(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1005 | } else { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1006 | code = ComputeLoadMonomorphic(lookup, receiver, name); |
| 1007 | if (code.is_null()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1010 | PatchCache(state, kNonStrictMode, receiver, name, code); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1011 | TRACE_IC("LoadIC", name, state, target()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1015 | void IC::UpdateMegamorphicCache(Map* map, String* name, Code* code) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1016 | // Cache code holding map should be consistent with |
| 1017 | // GenerateMonomorphicCacheProbe. |
| 1018 | isolate()->stub_cache()->Set(name, map, code); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1022 | Handle<Code> LoadIC::ComputeLoadMonomorphic(LookupResult* lookup, |
| 1023 | Handle<JSObject> receiver, |
| 1024 | Handle<String> name) { |
| 1025 | if (!lookup->IsProperty()) { |
| 1026 | // Nonexistent property. The result is undefined. |
| 1027 | return isolate()->stub_cache()->ComputeLoadNonexistent(name, receiver); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1028 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1029 | |
| 1030 | // Compute monomorphic stub. |
| 1031 | Handle<JSObject> holder(lookup->holder()); |
| 1032 | switch (lookup->type()) { |
| 1033 | case FIELD: |
| 1034 | return isolate()->stub_cache()->ComputeLoadField( |
| 1035 | name, receiver, holder, lookup->GetFieldIndex()); |
| 1036 | case CONSTANT_FUNCTION: { |
| 1037 | Handle<JSFunction> constant(lookup->GetConstantFunction()); |
| 1038 | return isolate()->stub_cache()->ComputeLoadConstant( |
| 1039 | name, receiver, holder, constant); |
| 1040 | } |
| 1041 | case NORMAL: |
| 1042 | if (holder->IsGlobalObject()) { |
| 1043 | Handle<GlobalObject> global = Handle<GlobalObject>::cast(holder); |
| 1044 | Handle<JSGlobalPropertyCell> cell(global->GetPropertyCell(lookup)); |
| 1045 | return isolate()->stub_cache()->ComputeLoadGlobal( |
| 1046 | name, receiver, global, cell, lookup->IsDontDelete()); |
| 1047 | } |
| 1048 | // There is only one shared stub for loading normalized |
| 1049 | // properties. It does not traverse the prototype chain, so the |
| 1050 | // property must be found in the receiver for the stub to be |
| 1051 | // applicable. |
| 1052 | if (!holder.is_identical_to(receiver)) break; |
| 1053 | return isolate()->stub_cache()->ComputeLoadNormal(); |
| 1054 | case CALLBACKS: { |
| 1055 | Handle<Object> callback(lookup->GetCallbackObject()); |
| 1056 | if (callback->IsAccessorInfo()) { |
| 1057 | Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(callback); |
| 1058 | if (v8::ToCData<Address>(info->getter()) == 0) break; |
| 1059 | if (!info->IsCompatibleReceiver(*receiver)) break; |
| 1060 | return isolate()->stub_cache()->ComputeLoadCallback( |
| 1061 | name, receiver, holder, info); |
| 1062 | } else if (callback->IsAccessorPair()) { |
| 1063 | Handle<Object> getter(Handle<AccessorPair>::cast(callback)->getter()); |
| 1064 | if (!getter->IsJSFunction()) break; |
| 1065 | if (holder->IsGlobalObject()) break; |
| 1066 | if (!holder->HasFastProperties()) break; |
| 1067 | return isolate()->stub_cache()->ComputeLoadViaGetter( |
| 1068 | name, receiver, holder, Handle<JSFunction>::cast(getter)); |
| 1069 | } |
| 1070 | ASSERT(callback->IsForeign()); |
| 1071 | // No IC support for old-style native accessors. |
| 1072 | break; |
| 1073 | } |
| 1074 | case INTERCEPTOR: |
| 1075 | ASSERT(HasInterceptorGetter(*holder)); |
| 1076 | return isolate()->stub_cache()->ComputeLoadInterceptor( |
| 1077 | name, receiver, holder); |
| 1078 | default: |
| 1079 | break; |
| 1080 | } |
| 1081 | return Handle<Code>::null(); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1085 | static Handle<Object> TryConvertKey(Handle<Object> key, Isolate* isolate) { |
| 1086 | // This helper implements a few common fast cases for converting |
| 1087 | // non-smi keys of keyed loads/stores to a smi or a string. |
| 1088 | if (key->IsHeapNumber()) { |
| 1089 | double value = Handle<HeapNumber>::cast(key)->value(); |
| 1090 | if (isnan(value)) { |
| 1091 | key = isolate->factory()->nan_symbol(); |
| 1092 | } else { |
| 1093 | int int_value = FastD2I(value); |
| 1094 | if (value == int_value && Smi::IsValid(int_value)) { |
| 1095 | key = Handle<Smi>(Smi::FromInt(int_value)); |
| 1096 | } |
| 1097 | } |
| 1098 | } else if (key->IsUndefined()) { |
| 1099 | key = isolate->factory()->undefined_symbol(); |
| 1100 | } |
| 1101 | return key; |
| 1102 | } |
| 1103 | |
| 1104 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1105 | static bool AddOneReceiverMapIfMissing(MapHandleList* receiver_maps, |
| 1106 | Handle<Map> new_receiver_map) { |
| 1107 | ASSERT(!new_receiver_map.is_null()); |
| 1108 | for (int current = 0; current < receiver_maps->length(); ++current) { |
| 1109 | if (!receiver_maps->at(current).is_null() && |
| 1110 | receiver_maps->at(current).is_identical_to(new_receiver_map)) { |
| 1111 | return false; |
| 1112 | } |
| 1113 | } |
| 1114 | receiver_maps->Add(new_receiver_map); |
| 1115 | return true; |
| 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | static void GetReceiverMapsForStub(Handle<Code> stub, |
| 1120 | MapHandleList* result) { |
| 1121 | ASSERT(stub->is_inline_cache_stub()); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1122 | ASSERT(stub->is_keyed_load_stub() || stub->is_keyed_store_stub()); |
| 1123 | switch (stub->ic_state()) { |
| 1124 | case MONOMORPHIC: { |
| 1125 | Map* map = stub->FindFirstMap(); |
| 1126 | if (map != NULL) { |
| 1127 | result->Add(Handle<Map>(map)); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1128 | } |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1129 | break; |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1130 | } |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1131 | case POLYMORPHIC: { |
| 1132 | AssertNoAllocation no_allocation; |
| 1133 | int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| 1134 | for (RelocIterator it(*stub, mask); !it.done(); it.next()) { |
| 1135 | RelocInfo* info = it.rinfo(); |
| 1136 | Handle<Object> object(info->target_object()); |
| 1137 | ASSERT(object->IsMap()); |
| 1138 | AddOneReceiverMapIfMissing(result, Handle<Map>::cast(object)); |
| 1139 | } |
| 1140 | break; |
| 1141 | } |
| 1142 | case MEGAMORPHIC: |
| 1143 | break; |
| 1144 | case UNINITIALIZED: |
| 1145 | case PREMONOMORPHIC: |
| 1146 | case MONOMORPHIC_PROTOTYPE_FAILURE: |
| 1147 | case GENERIC: |
| 1148 | case DEBUG_STUB: |
| 1149 | UNREACHABLE(); |
| 1150 | break; |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | Handle<Code> KeyedLoadIC::LoadElementStub(Handle<JSObject> receiver) { |
| 1156 | State ic_state = target()->ic_state(); |
| 1157 | |
| 1158 | // Don't handle megamorphic property accesses for INTERCEPTORS or CALLBACKS |
| 1159 | // via megamorphic stubs, since they don't have a map in their relocation info |
| 1160 | // and so the stubs can't be harvested for the object needed for a map check. |
| 1161 | if (target()->type() != Code::NORMAL) { |
| 1162 | TRACE_GENERIC_IC("KeyedIC", "non-NORMAL target type"); |
| 1163 | return generic_stub(); |
| 1164 | } |
| 1165 | |
| 1166 | Handle<Map> receiver_map(receiver->map()); |
| 1167 | MapHandleList target_receiver_maps; |
| 1168 | if (ic_state == UNINITIALIZED || ic_state == PREMONOMORPHIC) { |
| 1169 | // Optimistically assume that ICs that haven't reached the MONOMORPHIC state |
| 1170 | // yet will do so and stay there. |
| 1171 | return isolate()->stub_cache()->ComputeKeyedLoadElement(receiver_map); |
| 1172 | } |
| 1173 | |
| 1174 | if (target() == *string_stub()) { |
| 1175 | target_receiver_maps.Add(isolate()->factory()->string_map()); |
| 1176 | } else { |
| 1177 | GetReceiverMapsForStub(Handle<Code>(target()), &target_receiver_maps); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1178 | if (target_receiver_maps.length() == 0) { |
| 1179 | return isolate()->stub_cache()->ComputeKeyedLoadElement(receiver_map); |
| 1180 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | // The first time a receiver is seen that is a transitioned version of the |
| 1184 | // previous monomorphic receiver type, assume the new ElementsKind is the |
| 1185 | // monomorphic type. This benefits global arrays that only transition |
| 1186 | // once, and all call sites accessing them are faster if they remain |
| 1187 | // monomorphic. If this optimistic assumption is not true, the IC will |
| 1188 | // miss again and it will become polymorphic and support both the |
| 1189 | // untransitioned and transitioned maps. |
| 1190 | if (ic_state == MONOMORPHIC && |
| 1191 | IsMoreGeneralElementsKindTransition( |
| 1192 | target_receiver_maps.at(0)->elements_kind(), |
| 1193 | receiver->GetElementsKind())) { |
| 1194 | return isolate()->stub_cache()->ComputeKeyedLoadElement(receiver_map); |
| 1195 | } |
| 1196 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1197 | ASSERT(ic_state != GENERIC); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1198 | |
| 1199 | // Determine the list of receiver maps that this call site has seen, |
| 1200 | // adding the map that was just encountered. |
| 1201 | if (!AddOneReceiverMapIfMissing(&target_receiver_maps, receiver_map)) { |
| 1202 | // If the miss wasn't due to an unseen map, a polymorphic stub |
| 1203 | // won't help, use the generic stub. |
| 1204 | TRACE_GENERIC_IC("KeyedIC", "same map added twice"); |
| 1205 | return generic_stub(); |
| 1206 | } |
| 1207 | |
| 1208 | // If the maximum number of receiver maps has been exceeded, use the generic |
| 1209 | // version of the IC. |
| 1210 | if (target_receiver_maps.length() > kMaxKeyedPolymorphism) { |
| 1211 | TRACE_GENERIC_IC("KeyedIC", "max polymorph exceeded"); |
| 1212 | return generic_stub(); |
| 1213 | } |
| 1214 | |
| 1215 | return isolate()->stub_cache()->ComputeLoadElementPolymorphic( |
| 1216 | &target_receiver_maps); |
| 1217 | } |
| 1218 | |
| 1219 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1220 | MaybeObject* KeyedLoadIC::Load(State state, |
| 1221 | Handle<Object> object, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1222 | Handle<Object> key, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1223 | ICMissMode miss_mode) { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1224 | // Check for values that can be converted into a symbol directly or |
| 1225 | // is representable as a smi. |
| 1226 | key = TryConvertKey(key, isolate()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1227 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1228 | if (key->IsSymbol()) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1229 | return LoadIC::Load(state, object, Handle<String>::cast(key)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1232 | bool use_ic = FLAG_use_ic && !object->IsAccessCheckNeeded(); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1233 | ASSERT(!(use_ic && object->IsJSGlobalProxy())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1234 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1235 | if (use_ic) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1236 | Handle<Code> stub = generic_stub(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1237 | if (miss_mode != MISS_FORCE_GENERIC) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1238 | if (object->IsString() && key->IsNumber()) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1239 | if (state == UNINITIALIZED) { |
| 1240 | stub = string_stub(); |
| 1241 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1242 | } else if (object->IsJSObject()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1243 | Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
| 1244 | if (receiver->elements()->map() == |
| 1245 | isolate()->heap()->non_strict_arguments_elements_map()) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1246 | stub = non_strict_arguments_stub(); |
| 1247 | } else if (receiver->HasIndexedInterceptor()) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1248 | stub = indexed_interceptor_stub(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1249 | } else if (key->IsSmi() && (target() != *non_strict_arguments_stub())) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1250 | stub = LoadElementStub(receiver); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1251 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1252 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1253 | } else { |
| 1254 | TRACE_GENERIC_IC("KeyedLoadIC", "force generic"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1255 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1256 | ASSERT(!stub.is_null()); |
| 1257 | set_target(*stub); |
| 1258 | TRACE_IC("KeyedLoadIC", key, state, target()); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1259 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1260 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1261 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1262 | return Runtime::GetObjectProperty(isolate(), object, key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1266 | Handle<Code> KeyedLoadIC::ComputeLoadMonomorphic(LookupResult* lookup, |
| 1267 | Handle<JSObject> receiver, |
| 1268 | Handle<String> name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1269 | // Bail out if we didn't find a result. |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1270 | if (!lookup->IsProperty()) return Handle<Code>::null(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1271 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1272 | // Compute a monomorphic stub. |
| 1273 | Handle<JSObject> holder(lookup->holder()); |
| 1274 | switch (lookup->type()) { |
| 1275 | case FIELD: |
| 1276 | return isolate()->stub_cache()->ComputeKeyedLoadField( |
| 1277 | name, receiver, holder, lookup->GetFieldIndex()); |
| 1278 | case CONSTANT_FUNCTION: { |
| 1279 | Handle<JSFunction> constant(lookup->GetConstantFunction()); |
| 1280 | return isolate()->stub_cache()->ComputeKeyedLoadConstant( |
| 1281 | name, receiver, holder, constant); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1282 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1283 | case CALLBACKS: { |
| 1284 | Handle<Object> callback_object(lookup->GetCallbackObject()); |
| 1285 | if (!callback_object->IsAccessorInfo()) break; |
| 1286 | Handle<AccessorInfo> callback = |
| 1287 | Handle<AccessorInfo>::cast(callback_object); |
| 1288 | if (v8::ToCData<Address>(callback->getter()) == 0) break; |
| 1289 | if (!callback->IsCompatibleReceiver(*receiver)) break; |
| 1290 | return isolate()->stub_cache()->ComputeKeyedLoadCallback( |
| 1291 | name, receiver, holder, callback); |
| 1292 | } |
| 1293 | case INTERCEPTOR: |
| 1294 | ASSERT(HasInterceptorGetter(lookup->holder())); |
| 1295 | return isolate()->stub_cache()->ComputeKeyedLoadInterceptor( |
| 1296 | name, receiver, holder); |
| 1297 | default: |
| 1298 | // Always rewrite to the generic case so that we do not |
| 1299 | // repeatedly try to rewrite. |
| 1300 | return generic_stub(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1301 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1302 | return Handle<Code>::null(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1306 | static bool StoreICableLookup(LookupResult* lookup) { |
| 1307 | // Bail out if we didn't find a result. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 1308 | if (!lookup->IsFound()) return false; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1309 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1310 | // Bail out if inline caching is not allowed. |
| 1311 | if (!lookup->IsCacheable()) return false; |
| 1312 | |
| 1313 | // If the property is read-only, we leave the IC in its current state. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1314 | if (lookup->IsTransition()) { |
| 1315 | return !lookup->GetTransitionDetails().IsReadOnly(); |
| 1316 | } |
| 1317 | return !lookup->IsReadOnly(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1321 | static bool LookupForWrite(Handle<JSObject> receiver, |
| 1322 | Handle<String> name, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1323 | LookupResult* lookup) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1324 | receiver->LocalLookup(*name, lookup); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 1325 | if (!lookup->IsFound()) { |
| 1326 | receiver->map()->LookupTransition(*receiver, *name, lookup); |
| 1327 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1328 | if (!StoreICableLookup(lookup)) { |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1329 | // 2nd chance: There can be accessors somewhere in the prototype chain. |
svenpanne@chromium.org | 619781a | 2012-07-05 08:22:44 +0000 | [diff] [blame] | 1330 | receiver->Lookup(*name, lookup); |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1331 | return lookup->IsPropertyCallbacks() && StoreICableLookup(lookup); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 1334 | if (lookup->IsInterceptor() && |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1335 | receiver->GetNamedInterceptor()->setter()->IsUndefined()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1336 | receiver->LocalLookupRealNamedProperty(*name, lookup); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1337 | return StoreICableLookup(lookup); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | return true; |
| 1341 | } |
| 1342 | |
| 1343 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1344 | MaybeObject* StoreIC::Store(State state, |
| 1345 | StrictModeFlag strict_mode, |
| 1346 | Handle<Object> object, |
| 1347 | Handle<String> name, |
| 1348 | Handle<Object> value, |
| 1349 | JSReceiver::StoreFromKeyed store_mode) { |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1350 | // Handle proxies. |
| 1351 | if (object->IsJSProxy()) { |
| 1352 | return JSProxy::cast(*object)-> |
| 1353 | SetProperty(*name, *value, NONE, strict_mode); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1356 | // If the object is undefined or null it's illegal to try to set any |
| 1357 | // properties on it; throw a TypeError in that case. |
| 1358 | if (object->IsUndefined() || object->IsNull()) { |
| 1359 | return TypeError("non_object_property_store", object, name); |
| 1360 | } |
| 1361 | |
| 1362 | // The length property of string values is read-only. Throw in strict mode. |
| 1363 | if (strict_mode == kStrictMode && object->IsString() && |
| 1364 | name->Equals(isolate()->heap()->length_symbol())) { |
| 1365 | return TypeError("strict_read_only_property", object, name); |
| 1366 | } |
| 1367 | |
| 1368 | // Ignore other stores where the receiver is not a JSObject. |
| 1369 | // TODO(1475): Must check prototype chains of object wrappers. |
| 1370 | if (!object->IsJSObject()) return *value; |
| 1371 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1372 | Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
| 1373 | |
| 1374 | // Check if the given name is an array index. |
| 1375 | uint32_t index; |
| 1376 | if (name->AsArrayIndex(&index)) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1377 | Handle<Object> result = |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 1378 | JSObject::SetElement(receiver, index, value, NONE, strict_mode); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1379 | RETURN_IF_EMPTY_HANDLE(isolate(), result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1380 | return *value; |
| 1381 | } |
| 1382 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1383 | // Observed objects are always modified through the runtime. |
| 1384 | if (FLAG_harmony_observation && receiver->map()->is_observed()) { |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1385 | return receiver->SetProperty(*name, *value, NONE, strict_mode, store_mode); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 1388 | // Use specialized code for setting the length of arrays with fast |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1389 | // properties. Slow properties might indicate redefinition of the length |
| 1390 | // property. |
| 1391 | if (FLAG_use_ic && |
| 1392 | receiver->IsJSArray() && |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 1393 | name->Equals(isolate()->heap()->length_symbol()) && |
| 1394 | Handle<JSArray>::cast(receiver)->AllowsSetElementsLength() && |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1395 | receiver->HasFastProperties()) { |
| 1396 | Handle<Code> stub = StoreArrayLengthStub(kind(), strict_mode).GetCode(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1397 | set_target(*stub); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1398 | TRACE_IC("StoreIC", name, state, *stub); |
| 1399 | return receiver->SetProperty(*name, *value, NONE, strict_mode, store_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1402 | if (receiver->IsJSGlobalProxy()) { |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1403 | if (FLAG_use_ic && kind() != Code::KEYED_STORE_IC) { |
| 1404 | // Generate a generic stub that goes to the runtime when we see a global |
| 1405 | // proxy as receiver. |
| 1406 | Handle<Code> stub = (strict_mode == kStrictMode) |
| 1407 | ? global_proxy_stub_strict() |
| 1408 | : global_proxy_stub(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1409 | set_target(*stub); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1410 | TRACE_IC("StoreIC", name, state, *stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1411 | } |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1412 | return receiver->SetProperty(*name, *value, NONE, strict_mode, store_mode); |
| 1413 | } |
| 1414 | |
| 1415 | LookupResult lookup(isolate()); |
| 1416 | if (LookupForWrite(receiver, name, &lookup)) { |
| 1417 | if (FLAG_use_ic) { |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1418 | UpdateCaches(&lookup, state, strict_mode, receiver, name, value); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1419 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1420 | } else if (strict_mode == kStrictMode && |
| 1421 | !(lookup.IsProperty() && lookup.IsReadOnly()) && |
| 1422 | IsUndeclaredGlobal(object)) { |
mvstanton@chromium.org | c47dff5 | 2013-01-23 16:28:41 +0000 | [diff] [blame] | 1423 | // Strict mode doesn't allow setting non-existent global property. |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1424 | return ReferenceError("not_defined", name); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1427 | // Set the property. |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1428 | return receiver->SetProperty(*name, *value, NONE, strict_mode, store_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1432 | void StoreIC::UpdateCaches(LookupResult* lookup, |
| 1433 | State state, |
| 1434 | StrictModeFlag strict_mode, |
| 1435 | Handle<JSObject> receiver, |
| 1436 | Handle<String> name, |
| 1437 | Handle<Object> value) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1438 | ASSERT(!receiver->IsJSGlobalProxy()); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1439 | ASSERT(StoreICableLookup(lookup)); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 1440 | ASSERT(lookup->IsFound()); |
| 1441 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1442 | // These are not cacheable, so we never see such LookupResults here. |
yangguo@chromium.org | de0db00 | 2012-06-22 13:44:28 +0000 | [diff] [blame] | 1443 | ASSERT(!lookup->IsHandler()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1444 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1445 | Handle<Code> code = |
| 1446 | ComputeStoreMonomorphic(lookup, strict_mode, receiver, name); |
| 1447 | if (code.is_null()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1448 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1449 | PatchCache(state, strict_mode, receiver, name, code); |
| 1450 | TRACE_IC("StoreIC", name, state, target()); |
| 1451 | } |
| 1452 | |
| 1453 | |
| 1454 | Handle<Code> StoreIC::ComputeStoreMonomorphic(LookupResult* lookup, |
| 1455 | StrictModeFlag strict_mode, |
| 1456 | Handle<JSObject> receiver, |
| 1457 | Handle<String> name) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1458 | Handle<JSObject> holder(lookup->holder()); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1459 | switch (lookup->type()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1460 | case FIELD: |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1461 | return isolate()->stub_cache()->ComputeStoreField( |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1462 | name, receiver, lookup->GetFieldIndex().field_index(), |
| 1463 | Handle<Map>::null(), strict_mode); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1464 | case NORMAL: |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1465 | if (receiver->IsGlobalObject()) { |
| 1466 | // The stub generated for the global object picks the value directly |
| 1467 | // from the property cell. So the property must be directly on the |
| 1468 | // global object. |
| 1469 | Handle<GlobalObject> global = Handle<GlobalObject>::cast(receiver); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1470 | Handle<JSGlobalPropertyCell> cell(global->GetPropertyCell(lookup)); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1471 | return isolate()->stub_cache()->ComputeStoreGlobal( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1472 | name, global, cell, strict_mode); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1473 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1474 | if (!holder.is_identical_to(receiver)) break; |
| 1475 | return isolate()->stub_cache()->ComputeStoreNormal(strict_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1476 | case CALLBACKS: { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1477 | Handle<Object> callback(lookup->GetCallbackObject()); |
| 1478 | if (callback->IsAccessorInfo()) { |
| 1479 | Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(callback); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1480 | if (v8::ToCData<Address>(info->setter()) == 0) break; |
| 1481 | if (!holder->HasFastProperties()) break; |
| 1482 | if (!info->IsCompatibleReceiver(*receiver)) break; |
| 1483 | return isolate()->stub_cache()->ComputeStoreCallback( |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1484 | name, receiver, holder, info, strict_mode); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1485 | } else if (callback->IsAccessorPair()) { |
| 1486 | Handle<Object> setter(Handle<AccessorPair>::cast(callback)->setter()); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1487 | if (!setter->IsJSFunction()) break; |
| 1488 | if (holder->IsGlobalObject()) break; |
| 1489 | if (!holder->HasFastProperties()) break; |
| 1490 | return isolate()->stub_cache()->ComputeStoreViaSetter( |
svenpanne@chromium.org | 619781a | 2012-07-05 08:22:44 +0000 | [diff] [blame] | 1491 | name, receiver, holder, Handle<JSFunction>::cast(setter), |
| 1492 | strict_mode); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1493 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1494 | ASSERT(callback->IsForeign()); |
| 1495 | // No IC support for old-style native accessors. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1496 | break; |
| 1497 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1498 | case INTERCEPTOR: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1499 | ASSERT(!receiver->GetNamedInterceptor()->setter()->IsUndefined()); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1500 | return isolate()->stub_cache()->ComputeStoreInterceptor( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1501 | name, receiver, strict_mode); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1502 | case CONSTANT_FUNCTION: |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1503 | break; |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1504 | case TRANSITION: { |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1505 | Handle<Map> transition(lookup->GetTransitionTarget()); |
| 1506 | int descriptor = transition->LastAdded(); |
| 1507 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1508 | DescriptorArray* target_descriptors = transition->instance_descriptors(); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1509 | PropertyDetails details = target_descriptors->GetDetails(descriptor); |
| 1510 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1511 | if (details.type() != FIELD || details.attributes() != NONE) break; |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1512 | |
| 1513 | int field_index = target_descriptors->GetFieldIndex(descriptor); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1514 | return isolate()->stub_cache()->ComputeStoreField( |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1515 | name, receiver, field_index, transition, strict_mode); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1516 | } |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 1517 | case NONEXISTENT: |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1518 | case HANDLER: |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1519 | UNREACHABLE(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1520 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1521 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1522 | return Handle<Code>::null(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1526 | Handle<Code> KeyedStoreIC::StoreElementStub(Handle<JSObject> receiver, |
| 1527 | StubKind stub_kind, |
| 1528 | StrictModeFlag strict_mode) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1529 | State ic_state = target()->ic_state(); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1530 | KeyedAccessGrowMode grow_mode = IsGrowStubKind(stub_kind) |
| 1531 | ? ALLOW_JSARRAY_GROWTH |
| 1532 | : DO_NOT_ALLOW_JSARRAY_GROWTH; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1533 | |
| 1534 | // Don't handle megamorphic property accesses for INTERCEPTORS or CALLBACKS |
| 1535 | // via megamorphic stubs, since they don't have a map in their relocation info |
| 1536 | // and so the stubs can't be harvested for the object needed for a map check. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 1537 | if (target()->type() != Code::NORMAL) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1538 | TRACE_GENERIC_IC("KeyedIC", "non-NORMAL target type"); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1539 | return strict_mode == kStrictMode ? generic_stub_strict() : generic_stub(); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1542 | Handle<Map> receiver_map(receiver->map()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1543 | MapHandleList target_receiver_maps; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1544 | if (ic_state == UNINITIALIZED || ic_state == PREMONOMORPHIC) { |
| 1545 | // Optimistically assume that ICs that haven't reached the MONOMORPHIC state |
| 1546 | // yet will do so and stay there. |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1547 | stub_kind = GetNoTransitionStubKind(stub_kind); |
| 1548 | return isolate()->stub_cache()->ComputeKeyedStoreElement( |
| 1549 | receiver_map, stub_kind, strict_mode, grow_mode); |
| 1550 | } |
| 1551 | |
| 1552 | GetReceiverMapsForStub(Handle<Code>(target()), &target_receiver_maps); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1553 | if (target_receiver_maps.length() == 0) { |
| 1554 | // Optimistically assume that ICs that haven't reached the MONOMORPHIC state |
| 1555 | // yet will do so and stay there. |
| 1556 | stub_kind = GetNoTransitionStubKind(stub_kind); |
| 1557 | return isolate()->stub_cache()->ComputeKeyedStoreElement( |
| 1558 | receiver_map, stub_kind, strict_mode, grow_mode); |
| 1559 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1560 | // The first time a receiver is seen that is a transitioned version of the |
| 1561 | // previous monomorphic receiver type, assume the new ElementsKind is the |
| 1562 | // monomorphic type. This benefits global arrays that only transition |
| 1563 | // once, and all call sites accessing them are faster if they remain |
| 1564 | // monomorphic. If this optimistic assumption is not true, the IC will |
| 1565 | // miss again and it will become polymorphic and support both the |
| 1566 | // untransitioned and transitioned maps. |
| 1567 | if (ic_state == MONOMORPHIC && |
| 1568 | IsTransitionStubKind(stub_kind) && |
| 1569 | IsMoreGeneralElementsKindTransition( |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1570 | target_receiver_maps.at(0)->elements_kind(), |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1571 | receiver->GetElementsKind())) { |
| 1572 | Handle<Map> monomorphic_map = ComputeTransitionedMap(receiver, stub_kind); |
| 1573 | ASSERT(*monomorphic_map != *receiver_map); |
| 1574 | stub_kind = GetNoTransitionStubKind(stub_kind); |
| 1575 | return isolate()->stub_cache()->ComputeKeyedStoreElement( |
| 1576 | monomorphic_map, stub_kind, strict_mode, grow_mode); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 1579 | ASSERT(ic_state != GENERIC); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1580 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1581 | bool map_added = |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1582 | AddOneReceiverMapIfMissing(&target_receiver_maps, receiver_map); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1583 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1584 | if (IsTransitionStubKind(stub_kind)) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1585 | Handle<Map> new_map = ComputeTransitionedMap(receiver, stub_kind); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1586 | map_added |= AddOneReceiverMapIfMissing(&target_receiver_maps, new_map); |
| 1587 | } |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1588 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1589 | if (!map_added) { |
| 1590 | // If the miss wasn't due to an unseen map, a polymorphic stub |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1591 | // won't help, use the generic stub. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1592 | TRACE_GENERIC_IC("KeyedIC", "same map added twice"); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1593 | return strict_mode == kStrictMode ? generic_stub_strict() : generic_stub(); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 1596 | // If the maximum number of receiver maps has been exceeded, use the generic |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1597 | // version of the IC. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1598 | if (target_receiver_maps.length() > kMaxKeyedPolymorphism) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1599 | TRACE_GENERIC_IC("KeyedIC", "max polymorph exceeded"); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1600 | return strict_mode == kStrictMode ? generic_stub_strict() : generic_stub(); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1603 | if ((Code::GetKeyedAccessGrowMode(target()->extra_ic_state()) == |
| 1604 | ALLOW_JSARRAY_GROWTH)) { |
| 1605 | grow_mode = ALLOW_JSARRAY_GROWTH; |
| 1606 | } |
| 1607 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1608 | return isolate()->stub_cache()->ComputeStoreElementPolymorphic( |
| 1609 | &target_receiver_maps, grow_mode, strict_mode); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1613 | Handle<Map> KeyedStoreIC::ComputeTransitionedMap(Handle<JSObject> receiver, |
| 1614 | StubKind stub_kind) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1615 | switch (stub_kind) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1616 | case STORE_TRANSITION_SMI_TO_OBJECT: |
| 1617 | case STORE_TRANSITION_DOUBLE_TO_OBJECT: |
| 1618 | case STORE_AND_GROW_TRANSITION_SMI_TO_OBJECT: |
| 1619 | case STORE_AND_GROW_TRANSITION_DOUBLE_TO_OBJECT: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1620 | return JSObject::GetElementsTransitionMap(receiver, FAST_ELEMENTS); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1621 | case STORE_TRANSITION_SMI_TO_DOUBLE: |
| 1622 | case STORE_AND_GROW_TRANSITION_SMI_TO_DOUBLE: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1623 | return JSObject::GetElementsTransitionMap(receiver, FAST_DOUBLE_ELEMENTS); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1624 | case STORE_TRANSITION_HOLEY_SMI_TO_OBJECT: |
| 1625 | case STORE_TRANSITION_HOLEY_DOUBLE_TO_OBJECT: |
| 1626 | case STORE_AND_GROW_TRANSITION_HOLEY_SMI_TO_OBJECT: |
| 1627 | case STORE_AND_GROW_TRANSITION_HOLEY_DOUBLE_TO_OBJECT: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1628 | return JSObject::GetElementsTransitionMap(receiver, |
| 1629 | FAST_HOLEY_ELEMENTS); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1630 | case STORE_TRANSITION_HOLEY_SMI_TO_DOUBLE: |
| 1631 | case STORE_AND_GROW_TRANSITION_HOLEY_SMI_TO_DOUBLE: |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1632 | return JSObject::GetElementsTransitionMap(receiver, |
| 1633 | FAST_HOLEY_DOUBLE_ELEMENTS); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1634 | case STORE_NO_TRANSITION: |
| 1635 | case STORE_AND_GROW_NO_TRANSITION: |
jkummerow@chromium.org | f3eae90 | 2012-05-24 16:42:53 +0000 | [diff] [blame] | 1636 | UNREACHABLE(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1637 | break; |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1638 | } |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1639 | return Handle<Map>::null(); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1643 | KeyedStoreIC::StubKind KeyedStoreIC::GetStubKind(Handle<JSObject> receiver, |
| 1644 | Handle<Object> key, |
| 1645 | Handle<Object> value) { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1646 | ASSERT(key->IsSmi()); |
| 1647 | int index = Smi::cast(*key)->value(); |
| 1648 | bool allow_growth = receiver->IsJSArray() && |
| 1649 | JSArray::cast(*receiver)->length()->IsSmi() && |
| 1650 | index >= Smi::cast(JSArray::cast(*receiver)->length())->value(); |
| 1651 | |
| 1652 | if (allow_growth) { |
| 1653 | // Handle growing array in stub if necessary. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1654 | if (receiver->HasFastSmiElements()) { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1655 | if (value->IsHeapNumber()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1656 | if (receiver->HasFastHoleyElements()) { |
| 1657 | return STORE_AND_GROW_TRANSITION_HOLEY_SMI_TO_DOUBLE; |
| 1658 | } else { |
| 1659 | return STORE_AND_GROW_TRANSITION_SMI_TO_DOUBLE; |
| 1660 | } |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1661 | } |
| 1662 | if (value->IsHeapObject()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1663 | if (receiver->HasFastHoleyElements()) { |
| 1664 | return STORE_AND_GROW_TRANSITION_HOLEY_SMI_TO_OBJECT; |
| 1665 | } else { |
| 1666 | return STORE_AND_GROW_TRANSITION_SMI_TO_OBJECT; |
| 1667 | } |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1668 | } |
| 1669 | } else if (receiver->HasFastDoubleElements()) { |
| 1670 | if (!value->IsSmi() && !value->IsHeapNumber()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1671 | if (receiver->HasFastHoleyElements()) { |
| 1672 | return STORE_AND_GROW_TRANSITION_HOLEY_DOUBLE_TO_OBJECT; |
| 1673 | } else { |
| 1674 | return STORE_AND_GROW_TRANSITION_DOUBLE_TO_OBJECT; |
| 1675 | } |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1676 | } |
| 1677 | } |
| 1678 | return STORE_AND_GROW_NO_TRANSITION; |
| 1679 | } else { |
| 1680 | // Handle only in-bounds elements accesses. |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1681 | if (receiver->HasFastSmiElements()) { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1682 | if (value->IsHeapNumber()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1683 | if (receiver->HasFastHoleyElements()) { |
| 1684 | return STORE_TRANSITION_HOLEY_SMI_TO_DOUBLE; |
| 1685 | } else { |
| 1686 | return STORE_TRANSITION_SMI_TO_DOUBLE; |
| 1687 | } |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1688 | } else if (value->IsHeapObject()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1689 | if (receiver->HasFastHoleyElements()) { |
| 1690 | return STORE_TRANSITION_HOLEY_SMI_TO_OBJECT; |
| 1691 | } else { |
| 1692 | return STORE_TRANSITION_SMI_TO_OBJECT; |
| 1693 | } |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1694 | } |
| 1695 | } else if (receiver->HasFastDoubleElements()) { |
| 1696 | if (!value->IsSmi() && !value->IsHeapNumber()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1697 | if (receiver->HasFastHoleyElements()) { |
| 1698 | return STORE_TRANSITION_HOLEY_DOUBLE_TO_OBJECT; |
| 1699 | } else { |
| 1700 | return STORE_TRANSITION_DOUBLE_TO_OBJECT; |
| 1701 | } |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1702 | } |
| 1703 | } |
| 1704 | return STORE_NO_TRANSITION; |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1709 | MaybeObject* KeyedStoreIC::Store(State state, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1710 | StrictModeFlag strict_mode, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1711 | Handle<Object> object, |
| 1712 | Handle<Object> key, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1713 | Handle<Object> value, |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1714 | ICMissMode miss_mode) { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1715 | // Check for values that can be converted into a symbol directly or |
| 1716 | // is representable as a smi. |
| 1717 | key = TryConvertKey(key, isolate()); |
| 1718 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1719 | if (key->IsSymbol()) { |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1720 | return StoreIC::Store(state, |
| 1721 | strict_mode, |
| 1722 | object, |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1723 | Handle<String>::cast(key), |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1724 | value, |
| 1725 | JSReceiver::MAY_BE_STORE_FROM_KEYED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 1728 | bool use_ic = FLAG_use_ic && !object->IsAccessCheckNeeded() && |
| 1729 | !(FLAG_harmony_observation && object->IsJSObject() && |
| 1730 | JSObject::cast(*object)->map()->is_observed()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1731 | ASSERT(!(use_ic && object->IsJSGlobalProxy())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1732 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1733 | if (use_ic) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1734 | Handle<Code> stub = (strict_mode == kStrictMode) |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1735 | ? generic_stub_strict() |
| 1736 | : generic_stub(); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1737 | if (miss_mode != MISS_FORCE_GENERIC) { |
| 1738 | if (object->IsJSObject()) { |
| 1739 | Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
| 1740 | if (receiver->elements()->map() == |
| 1741 | isolate()->heap()->non_strict_arguments_elements_map()) { |
| 1742 | stub = non_strict_arguments_stub(); |
| 1743 | } else if (key->IsSmi() && (target() != *non_strict_arguments_stub())) { |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1744 | StubKind stub_kind = GetStubKind(receiver, key, value); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 1745 | stub = StoreElementStub(receiver, stub_kind, strict_mode); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1746 | } |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1747 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1748 | } else { |
| 1749 | TRACE_GENERIC_IC("KeyedStoreIC", "force generic"); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1750 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1751 | ASSERT(!stub.is_null()); |
| 1752 | set_target(*stub); |
| 1753 | TRACE_IC("KeyedStoreIC", key, state, target()); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1754 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1755 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1756 | return Runtime::SetObjectProperty( |
| 1757 | isolate(), object , key, value, NONE, strict_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1761 | Handle<Code> KeyedStoreIC::ComputeStoreMonomorphic(LookupResult* lookup, |
| 1762 | StrictModeFlag strict_mode, |
| 1763 | Handle<JSObject> receiver, |
| 1764 | Handle<String> name) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1765 | // If the property has a non-field type allowing map transitions |
| 1766 | // where there is extra room in the object, we leave the IC in its |
| 1767 | // current state. |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1768 | switch (lookup->type()) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1769 | case FIELD: |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1770 | return isolate()->stub_cache()->ComputeKeyedStoreField( |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 1771 | name, receiver, lookup->GetFieldIndex().field_index(), |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1772 | Handle<Map>::null(), strict_mode); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1773 | case TRANSITION: { |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 1774 | Handle<Map> transition(lookup->GetTransitionTarget()); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1775 | int descriptor = transition->LastAdded(); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1776 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1777 | DescriptorArray* target_descriptors = transition->instance_descriptors(); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1778 | PropertyDetails details = target_descriptors->GetDetails(descriptor); |
| 1779 | |
| 1780 | if (details.type() == FIELD && details.attributes() == NONE) { |
| 1781 | int field_index = target_descriptors->GetFieldIndex(descriptor); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1782 | return isolate()->stub_cache()->ComputeKeyedStoreField( |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1783 | name, receiver, field_index, transition, strict_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1784 | } |
| 1785 | // fall through. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1786 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1787 | case NORMAL: |
| 1788 | case CONSTANT_FUNCTION: |
| 1789 | case CALLBACKS: |
| 1790 | case INTERCEPTOR: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1791 | // Always rewrite to the generic case so that we do not |
| 1792 | // repeatedly try to rewrite. |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1793 | return (strict_mode == kStrictMode) |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1794 | ? generic_stub_strict() |
| 1795 | : generic_stub(); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1796 | case HANDLER: |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 1797 | case NONEXISTENT: |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1798 | UNREACHABLE(); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1799 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1800 | } |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1801 | return Handle<Code>::null(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1805 | #undef TRACE_IC |
| 1806 | |
| 1807 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1808 | // ---------------------------------------------------------------------------- |
| 1809 | // Static IC stub generators. |
| 1810 | // |
| 1811 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1812 | // Used from ic-<arch>.cc. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1813 | RUNTIME_FUNCTION(MaybeObject*, CallIC_Miss) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1814 | HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1815 | ASSERT(args.length() == 2); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1816 | CallIC ic(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1817 | IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1818 | Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
| 1819 | MaybeObject* maybe_result = ic.LoadFunction(state, |
| 1820 | extra_ic_state, |
| 1821 | args.at<Object>(0), |
| 1822 | args.at<String>(1)); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1823 | JSFunction* raw_function; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1824 | if (!maybe_result->To(&raw_function)) return maybe_result; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1825 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1826 | // The first time the inline cache is updated may be the first time the |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1827 | // function it references gets called. If the function is lazily compiled |
| 1828 | // then the first call will trigger a compilation. We check for this case |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1829 | // and we do the compilation immediately, instead of waiting for the stub |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1830 | // currently attached to the JSFunction object to trigger compilation. |
| 1831 | if (raw_function->is_compiled()) return raw_function; |
| 1832 | |
| 1833 | Handle<JSFunction> function(raw_function); |
| 1834 | JSFunction::CompileLazy(function, CLEAR_EXCEPTION); |
| 1835 | return *function; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1839 | // Used from ic-<arch>.cc. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1840 | RUNTIME_FUNCTION(MaybeObject*, KeyedCallIC_Miss) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1841 | HandleScope scope(isolate); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1842 | ASSERT(args.length() == 2); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1843 | KeyedCallIC ic(isolate); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1844 | IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1845 | MaybeObject* maybe_result = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1846 | ic.LoadFunction(state, args.at<Object>(0), args.at<Object>(1)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1847 | // Result could be a function or a failure. |
| 1848 | JSFunction* raw_function = NULL; |
| 1849 | if (!maybe_result->To(&raw_function)) return maybe_result; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1850 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1851 | if (raw_function->is_compiled()) return raw_function; |
| 1852 | |
| 1853 | Handle<JSFunction> function(raw_function); |
| 1854 | JSFunction::CompileLazy(function, CLEAR_EXCEPTION); |
| 1855 | return *function; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | |
| 1859 | // Used from ic-<arch>.cc. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1860 | RUNTIME_FUNCTION(MaybeObject*, LoadIC_Miss) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1861 | HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1862 | ASSERT(args.length() == 2); |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame^] | 1863 | LoadIC ic(IC::NO_EXTRA_FRAME, isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1864 | IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1865 | return ic.Load(state, args.at<Object>(0), args.at<String>(1)); |
| 1866 | } |
| 1867 | |
| 1868 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1869 | // Used from ic-<arch>.cc |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1870 | RUNTIME_FUNCTION(MaybeObject*, KeyedLoadIC_Miss) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1871 | HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1872 | ASSERT(args.length() == 2); |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame^] | 1873 | KeyedLoadIC ic(IC::NO_EXTRA_FRAME, isolate); |
| 1874 | IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
| 1875 | return ic.Load(state, args.at<Object>(0), args.at<Object>(1), MISS); |
| 1876 | } |
| 1877 | |
| 1878 | |
| 1879 | RUNTIME_FUNCTION(MaybeObject*, KeyedLoadIC_MissFromStubFailure) { |
| 1880 | HandleScope scope(isolate); |
| 1881 | ASSERT(args.length() == 2); |
| 1882 | KeyedLoadIC ic(IC::EXTRA_CALL_FRAME, isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1883 | IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1884 | return ic.Load(state, args.at<Object>(0), args.at<Object>(1), MISS); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | |
| 1888 | RUNTIME_FUNCTION(MaybeObject*, KeyedLoadIC_MissForceGeneric) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1889 | HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1890 | ASSERT(args.length() == 2); |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame^] | 1891 | KeyedLoadIC ic(IC::NO_EXTRA_FRAME, isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1892 | IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1893 | return ic.Load(state, |
| 1894 | args.at<Object>(0), |
| 1895 | args.at<Object>(1), |
| 1896 | MISS_FORCE_GENERIC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1900 | // Used from ic-<arch>.cc. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1901 | RUNTIME_FUNCTION(MaybeObject*, StoreIC_Miss) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1902 | HandleScope scope; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1903 | ASSERT(args.length() == 3); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1904 | StoreIC ic(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1905 | IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1906 | Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1907 | return ic.Store(state, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1908 | Code::GetStrictMode(extra_ic_state), |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1909 | args.at<Object>(0), |
| 1910 | args.at<String>(1), |
| 1911 | args.at<Object>(2)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1915 | RUNTIME_FUNCTION(MaybeObject*, StoreIC_ArrayLength) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1916 | NoHandleAllocation nha; |
| 1917 | |
| 1918 | ASSERT(args.length() == 2); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 1919 | JSArray* receiver = JSArray::cast(args[0]); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1920 | Object* len = args[1]; |
| 1921 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1922 | // The generated code should filter out non-Smis before we get here. |
| 1923 | ASSERT(len->IsSmi()); |
| 1924 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 1925 | #ifdef DEBUG |
| 1926 | // The length property has to be a writable callback property. |
| 1927 | LookupResult debug_lookup(isolate); |
| 1928 | receiver->LocalLookup(isolate->heap()->length_symbol(), &debug_lookup); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 1929 | ASSERT(debug_lookup.IsPropertyCallbacks() && !debug_lookup.IsReadOnly()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 1930 | #endif |
| 1931 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1932 | Object* result; |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1933 | MaybeObject* maybe_result = receiver->SetElementsLength(len); |
| 1934 | if (!maybe_result->To(&result)) return maybe_result; |
| 1935 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1936 | return len; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1940 | // Extend storage is called in a store inline cache when |
| 1941 | // it is necessary to extend the properties array of a |
| 1942 | // JSObject. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1943 | RUNTIME_FUNCTION(MaybeObject*, SharedStoreIC_ExtendStorage) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1944 | NoHandleAllocation na; |
| 1945 | ASSERT(args.length() == 3); |
| 1946 | |
| 1947 | // Convert the parameters |
| 1948 | JSObject* object = JSObject::cast(args[0]); |
| 1949 | Map* transition = Map::cast(args[1]); |
| 1950 | Object* value = args[2]; |
| 1951 | |
| 1952 | // Check the object has run out out property space. |
| 1953 | ASSERT(object->HasFastProperties()); |
| 1954 | ASSERT(object->map()->unused_property_fields() == 0); |
| 1955 | |
| 1956 | // Expand the properties array. |
| 1957 | FixedArray* old_storage = object->properties(); |
| 1958 | int new_unused = transition->unused_property_fields(); |
| 1959 | int new_size = old_storage->length() + new_unused + 1; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1960 | Object* result; |
| 1961 | { MaybeObject* maybe_result = old_storage->CopySize(new_size); |
| 1962 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1963 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1964 | FixedArray* new_storage = FixedArray::cast(result); |
| 1965 | new_storage->set(old_storage->length(), value); |
| 1966 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1967 | // Set the new property value and do the map transition. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1968 | object->set_properties(new_storage); |
| 1969 | object->set_map(transition); |
| 1970 | |
| 1971 | // Return the stored value. |
| 1972 | return value; |
| 1973 | } |
| 1974 | |
| 1975 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1976 | // Used from ic-<arch>.cc. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1977 | RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_Miss) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1978 | HandleScope scope(isolate); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1979 | ASSERT(args.length() == 3); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1980 | KeyedStoreIC ic(isolate); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1981 | IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1982 | Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
| 1983 | return ic.Store(state, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1984 | Code::GetStrictMode(extra_ic_state), |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1985 | args.at<Object>(0), |
| 1986 | args.at<Object>(1), |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1987 | args.at<Object>(2), |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1988 | MISS); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | |
| 1992 | RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_Slow) { |
| 1993 | NoHandleAllocation na; |
| 1994 | ASSERT(args.length() == 3); |
| 1995 | KeyedStoreIC ic(isolate); |
| 1996 | Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
| 1997 | Handle<Object> object = args.at<Object>(0); |
| 1998 | Handle<Object> key = args.at<Object>(1); |
| 1999 | Handle<Object> value = args.at<Object>(2); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2000 | StrictModeFlag strict_mode = Code::GetStrictMode(extra_ic_state); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2001 | return Runtime::SetObjectProperty(isolate, |
| 2002 | object, |
| 2003 | key, |
| 2004 | value, |
| 2005 | NONE, |
| 2006 | strict_mode); |
| 2007 | } |
| 2008 | |
| 2009 | |
| 2010 | RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_MissForceGeneric) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2011 | HandleScope scope(isolate); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2012 | ASSERT(args.length() == 3); |
| 2013 | KeyedStoreIC ic(isolate); |
| 2014 | IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
| 2015 | Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
| 2016 | return ic.Store(state, |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2017 | Code::GetStrictMode(extra_ic_state), |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2018 | args.at<Object>(0), |
| 2019 | args.at<Object>(1), |
| 2020 | args.at<Object>(2), |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2021 | MISS_FORCE_GENERIC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2025 | void UnaryOpIC::patch(Code* code) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2026 | set_target(code); |
| 2027 | } |
| 2028 | |
| 2029 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2030 | const char* UnaryOpIC::GetName(TypeInfo type_info) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2031 | switch (type_info) { |
| 2032 | case UNINITIALIZED: return "Uninitialized"; |
| 2033 | case SMI: return "Smi"; |
| 2034 | case HEAP_NUMBER: return "HeapNumbers"; |
| 2035 | case GENERIC: return "Generic"; |
| 2036 | default: return "Invalid"; |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2041 | UnaryOpIC::State UnaryOpIC::ToState(TypeInfo type_info) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2042 | switch (type_info) { |
| 2043 | case UNINITIALIZED: |
| 2044 | return ::v8::internal::UNINITIALIZED; |
| 2045 | case SMI: |
| 2046 | case HEAP_NUMBER: |
| 2047 | return MONOMORPHIC; |
| 2048 | case GENERIC: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2049 | return ::v8::internal::GENERIC; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2050 | } |
| 2051 | UNREACHABLE(); |
| 2052 | return ::v8::internal::UNINITIALIZED; |
| 2053 | } |
| 2054 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2055 | UnaryOpIC::TypeInfo UnaryOpIC::GetTypeInfo(Handle<Object> operand) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2056 | ::v8::internal::TypeInfo operand_type = |
| 2057 | ::v8::internal::TypeInfo::TypeFromValue(operand); |
| 2058 | if (operand_type.IsSmi()) { |
| 2059 | return SMI; |
| 2060 | } else if (operand_type.IsNumber()) { |
| 2061 | return HEAP_NUMBER; |
| 2062 | } else { |
| 2063 | return GENERIC; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2068 | UnaryOpIC::TypeInfo UnaryOpIC::ComputeNewType( |
| 2069 | UnaryOpIC::TypeInfo current_type, |
| 2070 | UnaryOpIC::TypeInfo previous_type) { |
| 2071 | switch (previous_type) { |
| 2072 | case UnaryOpIC::UNINITIALIZED: |
| 2073 | return current_type; |
| 2074 | case UnaryOpIC::SMI: |
| 2075 | return (current_type == UnaryOpIC::GENERIC) |
| 2076 | ? UnaryOpIC::GENERIC |
| 2077 | : UnaryOpIC::HEAP_NUMBER; |
| 2078 | case UnaryOpIC::HEAP_NUMBER: |
| 2079 | return UnaryOpIC::GENERIC; |
| 2080 | case UnaryOpIC::GENERIC: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2081 | // We should never do patching if we are in GENERIC state. |
| 2082 | UNREACHABLE(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2083 | return UnaryOpIC::GENERIC; |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2084 | } |
| 2085 | UNREACHABLE(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2086 | return UnaryOpIC::GENERIC; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2090 | void BinaryOpIC::patch(Code* code) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2091 | set_target(code); |
| 2092 | } |
| 2093 | |
| 2094 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2095 | const char* BinaryOpIC::GetName(TypeInfo type_info) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2096 | switch (type_info) { |
| 2097 | case UNINITIALIZED: return "Uninitialized"; |
| 2098 | case SMI: return "SMI"; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2099 | case INT32: return "Int32"; |
| 2100 | case HEAP_NUMBER: return "HeapNumber"; |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2101 | case ODDBALL: return "Oddball"; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2102 | case STRING: return "String"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2103 | case GENERIC: return "Generic"; |
| 2104 | default: return "Invalid"; |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2109 | BinaryOpIC::State BinaryOpIC::ToState(TypeInfo type_info) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2110 | switch (type_info) { |
| 2111 | case UNINITIALIZED: |
| 2112 | return ::v8::internal::UNINITIALIZED; |
| 2113 | case SMI: |
| 2114 | case INT32: |
| 2115 | case HEAP_NUMBER: |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 2116 | case ODDBALL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2117 | case STRING: |
| 2118 | return MONOMORPHIC; |
| 2119 | case GENERIC: |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 2120 | return ::v8::internal::GENERIC; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2121 | } |
| 2122 | UNREACHABLE(); |
| 2123 | return ::v8::internal::UNINITIALIZED; |
| 2124 | } |
| 2125 | |
| 2126 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2127 | RUNTIME_FUNCTION(MaybeObject*, UnaryOp_Patch) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2128 | ASSERT(args.length() == 4); |
| 2129 | |
| 2130 | HandleScope scope(isolate); |
| 2131 | Handle<Object> operand = args.at<Object>(0); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2132 | Token::Value op = static_cast<Token::Value>(args.smi_at(1)); |
| 2133 | UnaryOverwriteMode mode = static_cast<UnaryOverwriteMode>(args.smi_at(2)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2134 | UnaryOpIC::TypeInfo previous_type = |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2135 | static_cast<UnaryOpIC::TypeInfo>(args.smi_at(3)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2136 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2137 | UnaryOpIC::TypeInfo type = UnaryOpIC::GetTypeInfo(operand); |
| 2138 | type = UnaryOpIC::ComputeNewType(type, previous_type); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2139 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2140 | UnaryOpStub stub(op, mode, type); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2141 | Handle<Code> code = stub.GetCode(); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2142 | if (!code.is_null()) { |
| 2143 | if (FLAG_trace_ic) { |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 2144 | PrintF("[UnaryOpIC in "); |
| 2145 | JavaScriptFrame::PrintTop(stdout, false, true); |
| 2146 | PrintF(" (%s->%s)#%s @ %p]\n", |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2147 | UnaryOpIC::GetName(previous_type), |
| 2148 | UnaryOpIC::GetName(type), |
yangguo@chromium.org | 9768bf1 | 2013-01-11 14:51:07 +0000 | [diff] [blame] | 2149 | Token::Name(op), |
| 2150 | static_cast<void*>(*code)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2151 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2152 | UnaryOpIC ic(isolate); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2153 | ic.patch(*code); |
| 2154 | } |
| 2155 | |
| 2156 | Handle<JSBuiltinsObject> builtins = Handle<JSBuiltinsObject>( |
| 2157 | isolate->thread_local_top()->context_->builtins(), isolate); |
| 2158 | Object* builtin = NULL; // Initialization calms down the compiler. |
| 2159 | switch (op) { |
| 2160 | case Token::SUB: |
| 2161 | builtin = builtins->javascript_builtin(Builtins::UNARY_MINUS); |
| 2162 | break; |
| 2163 | case Token::BIT_NOT: |
| 2164 | builtin = builtins->javascript_builtin(Builtins::BIT_NOT); |
| 2165 | break; |
| 2166 | default: |
| 2167 | UNREACHABLE(); |
| 2168 | } |
| 2169 | |
| 2170 | Handle<JSFunction> builtin_function(JSFunction::cast(builtin), isolate); |
| 2171 | |
| 2172 | bool caught_exception; |
| 2173 | Handle<Object> result = Execution::Call(builtin_function, operand, 0, NULL, |
| 2174 | &caught_exception); |
| 2175 | if (caught_exception) { |
| 2176 | return Failure::Exception(); |
| 2177 | } |
| 2178 | return *result; |
| 2179 | } |
| 2180 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2181 | |
| 2182 | static BinaryOpIC::TypeInfo TypeInfoFromValue(Handle<Object> value, |
| 2183 | Token::Value op) { |
| 2184 | ::v8::internal::TypeInfo type = |
| 2185 | ::v8::internal::TypeInfo::TypeFromValue(value); |
| 2186 | if (type.IsSmi()) return BinaryOpIC::SMI; |
| 2187 | if (type.IsInteger32()) { |
| 2188 | if (kSmiValueSize == 32) return BinaryOpIC::SMI; |
| 2189 | return BinaryOpIC::INT32; |
| 2190 | } |
| 2191 | if (type.IsNumber()) return BinaryOpIC::HEAP_NUMBER; |
| 2192 | if (type.IsString()) return BinaryOpIC::STRING; |
| 2193 | if (value->IsUndefined()) { |
| 2194 | if (op == Token::BIT_AND || |
| 2195 | op == Token::BIT_OR || |
| 2196 | op == Token::BIT_XOR || |
| 2197 | op == Token::SAR || |
| 2198 | op == Token::SHL || |
| 2199 | op == Token::SHR) { |
| 2200 | if (kSmiValueSize == 32) return BinaryOpIC::SMI; |
| 2201 | return BinaryOpIC::INT32; |
| 2202 | } |
| 2203 | return BinaryOpIC::ODDBALL; |
| 2204 | } |
| 2205 | return BinaryOpIC::GENERIC; |
| 2206 | } |
| 2207 | |
| 2208 | |
| 2209 | static BinaryOpIC::TypeInfo InputState(BinaryOpIC::TypeInfo old_type, |
| 2210 | Handle<Object> value, |
| 2211 | Token::Value op) { |
| 2212 | BinaryOpIC::TypeInfo new_type = TypeInfoFromValue(value, op); |
| 2213 | if (old_type == BinaryOpIC::STRING) { |
| 2214 | if (new_type == BinaryOpIC::STRING) return new_type; |
| 2215 | return BinaryOpIC::GENERIC; |
| 2216 | } |
| 2217 | return Max(old_type, new_type); |
| 2218 | } |
| 2219 | |
| 2220 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2221 | RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2222 | ASSERT(args.length() == 3); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2223 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2224 | HandleScope scope(isolate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2225 | Handle<Object> left = args.at<Object>(0); |
| 2226 | Handle<Object> right = args.at<Object>(1); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2227 | int key = args.smi_at(2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2228 | Token::Value op = BinaryOpStub::decode_op_from_minor_key(key); |
| 2229 | BinaryOpIC::TypeInfo previous_left, previous_right, unused_previous_result; |
| 2230 | BinaryOpStub::decode_types_from_minor_key( |
| 2231 | key, &previous_left, &previous_right, &unused_previous_result); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2232 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2233 | BinaryOpIC::TypeInfo new_left = InputState(previous_left, left, op); |
| 2234 | BinaryOpIC::TypeInfo new_right = InputState(previous_right, right, op); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2235 | BinaryOpIC::TypeInfo result_type = BinaryOpIC::UNINITIALIZED; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2236 | |
| 2237 | // STRING is only used for ADD operations. |
| 2238 | if ((new_left == BinaryOpIC::STRING || new_right == BinaryOpIC::STRING) && |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2239 | op != Token::ADD) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2240 | new_left = new_right = BinaryOpIC::GENERIC; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2241 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2242 | |
| 2243 | BinaryOpIC::TypeInfo new_overall = Max(new_left, new_right); |
| 2244 | BinaryOpIC::TypeInfo previous_overall = Max(previous_left, previous_right); |
| 2245 | |
| 2246 | if (new_overall == BinaryOpIC::SMI && previous_overall == BinaryOpIC::SMI) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2247 | if (op == Token::DIV || |
| 2248 | op == Token::MUL || |
| 2249 | op == Token::SHR || |
| 2250 | kSmiValueSize == 32) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2251 | // Arithmetic on two Smi inputs has yielded a heap number. |
| 2252 | // That is the only way to get here from the Smi stub. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2253 | // With 32-bit Smis, all overflows give heap numbers, but with |
| 2254 | // 31-bit Smis, most operations overflow to int32 results. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2255 | result_type = BinaryOpIC::HEAP_NUMBER; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2256 | } else { |
| 2257 | // Other operations on SMIs that overflow yield int32s. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2258 | result_type = BinaryOpIC::INT32; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2259 | } |
| 2260 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2261 | if (new_overall == BinaryOpIC::INT32 && |
| 2262 | previous_overall == BinaryOpIC::INT32) { |
| 2263 | if (new_left == previous_left && new_right == previous_right) { |
| 2264 | result_type = BinaryOpIC::HEAP_NUMBER; |
| 2265 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2268 | BinaryOpStub stub(key, new_left, new_right, result_type); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2269 | Handle<Code> code = stub.GetCode(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2270 | if (!code.is_null()) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2271 | #ifdef DEBUG |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2272 | if (FLAG_trace_ic) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2273 | PrintF("[BinaryOpIC in "); |
| 2274 | JavaScriptFrame::PrintTop(stdout, false, true); |
| 2275 | PrintF(" ((%s+%s)->((%s+%s)->%s))#%s @ %p]\n", |
| 2276 | BinaryOpIC::GetName(previous_left), |
| 2277 | BinaryOpIC::GetName(previous_right), |
| 2278 | BinaryOpIC::GetName(new_left), |
| 2279 | BinaryOpIC::GetName(new_right), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2280 | BinaryOpIC::GetName(result_type), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2281 | Token::Name(op), |
| 2282 | static_cast<void*>(*code)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2283 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2284 | #endif |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2285 | BinaryOpIC ic(isolate); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2286 | ic.patch(*code); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2287 | |
| 2288 | // Activate inlined smi code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2289 | if (previous_overall == BinaryOpIC::UNINITIALIZED) { |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2290 | PatchInlinedSmiCode(ic.address(), ENABLE_INLINED_SMI_CHECK); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2291 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2294 | Handle<JSBuiltinsObject> builtins = Handle<JSBuiltinsObject>( |
| 2295 | isolate->thread_local_top()->context_->builtins(), isolate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2296 | Object* builtin = NULL; // Initialization calms down the compiler. |
| 2297 | switch (op) { |
| 2298 | case Token::ADD: |
| 2299 | builtin = builtins->javascript_builtin(Builtins::ADD); |
| 2300 | break; |
| 2301 | case Token::SUB: |
| 2302 | builtin = builtins->javascript_builtin(Builtins::SUB); |
| 2303 | break; |
| 2304 | case Token::MUL: |
| 2305 | builtin = builtins->javascript_builtin(Builtins::MUL); |
| 2306 | break; |
| 2307 | case Token::DIV: |
| 2308 | builtin = builtins->javascript_builtin(Builtins::DIV); |
| 2309 | break; |
| 2310 | case Token::MOD: |
| 2311 | builtin = builtins->javascript_builtin(Builtins::MOD); |
| 2312 | break; |
| 2313 | case Token::BIT_AND: |
| 2314 | builtin = builtins->javascript_builtin(Builtins::BIT_AND); |
| 2315 | break; |
| 2316 | case Token::BIT_OR: |
| 2317 | builtin = builtins->javascript_builtin(Builtins::BIT_OR); |
| 2318 | break; |
| 2319 | case Token::BIT_XOR: |
| 2320 | builtin = builtins->javascript_builtin(Builtins::BIT_XOR); |
| 2321 | break; |
| 2322 | case Token::SHR: |
| 2323 | builtin = builtins->javascript_builtin(Builtins::SHR); |
| 2324 | break; |
| 2325 | case Token::SAR: |
| 2326 | builtin = builtins->javascript_builtin(Builtins::SAR); |
| 2327 | break; |
| 2328 | case Token::SHL: |
| 2329 | builtin = builtins->javascript_builtin(Builtins::SHL); |
| 2330 | break; |
| 2331 | default: |
| 2332 | UNREACHABLE(); |
| 2333 | } |
| 2334 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2335 | Handle<JSFunction> builtin_function(JSFunction::cast(builtin), isolate); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2336 | |
| 2337 | bool caught_exception; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 2338 | Handle<Object> builtin_args[] = { right }; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2339 | Handle<Object> result = Execution::Call(builtin_function, |
| 2340 | left, |
| 2341 | ARRAY_SIZE(builtin_args), |
| 2342 | builtin_args, |
| 2343 | &caught_exception); |
| 2344 | if (caught_exception) { |
| 2345 | return Failure::Exception(); |
| 2346 | } |
| 2347 | return *result; |
| 2348 | } |
| 2349 | |
| 2350 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2351 | Code* CompareIC::GetRawUninitialized(Token::Value op) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2352 | ICCompareStub stub(op, UNINITIALIZED, UNINITIALIZED, UNINITIALIZED); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2353 | Code* code = NULL; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2354 | CHECK(stub.FindCodeInCache(&code, Isolate::Current())); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 2355 | return code; |
| 2356 | } |
| 2357 | |
| 2358 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2359 | Handle<Code> CompareIC::GetUninitialized(Token::Value op) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2360 | ICCompareStub stub(op, UNINITIALIZED, UNINITIALIZED, UNINITIALIZED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2361 | return stub.GetCode(); |
| 2362 | } |
| 2363 | |
| 2364 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2365 | const char* CompareIC::GetStateName(State state) { |
| 2366 | switch (state) { |
| 2367 | case UNINITIALIZED: return "UNINITIALIZED"; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2368 | case SMI: return "SMI"; |
| 2369 | case HEAP_NUMBER: return "HEAP_NUMBER"; |
| 2370 | case OBJECT: return "OBJECTS"; |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 2371 | case KNOWN_OBJECTS: return "KNOWN_OBJECTS"; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2372 | case SYMBOL: return "SYMBOL"; |
| 2373 | case STRING: return "STRING"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2374 | case GENERIC: return "GENERIC"; |
| 2375 | default: |
| 2376 | UNREACHABLE(); |
| 2377 | return NULL; |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2382 | static CompareIC::State InputState(CompareIC::State old_state, |
| 2383 | Handle<Object> value) { |
| 2384 | switch (old_state) { |
| 2385 | case CompareIC::UNINITIALIZED: |
| 2386 | if (value->IsSmi()) return CompareIC::SMI; |
| 2387 | if (value->IsHeapNumber()) return CompareIC::HEAP_NUMBER; |
| 2388 | if (value->IsSymbol()) return CompareIC::SYMBOL; |
| 2389 | if (value->IsString()) return CompareIC::STRING; |
| 2390 | if (value->IsJSObject()) return CompareIC::OBJECT; |
| 2391 | break; |
| 2392 | case CompareIC::SMI: |
| 2393 | if (value->IsSmi()) return CompareIC::SMI; |
| 2394 | if (value->IsHeapNumber()) return CompareIC::HEAP_NUMBER; |
| 2395 | break; |
| 2396 | case CompareIC::HEAP_NUMBER: |
| 2397 | if (value->IsNumber()) return CompareIC::HEAP_NUMBER; |
| 2398 | break; |
| 2399 | case CompareIC::SYMBOL: |
| 2400 | if (value->IsSymbol()) return CompareIC::SYMBOL; |
| 2401 | if (value->IsString()) return CompareIC::STRING; |
| 2402 | break; |
| 2403 | case CompareIC::STRING: |
| 2404 | if (value->IsSymbol() || value->IsString()) return CompareIC::STRING; |
| 2405 | break; |
| 2406 | case CompareIC::OBJECT: |
| 2407 | if (value->IsJSObject()) return CompareIC::OBJECT; |
| 2408 | break; |
| 2409 | case CompareIC::GENERIC: |
| 2410 | break; |
| 2411 | case CompareIC::KNOWN_OBJECTS: |
| 2412 | UNREACHABLE(); |
| 2413 | break; |
| 2414 | } |
| 2415 | return CompareIC::GENERIC; |
| 2416 | } |
| 2417 | |
| 2418 | |
| 2419 | CompareIC::State CompareIC::TargetState(State old_state, |
| 2420 | State old_left, |
| 2421 | State old_right, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2422 | bool has_inlined_smi_code, |
| 2423 | Handle<Object> x, |
| 2424 | Handle<Object> y) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2425 | switch (old_state) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2426 | case UNINITIALIZED: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2427 | if (x->IsSmi() && y->IsSmi()) return SMI; |
| 2428 | if (x->IsNumber() && y->IsNumber()) return HEAP_NUMBER; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2429 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 2430 | // Ordered comparisons treat undefined as NaN, so the |
| 2431 | // HEAP_NUMBER stub will do the right thing. |
| 2432 | if ((x->IsNumber() && y->IsUndefined()) || |
| 2433 | (y->IsNumber() && x->IsUndefined())) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2434 | return HEAP_NUMBER; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2435 | } |
| 2436 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2437 | if (x->IsSymbol() && y->IsSymbol()) { |
| 2438 | // We compare symbols as strings if we need to determine |
| 2439 | // the order in a non-equality compare. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2440 | return Token::IsEqualityOp(op_) ? SYMBOL : STRING; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2441 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2442 | if (x->IsString() && y->IsString()) return STRING; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 2443 | if (!Token::IsEqualityOp(op_)) return GENERIC; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2444 | if (x->IsJSObject() && y->IsJSObject()) { |
| 2445 | if (Handle<JSObject>::cast(x)->map() == |
| 2446 | Handle<JSObject>::cast(y)->map() && |
| 2447 | Token::IsEqualityOp(op_)) { |
| 2448 | return KNOWN_OBJECTS; |
| 2449 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2450 | return OBJECT; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | return GENERIC; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2454 | case SMI: |
| 2455 | return x->IsNumber() && y->IsNumber() |
| 2456 | ? HEAP_NUMBER |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2457 | : GENERIC; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2458 | case SYMBOL: |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2459 | ASSERT(Token::IsEqualityOp(op_)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2460 | return x->IsString() && y->IsString() ? STRING : GENERIC; |
| 2461 | case HEAP_NUMBER: |
| 2462 | if (old_left == SMI && x->IsHeapNumber()) return HEAP_NUMBER; |
| 2463 | if (old_right == SMI && y->IsHeapNumber()) return HEAP_NUMBER; |
| 2464 | case STRING: |
| 2465 | case OBJECT: |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2466 | case KNOWN_OBJECTS: |
| 2467 | case GENERIC: |
| 2468 | return GENERIC; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2469 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2470 | UNREACHABLE(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2471 | return GENERIC; // Make the compiler happy. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2475 | void CompareIC::UpdateCaches(Handle<Object> x, Handle<Object> y) { |
| 2476 | HandleScope scope; |
| 2477 | State previous_left, previous_right, previous_state; |
| 2478 | ICCompareStub::DecodeMinorKey(target()->stub_info(), &previous_left, |
| 2479 | &previous_right, &previous_state, NULL); |
| 2480 | State new_left = InputState(previous_left, x); |
| 2481 | State new_right = InputState(previous_right, y); |
| 2482 | State state = TargetState(previous_state, previous_left, previous_right, |
| 2483 | HasInlinedSmiCode(address()), x, y); |
| 2484 | ICCompareStub stub(op_, new_left, new_right, state); |
| 2485 | if (state == KNOWN_OBJECTS) { |
| 2486 | stub.set_known_map(Handle<Map>(Handle<JSObject>::cast(x)->map())); |
| 2487 | } |
| 2488 | set_target(*stub.GetCode()); |
| 2489 | |
| 2490 | #ifdef DEBUG |
| 2491 | if (FLAG_trace_ic) { |
| 2492 | PrintF("[CompareIC in "); |
| 2493 | JavaScriptFrame::PrintTop(stdout, false, true); |
| 2494 | PrintF(" ((%s+%s=%s)->(%s+%s=%s))#%s @ %p]\n", |
| 2495 | GetStateName(previous_left), |
| 2496 | GetStateName(previous_right), |
| 2497 | GetStateName(previous_state), |
| 2498 | GetStateName(new_left), |
| 2499 | GetStateName(new_right), |
| 2500 | GetStateName(state), |
| 2501 | Token::Name(op_), |
| 2502 | static_cast<void*>(*stub.GetCode())); |
| 2503 | } |
| 2504 | #endif |
| 2505 | |
| 2506 | // Activate inlined smi code. |
| 2507 | if (previous_state == UNINITIALIZED) { |
| 2508 | PatchInlinedSmiCode(address(), ENABLE_INLINED_SMI_CHECK); |
| 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | |
| 2513 | // Used from ICCompareStub::GenerateMiss in code-stubs-<arch>.cc. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2514 | RUNTIME_FUNCTION(Code*, CompareIC_Miss) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2515 | NoHandleAllocation na; |
| 2516 | ASSERT(args.length() == 3); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2517 | CompareIC ic(isolate, static_cast<Token::Value>(args.smi_at(2))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2518 | ic.UpdateCaches(args.at<Object>(0), args.at<Object>(1)); |
| 2519 | return ic.target(); |
| 2520 | } |
| 2521 | |
| 2522 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 2523 | RUNTIME_FUNCTION(MaybeObject*, ToBoolean_Patch) { |
| 2524 | ASSERT(args.length() == 3); |
| 2525 | |
| 2526 | HandleScope scope(isolate); |
| 2527 | Handle<Object> object = args.at<Object>(0); |
| 2528 | Register tos = Register::from_code(args.smi_at(1)); |
| 2529 | ToBooleanStub::Types old_types(args.smi_at(2)); |
| 2530 | |
| 2531 | ToBooleanStub::Types new_types(old_types); |
| 2532 | bool to_boolean_value = new_types.Record(object); |
| 2533 | old_types.TraceTransition(new_types); |
| 2534 | |
| 2535 | ToBooleanStub stub(tos, new_types); |
| 2536 | Handle<Code> code = stub.GetCode(); |
| 2537 | ToBooleanIC ic(isolate); |
| 2538 | ic.patch(*code); |
| 2539 | return Smi::FromInt(to_boolean_value ? 1 : 0); |
| 2540 | } |
| 2541 | |
| 2542 | |
| 2543 | void ToBooleanIC::patch(Code* code) { |
| 2544 | set_target(code); |
| 2545 | } |
| 2546 | |
| 2547 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2548 | static const Address IC_utilities[] = { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2549 | #define ADDR(name) FUNCTION_ADDR(name), |
| 2550 | IC_UTIL_LIST(ADDR) |
| 2551 | NULL |
| 2552 | #undef ADDR |
| 2553 | }; |
| 2554 | |
| 2555 | |
| 2556 | Address IC::AddressFromUtilityId(IC::UtilityId id) { |
| 2557 | return IC_utilities[id]; |
| 2558 | } |
| 2559 | |
| 2560 | |
| 2561 | } } // namespace v8::internal |