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