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