| 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 // Instance call that can switch from an IC call to a megamorphic call |
| 188 // load ICData load MegamorphicCache |
| 189 // call ICLookup stub -> call MegamorphicLookup stub |
| 190 // call target call target |
| 191 class SwitchableCall : public ValueObject { |
| 192 public: |
| 193 SwitchableCall(uword return_address, const Code& code) |
| 194 : start_(return_address - kCallPatternSize), |
| 195 object_pool_(ObjectPool::Handle(code.GetObjectPool())) { |
| 196 ASSERT(IsValid()); |
| 197 } |
| 198 |
| 199 static const int kCallPatternSize = 24; |
| 200 |
| 201 bool IsValid() const { |
| 202 static int16_t pattern[kCallPatternSize] = { |
| 203 0x49, 0x8b, 0x9f, -1, -1, -1, -1, // movq rbx, [PP + cache_offs] |
| 204 0x4d, 0x8b, 0xa7, -1, -1, -1, -1, // movq r12, [PP + code_offs] |
| 205 0x4d, 0x8b, 0x5c, 0x24, 0x07, // movq r11, [r12 + entrypoint_off] |
| 206 0x41, 0xff, 0xd3, // call r11 |
| 207 0xff, 0xd1, // call rcx |
| 208 }; |
| 209 return MatchesPattern(start_, pattern, kCallPatternSize); |
| 210 } |
| 211 |
| 212 intptr_t cache_index() const { |
| 213 return IndexFromPPLoad(start_ + 3); |
| 214 } |
| 215 intptr_t lookup_stub_index() const { |
| 216 return IndexFromPPLoad(start_ + 10); |
| 217 } |
| 218 |
| 219 RawObject* cache() const { |
| 220 return object_pool_.ObjectAt(cache_index()); |
| 221 } |
| 222 |
| 223 void SetCache(const MegamorphicCache& cache) const { |
| 224 ASSERT(Object::Handle(object_pool_.ObjectAt(cache_index())).IsICData()); |
| 225 object_pool_.SetObjectAt(cache_index(), cache); |
| 226 // No need to flush the instruction cache, since the code is not modified. |
| 227 } |
| 228 |
| 229 void SetLookupStub(const Code& lookup_stub) const { |
| 230 ASSERT(Object::Handle(object_pool_.ObjectAt(lookup_stub_index())).IsCode()); |
| 231 object_pool_.SetObjectAt(lookup_stub_index(), lookup_stub); |
| 232 // No need to flush the instruction cache, since the code is not modified. |
| 233 } |
| 234 |
| 235 protected: |
| 236 uword start_; |
| 237 const ObjectPool& object_pool_; |
| 238 |
| 239 private: |
| 240 DISALLOW_IMPLICIT_CONSTRUCTORS(SwitchableCall); |
| 241 }; |
| 242 |
| 243 |
| 244 |
| 187 RawCode* CodePatcher::GetStaticCallTargetAt(uword return_address, | 245 RawCode* CodePatcher::GetStaticCallTargetAt(uword return_address, |
| 188 const Code& code) { | 246 const Code& code) { |
| 189 ASSERT(code.ContainsInstructionAt(return_address)); | 247 ASSERT(code.ContainsInstructionAt(return_address)); |
| 190 PoolPointerCall call(return_address, code); | 248 PoolPointerCall call(return_address, code); |
| 191 return call.Target(); | 249 return call.Target(); |
| 192 } | 250 } |
| 193 | 251 |
| 194 | 252 |
| 195 void CodePatcher::PatchStaticCallAt(uword return_address, | 253 void CodePatcher::PatchStaticCallAt(uword return_address, |
| 196 const Code& code, | 254 const Code& code, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 UnoptimizedStaticCall static_call(return_address, code); | 299 UnoptimizedStaticCall static_call(return_address, code); |
| 242 ICData& ic_data = ICData::Handle(); | 300 ICData& ic_data = ICData::Handle(); |
| 243 ic_data ^= static_call.ic_data(); | 301 ic_data ^= static_call.ic_data(); |
| 244 if (ic_data_result != NULL) { | 302 if (ic_data_result != NULL) { |
| 245 *ic_data_result = ic_data.raw(); | 303 *ic_data_result = ic_data.raw(); |
| 246 } | 304 } |
| 247 return ic_data.GetTargetAt(0); | 305 return ic_data.GetTargetAt(0); |
| 248 } | 306 } |
| 249 | 307 |
| 250 | 308 |
| 309 void CodePatcher::PatchSwitchableCallAt(uword return_address, |
| 310 const Code& code, |
| 311 const ICData& ic_data, |
| 312 const MegamorphicCache& cache, |
| 313 const Code& lookup_stub) { |
| 314 ASSERT(code.ContainsInstructionAt(return_address)); |
| 315 SwitchableCall call(return_address, code); |
| 316 ASSERT(call.cache() == ic_data.raw()); |
| 317 call.SetLookupStub(lookup_stub); |
| 318 call.SetCache(cache); |
| 319 } |
| 320 |
| 321 |
| 251 void CodePatcher::PatchNativeCallAt(uword return_address, | 322 void CodePatcher::PatchNativeCallAt(uword return_address, |
| 252 const Code& code, | 323 const Code& code, |
| 253 NativeFunction target, | 324 NativeFunction target, |
| 254 const Code& trampoline) { | 325 const Code& trampoline) { |
| 255 ASSERT(code.ContainsInstructionAt(return_address)); | 326 ASSERT(code.ContainsInstructionAt(return_address)); |
| 256 NativeCall call(return_address, code); | 327 NativeCall call(return_address, code); |
| 257 call.set_target(trampoline); | 328 call.set_target(trampoline); |
| 258 call.set_native_function(target); | 329 call.set_native_function(target); |
| 259 } | 330 } |
| 260 | 331 |
| 261 | 332 |
| 262 RawCode* CodePatcher::GetNativeCallAt(uword return_address, | 333 RawCode* CodePatcher::GetNativeCallAt(uword return_address, |
| 263 const Code& code, | 334 const Code& code, |
| 264 NativeFunction* target) { | 335 NativeFunction* target) { |
| 265 ASSERT(code.ContainsInstructionAt(return_address)); | 336 ASSERT(code.ContainsInstructionAt(return_address)); |
| 266 NativeCall call(return_address, code); | 337 NativeCall call(return_address, code); |
| 267 *target = call.native_function(); | 338 *target = call.native_function(); |
| 268 return call.target(); | 339 return call.target(); |
| 269 } | 340 } |
| 270 | 341 |
| 271 } // namespace dart | 342 } // namespace dart |
| 272 | 343 |
| 273 #endif // defined TARGET_ARCH_X64 | 344 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |