OLD | NEW |
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 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/codegen.h" | 7 #include "src/codegen.h" |
8 #include "src/ic/ic.h" | 8 #include "src/ic/ic.h" |
9 #include "src/ic/stub-cache.h" | 9 #include "src/ic/stub-cache.h" |
10 #include "src/interface-descriptors.h" | 10 #include "src/interface-descriptors.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 #define __ ACCESS_MASM(masm) | 15 #define __ ACCESS_MASM(masm) |
16 | 16 |
17 static void ProbeTable(StubCache* stub_cache, MacroAssembler* masm, | 17 static void ProbeTable(StubCache* stub_cache, MacroAssembler* masm, |
18 Code::Flags flags, StubCache::Table table, | 18 StubCache::Table table, Register receiver, Register name, |
19 Register receiver, Register name, | |
20 // The offset is scaled by 4, based on | 19 // The offset is scaled by 4, based on |
21 // kCacheIndexShift, which is two bits | 20 // kCacheIndexShift, which is two bits |
22 Register offset) { | 21 Register offset) { |
23 // We need to scale up the pointer by 2 when the offset is scaled by less | 22 // We need to scale up the pointer by 2 when the offset is scaled by less |
24 // than the pointer size. | 23 // than the pointer size. |
25 DCHECK(kPointerSize == kInt64Size | 24 DCHECK(kPointerSize == kInt64Size |
26 ? kPointerSizeLog2 == StubCache::kCacheIndexShift + 1 | 25 ? kPointerSizeLog2 == StubCache::kCacheIndexShift + 1 |
27 : kPointerSizeLog2 == StubCache::kCacheIndexShift); | 26 : kPointerSizeLog2 == StubCache::kCacheIndexShift); |
28 ScaleFactor scale_factor = kPointerSize == kInt64Size ? times_2 : times_1; | 27 ScaleFactor scale_factor = kPointerSize == kInt64Size ? times_2 : times_1; |
29 | 28 |
(...skipping 20 matching lines...) Expand all Loading... |
50 kPointerSize * 2); | 49 kPointerSize * 2); |
51 __ movp(kScratchRegister, | 50 __ movp(kScratchRegister, |
52 Operand(kScratchRegister, offset, scale_factor, kPointerSize * 2)); | 51 Operand(kScratchRegister, offset, scale_factor, kPointerSize * 2)); |
53 __ cmpp(kScratchRegister, FieldOperand(receiver, HeapObject::kMapOffset)); | 52 __ cmpp(kScratchRegister, FieldOperand(receiver, HeapObject::kMapOffset)); |
54 __ j(not_equal, &miss); | 53 __ j(not_equal, &miss); |
55 | 54 |
56 // Get the code entry from the cache. | 55 // Get the code entry from the cache. |
57 __ LoadAddress(kScratchRegister, value_offset); | 56 __ LoadAddress(kScratchRegister, value_offset); |
58 __ movp(kScratchRegister, Operand(kScratchRegister, offset, scale_factor, 0)); | 57 __ movp(kScratchRegister, Operand(kScratchRegister, offset, scale_factor, 0)); |
59 | 58 |
60 // Check that the flags match what we're looking for. | |
61 __ movl(offset, FieldOperand(kScratchRegister, Code::kFlagsOffset)); | |
62 __ andp(offset, Immediate(~Code::kFlagsNotUsedInLookup)); | |
63 __ cmpl(offset, Immediate(flags)); | |
64 __ j(not_equal, &miss); | |
65 | |
66 #ifdef DEBUG | 59 #ifdef DEBUG |
67 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { | 60 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { |
68 __ jmp(&miss); | 61 __ jmp(&miss); |
69 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { | 62 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { |
70 __ jmp(&miss); | 63 __ jmp(&miss); |
71 } | 64 } |
72 #endif | 65 #endif |
73 | 66 |
74 // Jump to the first instruction in the code stub. | 67 // Jump to the first instruction in the code stub. |
75 __ addp(kScratchRegister, Immediate(Code::kHeaderSize - kHeapObjectTag)); | 68 __ addp(kScratchRegister, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
76 __ jmp(kScratchRegister); | 69 __ jmp(kScratchRegister); |
77 | 70 |
78 __ bind(&miss); | 71 __ bind(&miss); |
79 } | 72 } |
80 | 73 |
81 void StubCache::GenerateProbe(MacroAssembler* masm, Register receiver, | 74 void StubCache::GenerateProbe(MacroAssembler* masm, Register receiver, |
82 Register name, Register scratch, Register extra, | 75 Register name, Register scratch, Register extra, |
83 Register extra2, Register extra3) { | 76 Register extra2, Register extra3) { |
84 Code::Flags flags = | |
85 Code::RemoveHolderFromFlags(Code::ComputeHandlerFlags(ic_kind_)); | |
86 | |
87 Label miss; | 77 Label miss; |
88 USE(extra); // The register extra is not used on the X64 platform. | 78 USE(extra); // The register extra is not used on the X64 platform. |
89 USE(extra2); // The register extra2 is not used on the X64 platform. | 79 USE(extra2); // The register extra2 is not used on the X64 platform. |
90 USE(extra3); // The register extra2 is not used on the X64 platform. | 80 USE(extra3); // The register extra2 is not used on the X64 platform. |
91 // Make sure that code is valid. The multiplying code relies on the | 81 // Make sure that code is valid. The multiplying code relies on the |
92 // entry size being 3 * kPointerSize. | 82 // entry size being 3 * kPointerSize. |
93 DCHECK(sizeof(Entry) == 3 * kPointerSize); | 83 DCHECK(sizeof(Entry) == 3 * kPointerSize); |
94 | 84 |
95 // Make sure that there are no register conflicts. | 85 // Make sure that there are no register conflicts. |
96 DCHECK(!scratch.is(receiver)); | 86 DCHECK(!scratch.is(receiver)); |
(...skipping 25 matching lines...) Expand all Loading... |
122 Counters* counters = masm->isolate()->counters(); | 112 Counters* counters = masm->isolate()->counters(); |
123 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1); | 113 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1); |
124 | 114 |
125 // Check that the receiver isn't a smi. | 115 // Check that the receiver isn't a smi. |
126 __ JumpIfSmi(receiver, &miss); | 116 __ JumpIfSmi(receiver, &miss); |
127 | 117 |
128 // Get the map of the receiver and compute the hash. | 118 // Get the map of the receiver and compute the hash. |
129 __ movl(scratch, FieldOperand(name, Name::kHashFieldOffset)); | 119 __ movl(scratch, FieldOperand(name, Name::kHashFieldOffset)); |
130 // Use only the low 32 bits of the map pointer. | 120 // Use only the low 32 bits of the map pointer. |
131 __ addl(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); | 121 __ addl(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); |
132 __ xorp(scratch, Immediate(flags)); | 122 __ xorp(scratch, Immediate(kPrimaryMagic)); |
133 // We mask out the last two bits because they are not part of the hash and | 123 // We mask out the last two bits because they are not part of the hash and |
134 // they are always 01 for maps. Also in the two 'and' instructions below. | 124 // they are always 01 for maps. Also in the two 'and' instructions below. |
135 __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kCacheIndexShift)); | 125 __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kCacheIndexShift)); |
136 | 126 |
137 // Probe the primary table. | 127 // Probe the primary table. |
138 ProbeTable(this, masm, flags, kPrimary, receiver, name, scratch); | 128 ProbeTable(this, masm, kPrimary, receiver, name, scratch); |
139 | 129 |
140 // Primary miss: Compute hash for secondary probe. | 130 // Primary miss: Compute hash for secondary probe. |
141 __ movl(scratch, FieldOperand(name, Name::kHashFieldOffset)); | 131 __ movl(scratch, FieldOperand(name, Name::kHashFieldOffset)); |
142 __ addl(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); | 132 __ addl(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); |
143 __ xorp(scratch, Immediate(flags)); | 133 __ xorp(scratch, Immediate(kPrimaryMagic)); |
144 __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kCacheIndexShift)); | 134 __ andp(scratch, Immediate((kPrimaryTableSize - 1) << kCacheIndexShift)); |
145 __ subl(scratch, name); | 135 __ subl(scratch, name); |
146 __ addl(scratch, Immediate(flags)); | 136 __ addl(scratch, Immediate(kSecondaryMagic)); |
147 __ andp(scratch, Immediate((kSecondaryTableSize - 1) << kCacheIndexShift)); | 137 __ andp(scratch, Immediate((kSecondaryTableSize - 1) << kCacheIndexShift)); |
148 | 138 |
149 // Probe the secondary table. | 139 // Probe the secondary table. |
150 ProbeTable(this, masm, flags, kSecondary, receiver, name, scratch); | 140 ProbeTable(this, masm, kSecondary, receiver, name, scratch); |
151 | 141 |
152 // Cache miss: Fall-through and let caller handle the miss by | 142 // Cache miss: Fall-through and let caller handle the miss by |
153 // entering the runtime system. | 143 // entering the runtime system. |
154 __ bind(&miss); | 144 __ bind(&miss); |
155 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1); | 145 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1); |
156 } | 146 } |
157 | 147 |
158 | 148 |
159 #undef __ | 149 #undef __ |
160 } // namespace internal | 150 } // namespace internal |
161 } // namespace v8 | 151 } // namespace v8 |
162 | 152 |
163 #endif // V8_TARGET_ARCH_X64 | 153 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |