Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: src/ic/stub-cache.cc

Issue 2147213004: Revert of [ic] [stubs] Don't use Code::flags in megamorphic stub cache hash computations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@split-stub-cache
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ic/stub-cache.h ('k') | src/ic/x64/stub-cache-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 static void CommonStubCacheChecks(Name* name, Map* map, Code* code) { 22
23 static Code::Flags CommonStubCacheChecks(Name* name, Map* map,
24 Code::Flags flags) {
25 flags = Code::RemoveHolderFromFlags(flags);
26
23 // Validate that the name does not move on scavenge, and that we 27 // Validate that the name does not move on scavenge, and that we
24 // can use identity checks instead of structural equality checks. 28 // can use identity checks instead of structural equality checks.
25 DCHECK(!name->GetHeap()->InNewSpace(name)); 29 DCHECK(!name->GetHeap()->InNewSpace(name));
26 DCHECK(name->IsUniqueName()); 30 DCHECK(name->IsUniqueName());
27 DCHECK(name->HasHashCode()); 31
28 if (code) { 32 // The state bits are not important to the hash function because the stub
29 DCHECK_EQ(Code::HANDLER, Code::ExtractKindFromFlags(code->flags())); 33 // cache only contains handlers. Make sure that the bits are the least
30 } 34 // significant so they will be the ones masked out.
35 DCHECK_EQ(Code::HANDLER, Code::ExtractKindFromFlags(flags));
36
37 // Make sure that the cache holder are not included in the hash.
38 DCHECK(Code::ExtractCacheHolderFromFlags(flags) == 0);
39
40 return flags;
31 } 41 }
32 42
33 43
34 Code* StubCache::Set(Name* name, Map* map, Code* code) { 44 Code* StubCache::Set(Name* name, Map* map, Code* code) {
35 CommonStubCacheChecks(name, map, code); 45 Code::Flags flags = CommonStubCacheChecks(name, map, code->flags());
36 46
37 // Compute the primary entry. 47 // Compute the primary entry.
38 int primary_offset = PrimaryOffset(name, map); 48 int primary_offset = PrimaryOffset(name, flags, map);
39 Entry* primary = entry(primary_, primary_offset); 49 Entry* primary = entry(primary_, primary_offset);
40 Code* old_code = primary->value; 50 Code* old_code = primary->value;
41 51
42 // If the primary entry has useful data in it, we retire it to the 52 // If the primary entry has useful data in it, we retire it to the
43 // secondary cache before overwriting it. 53 // secondary cache before overwriting it.
44 if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) { 54 if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) {
45 Map* old_map = primary->map; 55 Map* old_map = primary->map;
46 int seed = PrimaryOffset(primary->key, old_map); 56 Code::Flags old_flags = Code::RemoveHolderFromFlags(old_code->flags());
47 int secondary_offset = SecondaryOffset(primary->key, seed); 57 int seed = PrimaryOffset(primary->key, old_flags, old_map);
58 int secondary_offset = SecondaryOffset(primary->key, old_flags, seed);
48 Entry* secondary = entry(secondary_, secondary_offset); 59 Entry* secondary = entry(secondary_, secondary_offset);
49 *secondary = *primary; 60 *secondary = *primary;
50 } 61 }
51 62
52 // Update primary cache. 63 // Update primary cache.
53 primary->key = name; 64 primary->key = name;
54 primary->value = code; 65 primary->value = code;
55 primary->map = map; 66 primary->map = map;
56 isolate()->counters()->megamorphic_stub_cache_updates()->Increment(); 67 isolate()->counters()->megamorphic_stub_cache_updates()->Increment();
57 return code; 68 return code;
58 } 69 }
59 70
60 Code* StubCache::Get(Name* name, Map* map) { 71
61 CommonStubCacheChecks(name, map, nullptr); 72 Code* StubCache::Get(Name* name, Map* map, Code::Flags flags) {
62 int primary_offset = PrimaryOffset(name, map); 73 flags = CommonStubCacheChecks(name, map, flags);
74 int primary_offset = PrimaryOffset(name, flags, map);
63 Entry* primary = entry(primary_, primary_offset); 75 Entry* primary = entry(primary_, primary_offset);
64 if (primary->key == name && primary->map == map) { 76 if (primary->key == name && primary->map == map &&
77 flags == Code::RemoveHolderFromFlags(primary->value->flags())) {
65 return primary->value; 78 return primary->value;
66 } 79 }
67 int secondary_offset = SecondaryOffset(name, primary_offset); 80 int secondary_offset = SecondaryOffset(name, flags, primary_offset);
68 Entry* secondary = entry(secondary_, secondary_offset); 81 Entry* secondary = entry(secondary_, secondary_offset);
69 if (secondary->key == name && secondary->map == map) { 82 if (secondary->key == name && secondary->map == map &&
83 flags == Code::RemoveHolderFromFlags(secondary->value->flags())) {
70 return secondary->value; 84 return secondary->value;
71 } 85 }
72 return NULL; 86 return NULL;
73 } 87 }
74 88
75 89
76 void StubCache::Clear() { 90 void StubCache::Clear() {
77 Code* empty = isolate_->builtins()->builtin(Builtins::kIllegal); 91 Code* empty = isolate_->builtins()->builtin(Builtins::kIllegal);
78 for (int i = 0; i < kPrimaryTableSize; i++) { 92 for (int i = 0; i < kPrimaryTableSize; i++) {
79 primary_[i].key = isolate()->heap()->empty_string(); 93 primary_[i].key = isolate()->heap()->empty_string();
80 primary_[i].map = NULL; 94 primary_[i].map = NULL;
81 primary_[i].value = empty; 95 primary_[i].value = empty;
82 } 96 }
83 for (int j = 0; j < kSecondaryTableSize; j++) { 97 for (int j = 0; j < kSecondaryTableSize; j++) {
84 secondary_[j].key = isolate()->heap()->empty_string(); 98 secondary_[j].key = isolate()->heap()->empty_string();
85 secondary_[j].map = NULL; 99 secondary_[j].map = NULL;
86 secondary_[j].value = empty; 100 secondary_[j].value = empty;
87 } 101 }
88 } 102 }
89 103
90 104
91 void StubCache::CollectMatchingMaps(SmallMapList* types, Handle<Name> name, 105 void StubCache::CollectMatchingMaps(SmallMapList* types, Handle<Name> name,
106 Code::Flags flags,
92 Handle<Context> native_context, 107 Handle<Context> native_context,
93 Zone* zone) { 108 Zone* zone) {
94 for (int i = 0; i < kPrimaryTableSize; i++) { 109 for (int i = 0; i < kPrimaryTableSize; i++) {
95 if (primary_[i].key == *name) { 110 if (primary_[i].key == *name) {
96 Map* map = primary_[i].map; 111 Map* map = primary_[i].map;
97 // Map can be NULL, if the stub is constant function call 112 // Map can be NULL, if the stub is constant function call
98 // with a primitive receiver. 113 // with a primitive receiver.
99 if (map == NULL) continue; 114 if (map == NULL) continue;
100 115
101 int offset = PrimaryOffset(*name, map); 116 int offset = PrimaryOffset(*name, flags, map);
102 if (entry(primary_, offset) == &primary_[i] && 117 if (entry(primary_, offset) == &primary_[i] &&
103 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { 118 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) {
104 types->AddMapIfMissing(Handle<Map>(map), zone); 119 types->AddMapIfMissing(Handle<Map>(map), zone);
105 } 120 }
106 } 121 }
107 } 122 }
108 123
109 for (int i = 0; i < kSecondaryTableSize; i++) { 124 for (int i = 0; i < kSecondaryTableSize; i++) {
110 if (secondary_[i].key == *name) { 125 if (secondary_[i].key == *name) {
111 Map* map = secondary_[i].map; 126 Map* map = secondary_[i].map;
112 // Map can be NULL, if the stub is constant function call 127 // Map can be NULL, if the stub is constant function call
113 // with a primitive receiver. 128 // with a primitive receiver.
114 if (map == NULL) continue; 129 if (map == NULL) continue;
115 130
116 // Lookup in primary table and skip duplicates. 131 // Lookup in primary table and skip duplicates.
117 int primary_offset = PrimaryOffset(*name, map); 132 int primary_offset = PrimaryOffset(*name, flags, map);
118 133
119 // Lookup in secondary table and add matches. 134 // Lookup in secondary table and add matches.
120 int offset = SecondaryOffset(*name, primary_offset); 135 int offset = SecondaryOffset(*name, flags, primary_offset);
121 if (entry(secondary_, offset) == &secondary_[i] && 136 if (entry(secondary_, offset) == &secondary_[i] &&
122 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) { 137 TypeFeedbackOracle::IsRelevantFeedback(map, *native_context)) {
123 types->AddMapIfMissing(Handle<Map>(map), zone); 138 types->AddMapIfMissing(Handle<Map>(map), zone);
124 } 139 }
125 } 140 }
126 } 141 }
127 } 142 }
128 } // namespace internal 143 } // namespace internal
129 } // namespace v8 144 } // namespace v8
OLDNEW
« no previous file with comments | « src/ic/stub-cache.h ('k') | src/ic/x64/stub-cache-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698