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