Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 5 | #include "src/type-feedback-vector.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7 | #include "src/code-stubs.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 8 | #include "src/ic/ic.h" |
| 9 | #include "src/ic/ic-state.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/objects.h" |
| 11 | #include "src/type-feedback-vector-inl.h" |
| 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 16 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 17 | static bool IsPropertyNameFeedback(Object* feedback) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 18 | if (feedback->IsString()) return true; |
| 19 | if (!feedback->IsSymbol()) return false; |
| 20 | Symbol* symbol = Symbol::cast(feedback); |
| 21 | Heap* heap = symbol->GetHeap(); |
| 22 | return symbol != heap->uninitialized_symbol() && |
| 23 | symbol != heap->premonomorphic_symbol() && |
| 24 | symbol != heap->megamorphic_symbol(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | std::ostream& operator<<(std::ostream& os, FeedbackVectorSlotKind kind) { |
| 29 | return os << TypeFeedbackMetadata::Kind2String(kind); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 33 | FeedbackVectorSlotKind TypeFeedbackMetadata::GetKind( |
| 34 | FeedbackVectorSlot slot) const { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 35 | int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); |
| 36 | int data = Smi::cast(get(index))->value(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 37 | return VectorICComputer::decode(data, slot.ToInt()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 41 | void TypeFeedbackMetadata::SetKind(FeedbackVectorSlot slot, |
| 42 | FeedbackVectorSlotKind kind) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 43 | int index = VectorICComputer::index(kReservedIndexCount, slot.ToInt()); |
| 44 | int data = Smi::cast(get(index))->value(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 45 | int new_data = VectorICComputer::encode(data, slot.ToInt(), kind); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 46 | set(index, Smi::FromInt(new_data)); |
| 47 | } |
| 48 | |
| 49 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | template Handle<TypeFeedbackMetadata> TypeFeedbackMetadata::New( |
| 51 | Isolate* isolate, const StaticFeedbackVectorSpec* spec); |
| 52 | template Handle<TypeFeedbackMetadata> TypeFeedbackMetadata::New( |
| 53 | Isolate* isolate, const FeedbackVectorSpec* spec); |
| 54 | |
| 55 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 56 | // static |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 57 | template <typename Spec> |
| 58 | Handle<TypeFeedbackMetadata> TypeFeedbackMetadata::New(Isolate* isolate, |
| 59 | const Spec* spec) { |
| 60 | const int slot_count = spec->slots(); |
| 61 | const int slot_kinds_length = VectorICComputer::word_count(slot_count); |
| 62 | const int length = slot_kinds_length + kReservedIndexCount; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 63 | if (length == kReservedIndexCount) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 64 | return Handle<TypeFeedbackMetadata>::cast( |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 65 | isolate->factory()->empty_fixed_array()); |
| 66 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 67 | #ifdef DEBUG |
| 68 | for (int i = 0; i < slot_count;) { |
| 69 | FeedbackVectorSlotKind kind = spec->GetKind(i); |
| 70 | int entry_size = TypeFeedbackMetadata::GetSlotSize(kind); |
| 71 | for (int j = 1; j < entry_size; j++) { |
| 72 | FeedbackVectorSlotKind kind = spec->GetKind(i + j); |
| 73 | DCHECK_EQ(FeedbackVectorSlotKind::INVALID, kind); |
| 74 | } |
| 75 | i += entry_size; |
| 76 | } |
| 77 | #endif |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 78 | |
| 79 | Handle<FixedArray> array = isolate->factory()->NewFixedArray(length, TENURED); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 80 | array->set(kSlotsCountIndex, Smi::FromInt(slot_count)); |
| 81 | // Fill the bit-vector part with zeros. |
| 82 | for (int i = 0; i < slot_kinds_length; i++) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 83 | array->set(kReservedIndexCount + i, Smi::FromInt(0)); |
| 84 | } |
| 85 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 86 | Handle<TypeFeedbackMetadata> metadata = |
| 87 | Handle<TypeFeedbackMetadata>::cast(array); |
| 88 | for (int i = 0; i < slot_count; i++) { |
| 89 | metadata->SetKind(FeedbackVectorSlot(i), spec->GetKind(i)); |
| 90 | } |
| 91 | return metadata; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | bool TypeFeedbackMetadata::SpecDiffersFrom( |
| 96 | const FeedbackVectorSpec* other_spec) const { |
| 97 | if (other_spec->slots() != slot_count()) { |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | int slots = slot_count(); |
| 102 | for (int i = 0; i < slots; i++) { |
| 103 | if (GetKind(FeedbackVectorSlot(i)) != other_spec->GetKind(i)) { |
| 104 | return true; |
| 105 | } |
| 106 | } |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | const char* TypeFeedbackMetadata::Kind2String(FeedbackVectorSlotKind kind) { |
| 112 | switch (kind) { |
| 113 | case FeedbackVectorSlotKind::INVALID: |
| 114 | return "INVALID"; |
| 115 | case FeedbackVectorSlotKind::CALL_IC: |
| 116 | return "CALL_IC"; |
| 117 | case FeedbackVectorSlotKind::LOAD_IC: |
| 118 | return "LOAD_IC"; |
| 119 | case FeedbackVectorSlotKind::KEYED_LOAD_IC: |
| 120 | return "KEYED_LOAD_IC"; |
| 121 | case FeedbackVectorSlotKind::STORE_IC: |
| 122 | return "STORE_IC"; |
| 123 | case FeedbackVectorSlotKind::KEYED_STORE_IC: |
| 124 | return "KEYED_STORE_IC"; |
| 125 | case FeedbackVectorSlotKind::GENERAL: |
| 126 | return "STUB"; |
| 127 | case FeedbackVectorSlotKind::KINDS_NUMBER: |
| 128 | break; |
| 129 | } |
| 130 | UNREACHABLE(); |
| 131 | return "?"; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | // static |
| 136 | Handle<TypeFeedbackVector> TypeFeedbackVector::New( |
| 137 | Isolate* isolate, Handle<TypeFeedbackMetadata> metadata) { |
| 138 | Factory* factory = isolate->factory(); |
| 139 | |
| 140 | const int slot_count = metadata->slot_count(); |
| 141 | const int length = slot_count + kReservedIndexCount; |
| 142 | if (length == kReservedIndexCount) { |
| 143 | return Handle<TypeFeedbackVector>::cast(factory->empty_fixed_array()); |
| 144 | } |
| 145 | |
| 146 | Handle<FixedArray> array = factory->NewFixedArray(length, TENURED); |
| 147 | array->set(kMetadataIndex, *metadata); |
| 148 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 149 | // Ensure we can skip the write barrier |
| 150 | Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 151 | DCHECK_EQ(*factory->uninitialized_symbol(), *uninitialized_sentinel); |
| 152 | for (int i = kReservedIndexCount; i < length; i++) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 153 | array->set(i, *uninitialized_sentinel, SKIP_WRITE_BARRIER); |
| 154 | } |
| 155 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 156 | return Handle<TypeFeedbackVector>::cast(array); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | // static |
| 161 | int TypeFeedbackVector::GetIndexFromSpec(const FeedbackVectorSpec* spec, |
| 162 | FeedbackVectorSlot slot) { |
| 163 | return kReservedIndexCount + slot.ToInt(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | |
| 167 | // static |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 168 | Handle<TypeFeedbackVector> TypeFeedbackVector::Copy( |
| 169 | Isolate* isolate, Handle<TypeFeedbackVector> vector) { |
| 170 | Handle<TypeFeedbackVector> result; |
| 171 | result = Handle<TypeFeedbackVector>::cast( |
| 172 | isolate->factory()->CopyFixedArray(Handle<FixedArray>::cast(vector))); |
| 173 | return result; |
| 174 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 175 | |
| 176 | |
| 177 | // This logic is copied from |
| 178 | // StaticMarkingVisitor<StaticVisitor>::VisitCodeTarget. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 179 | static bool ClearLogic(Isolate* isolate) { |
| 180 | return FLAG_cleanup_code_caches_at_gc && isolate->serializer_enabled(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 184 | void TypeFeedbackVector::ClearSlotsImpl(SharedFunctionInfo* shared, |
| 185 | bool force_clear) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 186 | Isolate* isolate = GetIsolate(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 187 | |
| 188 | if (!force_clear && !ClearLogic(isolate)) return; |
| 189 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 190 | Object* uninitialized_sentinel = |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 191 | TypeFeedbackVector::RawUninitializedSentinel(isolate); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 192 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 193 | TypeFeedbackMetadataIterator iter(metadata()); |
| 194 | while (iter.HasNext()) { |
| 195 | FeedbackVectorSlot slot = iter.Next(); |
| 196 | FeedbackVectorSlotKind kind = iter.kind(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 197 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 198 | Object* obj = Get(slot); |
| 199 | if (obj != uninitialized_sentinel) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 200 | switch (kind) { |
| 201 | case FeedbackVectorSlotKind::CALL_IC: { |
| 202 | CallICNexus nexus(this, slot); |
| 203 | nexus.Clear(shared->code()); |
| 204 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 205 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 206 | case FeedbackVectorSlotKind::LOAD_IC: { |
| 207 | LoadICNexus nexus(this, slot); |
| 208 | nexus.Clear(shared->code()); |
| 209 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 210 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 211 | case FeedbackVectorSlotKind::KEYED_LOAD_IC: { |
| 212 | KeyedLoadICNexus nexus(this, slot); |
| 213 | nexus.Clear(shared->code()); |
| 214 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 215 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 216 | case FeedbackVectorSlotKind::STORE_IC: { |
| 217 | StoreICNexus nexus(this, slot); |
| 218 | nexus.Clear(shared->code()); |
| 219 | break; |
| 220 | } |
| 221 | case FeedbackVectorSlotKind::KEYED_STORE_IC: { |
| 222 | KeyedStoreICNexus nexus(this, slot); |
| 223 | nexus.Clear(shared->code()); |
| 224 | break; |
| 225 | } |
| 226 | case FeedbackVectorSlotKind::GENERAL: { |
| 227 | if (obj->IsHeapObject()) { |
| 228 | InstanceType instance_type = |
| 229 | HeapObject::cast(obj)->map()->instance_type(); |
| 230 | // AllocationSites are exempt from clearing. They don't store Maps |
| 231 | // or Code pointers which can cause memory leaks if not cleared |
| 232 | // regularly. |
| 233 | if (instance_type != ALLOCATION_SITE_TYPE) { |
| 234 | Set(slot, uninitialized_sentinel, SKIP_WRITE_BARRIER); |
| 235 | } |
| 236 | } |
| 237 | break; |
| 238 | } |
| 239 | case FeedbackVectorSlotKind::INVALID: |
| 240 | case FeedbackVectorSlotKind::KINDS_NUMBER: |
| 241 | UNREACHABLE(); |
| 242 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 249 | // static |
| 250 | void TypeFeedbackVector::ClearAllKeyedStoreICs(Isolate* isolate) { |
| 251 | SharedFunctionInfo::Iterator iterator(isolate); |
| 252 | SharedFunctionInfo* shared; |
| 253 | while ((shared = iterator.Next())) { |
| 254 | TypeFeedbackVector* vector = shared->feedback_vector(); |
| 255 | vector->ClearKeyedStoreICs(shared); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | |
| 260 | void TypeFeedbackVector::ClearKeyedStoreICs(SharedFunctionInfo* shared) { |
| 261 | Isolate* isolate = GetIsolate(); |
| 262 | |
| 263 | Code* host = shared->code(); |
| 264 | Object* uninitialized_sentinel = |
| 265 | TypeFeedbackVector::RawUninitializedSentinel(isolate); |
| 266 | |
| 267 | TypeFeedbackMetadataIterator iter(metadata()); |
| 268 | while (iter.HasNext()) { |
| 269 | FeedbackVectorSlot slot = iter.Next(); |
| 270 | FeedbackVectorSlotKind kind = iter.kind(); |
| 271 | if (kind != FeedbackVectorSlotKind::KEYED_STORE_IC) continue; |
| 272 | Object* obj = Get(slot); |
| 273 | if (obj != uninitialized_sentinel) { |
| 274 | KeyedStoreICNexus nexus(this, slot); |
| 275 | nexus.Clear(host); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | |
| 281 | // static |
| 282 | Handle<TypeFeedbackVector> TypeFeedbackVector::DummyVector(Isolate* isolate) { |
| 283 | return isolate->factory()->dummy_vector(); |
| 284 | } |
| 285 | |
| 286 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 287 | Handle<FixedArray> FeedbackNexus::EnsureArrayOfSize(int length) { |
| 288 | Isolate* isolate = GetIsolate(); |
| 289 | Handle<Object> feedback = handle(GetFeedback(), isolate); |
| 290 | if (!feedback->IsFixedArray() || |
| 291 | FixedArray::cast(*feedback)->length() != length) { |
| 292 | Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); |
| 293 | SetFeedback(*array); |
| 294 | return array; |
| 295 | } |
| 296 | return Handle<FixedArray>::cast(feedback); |
| 297 | } |
| 298 | |
| 299 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 300 | Handle<FixedArray> FeedbackNexus::EnsureExtraArrayOfSize(int length) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 301 | Isolate* isolate = GetIsolate(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 302 | Handle<Object> feedback_extra = handle(GetFeedbackExtra(), isolate); |
| 303 | if (!feedback_extra->IsFixedArray() || |
| 304 | FixedArray::cast(*feedback_extra)->length() != length) { |
| 305 | Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); |
| 306 | SetFeedbackExtra(*array); |
| 307 | return array; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 308 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 309 | return Handle<FixedArray>::cast(feedback_extra); |
| 310 | } |
| 311 | |
| 312 | |
| 313 | void FeedbackNexus::InstallHandlers(Handle<FixedArray> array, |
| 314 | MapHandleList* maps, |
| 315 | CodeHandleList* handlers) { |
| 316 | int receiver_count = maps->length(); |
| 317 | for (int current = 0; current < receiver_count; ++current) { |
| 318 | Handle<Map> map = maps->at(current); |
| 319 | Handle<WeakCell> cell = Map::WeakCellForMap(map); |
| 320 | array->set(current * 2, *cell); |
| 321 | array->set(current * 2 + 1, *handlers->at(current)); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | |
| 326 | void FeedbackNexus::ConfigureUninitialized() { |
| 327 | SetFeedback(*TypeFeedbackVector::UninitializedSentinel(GetIsolate()), |
| 328 | SKIP_WRITE_BARRIER); |
| 329 | SetFeedbackExtra(*TypeFeedbackVector::UninitializedSentinel(GetIsolate()), |
| 330 | SKIP_WRITE_BARRIER); |
| 331 | } |
| 332 | |
| 333 | |
| 334 | void FeedbackNexus::ConfigurePremonomorphic() { |
| 335 | SetFeedback(*TypeFeedbackVector::PremonomorphicSentinel(GetIsolate()), |
| 336 | SKIP_WRITE_BARRIER); |
| 337 | SetFeedbackExtra(*TypeFeedbackVector::UninitializedSentinel(GetIsolate()), |
| 338 | SKIP_WRITE_BARRIER); |
| 339 | } |
| 340 | |
| 341 | |
| 342 | void FeedbackNexus::ConfigureMegamorphic() { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 343 | // Keyed ICs must use ConfigureMegamorphicKeyed. |
| 344 | DCHECK_NE(FeedbackVectorSlotKind::KEYED_LOAD_IC, vector()->GetKind(slot())); |
| 345 | DCHECK_NE(FeedbackVectorSlotKind::KEYED_STORE_IC, vector()->GetKind(slot())); |
| 346 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 347 | Isolate* isolate = GetIsolate(); |
| 348 | SetFeedback(*TypeFeedbackVector::MegamorphicSentinel(isolate), |
| 349 | SKIP_WRITE_BARRIER); |
| 350 | SetFeedbackExtra(*TypeFeedbackVector::UninitializedSentinel(isolate), |
| 351 | SKIP_WRITE_BARRIER); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 352 | } |
| 353 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 354 | void KeyedLoadICNexus::ConfigureMegamorphicKeyed(IcCheckType property_type) { |
| 355 | Isolate* isolate = GetIsolate(); |
| 356 | SetFeedback(*TypeFeedbackVector::MegamorphicSentinel(isolate), |
| 357 | SKIP_WRITE_BARRIER); |
| 358 | SetFeedbackExtra(Smi::FromInt(static_cast<int>(property_type)), |
| 359 | SKIP_WRITE_BARRIER); |
| 360 | } |
| 361 | |
| 362 | void KeyedStoreICNexus::ConfigureMegamorphicKeyed(IcCheckType property_type) { |
| 363 | Isolate* isolate = GetIsolate(); |
| 364 | SetFeedback(*TypeFeedbackVector::MegamorphicSentinel(isolate), |
| 365 | SKIP_WRITE_BARRIER); |
| 366 | SetFeedbackExtra(Smi::FromInt(static_cast<int>(property_type)), |
| 367 | SKIP_WRITE_BARRIER); |
| 368 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 369 | |
| 370 | InlineCacheState LoadICNexus::StateFromFeedback() const { |
| 371 | Isolate* isolate = GetIsolate(); |
| 372 | Object* feedback = GetFeedback(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 373 | |
| 374 | if (feedback == *TypeFeedbackVector::UninitializedSentinel(isolate)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 375 | return UNINITIALIZED; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 376 | } else if (feedback == *TypeFeedbackVector::MegamorphicSentinel(isolate)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 377 | return MEGAMORPHIC; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 378 | } else if (feedback == *TypeFeedbackVector::PremonomorphicSentinel(isolate)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 379 | return PREMONOMORPHIC; |
| 380 | } else if (feedback->IsFixedArray()) { |
| 381 | // Determine state purely by our structure, don't check if the maps are |
| 382 | // cleared. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 383 | return POLYMORPHIC; |
| 384 | } else if (feedback->IsWeakCell()) { |
| 385 | // Don't check if the map is cleared. |
| 386 | return MONOMORPHIC; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | return UNINITIALIZED; |
| 390 | } |
| 391 | |
| 392 | |
| 393 | InlineCacheState KeyedLoadICNexus::StateFromFeedback() const { |
| 394 | Isolate* isolate = GetIsolate(); |
| 395 | Object* feedback = GetFeedback(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 396 | |
| 397 | if (feedback == *TypeFeedbackVector::UninitializedSentinel(isolate)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 398 | return UNINITIALIZED; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 399 | } else if (feedback == *TypeFeedbackVector::PremonomorphicSentinel(isolate)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 400 | return PREMONOMORPHIC; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 401 | } else if (feedback == *TypeFeedbackVector::MegamorphicSentinel(isolate)) { |
| 402 | return MEGAMORPHIC; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 403 | } else if (feedback->IsFixedArray()) { |
| 404 | // Determine state purely by our structure, don't check if the maps are |
| 405 | // cleared. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 406 | return POLYMORPHIC; |
| 407 | } else if (feedback->IsWeakCell()) { |
| 408 | // Don't check if the map is cleared. |
| 409 | return MONOMORPHIC; |
| 410 | } else if (feedback->IsName()) { |
| 411 | Object* extra = GetFeedbackExtra(); |
| 412 | FixedArray* extra_array = FixedArray::cast(extra); |
| 413 | return extra_array->length() > 2 ? POLYMORPHIC : MONOMORPHIC; |
| 414 | } |
| 415 | |
| 416 | return UNINITIALIZED; |
| 417 | } |
| 418 | |
| 419 | |
| 420 | InlineCacheState StoreICNexus::StateFromFeedback() const { |
| 421 | Isolate* isolate = GetIsolate(); |
| 422 | Object* feedback = GetFeedback(); |
| 423 | |
| 424 | if (feedback == *TypeFeedbackVector::UninitializedSentinel(isolate)) { |
| 425 | return UNINITIALIZED; |
| 426 | } else if (feedback == *TypeFeedbackVector::MegamorphicSentinel(isolate)) { |
| 427 | return MEGAMORPHIC; |
| 428 | } else if (feedback == *TypeFeedbackVector::PremonomorphicSentinel(isolate)) { |
| 429 | return PREMONOMORPHIC; |
| 430 | } else if (feedback->IsFixedArray()) { |
| 431 | // Determine state purely by our structure, don't check if the maps are |
| 432 | // cleared. |
| 433 | return POLYMORPHIC; |
| 434 | } else if (feedback->IsWeakCell()) { |
| 435 | // Don't check if the map is cleared. |
| 436 | return MONOMORPHIC; |
| 437 | } |
| 438 | |
| 439 | return UNINITIALIZED; |
| 440 | } |
| 441 | |
| 442 | |
| 443 | InlineCacheState KeyedStoreICNexus::StateFromFeedback() const { |
| 444 | Isolate* isolate = GetIsolate(); |
| 445 | Object* feedback = GetFeedback(); |
| 446 | |
| 447 | if (feedback == *TypeFeedbackVector::UninitializedSentinel(isolate)) { |
| 448 | return UNINITIALIZED; |
| 449 | } else if (feedback == *TypeFeedbackVector::PremonomorphicSentinel(isolate)) { |
| 450 | return PREMONOMORPHIC; |
| 451 | } else if (feedback == *TypeFeedbackVector::MegamorphicSentinel(isolate)) { |
| 452 | return MEGAMORPHIC; |
| 453 | } else if (feedback->IsFixedArray()) { |
| 454 | // Determine state purely by our structure, don't check if the maps are |
| 455 | // cleared. |
| 456 | return POLYMORPHIC; |
| 457 | } else if (feedback->IsWeakCell()) { |
| 458 | // Don't check if the map is cleared. |
| 459 | return MONOMORPHIC; |
| 460 | } else if (feedback->IsName()) { |
| 461 | Object* extra = GetFeedbackExtra(); |
| 462 | FixedArray* extra_array = FixedArray::cast(extra); |
| 463 | return extra_array->length() > 2 ? POLYMORPHIC : MONOMORPHIC; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | return UNINITIALIZED; |
| 467 | } |
| 468 | |
| 469 | |
| 470 | InlineCacheState CallICNexus::StateFromFeedback() const { |
| 471 | Isolate* isolate = GetIsolate(); |
| 472 | Object* feedback = GetFeedback(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 473 | DCHECK(GetFeedbackExtra() == |
| 474 | *TypeFeedbackVector::UninitializedSentinel(isolate) || |
| 475 | GetFeedbackExtra()->IsSmi()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 476 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 477 | if (feedback == *TypeFeedbackVector::MegamorphicSentinel(isolate)) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 478 | return GENERIC; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 479 | } else if (feedback->IsAllocationSite() || feedback->IsWeakCell()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 480 | return MONOMORPHIC; |
| 481 | } |
| 482 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 483 | CHECK(feedback == *TypeFeedbackVector::UninitializedSentinel(isolate)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 484 | return UNINITIALIZED; |
| 485 | } |
| 486 | |
| 487 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 488 | int CallICNexus::ExtractCallCount() { |
| 489 | Object* call_count = GetFeedbackExtra(); |
| 490 | if (call_count->IsSmi()) { |
| 491 | int value = Smi::cast(call_count)->value() / 2; |
| 492 | return value; |
| 493 | } |
| 494 | return -1; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 498 | void CallICNexus::Clear(Code* host) { CallIC::Clear(GetIsolate(), host, this); } |
| 499 | |
| 500 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 501 | void CallICNexus::ConfigureMonomorphicArray() { |
| 502 | Object* feedback = GetFeedback(); |
| 503 | if (!feedback->IsAllocationSite()) { |
| 504 | Handle<AllocationSite> new_site = |
| 505 | GetIsolate()->factory()->NewAllocationSite(); |
| 506 | SetFeedback(*new_site); |
| 507 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 508 | SetFeedbackExtra(Smi::FromInt(kCallCountIncrement), SKIP_WRITE_BARRIER); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | |
| 512 | void CallICNexus::ConfigureMonomorphic(Handle<JSFunction> function) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 513 | Handle<WeakCell> new_cell = GetIsolate()->factory()->NewWeakCell(function); |
| 514 | SetFeedback(*new_cell); |
| 515 | SetFeedbackExtra(Smi::FromInt(kCallCountIncrement), SKIP_WRITE_BARRIER); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 519 | void CallICNexus::ConfigureMegamorphic() { |
| 520 | FeedbackNexus::ConfigureMegamorphic(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 524 | void CallICNexus::ConfigureMegamorphic(int call_count) { |
| 525 | SetFeedback(*TypeFeedbackVector::MegamorphicSentinel(GetIsolate()), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 526 | SKIP_WRITE_BARRIER); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 527 | SetFeedbackExtra(Smi::FromInt(call_count * kCallCountIncrement), |
| 528 | SKIP_WRITE_BARRIER); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 532 | void LoadICNexus::ConfigureMonomorphic(Handle<Map> receiver_map, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 533 | Handle<Code> handler) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 534 | Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 535 | SetFeedback(*cell); |
| 536 | SetFeedbackExtra(*handler); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
| 540 | void KeyedLoadICNexus::ConfigureMonomorphic(Handle<Name> name, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 541 | Handle<Map> receiver_map, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 542 | Handle<Code> handler) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 543 | Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 544 | if (name.is_null()) { |
| 545 | SetFeedback(*cell); |
| 546 | SetFeedbackExtra(*handler); |
| 547 | } else { |
| 548 | Handle<FixedArray> array = EnsureExtraArrayOfSize(2); |
| 549 | SetFeedback(*name); |
| 550 | array->set(0, *cell); |
| 551 | array->set(1, *handler); |
| 552 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 556 | void StoreICNexus::ConfigureMonomorphic(Handle<Map> receiver_map, |
| 557 | Handle<Code> handler) { |
| 558 | Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); |
| 559 | SetFeedback(*cell); |
| 560 | SetFeedbackExtra(*handler); |
| 561 | } |
| 562 | |
| 563 | |
| 564 | void KeyedStoreICNexus::ConfigureMonomorphic(Handle<Name> name, |
| 565 | Handle<Map> receiver_map, |
| 566 | Handle<Code> handler) { |
| 567 | Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); |
| 568 | if (name.is_null()) { |
| 569 | SetFeedback(*cell); |
| 570 | SetFeedbackExtra(*handler); |
| 571 | } else { |
| 572 | Handle<FixedArray> array = EnsureExtraArrayOfSize(2); |
| 573 | SetFeedback(*name); |
| 574 | array->set(0, *cell); |
| 575 | array->set(1, *handler); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | |
| 580 | void LoadICNexus::ConfigurePolymorphic(MapHandleList* maps, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 581 | CodeHandleList* handlers) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 582 | Isolate* isolate = GetIsolate(); |
| 583 | int receiver_count = maps->length(); |
| 584 | Handle<FixedArray> array = EnsureArrayOfSize(receiver_count * 2); |
| 585 | InstallHandlers(array, maps, handlers); |
| 586 | SetFeedbackExtra(*TypeFeedbackVector::UninitializedSentinel(isolate), |
| 587 | SKIP_WRITE_BARRIER); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | |
| 591 | void KeyedLoadICNexus::ConfigurePolymorphic(Handle<Name> name, |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 592 | MapHandleList* maps, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 593 | CodeHandleList* handlers) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 594 | int receiver_count = maps->length(); |
| 595 | DCHECK(receiver_count > 1); |
| 596 | Handle<FixedArray> array; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 597 | if (name.is_null()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 598 | array = EnsureArrayOfSize(receiver_count * 2); |
| 599 | SetFeedbackExtra(*TypeFeedbackVector::UninitializedSentinel(GetIsolate()), |
| 600 | SKIP_WRITE_BARRIER); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 601 | } else { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 602 | array = EnsureExtraArrayOfSize(receiver_count * 2); |
| 603 | SetFeedback(*name); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 604 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 605 | |
| 606 | InstallHandlers(array, maps, handlers); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 610 | void StoreICNexus::ConfigurePolymorphic(MapHandleList* maps, |
| 611 | CodeHandleList* handlers) { |
| 612 | Isolate* isolate = GetIsolate(); |
| 613 | int receiver_count = maps->length(); |
| 614 | Handle<FixedArray> array = EnsureArrayOfSize(receiver_count * 2); |
| 615 | InstallHandlers(array, maps, handlers); |
| 616 | SetFeedbackExtra(*TypeFeedbackVector::UninitializedSentinel(isolate), |
| 617 | SKIP_WRITE_BARRIER); |
| 618 | } |
| 619 | |
| 620 | |
| 621 | void KeyedStoreICNexus::ConfigurePolymorphic(Handle<Name> name, |
| 622 | MapHandleList* maps, |
| 623 | CodeHandleList* handlers) { |
| 624 | int receiver_count = maps->length(); |
| 625 | DCHECK(receiver_count > 1); |
| 626 | Handle<FixedArray> array; |
| 627 | if (name.is_null()) { |
| 628 | array = EnsureArrayOfSize(receiver_count * 2); |
| 629 | SetFeedbackExtra(*TypeFeedbackVector::UninitializedSentinel(GetIsolate()), |
| 630 | SKIP_WRITE_BARRIER); |
| 631 | } else { |
| 632 | array = EnsureExtraArrayOfSize(receiver_count * 2); |
| 633 | SetFeedback(*name); |
| 634 | } |
| 635 | |
| 636 | InstallHandlers(array, maps, handlers); |
| 637 | } |
| 638 | |
| 639 | |
| 640 | void KeyedStoreICNexus::ConfigurePolymorphic(MapHandleList* maps, |
| 641 | MapHandleList* transitioned_maps, |
| 642 | CodeHandleList* handlers) { |
| 643 | int receiver_count = maps->length(); |
| 644 | DCHECK(receiver_count > 1); |
| 645 | Handle<FixedArray> array = EnsureArrayOfSize(receiver_count * 3); |
| 646 | SetFeedbackExtra(*TypeFeedbackVector::UninitializedSentinel(GetIsolate()), |
| 647 | SKIP_WRITE_BARRIER); |
| 648 | |
| 649 | Handle<Oddball> undefined_value = GetIsolate()->factory()->undefined_value(); |
| 650 | for (int i = 0; i < receiver_count; ++i) { |
| 651 | Handle<Map> map = maps->at(i); |
| 652 | Handle<WeakCell> cell = Map::WeakCellForMap(map); |
| 653 | array->set(i * 3, *cell); |
| 654 | if (!transitioned_maps->at(i).is_null()) { |
| 655 | Handle<Map> transitioned_map = transitioned_maps->at(i); |
| 656 | cell = Map::WeakCellForMap(transitioned_map); |
| 657 | array->set((i * 3) + 1, *cell); |
| 658 | } else { |
| 659 | array->set((i * 3) + 1, *undefined_value); |
| 660 | } |
| 661 | array->set((i * 3) + 2, *handlers->at(i)); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | |
| 666 | int FeedbackNexus::ExtractMaps(MapHandleList* maps) const { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 667 | Isolate* isolate = GetIsolate(); |
| 668 | Object* feedback = GetFeedback(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 669 | bool is_named_feedback = IsPropertyNameFeedback(feedback); |
| 670 | if (feedback->IsFixedArray() || is_named_feedback) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 671 | int found = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 672 | if (is_named_feedback) { |
| 673 | feedback = GetFeedbackExtra(); |
| 674 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 675 | FixedArray* array = FixedArray::cast(feedback); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 676 | // The array should be of the form |
| 677 | // [map, handler, map, handler, ...] |
| 678 | // or |
| 679 | // [map, map, handler, map, map, handler, ...] |
| 680 | DCHECK(array->length() >= 2); |
| 681 | int increment = array->get(1)->IsCode() ? 2 : 3; |
| 682 | for (int i = 0; i < array->length(); i += increment) { |
| 683 | DCHECK(array->get(i)->IsWeakCell()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 684 | WeakCell* cell = WeakCell::cast(array->get(i)); |
| 685 | if (!cell->cleared()) { |
| 686 | Map* map = Map::cast(cell->value()); |
| 687 | maps->Add(handle(map, isolate)); |
| 688 | found++; |
| 689 | } |
| 690 | } |
| 691 | return found; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 692 | } else if (feedback->IsWeakCell()) { |
| 693 | WeakCell* cell = WeakCell::cast(feedback); |
| 694 | if (!cell->cleared()) { |
| 695 | Map* map = Map::cast(cell->value()); |
| 696 | maps->Add(handle(map, isolate)); |
| 697 | return 1; |
| 698 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 705 | MaybeHandle<Code> FeedbackNexus::FindHandlerForMap(Handle<Map> map) const { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 706 | Object* feedback = GetFeedback(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 707 | bool is_named_feedback = IsPropertyNameFeedback(feedback); |
| 708 | if (feedback->IsFixedArray() || is_named_feedback) { |
| 709 | if (is_named_feedback) { |
| 710 | feedback = GetFeedbackExtra(); |
| 711 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 712 | FixedArray* array = FixedArray::cast(feedback); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 713 | DCHECK(array->length() >= 2); |
| 714 | int increment = array->get(1)->IsCode() ? 2 : 3; |
| 715 | for (int i = 0; i < array->length(); i += increment) { |
| 716 | DCHECK(array->get(i)->IsWeakCell()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 717 | WeakCell* cell = WeakCell::cast(array->get(i)); |
| 718 | if (!cell->cleared()) { |
| 719 | Map* array_map = Map::cast(cell->value()); |
| 720 | if (array_map == *map) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 721 | Code* code = Code::cast(array->get(i + increment - 1)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 722 | DCHECK(code->kind() == Code::HANDLER); |
| 723 | return handle(code); |
| 724 | } |
| 725 | } |
| 726 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 727 | } else if (feedback->IsWeakCell()) { |
| 728 | WeakCell* cell = WeakCell::cast(feedback); |
| 729 | if (!cell->cleared()) { |
| 730 | Map* cell_map = Map::cast(cell->value()); |
| 731 | if (cell_map == *map) { |
| 732 | Code* code = Code::cast(GetFeedbackExtra()); |
| 733 | DCHECK(code->kind() == Code::HANDLER); |
| 734 | return handle(code); |
| 735 | } |
| 736 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | return MaybeHandle<Code>(); |
| 740 | } |
| 741 | |
| 742 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 743 | bool FeedbackNexus::FindHandlers(CodeHandleList* code_list, int length) const { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 744 | Object* feedback = GetFeedback(); |
| 745 | int count = 0; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 746 | bool is_named_feedback = IsPropertyNameFeedback(feedback); |
| 747 | if (feedback->IsFixedArray() || is_named_feedback) { |
| 748 | if (is_named_feedback) { |
| 749 | feedback = GetFeedbackExtra(); |
| 750 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 751 | FixedArray* array = FixedArray::cast(feedback); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 752 | // The array should be of the form |
| 753 | // [map, handler, map, handler, ...] |
| 754 | // or |
| 755 | // [map, map, handler, map, map, handler, ...] |
| 756 | // Be sure to skip handlers whose maps have been cleared. |
| 757 | DCHECK(array->length() >= 2); |
| 758 | int increment = array->get(1)->IsCode() ? 2 : 3; |
| 759 | for (int i = 0; i < array->length(); i += increment) { |
| 760 | DCHECK(array->get(i)->IsWeakCell()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 761 | WeakCell* cell = WeakCell::cast(array->get(i)); |
| 762 | if (!cell->cleared()) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 763 | Code* code = Code::cast(array->get(i + increment - 1)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 764 | DCHECK(code->kind() == Code::HANDLER); |
| 765 | code_list->Add(handle(code)); |
| 766 | count++; |
| 767 | } |
| 768 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 769 | } else if (feedback->IsWeakCell()) { |
| 770 | WeakCell* cell = WeakCell::cast(feedback); |
| 771 | if (!cell->cleared()) { |
| 772 | Code* code = Code::cast(GetFeedbackExtra()); |
| 773 | DCHECK(code->kind() == Code::HANDLER); |
| 774 | code_list->Add(handle(code)); |
| 775 | count++; |
| 776 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 777 | } |
| 778 | return count == length; |
| 779 | } |
| 780 | |
| 781 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 782 | void LoadICNexus::Clear(Code* host) { LoadIC::Clear(GetIsolate(), host, this); } |
| 783 | |
| 784 | |
| 785 | void KeyedLoadICNexus::Clear(Code* host) { |
| 786 | KeyedLoadIC::Clear(GetIsolate(), host, this); |
| 787 | } |
| 788 | |
| 789 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 790 | Name* KeyedLoadICNexus::FindFirstName() const { |
| 791 | Object* feedback = GetFeedback(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 792 | if (IsPropertyNameFeedback(feedback)) { |
| 793 | return Name::cast(feedback); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 794 | } |
| 795 | return NULL; |
| 796 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 797 | |
| 798 | |
| 799 | Name* KeyedStoreICNexus::FindFirstName() const { |
| 800 | Object* feedback = GetFeedback(); |
| 801 | if (IsPropertyNameFeedback(feedback)) { |
| 802 | return Name::cast(feedback); |
| 803 | } |
| 804 | return NULL; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 805 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 806 | |
| 807 | |
| 808 | void StoreICNexus::Clear(Code* host) { |
| 809 | StoreIC::Clear(GetIsolate(), host, this); |
| 810 | } |
| 811 | |
| 812 | |
| 813 | void KeyedStoreICNexus::Clear(Code* host) { |
| 814 | KeyedStoreIC::Clear(GetIsolate(), host, this); |
| 815 | } |
| 816 | |
| 817 | |
| 818 | KeyedAccessStoreMode KeyedStoreICNexus::GetKeyedAccessStoreMode() const { |
| 819 | KeyedAccessStoreMode mode = STANDARD_STORE; |
| 820 | MapHandleList maps; |
| 821 | CodeHandleList handlers; |
| 822 | |
| 823 | if (GetKeyType() == PROPERTY) return mode; |
| 824 | |
| 825 | ExtractMaps(&maps); |
| 826 | FindHandlers(&handlers, maps.length()); |
| 827 | for (int i = 0; i < handlers.length(); i++) { |
| 828 | // The first handler that isn't the slow handler will have the bits we need. |
| 829 | Handle<Code> handler = handlers.at(i); |
| 830 | CodeStub::Major major_key = CodeStub::MajorKeyFromKey(handler->stub_key()); |
| 831 | uint32_t minor_key = CodeStub::MinorKeyFromKey(handler->stub_key()); |
| 832 | CHECK(major_key == CodeStub::KeyedStoreSloppyArguments || |
| 833 | major_key == CodeStub::StoreFastElement || |
| 834 | major_key == CodeStub::StoreElement || |
| 835 | major_key == CodeStub::ElementsTransitionAndStore || |
| 836 | major_key == CodeStub::NoCache); |
| 837 | if (major_key != CodeStub::NoCache) { |
| 838 | mode = CommonStoreModeBits::decode(minor_key); |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | return mode; |
| 844 | } |
| 845 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 846 | IcCheckType KeyedLoadICNexus::GetKeyType() const { |
| 847 | Object* feedback = GetFeedback(); |
| 848 | if (feedback == *TypeFeedbackVector::MegamorphicSentinel(GetIsolate())) { |
| 849 | return static_cast<IcCheckType>(Smi::cast(GetFeedbackExtra())->value()); |
| 850 | } |
| 851 | return IsPropertyNameFeedback(feedback) ? PROPERTY : ELEMENT; |
| 852 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 853 | |
| 854 | IcCheckType KeyedStoreICNexus::GetKeyType() const { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 855 | Object* feedback = GetFeedback(); |
| 856 | if (feedback == *TypeFeedbackVector::MegamorphicSentinel(GetIsolate())) { |
| 857 | return static_cast<IcCheckType>(Smi::cast(GetFeedbackExtra())->value()); |
| 858 | } |
| 859 | return IsPropertyNameFeedback(feedback) ? PROPERTY : ELEMENT; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 860 | } |
| 861 | } // namespace internal |
| 862 | } // namespace v8 |