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/ast/ast.h" | 7 #include "src/ast/ast.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/ic/ic-inl.h" |
9 #include "src/type-info.h" | 10 #include "src/type-info.h" |
10 | 11 |
11 namespace v8 { | 12 namespace v8 { |
12 namespace internal { | 13 namespace internal { |
13 | 14 |
14 StubCache::StubCache(Isolate* isolate, Code::Kind ic_kind) | 15 StubCache::StubCache(Isolate* isolate, Code::Kind ic_kind) |
15 : isolate_(isolate), ic_kind_(ic_kind) {} | 16 : isolate_(isolate), ic_kind_(ic_kind) { |
| 17 // Ensure the nullptr (aka Smi::kZero) which StubCache::Get() returns |
| 18 // when the entry is not found is not considered as a handler. |
| 19 DCHECK(!IC::IsHandler(nullptr)); |
| 20 } |
16 | 21 |
17 void StubCache::Initialize() { | 22 void StubCache::Initialize() { |
18 DCHECK(base::bits::IsPowerOfTwo32(kPrimaryTableSize)); | 23 DCHECK(base::bits::IsPowerOfTwo32(kPrimaryTableSize)); |
19 DCHECK(base::bits::IsPowerOfTwo32(kSecondaryTableSize)); | 24 DCHECK(base::bits::IsPowerOfTwo32(kSecondaryTableSize)); |
20 Clear(); | 25 Clear(); |
21 } | 26 } |
22 | 27 |
23 #ifdef DEBUG | 28 #ifdef DEBUG |
24 namespace { | 29 namespace { |
25 | 30 |
26 bool CommonStubCacheChecks(StubCache* stub_cache, Name* name, Map* map, | 31 bool CommonStubCacheChecks(StubCache* stub_cache, Name* name, Map* map, |
27 Code* code) { | 32 Object* handler) { |
28 // Validate that the name does not move on scavenge, and that we | 33 // Validate that the name does not move on scavenge, and that we |
29 // can use identity checks instead of structural equality checks. | 34 // can use identity checks instead of structural equality checks. |
30 DCHECK(!name->GetHeap()->InNewSpace(name)); | 35 DCHECK(!name->GetHeap()->InNewSpace(name)); |
31 DCHECK(name->IsUniqueName()); | 36 DCHECK(name->IsUniqueName()); |
32 DCHECK(name->HasHashCode()); | 37 DCHECK(name->HasHashCode()); |
33 if (code) { | 38 if (handler) { |
34 Code::Flags expected_flags = Code::RemoveHolderFromFlags( | 39 DCHECK(IC::IsHandler(handler)); |
35 Code::ComputeHandlerFlags(stub_cache->ic_kind())); | 40 if (handler->IsCode()) { |
36 Code::Flags flags = Code::RemoveHolderFromFlags(code->flags()); | 41 Code* code = Code::cast(handler); |
37 DCHECK_EQ(expected_flags, flags); | 42 Code::Flags expected_flags = Code::RemoveHolderFromFlags( |
38 DCHECK_EQ(Code::HANDLER, Code::ExtractKindFromFlags(code->flags())); | 43 Code::ComputeHandlerFlags(stub_cache->ic_kind())); |
| 44 Code::Flags flags = Code::RemoveHolderFromFlags(code->flags()); |
| 45 DCHECK_EQ(expected_flags, flags); |
| 46 DCHECK_EQ(Code::HANDLER, Code::ExtractKindFromFlags(code->flags())); |
| 47 } |
39 } | 48 } |
40 return true; | 49 return true; |
41 } | 50 } |
42 | 51 |
43 } // namespace | 52 } // namespace |
44 #endif | 53 #endif |
45 | 54 |
46 Code* StubCache::Set(Name* name, Map* map, Code* code) { | 55 Object* StubCache::Set(Name* name, Map* map, Object* handler) { |
47 DCHECK(CommonStubCacheChecks(this, name, map, code)); | 56 DCHECK(CommonStubCacheChecks(this, name, map, handler)); |
48 | 57 |
49 // Compute the primary entry. | 58 // Compute the primary entry. |
50 int primary_offset = PrimaryOffset(name, map); | 59 int primary_offset = PrimaryOffset(name, map); |
51 Entry* primary = entry(primary_, primary_offset); | 60 Entry* primary = entry(primary_, primary_offset); |
52 Code* old_code = primary->value; | 61 Object* old_handler = primary->value; |
53 | 62 |
54 // If the primary entry has useful data in it, we retire it to the | 63 // If the primary entry has useful data in it, we retire it to the |
55 // secondary cache before overwriting it. | 64 // secondary cache before overwriting it. |
56 if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) { | 65 if (old_handler != isolate_->builtins()->builtin(Builtins::kIllegal)) { |
57 Map* old_map = primary->map; | 66 Map* old_map = primary->map; |
58 int seed = PrimaryOffset(primary->key, old_map); | 67 int seed = PrimaryOffset(primary->key, old_map); |
59 int secondary_offset = SecondaryOffset(primary->key, seed); | 68 int secondary_offset = SecondaryOffset(primary->key, seed); |
60 Entry* secondary = entry(secondary_, secondary_offset); | 69 Entry* secondary = entry(secondary_, secondary_offset); |
61 *secondary = *primary; | 70 *secondary = *primary; |
62 } | 71 } |
63 | 72 |
64 // Update primary cache. | 73 // Update primary cache. |
65 primary->key = name; | 74 primary->key = name; |
66 primary->value = code; | 75 primary->value = handler; |
67 primary->map = map; | 76 primary->map = map; |
68 isolate()->counters()->megamorphic_stub_cache_updates()->Increment(); | 77 isolate()->counters()->megamorphic_stub_cache_updates()->Increment(); |
69 return code; | 78 return handler; |
70 } | 79 } |
71 | 80 |
72 Code* StubCache::Get(Name* name, Map* map) { | 81 Object* StubCache::Get(Name* name, Map* map) { |
73 DCHECK(CommonStubCacheChecks(this, name, map, nullptr)); | 82 DCHECK(CommonStubCacheChecks(this, name, map, nullptr)); |
74 int primary_offset = PrimaryOffset(name, map); | 83 int primary_offset = PrimaryOffset(name, map); |
75 Entry* primary = entry(primary_, primary_offset); | 84 Entry* primary = entry(primary_, primary_offset); |
76 if (primary->key == name && primary->map == map) { | 85 if (primary->key == name && primary->map == map) { |
77 return primary->value; | 86 return primary->value; |
78 } | 87 } |
79 int secondary_offset = SecondaryOffset(name, primary_offset); | 88 int secondary_offset = SecondaryOffset(name, primary_offset); |
80 Entry* secondary = entry(secondary_, secondary_offset); | 89 Entry* secondary = entry(secondary_, secondary_offset); |
81 if (secondary->key == name && secondary->map == map) { | 90 if (secondary->key == name && secondary->map == map) { |
82 return secondary->value; | 91 return secondary->value; |
83 } | 92 } |
84 return NULL; | 93 return nullptr; |
85 } | 94 } |
86 | 95 |
87 | 96 |
88 void StubCache::Clear() { | 97 void StubCache::Clear() { |
89 Code* empty = isolate_->builtins()->builtin(Builtins::kIllegal); | 98 Code* empty = isolate_->builtins()->builtin(Builtins::kIllegal); |
90 for (int i = 0; i < kPrimaryTableSize; i++) { | 99 for (int i = 0; i < kPrimaryTableSize; i++) { |
91 primary_[i].key = isolate()->heap()->empty_string(); | 100 primary_[i].key = isolate()->heap()->empty_string(); |
92 primary_[i].map = NULL; | 101 primary_[i].map = NULL; |
93 primary_[i].value = empty; | 102 primary_[i].value = empty; |
94 } | 103 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 int offset = SecondaryOffset(*name, primary_offset); | 141 int offset = SecondaryOffset(*name, primary_offset); |
133 if (entry(secondary_, offset) == &secondary_[i] && | 142 if (entry(secondary_, offset) == &secondary_[i] && |
134 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { | 143 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { |
135 types->AddMapIfMissing(Handle<Map>(map), zone); | 144 types->AddMapIfMissing(Handle<Map>(map), zone); |
136 } | 145 } |
137 } | 146 } |
138 } | 147 } |
139 } | 148 } |
140 } // namespace internal | 149 } // namespace internal |
141 } // namespace v8 | 150 } // namespace v8 |
OLD | NEW |