OLD | NEW |
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 25 matching lines...) Expand all Loading... |
36 namespace v8 { | 36 namespace v8 { |
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 receiver, |
46 Register name, | 47 Register name, |
| 48 // Number of the cache entry, not scaled. |
47 Register offset, | 49 Register offset, |
48 Register scratch, | 50 Register scratch, |
49 Register scratch2) { | 51 Register scratch2, |
| 52 Register offset_scratch) { |
50 ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); | 53 ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); |
51 ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); | 54 ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); |
| 55 ExternalReference map_offset(isolate->stub_cache()->map_reference(table)); |
52 | 56 |
53 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address()); | 57 uint32_t key_off_addr = reinterpret_cast<uint32_t>(key_offset.address()); |
54 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address()); | 58 uint32_t value_off_addr = reinterpret_cast<uint32_t>(value_offset.address()); |
| 59 uint32_t map_off_addr = reinterpret_cast<uint32_t>(map_offset.address()); |
55 | 60 |
56 // Check the relative positions of the address fields. | 61 // Check the relative positions of the address fields. |
57 ASSERT(value_off_addr > key_off_addr); | 62 ASSERT(value_off_addr > key_off_addr); |
58 ASSERT((value_off_addr - key_off_addr) % 4 == 0); | 63 ASSERT((value_off_addr - key_off_addr) % 4 == 0); |
59 ASSERT((value_off_addr - key_off_addr) < (256 * 4)); | 64 ASSERT((value_off_addr - key_off_addr) < (256 * 4)); |
| 65 ASSERT(map_off_addr > key_off_addr); |
| 66 ASSERT((map_off_addr - key_off_addr) % 4 == 0); |
| 67 ASSERT((map_off_addr - key_off_addr) < (256 * 4)); |
60 | 68 |
61 Label miss; | 69 Label miss; |
62 Register offsets_base_addr = scratch; | 70 Register base_addr = scratch; |
| 71 scratch = no_reg; |
| 72 |
| 73 // Multiply by 3 because there are 3 fields per entry (name, code, map). |
| 74 __ sll(offset_scratch, offset, 1); |
| 75 __ Addu(offset_scratch, offset_scratch, offset); |
| 76 |
| 77 // Calculate the base address of the entry. |
| 78 __ li(base_addr, Operand(key_offset)); |
| 79 __ sll(at, offset_scratch, kPointerSizeLog2); |
| 80 __ Addu(base_addr, base_addr, at); |
63 | 81 |
64 // Check that the key in the entry matches the name. | 82 // Check that the key in the entry matches the name. |
65 __ li(offsets_base_addr, Operand(key_offset)); | 83 __ lw(at, MemOperand(base_addr, 0)); |
66 __ sll(scratch2, offset, 1); | 84 __ Branch(&miss, ne, name, Operand(at)); |
67 __ addu(scratch2, offsets_base_addr, scratch2); | 85 |
68 __ lw(scratch2, MemOperand(scratch2)); | 86 // Check the map matches. |
69 __ Branch(&miss, ne, name, Operand(scratch2)); | 87 __ lw(at, MemOperand(base_addr, map_off_addr - key_off_addr)); |
| 88 __ lw(scratch2, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 89 __ Branch(&miss, ne, at, Operand(scratch2)); |
70 | 90 |
71 // Get the code entry from the cache. | 91 // Get the code entry from the cache. |
72 __ Addu(offsets_base_addr, offsets_base_addr, | 92 Register code = scratch2; |
73 Operand(value_off_addr - key_off_addr)); | 93 scratch2 = no_reg; |
74 __ sll(scratch2, offset, 1); | 94 __ lw(code, MemOperand(base_addr, value_off_addr - key_off_addr)); |
75 __ addu(scratch2, offsets_base_addr, scratch2); | |
76 __ lw(scratch2, MemOperand(scratch2)); | |
77 | 95 |
78 // Check that the flags match what we're looking for. | 96 // Check that the flags match what we're looking for. |
79 __ lw(scratch2, FieldMemOperand(scratch2, Code::kFlagsOffset)); | 97 Register flags_reg = base_addr; |
80 __ And(scratch2, scratch2, Operand(~Code::kFlagsNotUsedInLookup)); | 98 base_addr = no_reg; |
81 __ Branch(&miss, ne, scratch2, Operand(flags)); | 99 __ lw(flags_reg, FieldMemOperand(code, Code::kFlagsOffset)); |
| 100 __ And(flags_reg, flags_reg, Operand(~Code::kFlagsNotUsedInLookup)); |
| 101 __ Branch(&miss, ne, flags_reg, Operand(flags)); |
82 | 102 |
83 // Re-load code entry from cache. | 103 #ifdef DEBUG |
84 __ sll(offset, offset, 1); | 104 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
85 __ addu(offset, offset, offsets_base_addr); | 105 __ jmp(&miss); |
86 __ lw(offset, MemOperand(offset)); | 106 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
| 107 __ jmp(&miss); |
| 108 } |
| 109 #endif |
87 | 110 |
88 // Jump to the first instruction in the code stub. | 111 // Jump to the first instruction in the code stub. |
89 __ Addu(offset, offset, Operand(Code::kHeaderSize - kHeapObjectTag)); | 112 __ Addu(at, code, Operand(Code::kHeaderSize - kHeapObjectTag)); |
90 __ Jump(offset); | 113 __ Jump(at); |
91 | 114 |
92 // Miss: fall through. | 115 // Miss: fall through. |
93 __ bind(&miss); | 116 __ bind(&miss); |
94 } | 117 } |
95 | 118 |
96 | 119 |
97 // Helper function used to check that the dictionary doesn't contain | 120 // Helper function used to check that the dictionary doesn't contain |
98 // the property. This function may return false negatives, so miss_label | 121 // the property. This function may return false negatives, so miss_label |
99 // must always call a backup property check that is complete. | 122 // must always call a backup property check that is complete. |
100 // This function is safe to call if the receiver has fast properties. | 123 // This function is safe to call if the receiver has fast properties. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1); | 173 __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1); |
151 } | 174 } |
152 | 175 |
153 | 176 |
154 void StubCache::GenerateProbe(MacroAssembler* masm, | 177 void StubCache::GenerateProbe(MacroAssembler* masm, |
155 Code::Flags flags, | 178 Code::Flags flags, |
156 Register receiver, | 179 Register receiver, |
157 Register name, | 180 Register name, |
158 Register scratch, | 181 Register scratch, |
159 Register extra, | 182 Register extra, |
160 Register extra2) { | 183 Register extra2, |
| 184 Register extra3) { |
161 Isolate* isolate = masm->isolate(); | 185 Isolate* isolate = masm->isolate(); |
162 Label miss; | 186 Label miss; |
163 | 187 |
164 // Make sure that code is valid. The shifting code relies on the | 188 // Make sure that code is valid. The multiplying code relies on the |
165 // entry size being 8. | 189 // entry size being 12. |
166 ASSERT(sizeof(Entry) == 8); | 190 ASSERT(sizeof(Entry) == 12); |
167 | 191 |
168 // Make sure the flags does not name a specific type. | 192 // Make sure the flags does not name a specific type. |
169 ASSERT(Code::ExtractTypeFromFlags(flags) == 0); | 193 ASSERT(Code::ExtractTypeFromFlags(flags) == 0); |
170 | 194 |
171 // Make sure that there are no register conflicts. | 195 // Make sure that there are no register conflicts. |
172 ASSERT(!scratch.is(receiver)); | 196 ASSERT(!scratch.is(receiver)); |
173 ASSERT(!scratch.is(name)); | 197 ASSERT(!scratch.is(name)); |
174 ASSERT(!extra.is(receiver)); | 198 ASSERT(!extra.is(receiver)); |
175 ASSERT(!extra.is(name)); | 199 ASSERT(!extra.is(name)); |
176 ASSERT(!extra.is(scratch)); | 200 ASSERT(!extra.is(scratch)); |
177 ASSERT(!extra2.is(receiver)); | 201 ASSERT(!extra2.is(receiver)); |
178 ASSERT(!extra2.is(name)); | 202 ASSERT(!extra2.is(name)); |
179 ASSERT(!extra2.is(scratch)); | 203 ASSERT(!extra2.is(scratch)); |
180 ASSERT(!extra2.is(extra)); | 204 ASSERT(!extra2.is(extra)); |
181 | 205 |
182 // Check scratch, extra and extra2 registers are valid. | 206 // Check register validity. |
183 ASSERT(!scratch.is(no_reg)); | 207 ASSERT(!scratch.is(no_reg)); |
184 ASSERT(!extra.is(no_reg)); | 208 ASSERT(!extra.is(no_reg)); |
185 ASSERT(!extra2.is(no_reg)); | 209 ASSERT(!extra2.is(no_reg)); |
| 210 ASSERT(!extra3.is(no_reg)); |
| 211 |
| 212 Counters* counters = masm->isolate()->counters(); |
| 213 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, |
| 214 extra2, extra3); |
186 | 215 |
187 // Check that the receiver isn't a smi. | 216 // Check that the receiver isn't a smi. |
188 __ JumpIfSmi(receiver, &miss, t0); | 217 __ JumpIfSmi(receiver, &miss); |
189 | 218 |
190 // Get the map of the receiver and compute the hash. | 219 // Get the map of the receiver and compute the hash. |
191 __ lw(scratch, FieldMemOperand(name, String::kHashFieldOffset)); | 220 __ lw(scratch, FieldMemOperand(name, String::kHashFieldOffset)); |
192 __ lw(t8, FieldMemOperand(receiver, HeapObject::kMapOffset)); | 221 __ lw(at, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
193 __ Addu(scratch, scratch, Operand(t8)); | 222 __ Addu(scratch, scratch, at); |
194 __ Xor(scratch, scratch, Operand(flags)); | 223 uint32_t mask = kPrimaryTableSize - 1; |
195 __ And(scratch, | 224 // We shift out the last two bits because they are not part of the hash and |
196 scratch, | 225 // they are always 01 for maps. |
197 Operand((kPrimaryTableSize - 1) << kHeapObjectTagSize)); | 226 __ srl(scratch, scratch, kHeapObjectTagSize); |
| 227 __ Xor(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask)); |
| 228 __ And(scratch, scratch, Operand(mask)); |
198 | 229 |
199 // Probe the primary table. | 230 // Probe the primary table. |
200 ProbeTable(isolate, masm, flags, kPrimary, name, scratch, extra, extra2); | 231 ProbeTable(isolate, |
| 232 masm, |
| 233 flags, |
| 234 kPrimary, |
| 235 receiver, |
| 236 name, |
| 237 scratch, |
| 238 extra, |
| 239 extra2, |
| 240 extra3); |
201 | 241 |
202 // Primary miss: Compute hash for secondary probe. | 242 // Primary miss: Compute hash for secondary probe. |
203 __ Subu(scratch, scratch, Operand(name)); | 243 __ srl(at, name, kHeapObjectTagSize); |
204 __ Addu(scratch, scratch, Operand(flags)); | 244 __ Subu(scratch, scratch, at); |
205 __ And(scratch, | 245 uint32_t mask2 = kSecondaryTableSize - 1; |
206 scratch, | 246 __ Addu(scratch, scratch, Operand((flags >> kHeapObjectTagSize) & mask2)); |
207 Operand((kSecondaryTableSize - 1) << kHeapObjectTagSize)); | 247 __ And(scratch, scratch, Operand(mask2)); |
208 | 248 |
209 // Probe the secondary table. | 249 // Probe the secondary table. |
210 ProbeTable(isolate, masm, flags, kSecondary, name, scratch, extra, extra2); | 250 ProbeTable(isolate, |
| 251 masm, |
| 252 flags, |
| 253 kSecondary, |
| 254 receiver, |
| 255 name, |
| 256 scratch, |
| 257 extra, |
| 258 extra2, |
| 259 extra3); |
211 | 260 |
212 // Cache miss: Fall-through and let caller handle the miss by | 261 // Cache miss: Fall-through and let caller handle the miss by |
213 // entering the runtime system. | 262 // entering the runtime system. |
214 __ bind(&miss); | 263 __ bind(&miss); |
| 264 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, |
| 265 extra2, extra3); |
215 } | 266 } |
216 | 267 |
217 | 268 |
218 void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, | 269 void StubCompiler::GenerateLoadGlobalFunctionPrototype(MacroAssembler* masm, |
219 int index, | 270 int index, |
220 Register prototype) { | 271 Register prototype) { |
221 // Load the global or builtins object from the current context. | 272 // Load the global or builtins object from the current context. |
222 __ lw(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); | 273 __ lw(prototype, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
223 // Load the global context from the global or builtins object. | 274 // Load the global context from the global or builtins object. |
224 __ lw(prototype, | 275 __ lw(prototype, |
(...skipping 4245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4470 __ Jump(ic_slow, RelocInfo::CODE_TARGET); | 4521 __ Jump(ic_slow, RelocInfo::CODE_TARGET); |
4471 } | 4522 } |
4472 } | 4523 } |
4473 | 4524 |
4474 | 4525 |
4475 #undef __ | 4526 #undef __ |
4476 | 4527 |
4477 } } // namespace v8::internal | 4528 } } // namespace v8::internal |
4478 | 4529 |
4479 #endif // V8_TARGET_ARCH_MIPS | 4530 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |