Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 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 "api.h" |
| 31 | #include "arguments.h" |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 32 | #include "gdb-jit.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | #include "ic-inl.h" |
| 34 | #include "stub-cache.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 35 | #include "vm-state-inl.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 36 | |
| 37 | namespace v8 { |
| 38 | namespace internal { |
| 39 | |
| 40 | // ----------------------------------------------------------------------- |
| 41 | // StubCache implementation. |
| 42 | |
| 43 | |
| 44 | StubCache::Entry StubCache::primary_[StubCache::kPrimaryTableSize]; |
| 45 | StubCache::Entry StubCache::secondary_[StubCache::kSecondaryTableSize]; |
| 46 | |
| 47 | void StubCache::Initialize(bool create_heap_objects) { |
| 48 | ASSERT(IsPowerOf2(kPrimaryTableSize)); |
| 49 | ASSERT(IsPowerOf2(kSecondaryTableSize)); |
| 50 | if (create_heap_objects) { |
| 51 | HandleScope scope; |
| 52 | Clear(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | |
| 57 | Code* StubCache::Set(String* name, Map* map, Code* code) { |
| 58 | // Get the flags from the code. |
| 59 | Code::Flags flags = Code::RemoveTypeFromFlags(code->flags()); |
| 60 | |
| 61 | // Validate that the name does not move on scavenge, and that we |
| 62 | // can use identity checks instead of string equality checks. |
| 63 | ASSERT(!Heap::InNewSpace(name)); |
| 64 | ASSERT(name->IsSymbol()); |
| 65 | |
| 66 | // The state bits are not important to the hash function because |
| 67 | // the stub cache only contains monomorphic stubs. Make sure that |
| 68 | // the bits are the least significant so they will be the ones |
| 69 | // masked out. |
| 70 | ASSERT(Code::ExtractICStateFromFlags(flags) == MONOMORPHIC); |
| 71 | ASSERT(Code::kFlagsICStateShift == 0); |
| 72 | |
| 73 | // Make sure that the code type is not included in the hash. |
| 74 | ASSERT(Code::ExtractTypeFromFlags(flags) == 0); |
| 75 | |
| 76 | // Compute the primary entry. |
| 77 | int primary_offset = PrimaryOffset(name, flags, map); |
| 78 | Entry* primary = entry(primary_, primary_offset); |
| 79 | Code* hit = primary->value; |
| 80 | |
| 81 | // If the primary entry has useful data in it, we retire it to the |
| 82 | // secondary cache before overwriting it. |
| 83 | if (hit != Builtins::builtin(Builtins::Illegal)) { |
| 84 | Code::Flags primary_flags = Code::RemoveTypeFromFlags(hit->flags()); |
| 85 | int secondary_offset = |
| 86 | SecondaryOffset(primary->key, primary_flags, primary_offset); |
| 87 | Entry* secondary = entry(secondary_, secondary_offset); |
| 88 | *secondary = *primary; |
| 89 | } |
| 90 | |
| 91 | // Update primary cache. |
| 92 | primary->key = name; |
| 93 | primary->value = code; |
| 94 | return code; |
| 95 | } |
| 96 | |
| 97 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 98 | MaybeObject* StubCache::ComputeLoadNonexistent(String* name, |
| 99 | JSObject* receiver) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 100 | ASSERT(receiver->IsGlobalObject() || receiver->HasFastProperties()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 101 | // If no global objects are present in the prototype chain, the load |
| 102 | // nonexistent IC stub can be shared for all names for a given map |
| 103 | // and we use the empty string for the map cache in that case. If |
| 104 | // there are global objects involved, we need to check global |
| 105 | // property cells in the stub and therefore the stub will be |
| 106 | // specific to the name. |
| 107 | String* cache_name = Heap::empty_string(); |
| 108 | if (receiver->IsGlobalObject()) cache_name = name; |
| 109 | JSObject* last = receiver; |
| 110 | while (last->GetPrototype() != Heap::null_value()) { |
| 111 | last = JSObject::cast(last->GetPrototype()); |
| 112 | if (last->IsGlobalObject()) cache_name = name; |
| 113 | } |
| 114 | // Compile the stub that is either shared for all names or |
| 115 | // name specific if there are global objects involved. |
| 116 | Code::Flags flags = |
| 117 | Code::ComputeMonomorphicFlags(Code::LOAD_IC, NONEXISTENT); |
| 118 | Object* code = receiver->map()->FindInCodeCache(cache_name, flags); |
| 119 | if (code->IsUndefined()) { |
| 120 | LoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 121 | { MaybeObject* maybe_code = |
| 122 | compiler.CompileLoadNonexistent(cache_name, receiver, last); |
| 123 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 124 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 125 | PROFILE(CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), cache_name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 126 | GDBJIT(AddCode(GDBJITInterface::LOAD_IC, cache_name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 127 | Object* result; |
| 128 | { MaybeObject* maybe_result = |
| 129 | receiver->UpdateMapCodeCache(cache_name, Code::cast(code)); |
| 130 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 131 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 132 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 133 | return code; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 137 | MaybeObject* StubCache::ComputeLoadField(String* name, |
| 138 | JSObject* receiver, |
| 139 | JSObject* holder, |
| 140 | int field_index) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 141 | ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 142 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, FIELD); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 143 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 144 | if (code->IsUndefined()) { |
| 145 | LoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 146 | { MaybeObject* maybe_code = |
| 147 | compiler.CompileLoadField(receiver, holder, field_index, name); |
| 148 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 149 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 150 | PROFILE(CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 151 | GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 152 | Object* result; |
| 153 | { MaybeObject* maybe_result = |
| 154 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 155 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 156 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 157 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 158 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 162 | MaybeObject* StubCache::ComputeLoadCallback(String* name, |
| 163 | JSObject* receiver, |
| 164 | JSObject* holder, |
| 165 | AccessorInfo* callback) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 166 | ASSERT(v8::ToCData<Address>(callback->getter()) != 0); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 167 | ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 168 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, CALLBACKS); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 169 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 170 | if (code->IsUndefined()) { |
| 171 | LoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 172 | { MaybeObject* maybe_code = |
| 173 | compiler.CompileLoadCallback(name, receiver, holder, callback); |
| 174 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 175 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 176 | PROFILE(CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 177 | GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 178 | Object* result; |
| 179 | { MaybeObject* maybe_result = |
| 180 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 181 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 182 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 183 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 184 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 188 | MaybeObject* StubCache::ComputeLoadConstant(String* name, |
| 189 | JSObject* receiver, |
| 190 | JSObject* holder, |
| 191 | Object* value) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 192 | ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 193 | Code::Flags flags = |
| 194 | Code::ComputeMonomorphicFlags(Code::LOAD_IC, CONSTANT_FUNCTION); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 195 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 196 | if (code->IsUndefined()) { |
| 197 | LoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 198 | { MaybeObject* maybe_code = |
| 199 | compiler.CompileLoadConstant(receiver, holder, value, name); |
| 200 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 201 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 202 | PROFILE(CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 203 | GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 204 | Object* result; |
| 205 | { MaybeObject* maybe_result = |
| 206 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 207 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 208 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 209 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 210 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 214 | MaybeObject* StubCache::ComputeLoadInterceptor(String* name, |
| 215 | JSObject* receiver, |
| 216 | JSObject* holder) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 217 | ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 218 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, INTERCEPTOR); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 219 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 220 | if (code->IsUndefined()) { |
| 221 | LoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 222 | { MaybeObject* maybe_code = |
| 223 | compiler.CompileLoadInterceptor(receiver, holder, name); |
| 224 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 225 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 226 | PROFILE(CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 227 | GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 228 | Object* result; |
| 229 | { MaybeObject* maybe_result = |
| 230 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 231 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 232 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 233 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 234 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 238 | MaybeObject* StubCache::ComputeLoadNormal() { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 239 | return Builtins::builtin(Builtins::LoadIC_Normal); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 243 | MaybeObject* StubCache::ComputeLoadGlobal(String* name, |
| 244 | JSObject* receiver, |
| 245 | GlobalObject* holder, |
| 246 | JSGlobalPropertyCell* cell, |
| 247 | bool is_dont_delete) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 248 | ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 249 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, NORMAL); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 250 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 251 | if (code->IsUndefined()) { |
| 252 | LoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 253 | { MaybeObject* maybe_code = compiler.CompileLoadGlobal(receiver, |
| 254 | holder, |
| 255 | cell, |
| 256 | name, |
| 257 | is_dont_delete); |
| 258 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 259 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 260 | PROFILE(CodeCreateEvent(Logger::LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 261 | GDBJIT(AddCode(GDBJITInterface::LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 262 | Object* result; |
| 263 | { MaybeObject* maybe_result = |
| 264 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 265 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 266 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 267 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 268 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 272 | MaybeObject* StubCache::ComputeKeyedLoadField(String* name, |
| 273 | JSObject* receiver, |
| 274 | JSObject* holder, |
| 275 | int field_index) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 276 | ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 277 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, FIELD); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 278 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 279 | if (code->IsUndefined()) { |
| 280 | KeyedLoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 281 | { MaybeObject* maybe_code = |
| 282 | compiler.CompileLoadField(name, receiver, holder, field_index); |
| 283 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 284 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 285 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 286 | GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 287 | Object* result; |
| 288 | { MaybeObject* maybe_result = |
| 289 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 290 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 291 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 292 | } |
| 293 | return code; |
| 294 | } |
| 295 | |
| 296 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 297 | MaybeObject* StubCache::ComputeKeyedLoadConstant(String* name, |
| 298 | JSObject* receiver, |
| 299 | JSObject* holder, |
| 300 | Object* value) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 301 | ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 302 | Code::Flags flags = |
| 303 | Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CONSTANT_FUNCTION); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 304 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 305 | if (code->IsUndefined()) { |
| 306 | KeyedLoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 307 | { MaybeObject* maybe_code = |
| 308 | compiler.CompileLoadConstant(name, receiver, holder, value); |
| 309 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 310 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 311 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 312 | GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 313 | Object* result; |
| 314 | { MaybeObject* maybe_result = |
| 315 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 316 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 317 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 318 | } |
| 319 | return code; |
| 320 | } |
| 321 | |
| 322 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 323 | MaybeObject* StubCache::ComputeKeyedLoadInterceptor(String* name, |
| 324 | JSObject* receiver, |
| 325 | JSObject* holder) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 326 | ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | Code::Flags flags = |
| 328 | Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, INTERCEPTOR); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 329 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 330 | if (code->IsUndefined()) { |
| 331 | KeyedLoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 332 | { MaybeObject* maybe_code = |
| 333 | compiler.CompileLoadInterceptor(receiver, holder, name); |
| 334 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 335 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 336 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 337 | GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 338 | Object* result; |
| 339 | { MaybeObject* maybe_result = |
| 340 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 341 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 342 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 343 | } |
| 344 | return code; |
| 345 | } |
| 346 | |
| 347 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 348 | MaybeObject* StubCache::ComputeKeyedLoadCallback(String* name, |
| 349 | JSObject* receiver, |
| 350 | JSObject* holder, |
| 351 | AccessorInfo* callback) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 352 | ASSERT(IC::GetCodeCacheForObject(receiver, holder) == OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 353 | Code::Flags flags = |
| 354 | Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 355 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 356 | if (code->IsUndefined()) { |
| 357 | KeyedLoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 358 | { MaybeObject* maybe_code = |
| 359 | compiler.CompileLoadCallback(name, receiver, holder, callback); |
| 360 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 361 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 362 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 363 | GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 364 | Object* result; |
| 365 | { MaybeObject* maybe_result = |
| 366 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 367 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 368 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 369 | } |
| 370 | return code; |
| 371 | } |
| 372 | |
| 373 | |
| 374 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 375 | MaybeObject* StubCache::ComputeKeyedLoadArrayLength(String* name, |
| 376 | JSArray* receiver) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 377 | Code::Flags flags = |
| 378 | Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 379 | ASSERT(receiver->IsJSObject()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 380 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 381 | if (code->IsUndefined()) { |
| 382 | KeyedLoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 383 | { MaybeObject* maybe_code = compiler.CompileLoadArrayLength(name); |
| 384 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 385 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 386 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 387 | GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 388 | Object* result; |
| 389 | { MaybeObject* maybe_result = |
| 390 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 391 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 392 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 393 | } |
| 394 | return code; |
| 395 | } |
| 396 | |
| 397 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 398 | MaybeObject* StubCache::ComputeKeyedLoadStringLength(String* name, |
| 399 | String* receiver) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 400 | Code::Flags flags = |
| 401 | Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 402 | Map* map = receiver->map(); |
| 403 | Object* code = map->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 404 | if (code->IsUndefined()) { |
| 405 | KeyedLoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 406 | { MaybeObject* maybe_code = compiler.CompileLoadStringLength(name); |
| 407 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 408 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 409 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 410 | GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 411 | Object* result; |
| 412 | { MaybeObject* maybe_result = map->UpdateCodeCache(name, Code::cast(code)); |
| 413 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 414 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 415 | } |
| 416 | return code; |
| 417 | } |
| 418 | |
| 419 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 420 | MaybeObject* StubCache::ComputeKeyedLoadFunctionPrototype( |
| 421 | String* name, |
| 422 | JSFunction* receiver) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 423 | Code::Flags flags = |
| 424 | Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, CALLBACKS); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 425 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 426 | if (code->IsUndefined()) { |
| 427 | KeyedLoadStubCompiler compiler; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 428 | { MaybeObject* maybe_code = compiler.CompileLoadFunctionPrototype(name); |
| 429 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 430 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 431 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 432 | GDBJIT(AddCode(GDBJITInterface::KEYED_LOAD_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 433 | Object* result; |
| 434 | { MaybeObject* maybe_result = |
| 435 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 436 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 437 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 438 | } |
| 439 | return code; |
| 440 | } |
| 441 | |
| 442 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 443 | MaybeObject* StubCache::ComputeKeyedLoadSpecialized(JSObject* receiver) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 444 | // Using NORMAL as the PropertyType for array element loads is a misuse. The |
| 445 | // generated stub always accesses fast elements, not slow-mode fields, but |
| 446 | // some property type is required for the stub lookup. Note that overloading |
| 447 | // the NORMAL PropertyType is only safe as long as no stubs are generated for |
| 448 | // other keyed field loads. This is guaranteed to be the case since all field |
| 449 | // keyed loads that are not array elements go through a generic builtin stub. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 450 | Code::Flags flags = |
| 451 | Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, NORMAL); |
| 452 | String* name = Heap::KeyedLoadSpecialized_symbol(); |
| 453 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 454 | if (code->IsUndefined()) { |
| 455 | KeyedLoadStubCompiler compiler; |
| 456 | { MaybeObject* maybe_code = compiler.CompileLoadSpecialized(receiver); |
| 457 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 458 | } |
| 459 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), 0)); |
| 460 | Object* result; |
| 461 | { MaybeObject* maybe_result = |
| 462 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 463 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 464 | } |
| 465 | } |
| 466 | return code; |
| 467 | } |
| 468 | |
| 469 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 470 | MaybeObject* StubCache::ComputeKeyedLoadPixelArray(JSObject* receiver) { |
| 471 | // Using NORMAL as the PropertyType for array element loads is a misuse. The |
| 472 | // generated stub always accesses fast elements, not slow-mode fields, but |
| 473 | // some property type is required for the stub lookup. Note that overloading |
| 474 | // the NORMAL PropertyType is only safe as long as no stubs are generated for |
| 475 | // other keyed field loads. This is guaranteed to be the case since all field |
| 476 | // keyed loads that are not array elements go through a generic builtin stub. |
| 477 | Code::Flags flags = |
| 478 | Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, NORMAL); |
| 479 | String* name = Heap::KeyedLoadPixelArray_symbol(); |
| 480 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 481 | if (code->IsUndefined()) { |
| 482 | KeyedLoadStubCompiler compiler; |
| 483 | { MaybeObject* maybe_code = compiler.CompileLoadPixelArray(receiver); |
| 484 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 485 | } |
| 486 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), 0)); |
| 487 | Object* result; |
| 488 | { MaybeObject* maybe_result = |
| 489 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 490 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 491 | } |
| 492 | } |
| 493 | return code; |
| 494 | } |
| 495 | |
| 496 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 497 | MaybeObject* StubCache::ComputeStoreField(String* name, |
| 498 | JSObject* receiver, |
| 499 | int field_index, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 500 | Map* transition, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 501 | StrictModeFlag strict_mode) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 502 | PropertyType type = (transition == NULL) ? FIELD : MAP_TRANSITION; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 503 | Code::Flags flags = Code::ComputeMonomorphicFlags( |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 504 | Code::STORE_IC, type, strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 505 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 506 | if (code->IsUndefined()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 507 | StoreStubCompiler compiler(strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 508 | { MaybeObject* maybe_code = |
| 509 | compiler.CompileStoreField(receiver, field_index, transition, name); |
| 510 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 511 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 512 | PROFILE(CodeCreateEvent(Logger::STORE_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 513 | GDBJIT(AddCode(GDBJITInterface::STORE_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 514 | Object* result; |
| 515 | { MaybeObject* maybe_result = |
| 516 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 517 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 518 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 519 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 520 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 524 | MaybeObject* StubCache::ComputeKeyedStoreSpecialized( |
| 525 | JSObject* receiver, |
| 526 | StrictModeFlag strict_mode) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 527 | Code::Flags flags = |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 528 | Code::ComputeMonomorphicFlags(Code::KEYED_STORE_IC, NORMAL, strict_mode); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 529 | String* name = Heap::KeyedStoreSpecialized_symbol(); |
| 530 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 531 | if (code->IsUndefined()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 532 | KeyedStoreStubCompiler compiler(strict_mode); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 533 | { MaybeObject* maybe_code = compiler.CompileStoreSpecialized(receiver); |
| 534 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 535 | } |
| 536 | PROFILE(CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, Code::cast(code), 0)); |
| 537 | Object* result; |
| 538 | { MaybeObject* maybe_result = |
| 539 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 540 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 541 | } |
| 542 | } |
| 543 | return code; |
| 544 | } |
| 545 | |
| 546 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 547 | MaybeObject* StubCache::ComputeKeyedStorePixelArray( |
| 548 | JSObject* receiver, |
| 549 | StrictModeFlag strict_mode) { |
| 550 | // Using NORMAL as the PropertyType for array element stores is a misuse. The |
| 551 | // generated stub always accesses fast elements, not slow-mode fields, but |
| 552 | // some property type is required for the stub lookup. Note that overloading |
| 553 | // the NORMAL PropertyType is only safe as long as no stubs are generated for |
| 554 | // other keyed field stores. This is guaranteed to be the case since all field |
| 555 | // keyed stores that are not array elements go through a generic builtin stub. |
| 556 | Code::Flags flags = |
| 557 | Code::ComputeMonomorphicFlags(Code::KEYED_STORE_IC, NORMAL, strict_mode); |
| 558 | String* name = Heap::KeyedStorePixelArray_symbol(); |
| 559 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 560 | if (code->IsUndefined()) { |
| 561 | KeyedStoreStubCompiler compiler(strict_mode); |
| 562 | { MaybeObject* maybe_code = compiler.CompileStorePixelArray(receiver); |
| 563 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 564 | } |
| 565 | PROFILE(CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, Code::cast(code), 0)); |
| 566 | Object* result; |
| 567 | { MaybeObject* maybe_result = |
| 568 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 569 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 570 | } |
| 571 | } |
| 572 | return code; |
| 573 | } |
| 574 | |
| 575 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 576 | namespace { |
| 577 | |
| 578 | ExternalArrayType ElementsKindToExternalArrayType(JSObject::ElementsKind kind) { |
| 579 | switch (kind) { |
| 580 | case JSObject::EXTERNAL_BYTE_ELEMENTS: |
| 581 | return kExternalByteArray; |
| 582 | case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 583 | return kExternalUnsignedByteArray; |
| 584 | case JSObject::EXTERNAL_SHORT_ELEMENTS: |
| 585 | return kExternalShortArray; |
| 586 | case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 587 | return kExternalUnsignedShortArray; |
| 588 | case JSObject::EXTERNAL_INT_ELEMENTS: |
| 589 | return kExternalIntArray; |
| 590 | case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 591 | return kExternalUnsignedIntArray; |
| 592 | case JSObject::EXTERNAL_FLOAT_ELEMENTS: |
| 593 | return kExternalFloatArray; |
| 594 | default: |
| 595 | UNREACHABLE(); |
| 596 | return static_cast<ExternalArrayType>(0); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | } // anonymous namespace |
| 601 | |
| 602 | |
| 603 | MaybeObject* StubCache::ComputeKeyedLoadOrStoreExternalArray( |
| 604 | JSObject* receiver, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 605 | bool is_store, |
| 606 | StrictModeFlag strict_mode) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 607 | Code::Flags flags = |
| 608 | Code::ComputeMonomorphicFlags( |
| 609 | is_store ? Code::KEYED_STORE_IC : Code::KEYED_LOAD_IC, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 610 | NORMAL, |
| 611 | strict_mode); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 612 | ExternalArrayType array_type = |
| 613 | ElementsKindToExternalArrayType(receiver->GetElementsKind()); |
| 614 | String* name = |
| 615 | is_store ? Heap::KeyedStoreExternalArray_symbol() |
| 616 | : Heap::KeyedLoadExternalArray_symbol(); |
| 617 | // Use the global maps for the particular external array types, |
| 618 | // rather than the receiver's map, when looking up the cached code, |
| 619 | // so that we actually canonicalize these stubs. |
| 620 | Map* map = Heap::MapForExternalArrayType(array_type); |
| 621 | Object* code = map->FindInCodeCache(name, flags); |
| 622 | if (code->IsUndefined()) { |
| 623 | ExternalArrayStubCompiler compiler; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 624 | { MaybeObject* maybe_code = is_store |
| 625 | ? compiler.CompileKeyedStoreStub(array_type, flags) |
| 626 | : compiler.CompileKeyedLoadStub(array_type, flags); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 627 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 628 | } |
| 629 | if (is_store) { |
| 630 | PROFILE( |
| 631 | CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, Code::cast(code), 0)); |
| 632 | } else { |
| 633 | PROFILE( |
| 634 | CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, Code::cast(code), 0)); |
| 635 | } |
| 636 | Object* result; |
| 637 | { MaybeObject* maybe_result = |
| 638 | map->UpdateCodeCache(name, Code::cast(code)); |
| 639 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 640 | } |
| 641 | } |
| 642 | return code; |
| 643 | } |
| 644 | |
| 645 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 646 | MaybeObject* StubCache::ComputeStoreNormal(StrictModeFlag strict_mode) { |
| 647 | return Builtins::builtin((strict_mode == kStrictMode) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 648 | ? Builtins::StoreIC_Normal_Strict |
| 649 | : Builtins::StoreIC_Normal); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 653 | MaybeObject* StubCache::ComputeStoreGlobal(String* name, |
| 654 | GlobalObject* receiver, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 655 | JSGlobalPropertyCell* cell, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 656 | StrictModeFlag strict_mode) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 657 | Code::Flags flags = Code::ComputeMonomorphicFlags( |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 658 | Code::STORE_IC, NORMAL, strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 659 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 660 | if (code->IsUndefined()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 661 | StoreStubCompiler compiler(strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 662 | { MaybeObject* maybe_code = |
| 663 | compiler.CompileStoreGlobal(receiver, cell, name); |
| 664 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 665 | } |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 666 | PROFILE(CodeCreateEvent(Logger::STORE_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 667 | GDBJIT(AddCode(GDBJITInterface::STORE_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 668 | Object* result; |
| 669 | { MaybeObject* maybe_result = |
| 670 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 671 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 672 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 673 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 674 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 678 | MaybeObject* StubCache::ComputeStoreCallback( |
| 679 | String* name, |
| 680 | JSObject* receiver, |
| 681 | AccessorInfo* callback, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 682 | StrictModeFlag strict_mode) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 683 | ASSERT(v8::ToCData<Address>(callback->setter()) != 0); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 684 | Code::Flags flags = Code::ComputeMonomorphicFlags( |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 685 | Code::STORE_IC, CALLBACKS, strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 686 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 687 | if (code->IsUndefined()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 688 | StoreStubCompiler compiler(strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 689 | { MaybeObject* maybe_code = |
| 690 | compiler.CompileStoreCallback(receiver, callback, name); |
| 691 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 692 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 693 | PROFILE(CodeCreateEvent(Logger::STORE_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 694 | GDBJIT(AddCode(GDBJITInterface::STORE_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 695 | Object* result; |
| 696 | { MaybeObject* maybe_result = |
| 697 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 698 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 699 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 700 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 701 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 705 | MaybeObject* StubCache::ComputeStoreInterceptor( |
| 706 | String* name, |
| 707 | JSObject* receiver, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 708 | StrictModeFlag strict_mode) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 709 | Code::Flags flags = Code::ComputeMonomorphicFlags( |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 710 | Code::STORE_IC, INTERCEPTOR, strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 711 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 712 | if (code->IsUndefined()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 713 | StoreStubCompiler compiler(strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 714 | { MaybeObject* maybe_code = |
| 715 | compiler.CompileStoreInterceptor(receiver, name); |
| 716 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 717 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 718 | PROFILE(CodeCreateEvent(Logger::STORE_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 719 | GDBJIT(AddCode(GDBJITInterface::STORE_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 720 | Object* result; |
| 721 | { MaybeObject* maybe_result = |
| 722 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 723 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 724 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 725 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 726 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 730 | MaybeObject* StubCache::ComputeKeyedStoreField(String* name, |
| 731 | JSObject* receiver, |
| 732 | int field_index, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 733 | Map* transition, |
| 734 | StrictModeFlag strict_mode) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 735 | PropertyType type = (transition == NULL) ? FIELD : MAP_TRANSITION; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 736 | Code::Flags flags = Code::ComputeMonomorphicFlags( |
| 737 | Code::KEYED_STORE_IC, type, strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 738 | Object* code = receiver->map()->FindInCodeCache(name, flags); |
| 739 | if (code->IsUndefined()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 740 | KeyedStoreStubCompiler compiler(strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 741 | { MaybeObject* maybe_code = |
| 742 | compiler.CompileStoreField(receiver, field_index, transition, name); |
| 743 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 744 | } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 745 | PROFILE(CodeCreateEvent( |
| 746 | Logger::KEYED_STORE_IC_TAG, Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 747 | GDBJIT(AddCode(GDBJITInterface::KEYED_STORE_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 748 | Object* result; |
| 749 | { MaybeObject* maybe_result = |
| 750 | receiver->UpdateMapCodeCache(name, Code::cast(code)); |
| 751 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 752 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 753 | } |
| 754 | return code; |
| 755 | } |
| 756 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 757 | #define CALL_LOGGER_TAG(kind, type) \ |
| 758 | (kind == Code::CALL_IC ? Logger::type : Logger::KEYED_##type) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 759 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 760 | MaybeObject* StubCache::ComputeCallConstant(int argc, |
| 761 | InLoopFlag in_loop, |
| 762 | Code::Kind kind, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 763 | Code::ExtraICState extra_ic_state, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 764 | String* name, |
| 765 | Object* object, |
| 766 | JSObject* holder, |
| 767 | JSFunction* function) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 768 | // Compute the check type and the map. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 769 | InlineCacheHolderFlag cache_holder = |
| 770 | IC::GetCodeCacheForObject(object, holder); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 771 | JSObject* map_holder = IC::GetCodeCacheHolder(object, cache_holder); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 772 | |
| 773 | // Compute check type based on receiver/holder. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 774 | CheckType check = RECEIVER_MAP_CHECK; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 775 | if (object->IsString()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 776 | check = STRING_CHECK; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 777 | } else if (object->IsNumber()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 778 | check = NUMBER_CHECK; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 779 | } else if (object->IsBoolean()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 780 | check = BOOLEAN_CHECK; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 783 | Code::Flags flags = Code::ComputeMonomorphicFlags(kind, |
| 784 | CONSTANT_FUNCTION, |
| 785 | extra_ic_state, |
| 786 | cache_holder, |
| 787 | in_loop, |
| 788 | argc); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 789 | Object* code = map_holder->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 790 | if (code->IsUndefined()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 791 | // If the function hasn't been compiled yet, we cannot do it now |
| 792 | // because it may cause GC. To avoid this issue, we return an |
| 793 | // internal error which will make sure we do not update any |
| 794 | // caches. |
| 795 | if (!function->is_compiled()) return Failure::InternalError(); |
| 796 | // Compile the stub - only create stubs for fully compiled functions. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 797 | CallStubCompiler compiler( |
| 798 | argc, in_loop, kind, extra_ic_state, cache_holder); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 799 | { MaybeObject* maybe_code = |
| 800 | compiler.CompileCallConstant(object, holder, function, name, check); |
| 801 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 802 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 803 | Code::cast(code)->set_check_type(check); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 804 | ASSERT_EQ(flags, Code::cast(code)->flags()); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 805 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), |
| 806 | Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 807 | GDBJIT(AddCode(GDBJITInterface::CALL_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 808 | Object* result; |
| 809 | { MaybeObject* maybe_result = |
| 810 | map_holder->UpdateMapCodeCache(name, Code::cast(code)); |
| 811 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 812 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 813 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 814 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 818 | MaybeObject* StubCache::ComputeCallField(int argc, |
| 819 | InLoopFlag in_loop, |
| 820 | Code::Kind kind, |
| 821 | String* name, |
| 822 | Object* object, |
| 823 | JSObject* holder, |
| 824 | int index) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 825 | // Compute the check type and the map. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 826 | InlineCacheHolderFlag cache_holder = |
| 827 | IC::GetCodeCacheForObject(object, holder); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 828 | JSObject* map_holder = IC::GetCodeCacheHolder(object, cache_holder); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 829 | |
| 830 | // TODO(1233596): We cannot do receiver map check for non-JS objects |
| 831 | // because they may be represented as immediates without a |
| 832 | // map. Instead, we check against the map in the holder. |
| 833 | if (object->IsNumber() || object->IsBoolean() || object->IsString()) { |
| 834 | object = holder; |
| 835 | } |
| 836 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 837 | Code::Flags flags = Code::ComputeMonomorphicFlags(kind, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 838 | FIELD, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 839 | Code::kNoExtraICState, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 840 | cache_holder, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 841 | in_loop, |
| 842 | argc); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 843 | Object* code = map_holder->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 844 | if (code->IsUndefined()) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 845 | CallStubCompiler compiler( |
| 846 | argc, in_loop, kind, Code::kNoExtraICState, cache_holder); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 847 | { MaybeObject* maybe_code = |
| 848 | compiler.CompileCallField(JSObject::cast(object), |
| 849 | holder, |
| 850 | index, |
| 851 | name); |
| 852 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 853 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 854 | ASSERT_EQ(flags, Code::cast(code)->flags()); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 855 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), |
| 856 | Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 857 | GDBJIT(AddCode(GDBJITInterface::CALL_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 858 | Object* result; |
| 859 | { MaybeObject* maybe_result = |
| 860 | map_holder->UpdateMapCodeCache(name, Code::cast(code)); |
| 861 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 862 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 863 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 864 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 868 | MaybeObject* StubCache::ComputeCallInterceptor(int argc, |
| 869 | Code::Kind kind, |
| 870 | String* name, |
| 871 | Object* object, |
| 872 | JSObject* holder) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 873 | // Compute the check type and the map. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 874 | InlineCacheHolderFlag cache_holder = |
| 875 | IC::GetCodeCacheForObject(object, holder); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 876 | JSObject* map_holder = IC::GetCodeCacheHolder(object, cache_holder); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 877 | |
| 878 | // TODO(1233596): We cannot do receiver map check for non-JS objects |
| 879 | // because they may be represented as immediates without a |
| 880 | // map. Instead, we check against the map in the holder. |
| 881 | if (object->IsNumber() || object->IsBoolean() || object->IsString()) { |
| 882 | object = holder; |
| 883 | } |
| 884 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 885 | Code::Flags flags = Code::ComputeMonomorphicFlags(kind, |
| 886 | INTERCEPTOR, |
| 887 | Code::kNoExtraICState, |
| 888 | cache_holder, |
| 889 | NOT_IN_LOOP, |
| 890 | argc); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 891 | Object* code = map_holder->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 892 | if (code->IsUndefined()) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 893 | CallStubCompiler compiler( |
| 894 | argc, NOT_IN_LOOP, kind, Code::kNoExtraICState, cache_holder); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 895 | { MaybeObject* maybe_code = |
| 896 | compiler.CompileCallInterceptor(JSObject::cast(object), holder, name); |
| 897 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 898 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 899 | ASSERT_EQ(flags, Code::cast(code)->flags()); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 900 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), |
| 901 | Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 902 | GDBJIT(AddCode(GDBJITInterface::CALL_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 903 | Object* result; |
| 904 | { MaybeObject* maybe_result = |
| 905 | map_holder->UpdateMapCodeCache(name, Code::cast(code)); |
| 906 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 907 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 908 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 909 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 913 | MaybeObject* StubCache::ComputeCallNormal(int argc, |
| 914 | InLoopFlag in_loop, |
| 915 | Code::Kind kind, |
| 916 | String* name, |
| 917 | JSObject* receiver) { |
| 918 | Object* code; |
| 919 | { MaybeObject* maybe_code = ComputeCallNormal(argc, in_loop, kind); |
| 920 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 921 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 922 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 926 | MaybeObject* StubCache::ComputeCallGlobal(int argc, |
| 927 | InLoopFlag in_loop, |
| 928 | Code::Kind kind, |
| 929 | String* name, |
| 930 | JSObject* receiver, |
| 931 | GlobalObject* holder, |
| 932 | JSGlobalPropertyCell* cell, |
| 933 | JSFunction* function) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 934 | InlineCacheHolderFlag cache_holder = |
| 935 | IC::GetCodeCacheForObject(receiver, holder); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 936 | JSObject* map_holder = IC::GetCodeCacheHolder(receiver, cache_holder); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 937 | Code::Flags flags = Code::ComputeMonomorphicFlags(kind, |
| 938 | NORMAL, |
| 939 | Code::kNoExtraICState, |
| 940 | cache_holder, |
| 941 | in_loop, |
| 942 | argc); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 943 | Object* code = map_holder->map()->FindInCodeCache(name, flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 944 | if (code->IsUndefined()) { |
| 945 | // If the function hasn't been compiled yet, we cannot do it now |
| 946 | // because it may cause GC. To avoid this issue, we return an |
| 947 | // internal error which will make sure we do not update any |
| 948 | // caches. |
| 949 | if (!function->is_compiled()) return Failure::InternalError(); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 950 | CallStubCompiler compiler( |
| 951 | argc, in_loop, kind, Code::kNoExtraICState, cache_holder); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 952 | { MaybeObject* maybe_code = |
| 953 | compiler.CompileCallGlobal(receiver, holder, cell, function, name); |
| 954 | if (!maybe_code->ToObject(&code)) return maybe_code; |
| 955 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 956 | ASSERT_EQ(flags, Code::cast(code)->flags()); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 957 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_IC_TAG), |
| 958 | Code::cast(code), name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 959 | GDBJIT(AddCode(GDBJITInterface::CALL_IC, name, Code::cast(code))); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 960 | Object* result; |
| 961 | { MaybeObject* maybe_result = |
| 962 | map_holder->UpdateMapCodeCache(name, Code::cast(code)); |
| 963 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 964 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 965 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 966 | return code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | |
| 970 | static Object* GetProbeValue(Code::Flags flags) { |
| 971 | // Use raw_unchecked... so we don't get assert failures during GC. |
| 972 | NumberDictionary* dictionary = Heap::raw_unchecked_non_monomorphic_cache(); |
| 973 | int entry = dictionary->FindEntry(flags); |
| 974 | if (entry != -1) return dictionary->ValueAt(entry); |
| 975 | return Heap::raw_unchecked_undefined_value(); |
| 976 | } |
| 977 | |
| 978 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 979 | MUST_USE_RESULT static MaybeObject* ProbeCache(Code::Flags flags) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 980 | Object* probe = GetProbeValue(flags); |
| 981 | if (probe != Heap::undefined_value()) return probe; |
| 982 | // Seed the cache with an undefined value to make sure that any |
| 983 | // generated code object can always be inserted into the cache |
| 984 | // without causing allocation failures. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 985 | Object* result; |
| 986 | { MaybeObject* maybe_result = |
| 987 | Heap::non_monomorphic_cache()->AtNumberPut(flags, |
| 988 | Heap::undefined_value()); |
| 989 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 990 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 991 | Heap::public_set_non_monomorphic_cache(NumberDictionary::cast(result)); |
| 992 | return probe; |
| 993 | } |
| 994 | |
| 995 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 996 | static MaybeObject* FillCache(MaybeObject* maybe_code) { |
| 997 | Object* code; |
| 998 | if (maybe_code->ToObject(&code)) { |
| 999 | if (code->IsCode()) { |
| 1000 | int entry = |
| 1001 | Heap::non_monomorphic_cache()->FindEntry( |
| 1002 | Code::cast(code)->flags()); |
| 1003 | // The entry must be present see comment in ProbeCache. |
| 1004 | ASSERT(entry != -1); |
| 1005 | ASSERT(Heap::non_monomorphic_cache()->ValueAt(entry) == |
| 1006 | Heap::undefined_value()); |
| 1007 | Heap::non_monomorphic_cache()->ValueAtPut(entry, code); |
| 1008 | CHECK(GetProbeValue(Code::cast(code)->flags()) == code); |
| 1009 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1010 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1011 | return maybe_code; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1015 | Code* StubCache::FindCallInitialize(int argc, |
| 1016 | InLoopFlag in_loop, |
| 1017 | Code::Kind kind) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1018 | Code::Flags flags = Code::ComputeFlags(kind, |
| 1019 | in_loop, |
| 1020 | UNINITIALIZED, |
| 1021 | Code::kNoExtraICState, |
| 1022 | NORMAL, |
| 1023 | argc); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1024 | Object* result = ProbeCache(flags)->ToObjectUnchecked(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1025 | ASSERT(!result->IsUndefined()); |
| 1026 | // This might be called during the marking phase of the collector |
| 1027 | // hence the unchecked cast. |
| 1028 | return reinterpret_cast<Code*>(result); |
| 1029 | } |
| 1030 | |
| 1031 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1032 | MaybeObject* StubCache::ComputeCallInitialize(int argc, |
| 1033 | InLoopFlag in_loop, |
| 1034 | Code::Kind kind) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1035 | Code::Flags flags = Code::ComputeFlags(kind, |
| 1036 | in_loop, |
| 1037 | UNINITIALIZED, |
| 1038 | Code::kNoExtraICState, |
| 1039 | NORMAL, |
| 1040 | argc); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1041 | Object* probe; |
| 1042 | { MaybeObject* maybe_probe = ProbeCache(flags); |
| 1043 | if (!maybe_probe->ToObject(&probe)) return maybe_probe; |
| 1044 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1045 | if (!probe->IsUndefined()) return probe; |
| 1046 | StubCompiler compiler; |
| 1047 | return FillCache(compiler.CompileCallInitialize(flags)); |
| 1048 | } |
| 1049 | |
| 1050 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1051 | Handle<Code> StubCache::ComputeCallInitialize(int argc, InLoopFlag in_loop) { |
| 1052 | if (in_loop == IN_LOOP) { |
| 1053 | // Force the creation of the corresponding stub outside loops, |
| 1054 | // because it may be used when clearing the ICs later - it is |
| 1055 | // possible for a series of IC transitions to lose the in-loop |
| 1056 | // information, and the IC clearing code can't generate a stub |
| 1057 | // that it needs so we need to ensure it is generated already. |
| 1058 | ComputeCallInitialize(argc, NOT_IN_LOOP); |
| 1059 | } |
| 1060 | CALL_HEAP_FUNCTION(ComputeCallInitialize(argc, in_loop, Code::CALL_IC), Code); |
| 1061 | } |
| 1062 | |
| 1063 | |
| 1064 | Handle<Code> StubCache::ComputeKeyedCallInitialize(int argc, |
| 1065 | InLoopFlag in_loop) { |
| 1066 | if (in_loop == IN_LOOP) { |
| 1067 | // Force the creation of the corresponding stub outside loops, |
| 1068 | // because it may be used when clearing the ICs later - it is |
| 1069 | // possible for a series of IC transitions to lose the in-loop |
| 1070 | // information, and the IC clearing code can't generate a stub |
| 1071 | // that it needs so we need to ensure it is generated already. |
| 1072 | ComputeKeyedCallInitialize(argc, NOT_IN_LOOP); |
| 1073 | } |
| 1074 | CALL_HEAP_FUNCTION( |
| 1075 | ComputeCallInitialize(argc, in_loop, Code::KEYED_CALL_IC), Code); |
| 1076 | } |
| 1077 | |
| 1078 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1079 | MaybeObject* StubCache::ComputeCallPreMonomorphic(int argc, |
| 1080 | InLoopFlag in_loop, |
| 1081 | Code::Kind kind) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1082 | Code::Flags flags = Code::ComputeFlags(kind, |
| 1083 | in_loop, |
| 1084 | PREMONOMORPHIC, |
| 1085 | Code::kNoExtraICState, |
| 1086 | NORMAL, |
| 1087 | argc); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1088 | Object* probe; |
| 1089 | { MaybeObject* maybe_probe = ProbeCache(flags); |
| 1090 | if (!maybe_probe->ToObject(&probe)) return maybe_probe; |
| 1091 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1092 | if (!probe->IsUndefined()) return probe; |
| 1093 | StubCompiler compiler; |
| 1094 | return FillCache(compiler.CompileCallPreMonomorphic(flags)); |
| 1095 | } |
| 1096 | |
| 1097 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1098 | MaybeObject* StubCache::ComputeCallNormal(int argc, |
| 1099 | InLoopFlag in_loop, |
| 1100 | Code::Kind kind) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1101 | Code::Flags flags = Code::ComputeFlags(kind, |
| 1102 | in_loop, |
| 1103 | MONOMORPHIC, |
| 1104 | Code::kNoExtraICState, |
| 1105 | NORMAL, |
| 1106 | argc); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1107 | Object* probe; |
| 1108 | { MaybeObject* maybe_probe = ProbeCache(flags); |
| 1109 | if (!maybe_probe->ToObject(&probe)) return maybe_probe; |
| 1110 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1111 | if (!probe->IsUndefined()) return probe; |
| 1112 | StubCompiler compiler; |
| 1113 | return FillCache(compiler.CompileCallNormal(flags)); |
| 1114 | } |
| 1115 | |
| 1116 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1117 | MaybeObject* StubCache::ComputeCallMegamorphic(int argc, |
| 1118 | InLoopFlag in_loop, |
| 1119 | Code::Kind kind) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1120 | Code::Flags flags = Code::ComputeFlags(kind, |
| 1121 | in_loop, |
| 1122 | MEGAMORPHIC, |
| 1123 | Code::kNoExtraICState, |
| 1124 | NORMAL, |
| 1125 | argc); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1126 | Object* probe; |
| 1127 | { MaybeObject* maybe_probe = ProbeCache(flags); |
| 1128 | if (!maybe_probe->ToObject(&probe)) return maybe_probe; |
| 1129 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1130 | if (!probe->IsUndefined()) return probe; |
| 1131 | StubCompiler compiler; |
| 1132 | return FillCache(compiler.CompileCallMegamorphic(flags)); |
| 1133 | } |
| 1134 | |
| 1135 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1136 | MaybeObject* StubCache::ComputeCallMiss(int argc, Code::Kind kind) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1137 | // MONOMORPHIC_PROTOTYPE_FAILURE state is used to make sure that miss stubs |
| 1138 | // and monomorphic stubs are not mixed up together in the stub cache. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1139 | Code::Flags flags = Code::ComputeFlags(kind, |
| 1140 | NOT_IN_LOOP, |
| 1141 | MONOMORPHIC_PROTOTYPE_FAILURE, |
| 1142 | Code::kNoExtraICState, |
| 1143 | NORMAL, |
| 1144 | argc, |
| 1145 | OWN_MAP); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1146 | Object* probe; |
| 1147 | { MaybeObject* maybe_probe = ProbeCache(flags); |
| 1148 | if (!maybe_probe->ToObject(&probe)) return maybe_probe; |
| 1149 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1150 | if (!probe->IsUndefined()) return probe; |
| 1151 | StubCompiler compiler; |
| 1152 | return FillCache(compiler.CompileCallMiss(flags)); |
| 1153 | } |
| 1154 | |
| 1155 | |
| 1156 | #ifdef ENABLE_DEBUGGER_SUPPORT |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1157 | MaybeObject* StubCache::ComputeCallDebugBreak(int argc, Code::Kind kind) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1158 | Code::Flags flags = Code::ComputeFlags(kind, |
| 1159 | NOT_IN_LOOP, |
| 1160 | DEBUG_BREAK, |
| 1161 | Code::kNoExtraICState, |
| 1162 | NORMAL, |
| 1163 | argc); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1164 | Object* probe; |
| 1165 | { MaybeObject* maybe_probe = ProbeCache(flags); |
| 1166 | if (!maybe_probe->ToObject(&probe)) return maybe_probe; |
| 1167 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1168 | if (!probe->IsUndefined()) return probe; |
| 1169 | StubCompiler compiler; |
| 1170 | return FillCache(compiler.CompileCallDebugBreak(flags)); |
| 1171 | } |
| 1172 | |
| 1173 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1174 | MaybeObject* StubCache::ComputeCallDebugPrepareStepIn(int argc, |
| 1175 | Code::Kind kind) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1176 | Code::Flags flags = Code::ComputeFlags(kind, |
| 1177 | NOT_IN_LOOP, |
| 1178 | DEBUG_PREPARE_STEP_IN, |
| 1179 | Code::kNoExtraICState, |
| 1180 | NORMAL, |
| 1181 | argc); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1182 | Object* probe; |
| 1183 | { MaybeObject* maybe_probe = ProbeCache(flags); |
| 1184 | if (!maybe_probe->ToObject(&probe)) return maybe_probe; |
| 1185 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1186 | if (!probe->IsUndefined()) return probe; |
| 1187 | StubCompiler compiler; |
| 1188 | return FillCache(compiler.CompileCallDebugPrepareStepIn(flags)); |
| 1189 | } |
| 1190 | #endif |
| 1191 | |
| 1192 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1193 | void StubCache::Clear() { |
| 1194 | for (int i = 0; i < kPrimaryTableSize; i++) { |
| 1195 | primary_[i].key = Heap::empty_string(); |
| 1196 | primary_[i].value = Builtins::builtin(Builtins::Illegal); |
| 1197 | } |
| 1198 | for (int j = 0; j < kSecondaryTableSize; j++) { |
| 1199 | secondary_[j].key = Heap::empty_string(); |
| 1200 | secondary_[j].value = Builtins::builtin(Builtins::Illegal); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1205 | void StubCache::CollectMatchingMaps(ZoneMapList* types, |
| 1206 | String* name, |
| 1207 | Code::Flags flags) { |
| 1208 | for (int i = 0; i < kPrimaryTableSize; i++) { |
| 1209 | if (primary_[i].key == name) { |
| 1210 | Map* map = primary_[i].value->FindFirstMap(); |
| 1211 | // Map can be NULL, if the stub is constant function call |
| 1212 | // with a primitive receiver. |
| 1213 | if (map == NULL) continue; |
| 1214 | |
| 1215 | int offset = PrimaryOffset(name, flags, map); |
| 1216 | if (entry(primary_, offset) == &primary_[i]) { |
| 1217 | types->Add(Handle<Map>(map)); |
| 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | for (int i = 0; i < kSecondaryTableSize; i++) { |
| 1223 | if (secondary_[i].key == name) { |
| 1224 | Map* map = secondary_[i].value->FindFirstMap(); |
| 1225 | // Map can be NULL, if the stub is constant function call |
| 1226 | // with a primitive receiver. |
| 1227 | if (map == NULL) continue; |
| 1228 | |
| 1229 | // Lookup in primary table and skip duplicates. |
| 1230 | int primary_offset = PrimaryOffset(name, flags, map); |
| 1231 | Entry* primary_entry = entry(primary_, primary_offset); |
| 1232 | if (primary_entry->key == name) { |
| 1233 | Map* primary_map = primary_entry->value->FindFirstMap(); |
| 1234 | if (map == primary_map) continue; |
| 1235 | } |
| 1236 | |
| 1237 | // Lookup in secondary table and add matches. |
| 1238 | int offset = SecondaryOffset(name, flags, primary_offset); |
| 1239 | if (entry(secondary_, offset) == &secondary_[i]) { |
| 1240 | types->Add(Handle<Map>(map)); |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1247 | // ------------------------------------------------------------------------ |
| 1248 | // StubCompiler implementation. |
| 1249 | |
| 1250 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1251 | MaybeObject* LoadCallbackProperty(Arguments args) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1252 | ASSERT(args[0]->IsJSObject()); |
| 1253 | ASSERT(args[1]->IsJSObject()); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1254 | AccessorInfo* callback = AccessorInfo::cast(args[3]); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1255 | Address getter_address = v8::ToCData<Address>(callback->getter()); |
| 1256 | v8::AccessorGetter fun = FUNCTION_CAST<v8::AccessorGetter>(getter_address); |
| 1257 | ASSERT(fun != NULL); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1258 | v8::AccessorInfo info(&args[0]); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1259 | HandleScope scope; |
| 1260 | v8::Handle<v8::Value> result; |
| 1261 | { |
| 1262 | // Leaving JavaScript. |
| 1263 | VMState state(EXTERNAL); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1264 | ExternalCallbackScope call_scope(getter_address); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1265 | result = fun(v8::Utils::ToLocal(args.at<String>(4)), info); |
| 1266 | } |
| 1267 | RETURN_IF_SCHEDULED_EXCEPTION(); |
| 1268 | if (result.IsEmpty()) return Heap::undefined_value(); |
| 1269 | return *v8::Utils::OpenHandle(*result); |
| 1270 | } |
| 1271 | |
| 1272 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1273 | MaybeObject* StoreCallbackProperty(Arguments args) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1274 | JSObject* recv = JSObject::cast(args[0]); |
| 1275 | AccessorInfo* callback = AccessorInfo::cast(args[1]); |
| 1276 | Address setter_address = v8::ToCData<Address>(callback->setter()); |
| 1277 | v8::AccessorSetter fun = FUNCTION_CAST<v8::AccessorSetter>(setter_address); |
| 1278 | ASSERT(fun != NULL); |
| 1279 | Handle<String> name = args.at<String>(2); |
| 1280 | Handle<Object> value = args.at<Object>(3); |
| 1281 | HandleScope scope; |
| 1282 | LOG(ApiNamedPropertyAccess("store", recv, *name)); |
| 1283 | CustomArguments custom_args(callback->data(), recv, recv); |
| 1284 | v8::AccessorInfo info(custom_args.end()); |
| 1285 | { |
| 1286 | // Leaving JavaScript. |
| 1287 | VMState state(EXTERNAL); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1288 | ExternalCallbackScope call_scope(setter_address); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1289 | fun(v8::Utils::ToLocal(name), v8::Utils::ToLocal(value), info); |
| 1290 | } |
| 1291 | RETURN_IF_SCHEDULED_EXCEPTION(); |
| 1292 | return *value; |
| 1293 | } |
| 1294 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1295 | |
| 1296 | static const int kAccessorInfoOffsetInInterceptorArgs = 2; |
| 1297 | |
| 1298 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1299 | /** |
| 1300 | * Attempts to load a property with an interceptor (which must be present), |
| 1301 | * but doesn't search the prototype chain. |
| 1302 | * |
| 1303 | * Returns |Heap::no_interceptor_result_sentinel()| if interceptor doesn't |
| 1304 | * provide any value for the given name. |
| 1305 | */ |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1306 | MaybeObject* LoadPropertyWithInterceptorOnly(Arguments args) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1307 | Handle<String> name_handle = args.at<String>(0); |
| 1308 | Handle<InterceptorInfo> interceptor_info = args.at<InterceptorInfo>(1); |
| 1309 | ASSERT(kAccessorInfoOffsetInInterceptorArgs == 2); |
| 1310 | ASSERT(args[2]->IsJSObject()); // Receiver. |
| 1311 | ASSERT(args[3]->IsJSObject()); // Holder. |
| 1312 | ASSERT(args.length() == 5); // Last arg is data object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1313 | |
| 1314 | Address getter_address = v8::ToCData<Address>(interceptor_info->getter()); |
| 1315 | v8::NamedPropertyGetter getter = |
| 1316 | FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address); |
| 1317 | ASSERT(getter != NULL); |
| 1318 | |
| 1319 | { |
| 1320 | // Use the interceptor getter. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1321 | v8::AccessorInfo info(args.arguments() - |
| 1322 | kAccessorInfoOffsetInInterceptorArgs); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1323 | HandleScope scope; |
| 1324 | v8::Handle<v8::Value> r; |
| 1325 | { |
| 1326 | // Leaving JavaScript. |
| 1327 | VMState state(EXTERNAL); |
| 1328 | r = getter(v8::Utils::ToLocal(name_handle), info); |
| 1329 | } |
| 1330 | RETURN_IF_SCHEDULED_EXCEPTION(); |
| 1331 | if (!r.IsEmpty()) { |
| 1332 | return *v8::Utils::OpenHandle(*r); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | return Heap::no_interceptor_result_sentinel(); |
| 1337 | } |
| 1338 | |
| 1339 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1340 | static MaybeObject* ThrowReferenceError(String* name) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1341 | // If the load is non-contextual, just return the undefined result. |
| 1342 | // Note that both keyed and non-keyed loads may end up here, so we |
| 1343 | // can't use either LoadIC or KeyedLoadIC constructors. |
| 1344 | IC ic(IC::NO_EXTRA_FRAME); |
| 1345 | ASSERT(ic.target()->is_load_stub() || ic.target()->is_keyed_load_stub()); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1346 | if (!ic.SlowIsContextual()) return Heap::undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1347 | |
| 1348 | // Throw a reference error. |
| 1349 | HandleScope scope; |
| 1350 | Handle<String> name_handle(name); |
| 1351 | Handle<Object> error = |
| 1352 | Factory::NewReferenceError("not_defined", |
| 1353 | HandleVector(&name_handle, 1)); |
| 1354 | return Top::Throw(*error); |
| 1355 | } |
| 1356 | |
| 1357 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1358 | static MaybeObject* LoadWithInterceptor(Arguments* args, |
| 1359 | PropertyAttributes* attrs) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1360 | Handle<String> name_handle = args->at<String>(0); |
| 1361 | Handle<InterceptorInfo> interceptor_info = args->at<InterceptorInfo>(1); |
| 1362 | ASSERT(kAccessorInfoOffsetInInterceptorArgs == 2); |
| 1363 | Handle<JSObject> receiver_handle = args->at<JSObject>(2); |
| 1364 | Handle<JSObject> holder_handle = args->at<JSObject>(3); |
| 1365 | ASSERT(args->length() == 5); // Last arg is data object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1366 | |
| 1367 | Address getter_address = v8::ToCData<Address>(interceptor_info->getter()); |
| 1368 | v8::NamedPropertyGetter getter = |
| 1369 | FUNCTION_CAST<v8::NamedPropertyGetter>(getter_address); |
| 1370 | ASSERT(getter != NULL); |
| 1371 | |
| 1372 | { |
| 1373 | // Use the interceptor getter. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1374 | v8::AccessorInfo info(args->arguments() - |
| 1375 | kAccessorInfoOffsetInInterceptorArgs); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1376 | HandleScope scope; |
| 1377 | v8::Handle<v8::Value> r; |
| 1378 | { |
| 1379 | // Leaving JavaScript. |
| 1380 | VMState state(EXTERNAL); |
| 1381 | r = getter(v8::Utils::ToLocal(name_handle), info); |
| 1382 | } |
| 1383 | RETURN_IF_SCHEDULED_EXCEPTION(); |
| 1384 | if (!r.IsEmpty()) { |
| 1385 | *attrs = NONE; |
| 1386 | return *v8::Utils::OpenHandle(*r); |
| 1387 | } |
| 1388 | } |
| 1389 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1390 | MaybeObject* result = holder_handle->GetPropertyPostInterceptor( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1391 | *receiver_handle, |
| 1392 | *name_handle, |
| 1393 | attrs); |
| 1394 | RETURN_IF_SCHEDULED_EXCEPTION(); |
| 1395 | return result; |
| 1396 | } |
| 1397 | |
| 1398 | |
| 1399 | /** |
| 1400 | * Loads a property with an interceptor performing post interceptor |
| 1401 | * lookup if interceptor failed. |
| 1402 | */ |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1403 | MaybeObject* LoadPropertyWithInterceptorForLoad(Arguments args) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1404 | PropertyAttributes attr = NONE; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1405 | Object* result; |
| 1406 | { MaybeObject* maybe_result = LoadWithInterceptor(&args, &attr); |
| 1407 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1408 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1409 | |
| 1410 | // If the property is present, return it. |
| 1411 | if (attr != ABSENT) return result; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1412 | return ThrowReferenceError(String::cast(args[0])); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1416 | MaybeObject* LoadPropertyWithInterceptorForCall(Arguments args) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1417 | PropertyAttributes attr; |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1418 | MaybeObject* result = LoadWithInterceptor(&args, &attr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1419 | RETURN_IF_SCHEDULED_EXCEPTION(); |
| 1420 | // This is call IC. In this case, we simply return the undefined result which |
| 1421 | // will lead to an exception when trying to invoke the result as a |
| 1422 | // function. |
| 1423 | return result; |
| 1424 | } |
| 1425 | |
| 1426 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1427 | MaybeObject* StoreInterceptorProperty(Arguments args) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1428 | ASSERT(args.length() == 4); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1429 | JSObject* recv = JSObject::cast(args[0]); |
| 1430 | String* name = String::cast(args[1]); |
| 1431 | Object* value = args[2]; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1432 | StrictModeFlag strict_mode = |
| 1433 | static_cast<StrictModeFlag>(Smi::cast(args[3])->value()); |
| 1434 | ASSERT(strict_mode == kStrictMode || strict_mode == kNonStrictMode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1435 | ASSERT(recv->HasNamedInterceptor()); |
| 1436 | PropertyAttributes attr = NONE; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1437 | MaybeObject* result = recv->SetPropertyWithInterceptor( |
| 1438 | name, value, attr, strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1439 | return result; |
| 1440 | } |
| 1441 | |
| 1442 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1443 | MaybeObject* KeyedLoadPropertyWithInterceptor(Arguments args) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1444 | JSObject* receiver = JSObject::cast(args[0]); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1445 | ASSERT(Smi::cast(args[1])->value() >= 0); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1446 | uint32_t index = Smi::cast(args[1])->value(); |
| 1447 | return receiver->GetElementWithInterceptor(receiver, index); |
| 1448 | } |
| 1449 | |
| 1450 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1451 | MaybeObject* StubCompiler::CompileCallInitialize(Code::Flags flags) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1452 | HandleScope scope; |
| 1453 | int argc = Code::ExtractArgumentsCountFromFlags(flags); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1454 | Code::Kind kind = Code::ExtractKindFromFlags(flags); |
| 1455 | if (kind == Code::CALL_IC) { |
| 1456 | CallIC::GenerateInitialize(masm(), argc); |
| 1457 | } else { |
| 1458 | KeyedCallIC::GenerateInitialize(masm(), argc); |
| 1459 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1460 | Object* result; |
| 1461 | { MaybeObject* maybe_result = |
| 1462 | GetCodeWithFlags(flags, "CompileCallInitialize"); |
| 1463 | if (!maybe_result->ToObject(&result)) return maybe_result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1464 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1465 | Counters::call_initialize_stubs.Increment(); |
| 1466 | Code* code = Code::cast(result); |
| 1467 | USE(code); |
| 1468 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_INITIALIZE_TAG), |
| 1469 | code, code->arguments_count())); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1470 | GDBJIT(AddCode(GDBJITInterface::CALL_INITIALIZE, Code::cast(code))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1471 | return result; |
| 1472 | } |
| 1473 | |
| 1474 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1475 | MaybeObject* StubCompiler::CompileCallPreMonomorphic(Code::Flags flags) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1476 | HandleScope scope; |
| 1477 | int argc = Code::ExtractArgumentsCountFromFlags(flags); |
| 1478 | // The code of the PreMonomorphic stub is the same as the code |
| 1479 | // of the Initialized stub. They just differ on the code object flags. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1480 | Code::Kind kind = Code::ExtractKindFromFlags(flags); |
| 1481 | if (kind == Code::CALL_IC) { |
| 1482 | CallIC::GenerateInitialize(masm(), argc); |
| 1483 | } else { |
| 1484 | KeyedCallIC::GenerateInitialize(masm(), argc); |
| 1485 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1486 | Object* result; |
| 1487 | { MaybeObject* maybe_result = |
| 1488 | GetCodeWithFlags(flags, "CompileCallPreMonomorphic"); |
| 1489 | if (!maybe_result->ToObject(&result)) return maybe_result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1490 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1491 | Counters::call_premonomorphic_stubs.Increment(); |
| 1492 | Code* code = Code::cast(result); |
| 1493 | USE(code); |
| 1494 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_PRE_MONOMORPHIC_TAG), |
| 1495 | code, code->arguments_count())); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1496 | GDBJIT(AddCode(GDBJITInterface::CALL_PRE_MONOMORPHIC, Code::cast(code))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1497 | return result; |
| 1498 | } |
| 1499 | |
| 1500 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1501 | MaybeObject* StubCompiler::CompileCallNormal(Code::Flags flags) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1502 | HandleScope scope; |
| 1503 | int argc = Code::ExtractArgumentsCountFromFlags(flags); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1504 | Code::Kind kind = Code::ExtractKindFromFlags(flags); |
| 1505 | if (kind == Code::CALL_IC) { |
| 1506 | CallIC::GenerateNormal(masm(), argc); |
| 1507 | } else { |
| 1508 | KeyedCallIC::GenerateNormal(masm(), argc); |
| 1509 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1510 | Object* result; |
| 1511 | { MaybeObject* maybe_result = GetCodeWithFlags(flags, "CompileCallNormal"); |
| 1512 | if (!maybe_result->ToObject(&result)) return maybe_result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1513 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1514 | Counters::call_normal_stubs.Increment(); |
| 1515 | Code* code = Code::cast(result); |
| 1516 | USE(code); |
| 1517 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_NORMAL_TAG), |
| 1518 | code, code->arguments_count())); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1519 | GDBJIT(AddCode(GDBJITInterface::CALL_NORMAL, Code::cast(code))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1520 | return result; |
| 1521 | } |
| 1522 | |
| 1523 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1524 | MaybeObject* StubCompiler::CompileCallMegamorphic(Code::Flags flags) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1525 | HandleScope scope; |
| 1526 | int argc = Code::ExtractArgumentsCountFromFlags(flags); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1527 | Code::Kind kind = Code::ExtractKindFromFlags(flags); |
| 1528 | if (kind == Code::CALL_IC) { |
| 1529 | CallIC::GenerateMegamorphic(masm(), argc); |
| 1530 | } else { |
| 1531 | KeyedCallIC::GenerateMegamorphic(masm(), argc); |
| 1532 | } |
| 1533 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1534 | Object* result; |
| 1535 | { MaybeObject* maybe_result = |
| 1536 | GetCodeWithFlags(flags, "CompileCallMegamorphic"); |
| 1537 | if (!maybe_result->ToObject(&result)) return maybe_result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1538 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1539 | Counters::call_megamorphic_stubs.Increment(); |
| 1540 | Code* code = Code::cast(result); |
| 1541 | USE(code); |
| 1542 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_MEGAMORPHIC_TAG), |
| 1543 | code, code->arguments_count())); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1544 | GDBJIT(AddCode(GDBJITInterface::CALL_MEGAMORPHIC, Code::cast(code))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1545 | return result; |
| 1546 | } |
| 1547 | |
| 1548 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1549 | MaybeObject* StubCompiler::CompileCallMiss(Code::Flags flags) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1550 | HandleScope scope; |
| 1551 | int argc = Code::ExtractArgumentsCountFromFlags(flags); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1552 | Code::Kind kind = Code::ExtractKindFromFlags(flags); |
| 1553 | if (kind == Code::CALL_IC) { |
| 1554 | CallIC::GenerateMiss(masm(), argc); |
| 1555 | } else { |
| 1556 | KeyedCallIC::GenerateMiss(masm(), argc); |
| 1557 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1558 | Object* result; |
| 1559 | { MaybeObject* maybe_result = GetCodeWithFlags(flags, "CompileCallMiss"); |
| 1560 | if (!maybe_result->ToObject(&result)) return maybe_result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1561 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1562 | Counters::call_megamorphic_stubs.Increment(); |
| 1563 | Code* code = Code::cast(result); |
| 1564 | USE(code); |
| 1565 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_MISS_TAG), |
| 1566 | code, code->arguments_count())); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1567 | GDBJIT(AddCode(GDBJITInterface::CALL_MISS, Code::cast(code))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1568 | return result; |
| 1569 | } |
| 1570 | |
| 1571 | |
| 1572 | #ifdef ENABLE_DEBUGGER_SUPPORT |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1573 | MaybeObject* StubCompiler::CompileCallDebugBreak(Code::Flags flags) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1574 | HandleScope scope; |
| 1575 | Debug::GenerateCallICDebugBreak(masm()); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1576 | Object* result; |
| 1577 | { MaybeObject* maybe_result = |
| 1578 | GetCodeWithFlags(flags, "CompileCallDebugBreak"); |
| 1579 | if (!maybe_result->ToObject(&result)) return maybe_result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1580 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1581 | Code* code = Code::cast(result); |
| 1582 | USE(code); |
| 1583 | Code::Kind kind = Code::ExtractKindFromFlags(flags); |
| 1584 | USE(kind); |
| 1585 | PROFILE(CodeCreateEvent(CALL_LOGGER_TAG(kind, CALL_DEBUG_BREAK_TAG), |
| 1586 | code, code->arguments_count())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1587 | return result; |
| 1588 | } |
| 1589 | |
| 1590 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1591 | MaybeObject* StubCompiler::CompileCallDebugPrepareStepIn(Code::Flags flags) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1592 | HandleScope scope; |
| 1593 | // Use the same code for the the step in preparations as we do for |
| 1594 | // the miss case. |
| 1595 | int argc = Code::ExtractArgumentsCountFromFlags(flags); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1596 | Code::Kind kind = Code::ExtractKindFromFlags(flags); |
| 1597 | if (kind == Code::CALL_IC) { |
| 1598 | CallIC::GenerateMiss(masm(), argc); |
| 1599 | } else { |
| 1600 | KeyedCallIC::GenerateMiss(masm(), argc); |
| 1601 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1602 | Object* result; |
| 1603 | { MaybeObject* maybe_result = |
| 1604 | GetCodeWithFlags(flags, "CompileCallDebugPrepareStepIn"); |
| 1605 | if (!maybe_result->ToObject(&result)) return maybe_result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1606 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1607 | Code* code = Code::cast(result); |
| 1608 | USE(code); |
| 1609 | PROFILE(CodeCreateEvent( |
| 1610 | CALL_LOGGER_TAG(kind, CALL_DEBUG_PREPARE_STEP_IN_TAG), |
| 1611 | code, |
| 1612 | code->arguments_count())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1613 | return result; |
| 1614 | } |
| 1615 | #endif |
| 1616 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1617 | #undef CALL_LOGGER_TAG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1618 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1619 | MaybeObject* StubCompiler::GetCodeWithFlags(Code::Flags flags, |
| 1620 | const char* name) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1621 | // Check for allocation failures during stub compilation. |
| 1622 | if (failure_->IsFailure()) return failure_; |
| 1623 | |
| 1624 | // Create code object in the heap. |
| 1625 | CodeDesc desc; |
| 1626 | masm_.GetCode(&desc); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1627 | MaybeObject* result = Heap::CreateCode(desc, flags, masm_.CodeObject()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1628 | #ifdef ENABLE_DISASSEMBLER |
| 1629 | if (FLAG_print_code_stubs && !result->IsFailure()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1630 | Code::cast(result->ToObjectUnchecked())->Disassemble(name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1631 | } |
| 1632 | #endif |
| 1633 | return result; |
| 1634 | } |
| 1635 | |
| 1636 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1637 | MaybeObject* StubCompiler::GetCodeWithFlags(Code::Flags flags, String* name) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1638 | if (FLAG_print_code_stubs && (name != NULL)) { |
| 1639 | return GetCodeWithFlags(flags, *name->ToCString()); |
| 1640 | } |
| 1641 | return GetCodeWithFlags(flags, reinterpret_cast<char*>(NULL)); |
| 1642 | } |
| 1643 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1644 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1645 | void StubCompiler::LookupPostInterceptor(JSObject* holder, |
| 1646 | String* name, |
| 1647 | LookupResult* lookup) { |
| 1648 | holder->LocalLookupRealNamedProperty(name, lookup); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1649 | if (!lookup->IsProperty()) { |
| 1650 | lookup->NotFound(); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1651 | Object* proto = holder->GetPrototype(); |
| 1652 | if (proto != Heap::null_value()) { |
| 1653 | proto->Lookup(name, lookup); |
| 1654 | } |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1659 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1660 | MaybeObject* LoadStubCompiler::GetCode(PropertyType type, String* name) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1661 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, type); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1662 | MaybeObject* result = GetCodeWithFlags(flags, name); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1663 | if (!result->IsFailure()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1664 | PROFILE(CodeCreateEvent(Logger::LOAD_IC_TAG, |
| 1665 | Code::cast(result->ToObjectUnchecked()), |
| 1666 | name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1667 | GDBJIT(AddCode(GDBJITInterface::LOAD_IC, |
| 1668 | name, |
| 1669 | Code::cast(result->ToObjectUnchecked()))); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1670 | } |
| 1671 | return result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1675 | MaybeObject* KeyedLoadStubCompiler::GetCode(PropertyType type, String* name) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1676 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::KEYED_LOAD_IC, type); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1677 | MaybeObject* result = GetCodeWithFlags(flags, name); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1678 | if (!result->IsFailure()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1679 | PROFILE(CodeCreateEvent(Logger::KEYED_LOAD_IC_TAG, |
| 1680 | Code::cast(result->ToObjectUnchecked()), |
| 1681 | name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1682 | GDBJIT(AddCode(GDBJITInterface::LOAD_IC, |
| 1683 | name, |
| 1684 | Code::cast(result->ToObjectUnchecked()))); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1685 | } |
| 1686 | return result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1690 | MaybeObject* StoreStubCompiler::GetCode(PropertyType type, String* name) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1691 | Code::Flags flags = Code::ComputeMonomorphicFlags( |
| 1692 | Code::STORE_IC, type, strict_mode_); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1693 | MaybeObject* result = GetCodeWithFlags(flags, name); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1694 | if (!result->IsFailure()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1695 | PROFILE(CodeCreateEvent(Logger::STORE_IC_TAG, |
| 1696 | Code::cast(result->ToObjectUnchecked()), |
| 1697 | name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1698 | GDBJIT(AddCode(GDBJITInterface::STORE_IC, |
| 1699 | name, |
| 1700 | Code::cast(result->ToObjectUnchecked()))); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1701 | } |
| 1702 | return result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1706 | MaybeObject* KeyedStoreStubCompiler::GetCode(PropertyType type, String* name) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1707 | Code::Flags flags = Code::ComputeMonomorphicFlags( |
| 1708 | Code::KEYED_STORE_IC, type, strict_mode_); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1709 | MaybeObject* result = GetCodeWithFlags(flags, name); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1710 | if (!result->IsFailure()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1711 | PROFILE(CodeCreateEvent(Logger::KEYED_STORE_IC_TAG, |
| 1712 | Code::cast(result->ToObjectUnchecked()), |
| 1713 | name)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1714 | GDBJIT(AddCode(GDBJITInterface::KEYED_STORE_IC, |
| 1715 | name, |
| 1716 | Code::cast(result->ToObjectUnchecked()))); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1717 | } |
| 1718 | return result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1722 | CallStubCompiler::CallStubCompiler(int argc, |
| 1723 | InLoopFlag in_loop, |
| 1724 | Code::Kind kind, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1725 | Code::ExtraICState extra_ic_state, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1726 | InlineCacheHolderFlag cache_holder) |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1727 | : arguments_(argc), |
| 1728 | in_loop_(in_loop), |
| 1729 | kind_(kind), |
| 1730 | extra_ic_state_(extra_ic_state), |
| 1731 | cache_holder_(cache_holder) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1735 | bool CallStubCompiler::HasCustomCallGenerator(BuiltinFunctionId id) { |
| 1736 | #define CALL_GENERATOR_CASE(name) if (id == k##name) return true; |
| 1737 | CUSTOM_CALL_IC_GENERATORS(CALL_GENERATOR_CASE) |
| 1738 | #undef CALL_GENERATOR_CASE |
| 1739 | return false; |
| 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | MaybeObject* CallStubCompiler::CompileCustomCall(BuiltinFunctionId id, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1744 | Object* object, |
| 1745 | JSObject* holder, |
| 1746 | JSGlobalPropertyCell* cell, |
| 1747 | JSFunction* function, |
| 1748 | String* fname) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1749 | #define CALL_GENERATOR_CASE(name) \ |
| 1750 | if (id == k##name) { \ |
| 1751 | return CallStubCompiler::Compile##name##Call(object, \ |
| 1752 | holder, \ |
| 1753 | cell, \ |
| 1754 | function, \ |
| 1755 | fname); \ |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1756 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1757 | CUSTOM_CALL_IC_GENERATORS(CALL_GENERATOR_CASE) |
| 1758 | #undef CALL_GENERATOR_CASE |
| 1759 | ASSERT(!HasCustomCallGenerator(id)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1760 | return Heap::undefined_value(); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1764 | MaybeObject* CallStubCompiler::GetCode(PropertyType type, String* name) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1765 | int argc = arguments_.immediate(); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1766 | Code::Flags flags = Code::ComputeMonomorphicFlags(kind_, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1767 | type, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1768 | extra_ic_state_, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1769 | cache_holder_, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1770 | in_loop_, |
| 1771 | argc); |
| 1772 | return GetCodeWithFlags(flags, name); |
| 1773 | } |
| 1774 | |
| 1775 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1776 | MaybeObject* CallStubCompiler::GetCode(JSFunction* function) { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1777 | String* function_name = NULL; |
| 1778 | if (function->shared()->name()->IsString()) { |
| 1779 | function_name = String::cast(function->shared()->name()); |
| 1780 | } |
| 1781 | return GetCode(CONSTANT_FUNCTION, function_name); |
| 1782 | } |
| 1783 | |
| 1784 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1785 | MaybeObject* ConstructStubCompiler::GetCode() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1786 | Code::Flags flags = Code::ComputeFlags(Code::STUB); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1787 | Object* result; |
| 1788 | { MaybeObject* maybe_result = GetCodeWithFlags(flags, "ConstructStub"); |
| 1789 | if (!maybe_result->ToObject(&result)) return maybe_result; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1790 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1791 | Code* code = Code::cast(result); |
| 1792 | USE(code); |
| 1793 | PROFILE(CodeCreateEvent(Logger::STUB_TAG, code, "ConstructStub")); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1794 | GDBJIT(AddCode(GDBJITInterface::STUB, "ConstructStub", Code::cast(code))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1795 | return result; |
| 1796 | } |
| 1797 | |
| 1798 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1799 | CallOptimization::CallOptimization(LookupResult* lookup) { |
| 1800 | if (!lookup->IsProperty() || !lookup->IsCacheable() || |
| 1801 | lookup->type() != CONSTANT_FUNCTION) { |
| 1802 | Initialize(NULL); |
| 1803 | } else { |
| 1804 | // We only optimize constant function calls. |
| 1805 | Initialize(lookup->GetConstantFunction()); |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | CallOptimization::CallOptimization(JSFunction* function) { |
| 1810 | Initialize(function); |
| 1811 | } |
| 1812 | |
| 1813 | |
| 1814 | int CallOptimization::GetPrototypeDepthOfExpectedType(JSObject* object, |
| 1815 | JSObject* holder) const { |
| 1816 | ASSERT(is_simple_api_call_); |
| 1817 | if (expected_receiver_type_ == NULL) return 0; |
| 1818 | int depth = 0; |
| 1819 | while (object != holder) { |
| 1820 | if (object->IsInstanceOf(expected_receiver_type_)) return depth; |
| 1821 | object = JSObject::cast(object->GetPrototype()); |
| 1822 | ++depth; |
| 1823 | } |
| 1824 | if (holder->IsInstanceOf(expected_receiver_type_)) return depth; |
| 1825 | return kInvalidProtoDepth; |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | void CallOptimization::Initialize(JSFunction* function) { |
| 1830 | constant_function_ = NULL; |
| 1831 | is_simple_api_call_ = false; |
| 1832 | expected_receiver_type_ = NULL; |
| 1833 | api_call_info_ = NULL; |
| 1834 | |
| 1835 | if (function == NULL || !function->is_compiled()) return; |
| 1836 | |
| 1837 | constant_function_ = function; |
| 1838 | AnalyzePossibleApiFunction(function); |
| 1839 | } |
| 1840 | |
| 1841 | |
| 1842 | void CallOptimization::AnalyzePossibleApiFunction(JSFunction* function) { |
| 1843 | SharedFunctionInfo* sfi = function->shared(); |
| 1844 | if (!sfi->IsApiFunction()) return; |
| 1845 | FunctionTemplateInfo* info = sfi->get_api_func_data(); |
| 1846 | |
| 1847 | // Require a C++ callback. |
| 1848 | if (info->call_code()->IsUndefined()) return; |
| 1849 | api_call_info_ = CallHandlerInfo::cast(info->call_code()); |
| 1850 | |
| 1851 | // Accept signatures that either have no restrictions at all or |
| 1852 | // only have restrictions on the receiver. |
| 1853 | if (!info->signature()->IsUndefined()) { |
| 1854 | SignatureInfo* signature = SignatureInfo::cast(info->signature()); |
| 1855 | if (!signature->args()->IsUndefined()) return; |
| 1856 | if (!signature->receiver()->IsUndefined()) { |
| 1857 | expected_receiver_type_ = |
| 1858 | FunctionTemplateInfo::cast(signature->receiver()); |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | is_simple_api_call_ = true; |
| 1863 | } |
| 1864 | |
| 1865 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1866 | MaybeObject* ExternalArrayStubCompiler::GetCode(Code::Flags flags) { |
| 1867 | Object* result; |
| 1868 | { MaybeObject* maybe_result = GetCodeWithFlags(flags, "ExternalArrayStub"); |
| 1869 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1870 | } |
| 1871 | Code* code = Code::cast(result); |
| 1872 | USE(code); |
| 1873 | PROFILE(CodeCreateEvent(Logger::STUB_TAG, code, "ExternalArrayStub")); |
| 1874 | return result; |
| 1875 | } |
| 1876 | |
| 1877 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1878 | } } // namespace v8::internal |