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