ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 28 | #include "v8.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 29 | |
| 30 | #include "ast.h" |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 31 | #include "code-stubs.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 32 | #include "compiler.h" |
| 33 | #include "ic.h" |
| 34 | #include "macro-assembler.h" |
| 35 | #include "stub-cache.h" |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 36 | #include "type-info.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 37 | |
| 38 | #include "ic-inl.h" |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 39 | #include "objects-inl.h" |
| 40 | |
| 41 | namespace v8 { |
| 42 | namespace internal { |
| 43 | |
| 44 | |
| 45 | TypeInfo TypeInfo::TypeFromValue(Handle<Object> value) { |
| 46 | TypeInfo info; |
| 47 | if (value->IsSmi()) { |
| 48 | info = TypeInfo::Smi(); |
| 49 | } else if (value->IsHeapNumber()) { |
| 50 | info = TypeInfo::IsInt32Double(HeapNumber::cast(*value)->value()) |
| 51 | ? TypeInfo::Integer32() |
| 52 | : TypeInfo::Double(); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 53 | } else if (value->IsString()) { |
| 54 | info = TypeInfo::String(); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 55 | } else { |
| 56 | info = TypeInfo::Unknown(); |
| 57 | } |
| 58 | return info; |
| 59 | } |
| 60 | |
| 61 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 62 | TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 63 | Handle<Context> native_context, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 64 | Isolate* isolate, |
| 65 | Zone* zone) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 66 | native_context_ = native_context; |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 67 | isolate_ = isolate; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 68 | zone_ = zone; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 69 | BuildDictionary(code); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 70 | ASSERT(reinterpret_cast<Address>(*dictionary_.location()) != kHandleZapValue); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 74 | static uint32_t IdToKey(TypeFeedbackId ast_id) { |
| 75 | return static_cast<uint32_t>(ast_id.ToInt()); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | Handle<Object> TypeFeedbackOracle::GetInfo(TypeFeedbackId ast_id) { |
| 80 | int entry = dictionary_->FindEntry(IdToKey(ast_id)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 81 | return entry != UnseededNumberDictionary::kNotFound |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 82 | ? Handle<Object>(dictionary_->ValueAt(entry), isolate_) |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 83 | : Handle<Object>::cast(isolate_->factory()->undefined_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | |
jkummerow@chromium.org | 531dfe8 | 2012-03-20 13:01:16 +0000 | [diff] [blame] | 87 | bool TypeFeedbackOracle::LoadIsUninitialized(Property* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 88 | Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId()); |
jkummerow@chromium.org | 531dfe8 | 2012-03-20 13:01:16 +0000 | [diff] [blame] | 89 | if (map_or_code->IsMap()) return false; |
| 90 | if (map_or_code->IsCode()) { |
| 91 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
| 92 | return code->is_inline_cache_stub() && code->ic_state() == UNINITIALIZED; |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 98 | bool TypeFeedbackOracle::LoadIsMonomorphicNormal(Property* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 99 | Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 100 | if (map_or_code->IsMap()) return true; |
| 101 | if (map_or_code->IsCode()) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 102 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 103 | bool preliminary_checks = code->is_keyed_load_stub() && |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 104 | code->ic_state() == MONOMORPHIC && |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 105 | Code::ExtractTypeFromFlags(code->flags()) == Code::NORMAL; |
| 106 | if (!preliminary_checks) return false; |
| 107 | Map* map = code->FindFirstMap(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 108 | return map != NULL && !CanRetainOtherContext(map, *native_context_); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 109 | } |
| 110 | return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 114 | bool TypeFeedbackOracle::LoadIsPolymorphic(Property* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 115 | Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 116 | if (map_or_code->IsCode()) { |
| 117 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 118 | return code->is_keyed_load_stub() && code->ic_state() == POLYMORPHIC; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 119 | } |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 124 | bool TypeFeedbackOracle::StoreIsMonomorphicNormal(TypeFeedbackId ast_id) { |
| 125 | Handle<Object> map_or_code = GetInfo(ast_id); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 126 | if (map_or_code->IsMap()) return true; |
| 127 | if (map_or_code->IsCode()) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 128 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 129 | bool allow_growth = |
| 130 | Code::GetKeyedAccessGrowMode(code->extra_ic_state()) == |
| 131 | ALLOW_JSARRAY_GROWTH; |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 132 | bool preliminary_checks = |
| 133 | code->is_keyed_store_stub() && |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 134 | !allow_growth && |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 135 | code->ic_state() == MONOMORPHIC && |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 136 | Code::ExtractTypeFromFlags(code->flags()) == Code::NORMAL; |
| 137 | if (!preliminary_checks) return false; |
| 138 | Map* map = code->FindFirstMap(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 139 | return map != NULL && !CanRetainOtherContext(map, *native_context_); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 140 | } |
| 141 | return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 145 | bool TypeFeedbackOracle::StoreIsPolymorphic(TypeFeedbackId ast_id) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 146 | Handle<Object> map_or_code = GetInfo(ast_id); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 147 | if (map_or_code->IsCode()) { |
| 148 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 149 | bool allow_growth = |
| 150 | Code::GetKeyedAccessGrowMode(code->extra_ic_state()) == |
| 151 | ALLOW_JSARRAY_GROWTH; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 152 | return code->is_keyed_store_stub() && !allow_growth && |
| 153 | code->ic_state() == POLYMORPHIC; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 154 | } |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 159 | bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 160 | Handle<Object> value = GetInfo(expr->CallFeedbackId()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 161 | return value->IsMap() || value->IsSmi() || value->IsJSFunction(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 165 | bool TypeFeedbackOracle::CallNewIsMonomorphic(CallNew* expr) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 166 | Handle<Object> info = GetInfo(expr->CallNewFeedbackId()); |
| 167 | if (info->IsSmi()) { |
| 168 | ASSERT(static_cast<ElementsKind>(Smi::cast(*info)->value()) <= |
| 169 | LAST_FAST_ELEMENTS_KIND); |
| 170 | return Isolate::Current()->global_context()->array_function(); |
| 171 | } |
| 172 | return info->IsJSFunction(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 176 | bool TypeFeedbackOracle::ObjectLiteralStoreIsMonomorphic( |
| 177 | ObjectLiteral::Property* prop) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 178 | Handle<Object> map_or_code = GetInfo(prop->key()->LiteralFeedbackId()); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 179 | return map_or_code->IsMap(); |
| 180 | } |
| 181 | |
| 182 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 183 | bool TypeFeedbackOracle::IsForInFastCase(ForInStatement* stmt) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 184 | Handle<Object> value = GetInfo(stmt->ForInFeedbackId()); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 185 | return value->IsSmi() && |
| 186 | Smi::cast(*value)->value() == TypeFeedbackCells::kForInFastCaseMarker; |
| 187 | } |
| 188 | |
| 189 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 190 | Handle<Map> TypeFeedbackOracle::LoadMonomorphicReceiverType(Property* expr) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 191 | ASSERT(LoadIsMonomorphicNormal(expr)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 192 | Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 193 | if (map_or_code->IsCode()) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 194 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
| 195 | Map* first_map = code->FindFirstMap(); |
| 196 | ASSERT(first_map != NULL); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 197 | return CanRetainOtherContext(first_map, *native_context_) |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 198 | ? Handle<Map>::null() |
| 199 | : Handle<Map>(first_map); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 200 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 201 | return Handle<Map>::cast(map_or_code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 205 | Handle<Map> TypeFeedbackOracle::StoreMonomorphicReceiverType( |
| 206 | TypeFeedbackId ast_id) { |
| 207 | ASSERT(StoreIsMonomorphicNormal(ast_id)); |
| 208 | Handle<Object> map_or_code = GetInfo(ast_id); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 209 | if (map_or_code->IsCode()) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 210 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 211 | Map* first_map = code->FindFirstMap(); |
| 212 | ASSERT(first_map != NULL); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 213 | return CanRetainOtherContext(first_map, *native_context_) |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 214 | ? Handle<Map>::null() |
| 215 | : Handle<Map>(first_map); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 216 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 217 | return Handle<Map>::cast(map_or_code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 221 | void TypeFeedbackOracle::LoadReceiverTypes(Property* expr, |
| 222 | Handle<String> name, |
| 223 | SmallMapList* types) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 224 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 225 | CollectReceiverTypes(expr->PropertyFeedbackId(), name, flags, types); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 229 | void TypeFeedbackOracle::StoreReceiverTypes(Assignment* expr, |
| 230 | Handle<String> name, |
| 231 | SmallMapList* types) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 232 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 233 | CollectReceiverTypes(expr->AssignmentFeedbackId(), name, flags, types); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 237 | void TypeFeedbackOracle::CallReceiverTypes(Call* expr, |
| 238 | Handle<String> name, |
| 239 | CallKind call_kind, |
| 240 | SmallMapList* types) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 241 | int arity = expr->arguments()->length(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 242 | |
| 243 | // Note: Currently we do not take string extra ic data into account |
| 244 | // here. |
| 245 | Code::ExtraICState extra_ic_state = |
| 246 | CallIC::Contextual::encode(call_kind == CALL_AS_FUNCTION); |
| 247 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 248 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::CALL_IC, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 249 | extra_ic_state, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 250 | Code::NORMAL, |
| 251 | arity, |
| 252 | OWN_MAP); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 253 | CollectReceiverTypes(expr->CallFeedbackId(), name, flags, types); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 257 | CheckType TypeFeedbackOracle::GetCallCheckType(Call* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 258 | Handle<Object> value = GetInfo(expr->CallFeedbackId()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 259 | if (!value->IsSmi()) return RECEIVER_MAP_CHECK; |
| 260 | CheckType check = static_cast<CheckType>(Smi::cast(*value)->value()); |
| 261 | ASSERT(check != RECEIVER_MAP_CHECK); |
| 262 | return check; |
| 263 | } |
| 264 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 265 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 266 | Handle<JSObject> TypeFeedbackOracle::GetPrototypeForPrimitiveCheck( |
| 267 | CheckType check) { |
| 268 | JSFunction* function = NULL; |
| 269 | switch (check) { |
| 270 | case RECEIVER_MAP_CHECK: |
| 271 | UNREACHABLE(); |
| 272 | break; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 273 | case SYMBOL_CHECK: |
| 274 | return Handle<JSObject>(native_context_->symbol_delegate()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 275 | case STRING_CHECK: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 276 | function = native_context_->string_function(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 277 | break; |
| 278 | case NUMBER_CHECK: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 279 | function = native_context_->number_function(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 280 | break; |
| 281 | case BOOLEAN_CHECK: |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 282 | function = native_context_->boolean_function(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 283 | break; |
| 284 | } |
| 285 | ASSERT(function != NULL); |
| 286 | return Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 287 | } |
| 288 | |
| 289 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 290 | Handle<JSFunction> TypeFeedbackOracle::GetCallTarget(Call* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 291 | return Handle<JSFunction>::cast(GetInfo(expr->CallFeedbackId())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 295 | Handle<JSFunction> TypeFeedbackOracle::GetCallNewTarget(CallNew* expr) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 296 | Handle<Object> info = GetInfo(expr->CallNewFeedbackId()); |
| 297 | if (info->IsSmi()) { |
| 298 | ASSERT(static_cast<ElementsKind>(Smi::cast(*info)->value()) <= |
| 299 | LAST_FAST_ELEMENTS_KIND); |
| 300 | return Handle<JSFunction>(Isolate::Current()->global_context()-> |
| 301 | array_function()); |
| 302 | } else { |
| 303 | return Handle<JSFunction>::cast(info); |
| 304 | } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 308 | ElementsKind TypeFeedbackOracle::GetCallNewElementsKind(CallNew* expr) { |
| 309 | Handle<Object> info = GetInfo(expr->CallNewFeedbackId()); |
| 310 | if (info->IsSmi()) { |
| 311 | return static_cast<ElementsKind>(Smi::cast(*info)->value()); |
| 312 | } else { |
| 313 | // TODO(mvstanton): avoided calling GetInitialFastElementsKind() for perf |
| 314 | // reasons. Is there a better fix? |
| 315 | if (FLAG_packed_arrays) { |
| 316 | return FAST_SMI_ELEMENTS; |
| 317 | } else { |
| 318 | return FAST_HOLEY_SMI_ELEMENTS; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 323 | Handle<Map> TypeFeedbackOracle::GetObjectLiteralStoreMap( |
| 324 | ObjectLiteral::Property* prop) { |
| 325 | ASSERT(ObjectLiteralStoreIsMonomorphic(prop)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 326 | return Handle<Map>::cast(GetInfo(prop->key()->LiteralFeedbackId())); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 330 | bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 331 | return *GetInfo(expr->PropertyFeedbackId()) == |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 332 | isolate_->builtins()->builtin(id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 336 | bool TypeFeedbackOracle::LoadIsStub(Property* expr, ICStub* stub) { |
| 337 | Handle<Object> object = GetInfo(expr->PropertyFeedbackId()); |
| 338 | if (!object->IsCode()) return false; |
| 339 | Handle<Code> code = Handle<Code>::cast(object); |
| 340 | if (!code->is_load_stub()) return false; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 341 | if (code->ic_state() != MONOMORPHIC) return false; |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 342 | return stub->Describes(*code); |
| 343 | } |
| 344 | |
| 345 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 346 | static TypeInfo TypeFromCompareType(CompareIC::State state) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 347 | switch (state) { |
| 348 | case CompareIC::UNINITIALIZED: |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 349 | // Uninitialized means never executed. |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 350 | return TypeInfo::Uninitialized(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 351 | case CompareIC::SMI: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 352 | return TypeInfo::Smi(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 353 | case CompareIC::NUMBER: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 354 | return TypeInfo::Number(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 355 | case CompareIC::INTERNALIZED_STRING: |
| 356 | return TypeInfo::InternalizedString(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 357 | case CompareIC::STRING: |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 358 | return TypeInfo::String(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 359 | case CompareIC::OBJECT: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 360 | case CompareIC::KNOWN_OBJECT: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 361 | // TODO(kasperl): We really need a type for JS objects here. |
| 362 | return TypeInfo::NonPrimitive(); |
| 363 | case CompareIC::GENERIC: |
| 364 | default: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 365 | return TypeInfo::Unknown(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
| 369 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 370 | void TypeFeedbackOracle::CompareType(CompareOperation* expr, |
| 371 | TypeInfo* left_type, |
| 372 | TypeInfo* right_type, |
| 373 | TypeInfo* overall_type) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 374 | Handle<Object> object = GetInfo(expr->CompareOperationFeedbackId()); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 375 | TypeInfo unknown = TypeInfo::Unknown(); |
| 376 | if (!object->IsCode()) { |
| 377 | *left_type = *right_type = *overall_type = unknown; |
| 378 | return; |
| 379 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 380 | Handle<Code> code = Handle<Code>::cast(object); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 381 | if (!code->is_compare_ic_stub()) { |
| 382 | *left_type = *right_type = *overall_type = unknown; |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | int stub_minor_key = code->stub_info(); |
| 387 | CompareIC::State left_state, right_state, handler_state; |
| 388 | ICCompareStub::DecodeMinorKey(stub_minor_key, &left_state, &right_state, |
| 389 | &handler_state, NULL); |
| 390 | *left_type = TypeFromCompareType(left_state); |
| 391 | *right_type = TypeFromCompareType(right_state); |
| 392 | *overall_type = TypeFromCompareType(handler_state); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 396 | Handle<Map> TypeFeedbackOracle::GetCompareMap(CompareOperation* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 397 | Handle<Object> object = GetInfo(expr->CompareOperationFeedbackId()); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 398 | if (!object->IsCode()) return Handle<Map>::null(); |
| 399 | Handle<Code> code = Handle<Code>::cast(object); |
| 400 | if (!code->is_compare_ic_stub()) return Handle<Map>::null(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 401 | CompareIC::State state = ICCompareStub::CompareState(code->stub_info()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 402 | if (state != CompareIC::KNOWN_OBJECT) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 403 | return Handle<Map>::null(); |
| 404 | } |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 405 | Map* first_map = code->FindFirstMap(); |
| 406 | ASSERT(first_map != NULL); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 407 | return CanRetainOtherContext(first_map, *native_context_) |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 408 | ? Handle<Map>::null() |
| 409 | : Handle<Map>(first_map); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 413 | TypeInfo TypeFeedbackOracle::UnaryType(UnaryOperation* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 414 | Handle<Object> object = GetInfo(expr->UnaryOperationFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 415 | TypeInfo unknown = TypeInfo::Unknown(); |
| 416 | if (!object->IsCode()) return unknown; |
| 417 | Handle<Code> code = Handle<Code>::cast(object); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 418 | ASSERT(code->is_unary_op_stub()); |
| 419 | UnaryOpIC::TypeInfo type = static_cast<UnaryOpIC::TypeInfo>( |
| 420 | code->unary_op_type()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 421 | switch (type) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 422 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 423 | return TypeInfo::Smi(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 424 | case UnaryOpIC::NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 425 | return TypeInfo::Double(); |
| 426 | default: |
| 427 | return unknown; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 432 | static TypeInfo TypeFromBinaryOpType(BinaryOpIC::TypeInfo binary_type) { |
| 433 | switch (binary_type) { |
| 434 | // Uninitialized means never executed. |
| 435 | case BinaryOpIC::UNINITIALIZED: return TypeInfo::Uninitialized(); |
| 436 | case BinaryOpIC::SMI: return TypeInfo::Smi(); |
| 437 | case BinaryOpIC::INT32: return TypeInfo::Integer32(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 438 | case BinaryOpIC::NUMBER: return TypeInfo::Double(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 439 | case BinaryOpIC::ODDBALL: return TypeInfo::Unknown(); |
| 440 | case BinaryOpIC::STRING: return TypeInfo::String(); |
| 441 | case BinaryOpIC::GENERIC: return TypeInfo::Unknown(); |
| 442 | } |
| 443 | UNREACHABLE(); |
| 444 | return TypeInfo::Unknown(); |
| 445 | } |
| 446 | |
| 447 | |
| 448 | void TypeFeedbackOracle::BinaryType(BinaryOperation* expr, |
| 449 | TypeInfo* left, |
| 450 | TypeInfo* right, |
| 451 | TypeInfo* result) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 452 | Handle<Object> object = GetInfo(expr->BinaryOperationFeedbackId()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 453 | TypeInfo unknown = TypeInfo::Unknown(); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 454 | if (!object->IsCode()) { |
| 455 | *left = *right = *result = unknown; |
| 456 | return; |
| 457 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 458 | Handle<Code> code = Handle<Code>::cast(object); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 459 | if (code->is_binary_op_stub()) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 460 | BinaryOpIC::TypeInfo left_type, right_type, result_type; |
| 461 | BinaryOpStub::decode_types_from_minor_key(code->stub_info(), &left_type, |
| 462 | &right_type, &result_type); |
| 463 | *left = TypeFromBinaryOpType(left_type); |
| 464 | *right = TypeFromBinaryOpType(right_type); |
| 465 | *result = TypeFromBinaryOpType(result_type); |
| 466 | return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 467 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 468 | // Not a binary op stub. |
| 469 | *left = *right = *result = unknown; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 470 | } |
| 471 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 472 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 473 | TypeInfo TypeFeedbackOracle::SwitchType(CaseClause* clause) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 474 | Handle<Object> object = GetInfo(clause->CompareId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 475 | TypeInfo unknown = TypeInfo::Unknown(); |
| 476 | if (!object->IsCode()) return unknown; |
| 477 | Handle<Code> code = Handle<Code>::cast(object); |
| 478 | if (!code->is_compare_ic_stub()) return unknown; |
| 479 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 480 | CompareIC::State state = ICCompareStub::CompareState(code->stub_info()); |
| 481 | return TypeFromCompareType(state); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 485 | TypeInfo TypeFeedbackOracle::IncrementType(CountOperation* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 486 | Handle<Object> object = GetInfo(expr->CountBinOpFeedbackId()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 487 | TypeInfo unknown = TypeInfo::Unknown(); |
| 488 | if (!object->IsCode()) return unknown; |
| 489 | Handle<Code> code = Handle<Code>::cast(object); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 490 | if (!code->is_binary_op_stub()) return unknown; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 491 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 492 | BinaryOpIC::TypeInfo left_type, right_type, unused_result_type; |
| 493 | BinaryOpStub::decode_types_from_minor_key(code->stub_info(), &left_type, |
| 494 | &right_type, &unused_result_type); |
| 495 | // CountOperations should always have +1 or -1 as their right input. |
| 496 | ASSERT(right_type == BinaryOpIC::SMI || |
| 497 | right_type == BinaryOpIC::UNINITIALIZED); |
| 498 | |
| 499 | switch (left_type) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 500 | case BinaryOpIC::UNINITIALIZED: |
| 501 | case BinaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 502 | return TypeInfo::Smi(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 503 | case BinaryOpIC::INT32: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 504 | return TypeInfo::Integer32(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 505 | case BinaryOpIC::NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 506 | return TypeInfo::Double(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 507 | case BinaryOpIC::STRING: |
| 508 | case BinaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 509 | return unknown; |
| 510 | default: |
| 511 | return unknown; |
| 512 | } |
| 513 | UNREACHABLE(); |
| 514 | return unknown; |
| 515 | } |
| 516 | |
| 517 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 518 | static void AddMapIfMissing(Handle<Map> map, SmallMapList* list, |
| 519 | Zone* zone) { |
| 520 | for (int i = 0; i < list->length(); ++i) { |
| 521 | if (list->at(i).is_identical_to(map)) return; |
| 522 | } |
| 523 | list->Add(map, zone); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | void TypeFeedbackOracle::CollectPolymorphicMaps(Handle<Code> code, |
| 528 | SmallMapList* types) { |
| 529 | MapHandleList maps; |
| 530 | code->FindAllMaps(&maps); |
| 531 | types->Reserve(maps.length(), zone()); |
| 532 | for (int i = 0; i < maps.length(); i++) { |
| 533 | Handle<Map> map(maps.at(i)); |
| 534 | if (!CanRetainOtherContext(*map, *native_context_)) { |
| 535 | AddMapIfMissing(map, types, zone()); |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 541 | void TypeFeedbackOracle::CollectReceiverTypes(TypeFeedbackId ast_id, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 542 | Handle<String> name, |
| 543 | Code::Flags flags, |
| 544 | SmallMapList* types) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 545 | Handle<Object> object = GetInfo(ast_id); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 546 | if (object->IsUndefined() || object->IsSmi()) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 547 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 548 | if (object.is_identical_to(isolate_->builtins()->StoreIC_GlobalProxy())) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 549 | // TODO(fschneider): We could collect the maps and signal that |
| 550 | // we need a generic store (or load) here. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 551 | ASSERT(Handle<Code>::cast(object)->ic_state() == GENERIC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 552 | } else if (object->IsMap()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 553 | types->Add(Handle<Map>::cast(object), zone()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 554 | } else if (Handle<Code>::cast(object)->ic_state() == POLYMORPHIC) { |
| 555 | CollectPolymorphicMaps(Handle<Code>::cast(object), types); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 556 | } else if (FLAG_collect_megamorphic_maps_from_stub_cache && |
| 557 | Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 558 | types->Reserve(4, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 559 | ASSERT(object->IsCode()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 560 | isolate_->stub_cache()->CollectMatchingMaps(types, |
| 561 | *name, |
| 562 | flags, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 563 | native_context_, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 564 | zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 569 | // Check if a map originates from a given native context. We use this |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 570 | // information to filter out maps from different context to avoid |
| 571 | // retaining objects from different tabs in Chrome via optimized code. |
| 572 | bool TypeFeedbackOracle::CanRetainOtherContext(Map* map, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 573 | Context* native_context) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 574 | Object* constructor = NULL; |
| 575 | while (!map->prototype()->IsNull()) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 576 | constructor = map->constructor(); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 577 | if (!constructor->IsNull()) { |
| 578 | // If the constructor is not null or a JSFunction, we have to |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 579 | // conservatively assume that it may retain a native context. |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 580 | if (!constructor->IsJSFunction()) return true; |
| 581 | // Check if the constructor directly references a foreign context. |
| 582 | if (CanRetainOtherContext(JSFunction::cast(constructor), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 583 | native_context)) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 584 | return true; |
| 585 | } |
| 586 | } |
| 587 | map = HeapObject::cast(map->prototype())->map(); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 588 | } |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 589 | constructor = map->constructor(); |
| 590 | if (constructor->IsNull()) return false; |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 591 | JSFunction* function = JSFunction::cast(constructor); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 592 | return CanRetainOtherContext(function, native_context); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | |
| 596 | bool TypeFeedbackOracle::CanRetainOtherContext(JSFunction* function, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 597 | Context* native_context) { |
| 598 | return function->context()->global_object() != native_context->global_object() |
| 599 | && function->context()->global_object() != native_context->builtins(); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 603 | void TypeFeedbackOracle::CollectKeyedReceiverTypes(TypeFeedbackId ast_id, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 604 | SmallMapList* types) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 605 | Handle<Object> object = GetInfo(ast_id); |
| 606 | if (!object->IsCode()) return; |
| 607 | Handle<Code> code = Handle<Code>::cast(object); |
| 608 | if (code->kind() == Code::KEYED_LOAD_IC || |
| 609 | code->kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 610 | CollectPolymorphicMaps(code, types); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | |
| 614 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 615 | byte TypeFeedbackOracle::ToBooleanTypes(TypeFeedbackId ast_id) { |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 616 | Handle<Object> object = GetInfo(ast_id); |
| 617 | return object->IsCode() ? Handle<Code>::cast(object)->to_boolean_state() : 0; |
| 618 | } |
| 619 | |
| 620 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 621 | // Things are a bit tricky here: The iterator for the RelocInfos and the infos |
| 622 | // themselves are not GC-safe, so we first get all infos, then we create the |
| 623 | // dictionary (possibly triggering GC), and finally we relocate the collected |
| 624 | // infos before we process them. |
| 625 | void TypeFeedbackOracle::BuildDictionary(Handle<Code> code) { |
| 626 | AssertNoAllocation no_allocation; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 627 | ZoneList<RelocInfo> infos(16, zone()); |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 628 | HandleScope scope(code->GetIsolate()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 629 | GetRelocInfos(code, &infos); |
| 630 | CreateDictionary(code, &infos); |
| 631 | ProcessRelocInfos(&infos); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 632 | ProcessTypeFeedbackCells(code); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 633 | // Allocate handle in the parent scope. |
| 634 | dictionary_ = scope.CloseAndEscape(dictionary_); |
| 635 | } |
| 636 | |
| 637 | |
| 638 | void TypeFeedbackOracle::GetRelocInfos(Handle<Code> code, |
| 639 | ZoneList<RelocInfo>* infos) { |
| 640 | int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); |
| 641 | for (RelocIterator it(*code, mask); !it.done(); it.next()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 642 | infos->Add(*it.rinfo(), zone()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
| 646 | |
| 647 | void TypeFeedbackOracle::CreateDictionary(Handle<Code> code, |
| 648 | ZoneList<RelocInfo>* infos) { |
| 649 | DisableAssertNoAllocation allocation_allowed; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 650 | int cell_count = code->type_feedback_info()->IsTypeFeedbackInfo() |
| 651 | ? TypeFeedbackInfo::cast(code->type_feedback_info())-> |
| 652 | type_feedback_cells()->CellCount() |
| 653 | : 0; |
| 654 | int length = infos->length() + cell_count; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 655 | byte* old_start = code->instruction_start(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 656 | dictionary_ = FACTORY->NewUnseededNumberDictionary(length); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 657 | byte* new_start = code->instruction_start(); |
| 658 | RelocateRelocInfos(infos, old_start, new_start); |
| 659 | } |
| 660 | |
| 661 | |
| 662 | void TypeFeedbackOracle::RelocateRelocInfos(ZoneList<RelocInfo>* infos, |
| 663 | byte* old_start, |
| 664 | byte* new_start) { |
| 665 | for (int i = 0; i < infos->length(); i++) { |
| 666 | RelocInfo* info = &(*infos)[i]; |
| 667 | info->set_pc(new_start + (info->pc() - old_start)); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | |
| 672 | void TypeFeedbackOracle::ProcessRelocInfos(ZoneList<RelocInfo>* infos) { |
| 673 | for (int i = 0; i < infos->length(); i++) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 674 | RelocInfo reloc_entry = (*infos)[i]; |
| 675 | Address target_address = reloc_entry.target_address(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 676 | TypeFeedbackId ast_id = |
| 677 | TypeFeedbackId(static_cast<unsigned>((*infos)[i].data())); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 678 | Code* target = Code::GetCodeFromTargetAddress(target_address); |
| 679 | switch (target->kind()) { |
| 680 | case Code::LOAD_IC: |
| 681 | case Code::STORE_IC: |
| 682 | case Code::CALL_IC: |
| 683 | case Code::KEYED_CALL_IC: |
| 684 | if (target->ic_state() == MONOMORPHIC) { |
| 685 | if (target->kind() == Code::CALL_IC && |
| 686 | target->check_type() != RECEIVER_MAP_CHECK) { |
| 687 | SetInfo(ast_id, Smi::FromInt(target->check_type())); |
| 688 | } else { |
| 689 | Object* map = target->FindFirstMap(); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 690 | if (map == NULL) { |
| 691 | SetInfo(ast_id, static_cast<Object*>(target)); |
| 692 | } else if (!CanRetainOtherContext(Map::cast(map), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 693 | *native_context_)) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 694 | SetInfo(ast_id, map); |
| 695 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 696 | } |
jkummerow@chromium.org | 531dfe8 | 2012-03-20 13:01:16 +0000 | [diff] [blame] | 697 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 698 | SetInfo(ast_id, target); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 699 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 700 | break; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 701 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 702 | case Code::KEYED_LOAD_IC: |
| 703 | case Code::KEYED_STORE_IC: |
| 704 | if (target->ic_state() == MONOMORPHIC || |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 705 | target->ic_state() == POLYMORPHIC) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 706 | SetInfo(ast_id, target); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 707 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 708 | break; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 709 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 710 | case Code::UNARY_OP_IC: |
| 711 | case Code::BINARY_OP_IC: |
| 712 | case Code::COMPARE_IC: |
| 713 | case Code::TO_BOOLEAN_IC: |
| 714 | SetInfo(ast_id, target); |
| 715 | break; |
| 716 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 717 | default: |
| 718 | break; |
| 719 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 724 | void TypeFeedbackOracle::ProcessTypeFeedbackCells(Handle<Code> code) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 725 | Object* raw_info = code->type_feedback_info(); |
| 726 | if (!raw_info->IsTypeFeedbackInfo()) return; |
| 727 | Handle<TypeFeedbackCells> cache( |
| 728 | TypeFeedbackInfo::cast(raw_info)->type_feedback_cells()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 729 | for (int i = 0; i < cache->CellCount(); i++) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 730 | TypeFeedbackId ast_id = cache->AstId(i); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 731 | Object* value = cache->Cell(i)->value(); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 732 | if (value->IsSmi() || |
| 733 | (value->IsJSFunction() && |
| 734 | !CanRetainOtherContext(JSFunction::cast(value), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 735 | *native_context_))) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 736 | SetInfo(ast_id, value); |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 742 | void TypeFeedbackOracle::SetInfo(TypeFeedbackId ast_id, Object* target) { |
| 743 | ASSERT(dictionary_->FindEntry(IdToKey(ast_id)) == |
| 744 | UnseededNumberDictionary::kNotFound); |
| 745 | MaybeObject* maybe_result = dictionary_->AtNumberPut(IdToKey(ast_id), target); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 746 | USE(maybe_result); |
| 747 | #ifdef DEBUG |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 748 | Object* result = NULL; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 749 | // Dictionary has been allocated with sufficient size for all elements. |
| 750 | ASSERT(maybe_result->ToObject(&result)); |
| 751 | ASSERT(*dictionary_ == result); |
| 752 | #endif |
| 753 | } |
| 754 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 755 | } } // namespace v8::internal |