Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/ic/stub-cache.h" | 5 #include "src/ic/stub-cache.h" |
| 6 | 6 |
| 7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/type-info.h" | 8 #include "src/type-info.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 StubCache::StubCache(Isolate* isolate, Code::Kind ic_kind) | 13 StubCache::StubCache(Isolate* isolate, Code::Kind ic_kind) |
| 14 : isolate_(isolate), ic_kind_(ic_kind) {} | 14 : isolate_(isolate), ic_kind_(ic_kind) {} |
| 15 | 15 |
| 16 void StubCache::Initialize() { | 16 void StubCache::Initialize() { |
| 17 DCHECK(base::bits::IsPowerOfTwo32(kPrimaryTableSize)); | 17 DCHECK(base::bits::IsPowerOfTwo32(kPrimaryTableSize)); |
| 18 DCHECK(base::bits::IsPowerOfTwo32(kSecondaryTableSize)); | 18 DCHECK(base::bits::IsPowerOfTwo32(kSecondaryTableSize)); |
| 19 Clear(); | 19 Clear(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 | 22 static void CommonStubCacheChecks(Name* name, Map* map, Code* code) { |
| 23 static Code::Flags CommonStubCacheChecks(Name* name, Map* map, | |
| 24 Code::Flags flags) { | |
| 25 flags = Code::RemoveHolderFromFlags(flags); | |
| 26 | |
| 27 // Validate that the name does not move on scavenge, and that we | 23 // Validate that the name does not move on scavenge, and that we |
| 28 // can use identity checks instead of structural equality checks. | 24 // can use identity checks instead of structural equality checks. |
| 29 DCHECK(!name->GetHeap()->InNewSpace(name)); | 25 DCHECK(!name->GetHeap()->InNewSpace(name)); |
| 30 DCHECK(name->IsUniqueName()); | 26 DCHECK(name->IsUniqueName()); |
| 31 | 27 DCHECK(name->HasHashCode()); |
| 32 // The state bits are not important to the hash function because the stub | 28 if (code) { |
| 33 // cache only contains handlers. Make sure that the bits are the least | 29 Code::Flags flags = code->flags(); |
|
Jakob Kummerow
2016/07/12 12:55:50
Just inline this variable into the DCHECK to make
Igor Sheludko
2016/07/12 13:06:55
Done.
| |
| 34 // significant so they will be the ones masked out. | 30 // The state bits are not important to the hash function because the stub |
| 35 DCHECK_EQ(Code::HANDLER, Code::ExtractKindFromFlags(flags)); | 31 // cache only contains handlers. Make sure that the bits are the least |
| 36 | 32 // significant so they will be the ones masked out. |
| 37 // Make sure that the cache holder are not included in the hash. | 33 DCHECK_EQ(Code::HANDLER, Code::ExtractKindFromFlags(flags)); |
| 38 DCHECK(Code::ExtractCacheHolderFromFlags(flags) == 0); | 34 } |
| 39 | |
| 40 return flags; | |
| 41 } | 35 } |
| 42 | 36 |
| 43 | 37 |
| 44 Code* StubCache::Set(Name* name, Map* map, Code* code) { | 38 Code* StubCache::Set(Name* name, Map* map, Code* code) { |
| 45 Code::Flags flags = CommonStubCacheChecks(name, map, code->flags()); | 39 CommonStubCacheChecks(name, map, code); |
| 46 | 40 |
| 47 // Compute the primary entry. | 41 // Compute the primary entry. |
| 48 int primary_offset = PrimaryOffset(name, flags, map); | 42 int primary_offset = PrimaryOffset(name, map); |
| 49 Entry* primary = entry(primary_, primary_offset); | 43 Entry* primary = entry(primary_, primary_offset); |
| 50 Code* old_code = primary->value; | 44 Code* old_code = primary->value; |
| 51 | 45 |
| 52 // If the primary entry has useful data in it, we retire it to the | 46 // If the primary entry has useful data in it, we retire it to the |
| 53 // secondary cache before overwriting it. | 47 // secondary cache before overwriting it. |
| 54 if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) { | 48 if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) { |
| 55 Map* old_map = primary->map; | 49 Map* old_map = primary->map; |
| 56 Code::Flags old_flags = Code::RemoveHolderFromFlags(old_code->flags()); | 50 int seed = PrimaryOffset(primary->key, old_map); |
| 57 int seed = PrimaryOffset(primary->key, old_flags, old_map); | 51 int secondary_offset = SecondaryOffset(primary->key, seed); |
| 58 int secondary_offset = SecondaryOffset(primary->key, old_flags, seed); | |
| 59 Entry* secondary = entry(secondary_, secondary_offset); | 52 Entry* secondary = entry(secondary_, secondary_offset); |
| 60 *secondary = *primary; | 53 *secondary = *primary; |
| 61 } | 54 } |
| 62 | 55 |
| 63 // Update primary cache. | 56 // Update primary cache. |
| 64 primary->key = name; | 57 primary->key = name; |
| 65 primary->value = code; | 58 primary->value = code; |
| 66 primary->map = map; | 59 primary->map = map; |
| 67 isolate()->counters()->megamorphic_stub_cache_updates()->Increment(); | 60 isolate()->counters()->megamorphic_stub_cache_updates()->Increment(); |
| 68 return code; | 61 return code; |
| 69 } | 62 } |
| 70 | 63 |
| 71 | 64 Code* StubCache::Get(Name* name, Map* map) { |
| 72 Code* StubCache::Get(Name* name, Map* map, Code::Flags flags) { | 65 CommonStubCacheChecks(name, map, nullptr); |
| 73 flags = CommonStubCacheChecks(name, map, flags); | 66 int primary_offset = PrimaryOffset(name, map); |
| 74 int primary_offset = PrimaryOffset(name, flags, map); | |
| 75 Entry* primary = entry(primary_, primary_offset); | 67 Entry* primary = entry(primary_, primary_offset); |
| 76 if (primary->key == name && primary->map == map && | 68 if (primary->key == name && primary->map == map) { |
| 77 flags == Code::RemoveHolderFromFlags(primary->value->flags())) { | |
| 78 return primary->value; | 69 return primary->value; |
| 79 } | 70 } |
| 80 int secondary_offset = SecondaryOffset(name, flags, primary_offset); | 71 int secondary_offset = SecondaryOffset(name, primary_offset); |
| 81 Entry* secondary = entry(secondary_, secondary_offset); | 72 Entry* secondary = entry(secondary_, secondary_offset); |
| 82 if (secondary->key == name && secondary->map == map && | 73 if (secondary->key == name && secondary->map == map) { |
| 83 flags == Code::RemoveHolderFromFlags(secondary->value->flags())) { | |
| 84 return secondary->value; | 74 return secondary->value; |
| 85 } | 75 } |
| 86 return NULL; | 76 return NULL; |
| 87 } | 77 } |
| 88 | 78 |
| 89 | 79 |
| 90 void StubCache::Clear() { | 80 void StubCache::Clear() { |
| 91 Code* empty = isolate_->builtins()->builtin(Builtins::kIllegal); | 81 Code* empty = isolate_->builtins()->builtin(Builtins::kIllegal); |
| 92 for (int i = 0; i < kPrimaryTableSize; i++) { | 82 for (int i = 0; i < kPrimaryTableSize; i++) { |
| 93 primary_[i].key = isolate()->heap()->empty_string(); | 83 primary_[i].key = isolate()->heap()->empty_string(); |
| 94 primary_[i].map = NULL; | 84 primary_[i].map = NULL; |
| 95 primary_[i].value = empty; | 85 primary_[i].value = empty; |
| 96 } | 86 } |
| 97 for (int j = 0; j < kSecondaryTableSize; j++) { | 87 for (int j = 0; j < kSecondaryTableSize; j++) { |
| 98 secondary_[j].key = isolate()->heap()->empty_string(); | 88 secondary_[j].key = isolate()->heap()->empty_string(); |
| 99 secondary_[j].map = NULL; | 89 secondary_[j].map = NULL; |
| 100 secondary_[j].value = empty; | 90 secondary_[j].value = empty; |
| 101 } | 91 } |
| 102 } | 92 } |
| 103 | 93 |
| 104 | 94 |
| 105 void StubCache::CollectMatchingMaps(SmallMapList* types, Handle<Name> name, | 95 void StubCache::CollectMatchingMaps(SmallMapList* types, Handle<Name> name, |
| 106 Code::Flags flags, | |
| 107 Handle<Context> native_context, | 96 Handle<Context> native_context, |
| 108 Zone* zone) { | 97 Zone* zone) { |
| 109 for (int i = 0; i < kPrimaryTableSize; i++) { | 98 for (int i = 0; i < kPrimaryTableSize; i++) { |
| 110 if (primary_[i].key == *name) { | 99 if (primary_[i].key == *name) { |
| 111 Map* map = primary_[i].map; | 100 Map* map = primary_[i].map; |
| 112 // Map can be NULL, if the stub is constant function call | 101 // Map can be NULL, if the stub is constant function call |
| 113 // with a primitive receiver. | 102 // with a primitive receiver. |
| 114 if (map == NULL) continue; | 103 if (map == NULL) continue; |
| 115 | 104 |
| 116 int offset = PrimaryOffset(*name, flags, map); | 105 int offset = PrimaryOffset(*name, map); |
| 117 if (entry(primary_, offset) == &primary_[i] && | 106 if (entry(primary_, offset) == &primary_[i] && |
| 118 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { | 107 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { |
| 119 types->AddMapIfMissing(Handle<Map>(map), zone); | 108 types->AddMapIfMissing(Handle<Map>(map), zone); |
| 120 } | 109 } |
| 121 } | 110 } |
| 122 } | 111 } |
| 123 | 112 |
| 124 for (int i = 0; i < kSecondaryTableSize; i++) { | 113 for (int i = 0; i < kSecondaryTableSize; i++) { |
| 125 if (secondary_[i].key == *name) { | 114 if (secondary_[i].key == *name) { |
| 126 Map* map = secondary_[i].map; | 115 Map* map = secondary_[i].map; |
| 127 // Map can be NULL, if the stub is constant function call | 116 // Map can be NULL, if the stub is constant function call |
| 128 // with a primitive receiver. | 117 // with a primitive receiver. |
| 129 if (map == NULL) continue; | 118 if (map == NULL) continue; |
| 130 | 119 |
| 131 // Lookup in primary table and skip duplicates. | 120 // Lookup in primary table and skip duplicates. |
| 132 int primary_offset = PrimaryOffset(*name, flags, map); | 121 int primary_offset = PrimaryOffset(*name, map); |
| 133 | 122 |
| 134 // Lookup in secondary table and add matches. | 123 // Lookup in secondary table and add matches. |
| 135 int offset = SecondaryOffset(*name, flags, primary_offset); | 124 int offset = SecondaryOffset(*name, primary_offset); |
| 136 if (entry(secondary_, offset) == &secondary_[i] && | 125 if (entry(secondary_, offset) == &secondary_[i] && |
| 137 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { | 126 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { |
| 138 types->AddMapIfMissing(Handle<Map>(map), zone); | 127 types->AddMapIfMissing(Handle<Map>(map), zone); |
| 139 } | 128 } |
| 140 } | 129 } |
| 141 } | 130 } |
| 142 } | 131 } |
| 143 } // namespace internal | 132 } // namespace internal |
| 144 } // namespace v8 | 133 } // namespace v8 |
| OLD | NEW |