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

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

Issue 9496010: Fix secondary stub cache and add a test for the stub cache lookups. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 26 matching lines...) Expand all
37 namespace internal { 37 namespace internal {
38 38
39 #define __ ACCESS_MASM(masm) 39 #define __ ACCESS_MASM(masm)
40 40
41 41
42 static void ProbeTable(Isolate* isolate, 42 static void ProbeTable(Isolate* isolate,
43 MacroAssembler* masm, 43 MacroAssembler* masm,
44 Code::Flags flags, 44 Code::Flags flags,
45 StubCache::Table table, 45 StubCache::Table table,
46 Register name, 46 Register name,
47 Register receiver,
47 Register offset, 48 Register offset,
48 Register extra) { 49 Register extra) {
49 ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); 50 ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
50 ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); 51 ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
52 ExternalReference map_offset(isolate->stub_cache()->map_reference(table));
51 53
52 Label miss; 54 Label miss;
53 55
56 // Multiply by 3.
57 __ lea(offset, Operand(offset, offset, times_2, 0));
58
54 if (extra.is_valid()) { 59 if (extra.is_valid()) {
55 // Get the code entry from the cache. 60 // Get the code entry from the cache.
56 __ mov(extra, Operand::StaticArray(offset, times_2, value_offset)); 61 __ mov(extra, Operand::StaticArray(offset, times_1, value_offset));
57 62
58 // Check that the key in the entry matches the name. 63 // Check that the key in the entry matches the name.
59 __ cmp(name, Operand::StaticArray(offset, times_2, key_offset)); 64 __ cmp(name, Operand::StaticArray(offset, times_1, key_offset));
65 __ j(not_equal, &miss);
66
67 // Check the map matches.
68 __ mov(offset, Operand::StaticArray(offset, times_1, map_offset));
69 __ cmp(offset, FieldOperand(receiver, HeapObject::kMapOffset));
60 __ j(not_equal, &miss); 70 __ j(not_equal, &miss);
61 71
62 // Check that the flags match what we're looking for. 72 // Check that the flags match what we're looking for.
63 __ mov(offset, FieldOperand(extra, Code::kFlagsOffset)); 73 __ mov(offset, FieldOperand(extra, Code::kFlagsOffset));
64 __ and_(offset, ~Code::kFlagsNotUsedInLookup); 74 __ and_(offset, ~Code::kFlagsNotUsedInLookup);
65 __ cmp(offset, flags); 75 __ cmp(offset, flags);
66 __ j(not_equal, &miss); 76 __ j(not_equal, &miss);
67 77
78 #ifdef DEBUG
79 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
80 __ jmp(&miss);
81 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
82 __ jmp(&miss);
83 }
84 #endif
85
68 // Jump to the first instruction in the code stub. 86 // Jump to the first instruction in the code stub.
69 __ add(extra, Immediate(Code::kHeaderSize - kHeapObjectTag)); 87 __ add(extra, Immediate(Code::kHeaderSize - kHeapObjectTag));
70 __ jmp(extra); 88 __ jmp(extra);
71 89
72 __ bind(&miss); 90 __ bind(&miss);
73 } else { 91 } else {
74 // Save the offset on the stack. 92 // Save the offset on the stack.
75 __ push(offset); 93 __ push(offset);
76 94
77 // Check that the key in the entry matches the name. 95 // Check that the key in the entry matches the name.
78 __ cmp(name, Operand::StaticArray(offset, times_2, key_offset)); 96 __ cmp(name, Operand::StaticArray(offset, times_1, key_offset));
79 __ j(not_equal, &miss); 97 __ j(not_equal, &miss);
80 98
99 // Check the map matches.
100 __ mov(offset, Operand::StaticArray(offset, times_1, map_offset));
101 __ cmp(offset, FieldOperand(receiver, HeapObject::kMapOffset));
102 __ j(not_equal, &miss);
103
104 // Restore offset register.
105 __ mov(offset, Operand(esp, 0));
106
81 // Get the code entry from the cache. 107 // Get the code entry from the cache.
82 __ mov(offset, Operand::StaticArray(offset, times_2, value_offset)); 108 __ mov(offset, Operand::StaticArray(offset, times_1, value_offset));
83 109
84 // Check that the flags match what we're looking for. 110 // Check that the flags match what we're looking for.
85 __ mov(offset, FieldOperand(offset, Code::kFlagsOffset)); 111 __ mov(offset, FieldOperand(offset, Code::kFlagsOffset));
86 __ and_(offset, ~Code::kFlagsNotUsedInLookup); 112 __ and_(offset, ~Code::kFlagsNotUsedInLookup);
87 __ cmp(offset, flags); 113 __ cmp(offset, flags);
88 __ j(not_equal, &miss); 114 __ j(not_equal, &miss);
89 115
116 #ifdef DEBUG
117 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
118 __ jmp(&miss);
119 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
120 __ jmp(&miss);
121 }
122 #endif
123
90 // Restore offset and re-load code entry from cache. 124 // Restore offset and re-load code entry from cache.
91 __ pop(offset); 125 __ pop(offset);
92 __ mov(offset, Operand::StaticArray(offset, times_2, value_offset)); 126 __ mov(offset, Operand::StaticArray(offset, times_1, value_offset));
93 127
94 // Jump to the first instruction in the code stub. 128 // Jump to the first instruction in the code stub.
95 __ add(offset, Immediate(Code::kHeaderSize - kHeapObjectTag)); 129 __ add(offset, Immediate(Code::kHeaderSize - kHeapObjectTag));
96 __ jmp(offset); 130 __ jmp(offset);
97 131
98 // Pop at miss. 132 // Pop at miss.
99 __ bind(&miss); 133 __ bind(&miss);
100 __ pop(offset); 134 __ pop(offset);
101 } 135 }
102 } 136 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 __ DecrementCounter(counters->negative_lookups_miss(), 1); 186 __ DecrementCounter(counters->negative_lookups_miss(), 1);
153 } 187 }
154 188
155 189
156 void StubCache::GenerateProbe(MacroAssembler* masm, 190 void StubCache::GenerateProbe(MacroAssembler* masm,
157 Code::Flags flags, 191 Code::Flags flags,
158 Register receiver, 192 Register receiver,
159 Register name, 193 Register name,
160 Register scratch, 194 Register scratch,
161 Register extra, 195 Register extra,
162 Register extra2) { 196 Register extra2,
197 Register extra3) {
163 Label miss; 198 Label miss;
164 199
165 // Assert that code is valid. The shifting code relies on the entry size 200 // Assert that code is valid. The multiplying code relies on the entry size
166 // being 8. 201 // being 12.
167 ASSERT(sizeof(Entry) == 8); 202 ASSERT(sizeof(Entry) == 12);
168 203
169 // Assert the flags do not name a specific type. 204 // Assert the flags do not name a specific type.
170 ASSERT(Code::ExtractTypeFromFlags(flags) == 0); 205 ASSERT(Code::ExtractTypeFromFlags(flags) == 0);
171 206
172 // Assert that there are no register conflicts. 207 // Assert that there are no register conflicts.
173 ASSERT(!scratch.is(receiver)); 208 ASSERT(!scratch.is(receiver));
174 ASSERT(!scratch.is(name)); 209 ASSERT(!scratch.is(name));
175 ASSERT(!extra.is(receiver)); 210 ASSERT(!extra.is(receiver));
176 ASSERT(!extra.is(name)); 211 ASSERT(!extra.is(name));
177 ASSERT(!extra.is(scratch)); 212 ASSERT(!extra.is(scratch));
178 213
179 // Assert scratch and extra registers are valid, and extra2 is unused. 214 // Assert scratch and extra registers are valid, and extra2/3 are unused.
180 ASSERT(!scratch.is(no_reg)); 215 ASSERT(!scratch.is(no_reg));
181 ASSERT(extra2.is(no_reg)); 216 ASSERT(extra2.is(no_reg));
217 ASSERT(extra3.is(no_reg));
218
219 Counters* counters = masm->isolate()->counters();
220 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1);
182 221
183 // Check that the receiver isn't a smi. 222 // Check that the receiver isn't a smi.
184 __ JumpIfSmi(receiver, &miss); 223 __ JumpIfSmi(receiver, &miss);
185 224
186 // Get the map of the receiver and compute the hash. 225 // Get the map of the receiver and compute the hash.
187 __ mov(scratch, FieldOperand(name, String::kHashFieldOffset)); 226 __ mov(scratch, FieldOperand(name, String::kHashFieldOffset));
188 __ add(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); 227 __ add(scratch, FieldOperand(receiver, HeapObject::kMapOffset));
189 __ xor_(scratch, flags); 228 __ xor_(scratch, flags);
190 __ and_(scratch, (kPrimaryTableSize - 1) << kHeapObjectTagSize); 229 __ and_(scratch, (kPrimaryTableSize - 1) << kHeapObjectTagSize);
191 230
192 // Probe the primary table. 231 // Probe the primary table.
193 ProbeTable(isolate(), masm, flags, kPrimary, name, scratch, extra); 232 ProbeTable(isolate(), masm, flags, kPrimary, name, receiver, scratch, extra);
194 233
195 // Primary miss: Compute hash for secondary probe. 234 // Primary miss: Compute hash for secondary probe.
196 __ mov(scratch, FieldOperand(name, String::kHashFieldOffset)); 235 __ mov(scratch, FieldOperand(name, String::kHashFieldOffset));
197 __ add(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); 236 __ add(scratch, FieldOperand(receiver, HeapObject::kMapOffset));
198 __ xor_(scratch, flags); 237 __ xor_(scratch, flags);
199 __ and_(scratch, (kPrimaryTableSize - 1) << kHeapObjectTagSize); 238 __ and_(scratch, (kPrimaryTableSize - 1) << kHeapObjectTagSize);
200 __ sub(scratch, name); 239 __ sub(scratch, name);
201 __ add(scratch, Immediate(flags)); 240 __ add(scratch, Immediate(flags));
202 __ and_(scratch, (kSecondaryTableSize - 1) << kHeapObjectTagSize); 241 __ and_(scratch, (kSecondaryTableSize - 1) << kHeapObjectTagSize);
203 242
204 // Probe the secondary table. 243 // Probe the secondary table.
205 ProbeTable(isolate(), masm, flags, kSecondary, name, scratch, extra); 244 ProbeTable(
245 isolate(), masm, flags, kSecondary, name, receiver, scratch, extra);
206 246
207 // Cache miss: Fall-through and let caller handle the miss by 247 // Cache miss: Fall-through and let caller handle the miss by
208 // entering the runtime system. 248 // entering the runtime system.
209 __ bind(&miss); 249 __ bind(&miss);
250 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1);
210 } 251 }
211 252
212 253
213 void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, 254 void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm,
214 int index, 255 int index,
215 Register prototype) { 256 Register prototype) {
216 __ LoadGlobalFunction(index, prototype); 257 __ LoadGlobalFunction(index, prototype);
217 __ LoadGlobalFunctionInitialMap(prototype, prototype); 258 __ LoadGlobalFunctionInitialMap(prototype, prototype);
218 // Load the prototype from the initial map. 259 // Load the prototype from the initial map.
219 __ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset)); 260 __ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset));
(...skipping 3777 matching lines...) Expand 10 before | Expand all | Expand 10 after
3997 __ jmp(ic_slow, RelocInfo::CODE_TARGET); 4038 __ jmp(ic_slow, RelocInfo::CODE_TARGET);
3998 } 4039 }
3999 } 4040 }
4000 4041
4001 4042
4002 #undef __ 4043 #undef __
4003 4044
4004 } } // namespace v8::internal 4045 } } // namespace v8::internal
4005 4046
4006 #endif // V8_TARGET_ARCH_IA32 4047 #endif // V8_TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698