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 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 45 | TypeInfo TypeInfo::FromValue(Handle<Object> value) { |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 46 | if (value->IsSmi()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 47 | return TypeInfo::Smi(); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 48 | } else if (value->IsHeapNumber()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 49 | return TypeInfo::IsInt32Double(HeapNumber::cast(*value)->value()) |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 50 | ? TypeInfo::Integer32() |
| 51 | : TypeInfo::Double(); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 52 | } else if (value->IsString()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 53 | return TypeInfo::String(); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 54 | } |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 55 | return TypeInfo::Unknown(); |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 59 | TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 60 | Handle<Context> native_context, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 61 | Isolate* isolate, |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 62 | Zone* zone) |
| 63 | : native_context_(native_context), |
| 64 | isolate_(isolate), |
| 65 | zone_(zone) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 66 | BuildDictionary(code); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 67 | ASSERT(dictionary_->IsDictionary()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 71 | static uint32_t IdToKey(TypeFeedbackId ast_id) { |
| 72 | return static_cast<uint32_t>(ast_id.ToInt()); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | Handle<Object> TypeFeedbackOracle::GetInfo(TypeFeedbackId ast_id) { |
| 77 | int entry = dictionary_->FindEntry(IdToKey(ast_id)); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 78 | if (entry != UnseededNumberDictionary::kNotFound) { |
| 79 | Object* value = dictionary_->ValueAt(entry); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 80 | if (value->IsCell()) { |
| 81 | Cell* cell = Cell::cast(value); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 82 | return Handle<Object>(cell->value(), isolate_); |
| 83 | } else { |
| 84 | return Handle<Object>(value, isolate_); |
| 85 | } |
| 86 | } |
| 87 | return Handle<Object>::cast(isolate_->factory()->undefined_value()); |
| 88 | } |
| 89 | |
| 90 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 91 | Handle<Cell> TypeFeedbackOracle::GetInfoCell( |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 92 | TypeFeedbackId ast_id) { |
| 93 | int entry = dictionary_->FindEntry(IdToKey(ast_id)); |
| 94 | if (entry != UnseededNumberDictionary::kNotFound) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 95 | Cell* cell = Cell::cast(dictionary_->ValueAt(entry)); |
| 96 | return Handle<Cell>(cell, isolate_); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 97 | } |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 98 | return Handle<Cell>::null(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
jkummerow@chromium.org | 531dfe8 | 2012-03-20 13:01:16 +0000 | [diff] [blame] | 102 | bool TypeFeedbackOracle::LoadIsUninitialized(Property* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 103 | Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId()); |
jkummerow@chromium.org | 531dfe8 | 2012-03-20 13:01:16 +0000 | [diff] [blame] | 104 | if (map_or_code->IsMap()) return false; |
| 105 | if (map_or_code->IsCode()) { |
| 106 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
| 107 | return code->is_inline_cache_stub() && code->ic_state() == UNINITIALIZED; |
| 108 | } |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 113 | bool TypeFeedbackOracle::LoadIsMonomorphicNormal(Property* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 114 | Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 115 | if (map_or_code->IsMap()) return true; |
| 116 | if (map_or_code->IsCode()) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 117 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 118 | bool preliminary_checks = code->is_keyed_load_stub() && |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 119 | code->ic_state() == MONOMORPHIC && |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 120 | Code::ExtractTypeFromFlags(code->flags()) == Code::NORMAL; |
| 121 | if (!preliminary_checks) return false; |
| 122 | Map* map = code->FindFirstMap(); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 123 | if (map == NULL) return false; |
| 124 | map = map->CurrentMapForDeprecated(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 125 | return map != NULL && !CanRetainOtherContext(map, *native_context_); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 126 | } |
| 127 | return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 131 | bool TypeFeedbackOracle::LoadIsPolymorphic(Property* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 132 | Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 133 | if (map_or_code->IsCode()) { |
| 134 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 135 | return code->is_keyed_load_stub() && code->ic_state() == POLYMORPHIC; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 136 | } |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 141 | bool TypeFeedbackOracle::StoreIsUninitialized(TypeFeedbackId ast_id) { |
| 142 | Handle<Object> map_or_code = GetInfo(ast_id); |
| 143 | if (map_or_code->IsMap()) return false; |
| 144 | if (!map_or_code->IsCode()) return true; |
| 145 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
| 146 | return code->ic_state() == UNINITIALIZED; |
| 147 | } |
| 148 | |
| 149 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 150 | bool TypeFeedbackOracle::StoreIsMonomorphicNormal(TypeFeedbackId ast_id) { |
| 151 | Handle<Object> map_or_code = GetInfo(ast_id); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 152 | if (map_or_code->IsMap()) return true; |
| 153 | if (map_or_code->IsCode()) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 154 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 155 | bool standard_store = FLAG_compiled_keyed_stores || |
| 156 | (Code::GetKeyedAccessStoreMode(code->extra_ic_state()) == |
| 157 | STANDARD_STORE); |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 158 | bool preliminary_checks = |
| 159 | code->is_keyed_store_stub() && |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 160 | standard_store && |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 161 | code->ic_state() == MONOMORPHIC && |
erik.corry@gmail.com | 8876724 | 2012-08-08 14:43:45 +0000 | [diff] [blame] | 162 | Code::ExtractTypeFromFlags(code->flags()) == Code::NORMAL; |
| 163 | if (!preliminary_checks) return false; |
| 164 | Map* map = code->FindFirstMap(); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 165 | if (map == NULL) return false; |
| 166 | map = map->CurrentMapForDeprecated(); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 167 | return map != NULL && !CanRetainOtherContext(map, *native_context_); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 168 | } |
| 169 | return false; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 173 | bool TypeFeedbackOracle::StoreIsPolymorphic(TypeFeedbackId ast_id) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 174 | Handle<Object> map_or_code = GetInfo(ast_id); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 175 | if (map_or_code->IsCode()) { |
| 176 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 177 | bool standard_store = FLAG_compiled_keyed_stores || |
| 178 | (Code::GetKeyedAccessStoreMode(code->extra_ic_state()) == |
| 179 | STANDARD_STORE); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 180 | return code->is_keyed_store_stub() && standard_store && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 181 | code->ic_state() == POLYMORPHIC; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 182 | } |
| 183 | return false; |
| 184 | } |
| 185 | |
| 186 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 187 | bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 188 | Handle<Object> value = GetInfo(expr->CallFeedbackId()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 189 | return value->IsMap() || value->IsSmi() || value->IsJSFunction(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 193 | bool TypeFeedbackOracle::CallNewIsMonomorphic(CallNew* expr) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 194 | Handle<Object> info = GetInfo(expr->CallNewFeedbackId()); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 195 | return info->IsSmi() || info->IsJSFunction(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 199 | bool TypeFeedbackOracle::ObjectLiteralStoreIsMonomorphic( |
| 200 | ObjectLiteral::Property* prop) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 201 | Handle<Object> map_or_code = GetInfo(prop->key()->LiteralFeedbackId()); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 202 | return map_or_code->IsMap(); |
| 203 | } |
| 204 | |
| 205 | |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 206 | byte TypeFeedbackOracle::ForInType(ForInStatement* stmt) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 207 | Handle<Object> value = GetInfo(stmt->ForInFeedbackId()); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 208 | return value->IsSmi() && |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 209 | Smi::cast(*value)->value() == TypeFeedbackCells::kForInFastCaseMarker |
| 210 | ? ForInStatement::FAST_FOR_IN : ForInStatement::SLOW_FOR_IN; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 214 | Handle<Map> TypeFeedbackOracle::LoadMonomorphicReceiverType(Property* expr) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 215 | ASSERT(LoadIsMonomorphicNormal(expr)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 216 | Handle<Object> map_or_code = GetInfo(expr->PropertyFeedbackId()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 217 | if (map_or_code->IsCode()) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 218 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 219 | Map* map = code->FindFirstMap()->CurrentMapForDeprecated(); |
| 220 | return map == NULL || CanRetainOtherContext(map, *native_context_) |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 221 | ? Handle<Map>::null() |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 222 | : Handle<Map>(map); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 223 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 224 | return Handle<Map>::cast(map_or_code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 228 | Handle<Map> TypeFeedbackOracle::StoreMonomorphicReceiverType( |
| 229 | TypeFeedbackId ast_id) { |
| 230 | ASSERT(StoreIsMonomorphicNormal(ast_id)); |
| 231 | Handle<Object> map_or_code = GetInfo(ast_id); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 232 | if (map_or_code->IsCode()) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 233 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 234 | Map* map = code->FindFirstMap()->CurrentMapForDeprecated(); |
| 235 | return map == NULL || CanRetainOtherContext(map, *native_context_) |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 236 | ? Handle<Map>::null() |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 237 | : Handle<Map>(map); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 238 | } |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 239 | return Handle<Map>::cast(map_or_code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 243 | KeyedAccessStoreMode TypeFeedbackOracle::GetStoreMode( |
| 244 | TypeFeedbackId ast_id) { |
| 245 | Handle<Object> map_or_code = GetInfo(ast_id); |
| 246 | if (map_or_code->IsCode()) { |
| 247 | Handle<Code> code = Handle<Code>::cast(map_or_code); |
| 248 | if (code->kind() == Code::KEYED_STORE_IC) { |
| 249 | return Code::GetKeyedAccessStoreMode(code->extra_ic_state()); |
| 250 | } |
| 251 | } |
| 252 | return STANDARD_STORE; |
| 253 | } |
| 254 | |
| 255 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 256 | void TypeFeedbackOracle::LoadReceiverTypes(Property* expr, |
| 257 | Handle<String> name, |
| 258 | SmallMapList* types) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 259 | Code::Flags flags = Code::ComputeFlags( |
| 260 | Code::STUB, MONOMORPHIC, Code::kNoExtraICState, |
| 261 | Code::NORMAL, Code::LOAD_IC); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 262 | CollectReceiverTypes(expr->PropertyFeedbackId(), name, flags, types); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 266 | void TypeFeedbackOracle::StoreReceiverTypes(Assignment* expr, |
| 267 | Handle<String> name, |
| 268 | SmallMapList* types) { |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 269 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 270 | CollectReceiverTypes(expr->AssignmentFeedbackId(), name, flags, types); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 274 | void TypeFeedbackOracle::CallReceiverTypes(Call* expr, |
| 275 | Handle<String> name, |
| 276 | CallKind call_kind, |
| 277 | SmallMapList* types) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 278 | int arity = expr->arguments()->length(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 279 | |
| 280 | // Note: Currently we do not take string extra ic data into account |
| 281 | // here. |
| 282 | Code::ExtraICState extra_ic_state = |
| 283 | CallIC::Contextual::encode(call_kind == CALL_AS_FUNCTION); |
| 284 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 285 | Code::Flags flags = Code::ComputeMonomorphicFlags(Code::CALL_IC, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 286 | extra_ic_state, |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 287 | Code::NORMAL, |
| 288 | arity, |
| 289 | OWN_MAP); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 290 | CollectReceiverTypes(expr->CallFeedbackId(), name, flags, types); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 294 | CheckType TypeFeedbackOracle::GetCallCheckType(Call* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 295 | Handle<Object> value = GetInfo(expr->CallFeedbackId()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 296 | if (!value->IsSmi()) return RECEIVER_MAP_CHECK; |
| 297 | CheckType check = static_cast<CheckType>(Smi::cast(*value)->value()); |
| 298 | ASSERT(check != RECEIVER_MAP_CHECK); |
| 299 | return check; |
| 300 | } |
| 301 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 302 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 303 | Handle<JSFunction> TypeFeedbackOracle::GetCallTarget(Call* expr) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 304 | Handle<Object> info = GetInfo(expr->CallFeedbackId()); |
| 305 | if (info->IsSmi()) { |
| 306 | ASSERT(static_cast<ElementsKind>(Smi::cast(*info)->value()) <= |
| 307 | LAST_FAST_ELEMENTS_KIND); |
| 308 | return Handle<JSFunction>(isolate_->global_context()->array_function()); |
| 309 | } else { |
| 310 | return Handle<JSFunction>::cast(info); |
| 311 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 315 | Handle<JSFunction> TypeFeedbackOracle::GetCallNewTarget(CallNew* expr) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 316 | Handle<Object> info = GetInfo(expr->CallNewFeedbackId()); |
| 317 | if (info->IsSmi()) { |
| 318 | ASSERT(static_cast<ElementsKind>(Smi::cast(*info)->value()) <= |
| 319 | LAST_FAST_ELEMENTS_KIND); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 320 | return Handle<JSFunction>(isolate_->global_context()->array_function()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 321 | } else { |
| 322 | return Handle<JSFunction>::cast(info); |
| 323 | } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 327 | Handle<Cell> TypeFeedbackOracle::GetCallNewAllocationInfoCell(CallNew* expr) { |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 328 | return GetInfoCell(expr->CallNewFeedbackId()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 329 | } |
| 330 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 331 | |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 332 | Handle<Map> TypeFeedbackOracle::GetObjectLiteralStoreMap( |
| 333 | ObjectLiteral::Property* prop) { |
| 334 | ASSERT(ObjectLiteralStoreIsMonomorphic(prop)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 335 | return Handle<Map>::cast(GetInfo(prop->key()->LiteralFeedbackId())); |
mstarzinger@chromium.org | 3233d2f | 2012-03-14 11:16:03 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 339 | bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 340 | return *GetInfo(expr->PropertyFeedbackId()) == |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 341 | isolate_->builtins()->builtin(id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 345 | bool TypeFeedbackOracle::LoadIsStub(Property* expr, ICStub* stub) { |
| 346 | Handle<Object> object = GetInfo(expr->PropertyFeedbackId()); |
| 347 | if (!object->IsCode()) return false; |
| 348 | Handle<Code> code = Handle<Code>::cast(object); |
| 349 | if (!code->is_load_stub()) return false; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 350 | if (code->ic_state() != MONOMORPHIC) return false; |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 351 | return stub->Describes(*code); |
| 352 | } |
| 353 | |
| 354 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 355 | void TypeFeedbackOracle::CompareType(TypeFeedbackId id, |
| 356 | Handle<Type>* left_type, |
| 357 | Handle<Type>* right_type, |
| 358 | Handle<Type>* combined_type) { |
| 359 | *left_type = *right_type = *combined_type = handle(Type::Any(), isolate_); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 360 | Handle<Object> info = GetInfo(id); |
| 361 | if (!info->IsCode()) return; |
| 362 | Handle<Code> code = Handle<Code>::cast(info); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 363 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 364 | Handle<Map> map; |
| 365 | Map* raw_map = code->FindFirstMap(); |
| 366 | if (raw_map != NULL) { |
| 367 | raw_map = raw_map->CurrentMapForDeprecated(); |
jkummerow@chromium.org | efe19a9 | 2013-06-14 16:54:00 +0000 | [diff] [blame] | 368 | if (raw_map != NULL && !CanRetainOtherContext(raw_map, *native_context_)) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 369 | map = handle(raw_map, isolate_); |
| 370 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 371 | } |
| 372 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 373 | if (code->is_compare_ic_stub()) { |
| 374 | int stub_minor_key = code->stub_info(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 375 | CompareIC::StubInfoToType( |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 376 | stub_minor_key, left_type, right_type, combined_type, map, isolate()); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 377 | } else if (code->is_compare_nil_ic_stub()) { |
| 378 | CompareNilICStub::State state(code->compare_nil_state()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 379 | *combined_type = CompareNilICStub::StateToType(isolate_, state, map); |
| 380 | Handle<Type> nil_type = handle(code->compare_nil_value() == kNullValue |
| 381 | ? Type::Null() : Type::Undefined(), isolate_); |
| 382 | *left_type = *right_type = |
| 383 | handle(Type::Union(*combined_type, nil_type), isolate_); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 384 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 388 | Handle<Type> TypeFeedbackOracle::UnaryType(TypeFeedbackId id) { |
| 389 | Handle<Object> object = GetInfo(id); |
| 390 | if (!object->IsCode()) return handle(Type::Any(), isolate()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 391 | Handle<Code> code = Handle<Code>::cast(object); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 392 | ASSERT(code->is_unary_op_stub()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 393 | return UnaryOpIC::TypeInfoToType( |
| 394 | static_cast<UnaryOpIC::TypeInfo>(code->unary_op_type()), isolate()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 398 | void TypeFeedbackOracle::BinaryType(TypeFeedbackId id, |
| 399 | Handle<Type>* left, |
| 400 | Handle<Type>* right, |
| 401 | Handle<Type>* result, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 402 | Maybe<int>* fixed_right_arg) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 403 | Handle<Object> object = GetInfo(id); |
| 404 | *left = *right = *result = handle(Type::Any(), isolate_); |
| 405 | if (!object->IsCode()) return; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 406 | Handle<Code> code = Handle<Code>::cast(object); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 407 | if (!code->is_binary_op_stub()) return; |
| 408 | |
| 409 | int minor_key = code->stub_info(); |
| 410 | BinaryOpIC::StubInfoToType(minor_key, left, right, result, isolate()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame^] | 411 | *fixed_right_arg = |
| 412 | BinaryOpStub::decode_fixed_right_arg_from_minor_key(minor_key); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 413 | } |
| 414 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 415 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 416 | Handle<Type> TypeFeedbackOracle::ClauseType(TypeFeedbackId id) { |
| 417 | Handle<Object> info = GetInfo(id); |
| 418 | Handle<Type> result(Type::None(), isolate_); |
| 419 | if (info->IsCode() && Handle<Code>::cast(info)->is_compare_ic_stub()) { |
| 420 | Handle<Code> code = Handle<Code>::cast(info); |
| 421 | CompareIC::State state = ICCompareStub::CompareState(code->stub_info()); |
| 422 | result = CompareIC::StateToType(isolate_, state); |
| 423 | } |
| 424 | return result; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 428 | TypeInfo TypeFeedbackOracle::IncrementType(CountOperation* expr) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 429 | Handle<Object> object = GetInfo(expr->CountBinOpFeedbackId()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 430 | TypeInfo unknown = TypeInfo::Unknown(); |
| 431 | if (!object->IsCode()) return unknown; |
| 432 | Handle<Code> code = Handle<Code>::cast(object); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 433 | if (!code->is_binary_op_stub()) return unknown; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 434 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 435 | BinaryOpIC::TypeInfo left_type, right_type, unused_result_type; |
| 436 | BinaryOpStub::decode_types_from_minor_key(code->stub_info(), &left_type, |
| 437 | &right_type, &unused_result_type); |
| 438 | // CountOperations should always have +1 or -1 as their right input. |
| 439 | ASSERT(right_type == BinaryOpIC::SMI || |
| 440 | right_type == BinaryOpIC::UNINITIALIZED); |
| 441 | |
| 442 | switch (left_type) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 443 | case BinaryOpIC::UNINITIALIZED: |
| 444 | case BinaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 445 | return TypeInfo::Smi(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 446 | case BinaryOpIC::INT32: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 447 | return TypeInfo::Integer32(); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 448 | case BinaryOpIC::NUMBER: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 449 | return TypeInfo::Double(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 450 | case BinaryOpIC::STRING: |
| 451 | case BinaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 452 | return unknown; |
| 453 | default: |
| 454 | return unknown; |
| 455 | } |
| 456 | UNREACHABLE(); |
| 457 | return unknown; |
| 458 | } |
| 459 | |
| 460 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 461 | void TypeFeedbackOracle::CollectPolymorphicMaps(Handle<Code> code, |
| 462 | SmallMapList* types) { |
| 463 | MapHandleList maps; |
| 464 | code->FindAllMaps(&maps); |
| 465 | types->Reserve(maps.length(), zone()); |
| 466 | for (int i = 0; i < maps.length(); i++) { |
| 467 | Handle<Map> map(maps.at(i)); |
| 468 | if (!CanRetainOtherContext(*map, *native_context_)) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 469 | types->AddMapIfMissing(map, zone()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 475 | void TypeFeedbackOracle::CollectReceiverTypes(TypeFeedbackId ast_id, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 476 | Handle<String> name, |
| 477 | Code::Flags flags, |
| 478 | SmallMapList* types) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 479 | Handle<Object> object = GetInfo(ast_id); |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 480 | if (object->IsUndefined() || object->IsSmi()) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 481 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 482 | if (object.is_identical_to(isolate_->builtins()->StoreIC_GlobalProxy())) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 483 | // TODO(fschneider): We could collect the maps and signal that |
| 484 | // we need a generic store (or load) here. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 485 | ASSERT(Handle<Code>::cast(object)->ic_state() == GENERIC); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 486 | } else if (object->IsMap()) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 487 | types->AddMapIfMissing(Handle<Map>::cast(object), zone()); |
danno@chromium.org | db6c80e9 | 2013-06-20 16:56:08 +0000 | [diff] [blame] | 488 | } else if (Handle<Code>::cast(object)->ic_state() == POLYMORPHIC || |
| 489 | Handle<Code>::cast(object)->ic_state() == MONOMORPHIC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 490 | CollectPolymorphicMaps(Handle<Code>::cast(object), types); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 491 | } else if (FLAG_collect_megamorphic_maps_from_stub_cache && |
| 492 | Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 493 | types->Reserve(4, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 494 | ASSERT(object->IsCode()); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 495 | isolate_->stub_cache()->CollectMatchingMaps(types, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 496 | name, |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 497 | flags, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 498 | native_context_, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 499 | zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
| 503 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 504 | // 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] | 505 | // information to filter out maps from different context to avoid |
| 506 | // retaining objects from different tabs in Chrome via optimized code. |
| 507 | bool TypeFeedbackOracle::CanRetainOtherContext(Map* map, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 508 | Context* native_context) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 509 | Object* constructor = NULL; |
| 510 | while (!map->prototype()->IsNull()) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 511 | constructor = map->constructor(); |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 512 | if (!constructor->IsNull()) { |
| 513 | // 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] | 514 | // conservatively assume that it may retain a native context. |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 515 | if (!constructor->IsJSFunction()) return true; |
| 516 | // Check if the constructor directly references a foreign context. |
| 517 | if (CanRetainOtherContext(JSFunction::cast(constructor), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 518 | native_context)) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 519 | return true; |
| 520 | } |
| 521 | } |
| 522 | map = HeapObject::cast(map->prototype())->map(); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 523 | } |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 524 | constructor = map->constructor(); |
| 525 | if (constructor->IsNull()) return false; |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 526 | JSFunction* function = JSFunction::cast(constructor); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 527 | return CanRetainOtherContext(function, native_context); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | |
| 531 | bool TypeFeedbackOracle::CanRetainOtherContext(JSFunction* function, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 532 | Context* native_context) { |
| 533 | return function->context()->global_object() != native_context->global_object() |
| 534 | && function->context()->global_object() != native_context->builtins(); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 538 | void TypeFeedbackOracle::CollectKeyedReceiverTypes(TypeFeedbackId ast_id, |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 539 | SmallMapList* types) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 540 | Handle<Object> object = GetInfo(ast_id); |
| 541 | if (!object->IsCode()) return; |
| 542 | Handle<Code> code = Handle<Code>::cast(object); |
| 543 | if (code->kind() == Code::KEYED_LOAD_IC || |
| 544 | code->kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 545 | CollectPolymorphicMaps(code, types); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | |
| 549 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 550 | byte TypeFeedbackOracle::ToBooleanTypes(TypeFeedbackId id) { |
| 551 | Handle<Object> object = GetInfo(id); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 552 | return object->IsCode() ? Handle<Code>::cast(object)->to_boolean_state() : 0; |
| 553 | } |
| 554 | |
| 555 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 556 | // Things are a bit tricky here: The iterator for the RelocInfos and the infos |
| 557 | // themselves are not GC-safe, so we first get all infos, then we create the |
| 558 | // dictionary (possibly triggering GC), and finally we relocate the collected |
| 559 | // infos before we process them. |
| 560 | void TypeFeedbackOracle::BuildDictionary(Handle<Code> code) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 561 | DisallowHeapAllocation no_allocation; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 562 | ZoneList<RelocInfo> infos(16, zone()); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 563 | HandleScope scope(isolate_); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 564 | GetRelocInfos(code, &infos); |
| 565 | CreateDictionary(code, &infos); |
| 566 | ProcessRelocInfos(&infos); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 567 | ProcessTypeFeedbackCells(code); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 568 | // Allocate handle in the parent scope. |
| 569 | dictionary_ = scope.CloseAndEscape(dictionary_); |
| 570 | } |
| 571 | |
| 572 | |
| 573 | void TypeFeedbackOracle::GetRelocInfos(Handle<Code> code, |
| 574 | ZoneList<RelocInfo>* infos) { |
| 575 | int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET_WITH_ID); |
| 576 | for (RelocIterator it(*code, mask); !it.done(); it.next()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 577 | infos->Add(*it.rinfo(), zone()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
| 581 | |
| 582 | void TypeFeedbackOracle::CreateDictionary(Handle<Code> code, |
| 583 | ZoneList<RelocInfo>* infos) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 584 | AllowHeapAllocation allocation_allowed; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 585 | int cell_count = code->type_feedback_info()->IsTypeFeedbackInfo() |
| 586 | ? TypeFeedbackInfo::cast(code->type_feedback_info())-> |
| 587 | type_feedback_cells()->CellCount() |
| 588 | : 0; |
| 589 | int length = infos->length() + cell_count; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 590 | byte* old_start = code->instruction_start(); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 591 | dictionary_ = isolate()->factory()->NewUnseededNumberDictionary(length); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 592 | byte* new_start = code->instruction_start(); |
| 593 | RelocateRelocInfos(infos, old_start, new_start); |
| 594 | } |
| 595 | |
| 596 | |
| 597 | void TypeFeedbackOracle::RelocateRelocInfos(ZoneList<RelocInfo>* infos, |
| 598 | byte* old_start, |
| 599 | byte* new_start) { |
| 600 | for (int i = 0; i < infos->length(); i++) { |
| 601 | RelocInfo* info = &(*infos)[i]; |
| 602 | info->set_pc(new_start + (info->pc() - old_start)); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | |
| 607 | void TypeFeedbackOracle::ProcessRelocInfos(ZoneList<RelocInfo>* infos) { |
| 608 | for (int i = 0; i < infos->length(); i++) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 609 | RelocInfo reloc_entry = (*infos)[i]; |
| 610 | Address target_address = reloc_entry.target_address(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 611 | TypeFeedbackId ast_id = |
| 612 | TypeFeedbackId(static_cast<unsigned>((*infos)[i].data())); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 613 | Code* target = Code::GetCodeFromTargetAddress(target_address); |
| 614 | switch (target->kind()) { |
| 615 | case Code::LOAD_IC: |
| 616 | case Code::STORE_IC: |
| 617 | case Code::CALL_IC: |
| 618 | case Code::KEYED_CALL_IC: |
| 619 | if (target->ic_state() == MONOMORPHIC) { |
| 620 | if (target->kind() == Code::CALL_IC && |
| 621 | target->check_type() != RECEIVER_MAP_CHECK) { |
| 622 | SetInfo(ast_id, Smi::FromInt(target->check_type())); |
| 623 | } else { |
| 624 | Object* map = target->FindFirstMap(); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 625 | if (map == NULL) { |
| 626 | SetInfo(ast_id, static_cast<Object*>(target)); |
| 627 | } else if (!CanRetainOtherContext(Map::cast(map), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 628 | *native_context_)) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 629 | Map* feedback = Map::cast(map)->CurrentMapForDeprecated(); |
| 630 | if (feedback != NULL) SetInfo(ast_id, feedback); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 631 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 632 | } |
jkummerow@chromium.org | 531dfe8 | 2012-03-20 13:01:16 +0000 | [diff] [blame] | 633 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 634 | SetInfo(ast_id, target); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 635 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 636 | break; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 637 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 638 | case Code::KEYED_LOAD_IC: |
| 639 | case Code::KEYED_STORE_IC: |
| 640 | if (target->ic_state() == MONOMORPHIC || |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 641 | target->ic_state() == POLYMORPHIC) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 642 | SetInfo(ast_id, target); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 643 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 644 | break; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 645 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 646 | case Code::UNARY_OP_IC: |
| 647 | case Code::BINARY_OP_IC: |
| 648 | case Code::COMPARE_IC: |
| 649 | case Code::TO_BOOLEAN_IC: |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 650 | case Code::COMPARE_NIL_IC: |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 651 | SetInfo(ast_id, target); |
| 652 | break; |
| 653 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 654 | default: |
| 655 | break; |
| 656 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | |
| 660 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 661 | void TypeFeedbackOracle::ProcessTypeFeedbackCells(Handle<Code> code) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 662 | Object* raw_info = code->type_feedback_info(); |
| 663 | if (!raw_info->IsTypeFeedbackInfo()) return; |
| 664 | Handle<TypeFeedbackCells> cache( |
| 665 | TypeFeedbackInfo::cast(raw_info)->type_feedback_cells()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 666 | for (int i = 0; i < cache->CellCount(); i++) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 667 | TypeFeedbackId ast_id = cache->AstId(i); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 668 | Cell* cell = cache->GetCell(i); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 669 | Object* value = cell->value(); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 670 | if (value->IsSmi() || |
| 671 | (value->IsJSFunction() && |
| 672 | !CanRetainOtherContext(JSFunction::cast(value), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 673 | *native_context_))) { |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 674 | SetInfo(ast_id, cell); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 680 | void TypeFeedbackOracle::SetInfo(TypeFeedbackId ast_id, Object* target) { |
| 681 | ASSERT(dictionary_->FindEntry(IdToKey(ast_id)) == |
| 682 | UnseededNumberDictionary::kNotFound); |
| 683 | MaybeObject* maybe_result = dictionary_->AtNumberPut(IdToKey(ast_id), target); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 684 | USE(maybe_result); |
| 685 | #ifdef DEBUG |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 686 | Object* result = NULL; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 687 | // Dictionary has been allocated with sufficient size for all elements. |
| 688 | ASSERT(maybe_result->ToObject(&result)); |
| 689 | ASSERT(*dictionary_ == result); |
| 690 | #endif |
| 691 | } |
| 692 | |
sgjesse@chromium.org | df7a284 | 2010-03-25 14:34:15 +0000 | [diff] [blame] | 693 | } } // namespace v8::internal |