Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/v8.h" |
| 6 | |
| 7 | #if V8_TARGET_ARCH_X87 |
| 8 | |
| 9 | #include "src/codegen.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 10 | #include "src/ic/ic.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #include "src/ic/stub-cache.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 12 | #include "src/interface-descriptors.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
| 17 | #define __ ACCESS_MASM(masm) |
| 18 | |
| 19 | |
| 20 | static void ProbeTable(Isolate* isolate, MacroAssembler* masm, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 21 | Code::Kind ic_kind, Code::Flags flags, bool leave_frame, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | StubCache::Table table, Register name, Register receiver, |
| 23 | // Number of the cache entry pointer-size scaled. |
| 24 | Register offset, Register extra) { |
| 25 | ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); |
| 26 | ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); |
| 27 | ExternalReference map_offset(isolate->stub_cache()->map_reference(table)); |
| 28 | |
| 29 | Label miss; |
| 30 | |
| 31 | // Multiply by 3 because there are 3 fields per entry (name, code, map). |
| 32 | __ lea(offset, Operand(offset, offset, times_2, 0)); |
| 33 | |
| 34 | if (extra.is_valid()) { |
| 35 | // Get the code entry from the cache. |
| 36 | __ mov(extra, Operand::StaticArray(offset, times_1, value_offset)); |
| 37 | |
| 38 | // Check that the key in the entry matches the name. |
| 39 | __ cmp(name, Operand::StaticArray(offset, times_1, key_offset)); |
| 40 | __ j(not_equal, &miss); |
| 41 | |
| 42 | // Check the map matches. |
| 43 | __ mov(offset, Operand::StaticArray(offset, times_1, map_offset)); |
| 44 | __ cmp(offset, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 45 | __ j(not_equal, &miss); |
| 46 | |
| 47 | // Check that the flags match what we're looking for. |
| 48 | __ mov(offset, FieldOperand(extra, Code::kFlagsOffset)); |
| 49 | __ and_(offset, ~Code::kFlagsNotUsedInLookup); |
| 50 | __ cmp(offset, flags); |
| 51 | __ j(not_equal, &miss); |
| 52 | |
| 53 | #ifdef DEBUG |
| 54 | if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
| 55 | __ jmp(&miss); |
| 56 | } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
| 57 | __ jmp(&miss); |
| 58 | } |
| 59 | #endif |
| 60 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 61 | if (IC::ICUseVector(ic_kind)) { |
| 62 | // The vector and slot were pushed onto the stack before starting the |
| 63 | // probe, and need to be dropped before calling the handler. |
| 64 | __ pop(VectorLoadICDescriptor::VectorRegister()); |
| 65 | __ pop(VectorLoadICDescriptor::SlotRegister()); |
| 66 | } |
| 67 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | if (leave_frame) __ leave(); |
| 69 | |
| 70 | // Jump to the first instruction in the code stub. |
| 71 | __ add(extra, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 72 | __ jmp(extra); |
| 73 | |
| 74 | __ bind(&miss); |
| 75 | } else { |
| 76 | // Save the offset on the stack. |
| 77 | __ push(offset); |
| 78 | |
| 79 | // Check that the key in the entry matches the name. |
| 80 | __ cmp(name, Operand::StaticArray(offset, times_1, key_offset)); |
| 81 | __ j(not_equal, &miss); |
| 82 | |
| 83 | // Check the map matches. |
| 84 | __ mov(offset, Operand::StaticArray(offset, times_1, map_offset)); |
| 85 | __ cmp(offset, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 86 | __ j(not_equal, &miss); |
| 87 | |
| 88 | // Restore offset register. |
| 89 | __ mov(offset, Operand(esp, 0)); |
| 90 | |
| 91 | // Get the code entry from the cache. |
| 92 | __ mov(offset, Operand::StaticArray(offset, times_1, value_offset)); |
| 93 | |
| 94 | // Check that the flags match what we're looking for. |
| 95 | __ mov(offset, FieldOperand(offset, Code::kFlagsOffset)); |
| 96 | __ and_(offset, ~Code::kFlagsNotUsedInLookup); |
| 97 | __ cmp(offset, flags); |
| 98 | __ j(not_equal, &miss); |
| 99 | |
| 100 | #ifdef DEBUG |
| 101 | if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
| 102 | __ jmp(&miss); |
| 103 | } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
| 104 | __ jmp(&miss); |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | // Restore offset and re-load code entry from cache. |
| 109 | __ pop(offset); |
| 110 | __ mov(offset, Operand::StaticArray(offset, times_1, value_offset)); |
| 111 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 112 | if (IC::ICUseVector(ic_kind)) { |
| 113 | // The vector and slot were pushed onto the stack before starting the |
| 114 | // probe, and need to be dropped before calling the handler. |
| 115 | Register vector = VectorLoadICDescriptor::VectorRegister(); |
| 116 | Register slot = VectorLoadICDescriptor::SlotRegister(); |
| 117 | DCHECK(!offset.is(vector) && !offset.is(slot)); |
| 118 | |
| 119 | __ pop(vector); |
| 120 | __ pop(slot); |
| 121 | } |
| 122 | |
| 123 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 124 | if (leave_frame) __ leave(); |
| 125 | |
| 126 | // Jump to the first instruction in the code stub. |
| 127 | __ add(offset, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 128 | __ jmp(offset); |
| 129 | |
| 130 | // Pop at miss. |
| 131 | __ bind(&miss); |
| 132 | __ pop(offset); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 137 | void StubCache::GenerateProbe(MacroAssembler* masm, Code::Kind ic_kind, |
| 138 | Code::Flags flags, bool leave_frame, |
| 139 | Register receiver, Register name, |
| 140 | Register scratch, Register extra, Register extra2, |
| 141 | Register extra3) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 142 | Label miss; |
| 143 | |
| 144 | // Assert that code is valid. The multiplying code relies on the entry size |
| 145 | // being 12. |
| 146 | DCHECK(sizeof(Entry) == 12); |
| 147 | |
| 148 | // Assert the flags do not name a specific type. |
| 149 | DCHECK(Code::ExtractTypeFromFlags(flags) == 0); |
| 150 | |
| 151 | // Assert that there are no register conflicts. |
| 152 | DCHECK(!scratch.is(receiver)); |
| 153 | DCHECK(!scratch.is(name)); |
| 154 | DCHECK(!extra.is(receiver)); |
| 155 | DCHECK(!extra.is(name)); |
| 156 | DCHECK(!extra.is(scratch)); |
| 157 | |
| 158 | // Assert scratch and extra registers are valid, and extra2/3 are unused. |
| 159 | DCHECK(!scratch.is(no_reg)); |
| 160 | DCHECK(extra2.is(no_reg)); |
| 161 | DCHECK(extra3.is(no_reg)); |
| 162 | |
| 163 | Register offset = scratch; |
| 164 | scratch = no_reg; |
| 165 | |
| 166 | Counters* counters = masm->isolate()->counters(); |
| 167 | __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1); |
| 168 | |
| 169 | // Check that the receiver isn't a smi. |
| 170 | __ JumpIfSmi(receiver, &miss); |
| 171 | |
| 172 | // Get the map of the receiver and compute the hash. |
| 173 | __ mov(offset, FieldOperand(name, Name::kHashFieldOffset)); |
| 174 | __ add(offset, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 175 | __ xor_(offset, flags); |
| 176 | // We mask out the last two bits because they are not part of the hash and |
| 177 | // they are always 01 for maps. Also in the two 'and' instructions below. |
| 178 | __ and_(offset, (kPrimaryTableSize - 1) << kCacheIndexShift); |
| 179 | // ProbeTable expects the offset to be pointer scaled, which it is, because |
| 180 | // the heap object tag size is 2 and the pointer size log 2 is also 2. |
| 181 | DCHECK(kCacheIndexShift == kPointerSizeLog2); |
| 182 | |
| 183 | // Probe the primary table. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 184 | ProbeTable(isolate(), masm, ic_kind, flags, leave_frame, kPrimary, name, |
| 185 | receiver, offset, extra); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 186 | |
| 187 | // Primary miss: Compute hash for secondary probe. |
| 188 | __ mov(offset, FieldOperand(name, Name::kHashFieldOffset)); |
| 189 | __ add(offset, FieldOperand(receiver, HeapObject::kMapOffset)); |
| 190 | __ xor_(offset, flags); |
| 191 | __ and_(offset, (kPrimaryTableSize - 1) << kCacheIndexShift); |
| 192 | __ sub(offset, name); |
| 193 | __ add(offset, Immediate(flags)); |
| 194 | __ and_(offset, (kSecondaryTableSize - 1) << kCacheIndexShift); |
| 195 | |
| 196 | // Probe the secondary table. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 197 | ProbeTable(isolate(), masm, ic_kind, flags, leave_frame, kSecondary, name, |
| 198 | receiver, offset, extra); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 199 | |
| 200 | // Cache miss: Fall-through and let caller handle the miss by |
| 201 | // entering the runtime system. |
| 202 | __ bind(&miss); |
| 203 | __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | #undef __ |
| 208 | } |
| 209 | } // namespace v8::internal |
| 210 | |
| 211 | #endif // V8_TARGET_ARCH_X87 |