| 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 | 13 |
| 14 StubCache::StubCache(Isolate* isolate) : isolate_(isolate) {} | 14 StubCache::StubCache(Isolate* isolate) : isolate_(isolate) {} |
| 15 | 15 |
| 16 | 16 |
| 17 void StubCache::Initialize() { | 17 void StubCache::Initialize() { |
| 18 DCHECK(base::bits::IsPowerOfTwo32(kPrimaryTableSize)); | 18 DCHECK(base::bits::IsPowerOfTwo32(kPrimaryTableSize)); |
| 19 DCHECK(base::bits::IsPowerOfTwo32(kSecondaryTableSize)); | 19 DCHECK(base::bits::IsPowerOfTwo32(kSecondaryTableSize)); |
| 20 Clear(); | 20 Clear(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 | 23 |
| 24 static Code::Flags CommonStubCacheChecks(Name* name, Map* map, | 24 static Code::Flags CommonStubCacheChecks(Name* name, Map* map, |
| 25 Code::Flags flags) { | 25 Code::Flags flags) { |
| 26 flags = Code::RemoveTypeAndHolderFromFlags(flags); | 26 flags = Code::RemoveHolderFromFlags(flags); |
| 27 | 27 |
| 28 // Validate that the name does not move on scavenge, and that we | 28 // Validate that the name does not move on scavenge, and that we |
| 29 // can use identity checks instead of structural equality checks. | 29 // can use identity checks instead of structural equality checks. |
| 30 DCHECK(!name->GetHeap()->InNewSpace(name)); | 30 DCHECK(!name->GetHeap()->InNewSpace(name)); |
| 31 DCHECK(name->IsUniqueName()); | 31 DCHECK(name->IsUniqueName()); |
| 32 | 32 |
| 33 // The state bits are not important to the hash function because the stub | 33 // The state bits are not important to the hash function because the stub |
| 34 // cache only contains handlers. Make sure that the bits are the least | 34 // cache only contains handlers. Make sure that the bits are the least |
| 35 // significant so they will be the ones masked out. | 35 // significant so they will be the ones masked out. |
| 36 DCHECK_EQ(Code::HANDLER, Code::ExtractKindFromFlags(flags)); | 36 DCHECK_EQ(Code::HANDLER, Code::ExtractKindFromFlags(flags)); |
| 37 STATIC_ASSERT((Code::ICStateField::kMask & 1) == 1); | 37 STATIC_ASSERT((Code::ICStateField::kMask & 1) == 1); |
| 38 | 38 |
| 39 // Make sure that the code type and cache holder are not included in the hash. | 39 // Make sure that the cache holder are not included in the hash. |
| 40 DCHECK(Code::ExtractTypeFromFlags(flags) == 0); | |
| 41 DCHECK(Code::ExtractCacheHolderFromFlags(flags) == 0); | 40 DCHECK(Code::ExtractCacheHolderFromFlags(flags) == 0); |
| 42 | 41 |
| 43 return flags; | 42 return flags; |
| 44 } | 43 } |
| 45 | 44 |
| 46 | 45 |
| 47 Code* StubCache::Set(Name* name, Map* map, Code* code) { | 46 Code* StubCache::Set(Name* name, Map* map, Code* code) { |
| 48 Code::Flags flags = CommonStubCacheChecks(name, map, code->flags()); | 47 Code::Flags flags = CommonStubCacheChecks(name, map, code->flags()); |
| 49 | 48 |
| 50 // Compute the primary entry. | 49 // Compute the primary entry. |
| 51 int primary_offset = PrimaryOffset(name, flags, map); | 50 int primary_offset = PrimaryOffset(name, flags, map); |
| 52 Entry* primary = entry(primary_, primary_offset); | 51 Entry* primary = entry(primary_, primary_offset); |
| 53 Code* old_code = primary->value; | 52 Code* old_code = primary->value; |
| 54 | 53 |
| 55 // If the primary entry has useful data in it, we retire it to the | 54 // If the primary entry has useful data in it, we retire it to the |
| 56 // secondary cache before overwriting it. | 55 // secondary cache before overwriting it. |
| 57 if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) { | 56 if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) { |
| 58 Map* old_map = primary->map; | 57 Map* old_map = primary->map; |
| 59 Code::Flags old_flags = | 58 Code::Flags old_flags = Code::RemoveHolderFromFlags(old_code->flags()); |
| 60 Code::RemoveTypeAndHolderFromFlags(old_code->flags()); | |
| 61 int seed = PrimaryOffset(primary->key, old_flags, old_map); | 59 int seed = PrimaryOffset(primary->key, old_flags, old_map); |
| 62 int secondary_offset = SecondaryOffset(primary->key, old_flags, seed); | 60 int secondary_offset = SecondaryOffset(primary->key, old_flags, seed); |
| 63 Entry* secondary = entry(secondary_, secondary_offset); | 61 Entry* secondary = entry(secondary_, secondary_offset); |
| 64 *secondary = *primary; | 62 *secondary = *primary; |
| 65 } | 63 } |
| 66 | 64 |
| 67 // Update primary cache. | 65 // Update primary cache. |
| 68 primary->key = name; | 66 primary->key = name; |
| 69 primary->value = code; | 67 primary->value = code; |
| 70 primary->map = map; | 68 primary->map = map; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 int offset = SecondaryOffset(*name, flags, primary_offset); | 135 int offset = SecondaryOffset(*name, flags, primary_offset); |
| 138 if (entry(secondary_, offset) == &secondary_[i] && | 136 if (entry(secondary_, offset) == &secondary_[i] && |
| 139 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { | 137 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { |
| 140 types->AddMapIfMissing(Handle<Map>(map), zone); | 138 types->AddMapIfMissing(Handle<Map>(map), zone); |
| 141 } | 139 } |
| 142 } | 140 } |
| 143 } | 141 } |
| 144 } | 142 } |
| 145 } // namespace internal | 143 } // namespace internal |
| 146 } // namespace v8 | 144 } // namespace v8 |
| OLD | NEW |