OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 | 177 |
178 protected: | 178 protected: |
179 uword start_; | 179 uword start_; |
180 const ObjectPool& object_pool_; | 180 const ObjectPool& object_pool_; |
181 | 181 |
182 private: | 182 private: |
183 DISALLOW_IMPLICIT_CONSTRUCTORS(PoolPointerCall); | 183 DISALLOW_IMPLICIT_CONSTRUCTORS(PoolPointerCall); |
184 }; | 184 }; |
185 | 185 |
186 | 186 |
187 class SwitchableCall : public ValueObject { | |
srdjan
2015/11/03 22:30:49
Add a comment before class definition.
rmacnak
2015/11/03 23:54:29
Done.
| |
188 public: | |
189 SwitchableCall(uword return_address, const Code& code) | |
190 : start_(return_address - kCallPatternSize), | |
191 object_pool_(ObjectPool::Handle(code.GetObjectPool())) { | |
192 ASSERT(IsValid()); | |
193 } | |
194 | |
195 static const int kCallPatternSize = 24; | |
196 | |
197 bool IsValid() const { | |
198 static int16_t pattern[kCallPatternSize] = { | |
199 0x49, 0x8b, 0x9f, -1, -1, -1, -1, // movq rbx, [PP + cache_offs] | |
200 0x4d, 0x8b, 0xa7, -1, -1, -1, -1, // movq r12, [PP + code_offs] | |
201 0x4d, 0x8b, 0x5c, 0x24, 0x07, // movq r11, [r12 + entrypoint_off] | |
202 0x41, 0xff, 0xd3, // call r11 | |
203 0xff, 0xd1, // call rcx | |
204 }; | |
205 return MatchesPattern(start_, pattern, kCallPatternSize); | |
206 } | |
207 | |
208 intptr_t cache_index() const { | |
209 return IndexFromPPLoad(start_ + 3); | |
210 } | |
211 intptr_t lookup_stub_index() const { | |
212 return IndexFromPPLoad(start_ + 10); | |
213 } | |
214 | |
215 RawObject* cache() const { | |
216 return object_pool_.ObjectAt(cache_index()); | |
217 } | |
218 | |
219 void SetCache(const MegamorphicCache& cache) const { | |
220 ASSERT(Object::Handle(object_pool_.ObjectAt(cache_index())).IsICData()); | |
221 object_pool_.SetObjectAt(cache_index(), cache); | |
222 // No need to flush the instruction cache, since the code is not modified. | |
223 } | |
224 | |
225 void SetLookupStub(const Code& lookup_stub) const { | |
226 ASSERT(Object::Handle(object_pool_.ObjectAt(lookup_stub_index())).IsCode()); | |
227 object_pool_.SetObjectAt(lookup_stub_index(), lookup_stub); | |
228 // No need to flush the instruction cache, since the code is not modified. | |
229 } | |
230 | |
231 protected: | |
232 uword start_; | |
233 const ObjectPool& object_pool_; | |
234 | |
235 private: | |
236 DISALLOW_IMPLICIT_CONSTRUCTORS(SwitchableCall); | |
237 }; | |
238 | |
239 | |
240 | |
187 RawCode* CodePatcher::GetStaticCallTargetAt(uword return_address, | 241 RawCode* CodePatcher::GetStaticCallTargetAt(uword return_address, |
188 const Code& code) { | 242 const Code& code) { |
189 ASSERT(code.ContainsInstructionAt(return_address)); | 243 ASSERT(code.ContainsInstructionAt(return_address)); |
190 PoolPointerCall call(return_address, code); | 244 PoolPointerCall call(return_address, code); |
191 return call.Target(); | 245 return call.Target(); |
192 } | 246 } |
193 | 247 |
194 | 248 |
195 void CodePatcher::PatchStaticCallAt(uword return_address, | 249 void CodePatcher::PatchStaticCallAt(uword return_address, |
196 const Code& code, | 250 const Code& code, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 UnoptimizedStaticCall static_call(return_address, code); | 295 UnoptimizedStaticCall static_call(return_address, code); |
242 ICData& ic_data = ICData::Handle(); | 296 ICData& ic_data = ICData::Handle(); |
243 ic_data ^= static_call.ic_data(); | 297 ic_data ^= static_call.ic_data(); |
244 if (ic_data_result != NULL) { | 298 if (ic_data_result != NULL) { |
245 *ic_data_result = ic_data.raw(); | 299 *ic_data_result = ic_data.raw(); |
246 } | 300 } |
247 return ic_data.GetTargetAt(0); | 301 return ic_data.GetTargetAt(0); |
248 } | 302 } |
249 | 303 |
250 | 304 |
305 void CodePatcher::PatchSwitchableCallAt(uword return_address, | |
306 const Code& code, | |
307 const ICData& ic_data, | |
308 const MegamorphicCache& cache, | |
309 const Code& lookup_stub) { | |
310 ASSERT(code.ContainsInstructionAt(return_address)); | |
311 SwitchableCall call(return_address, code); | |
312 ASSERT(call.cache() == ic_data.raw()); | |
313 call.SetLookupStub(lookup_stub); | |
314 call.SetCache(cache); | |
315 } | |
316 | |
317 | |
251 void CodePatcher::PatchNativeCallAt(uword return_address, | 318 void CodePatcher::PatchNativeCallAt(uword return_address, |
252 const Code& code, | 319 const Code& code, |
253 NativeFunction target, | 320 NativeFunction target, |
254 const Code& trampoline) { | 321 const Code& trampoline) { |
255 ASSERT(code.ContainsInstructionAt(return_address)); | 322 ASSERT(code.ContainsInstructionAt(return_address)); |
256 NativeCall call(return_address, code); | 323 NativeCall call(return_address, code); |
257 call.set_target(trampoline); | 324 call.set_target(trampoline); |
258 call.set_native_function(target); | 325 call.set_native_function(target); |
259 } | 326 } |
260 | 327 |
261 | 328 |
262 RawCode* CodePatcher::GetNativeCallAt(uword return_address, | 329 RawCode* CodePatcher::GetNativeCallAt(uword return_address, |
263 const Code& code, | 330 const Code& code, |
264 NativeFunction* target) { | 331 NativeFunction* target) { |
265 ASSERT(code.ContainsInstructionAt(return_address)); | 332 ASSERT(code.ContainsInstructionAt(return_address)); |
266 NativeCall call(return_address, code); | 333 NativeCall call(return_address, code); |
267 *target = call.native_function(); | 334 *target = call.native_function(); |
268 return call.target(); | 335 return call.target(); |
269 } | 336 } |
270 | 337 |
271 } // namespace dart | 338 } // namespace dart |
272 | 339 |
273 #endif // defined TARGET_ARCH_X64 | 340 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |