| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_ARM64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. |
| 6 #if defined(TARGET_ARCH_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
| 7 | 7 |
| 8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
| 9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
| 10 #include "vm/instructions.h" | 10 #include "vm/instructions.h" |
| 11 #include "vm/object.h" | 11 #include "vm/object.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 uword CodePatcher::GetStaticCallTargetAt(uword return_address, | |
| 16 const Code& code) { | |
| 17 ASSERT(code.ContainsInstructionAt(return_address)); | |
| 18 CallPattern call(return_address, code); | |
| 19 return call.TargetAddress(); | |
| 20 } | |
| 21 | |
| 22 | |
| 23 void CodePatcher::PatchStaticCallAt(uword return_address, | |
| 24 const Code& code, | |
| 25 uword new_target) { | |
| 26 ASSERT(code.ContainsInstructionAt(return_address)); | |
| 27 CallPattern call(return_address, code); | |
| 28 call.SetTargetAddress(new_target); | |
| 29 } | |
| 30 | |
| 31 | |
| 32 void CodePatcher::PatchInstanceCallAt(uword return_address, | 15 void CodePatcher::PatchInstanceCallAt(uword return_address, |
| 33 const Code& code, | 16 const Code& code, |
| 34 uword new_target) { | 17 uword new_target) { |
| 35 ASSERT(code.ContainsInstructionAt(return_address)); | 18 ASSERT(code.ContainsInstructionAt(return_address)); |
| 36 CallPattern call(return_address, code); | 19 CallPattern call(return_address, code); |
| 37 call.SetTargetAddress(new_target); | 20 call.SetTargetAddress(new_target); |
| 38 } | 21 } |
| 39 | 22 |
| 40 | 23 |
| 41 class PoolPointerCall : public ValueObject { | 24 class PoolPointerCall : public ValueObject { |
| 42 public: | 25 public: |
| 43 explicit PoolPointerCall(uword pc) : end_(pc) { | 26 PoolPointerCall(uword pc, const Code& code) |
| 27 : end_(pc), |
| 28 object_pool_(Array::Handle(code.ObjectPool())) { |
| 44 // Last instruction: blr ip0. | 29 // Last instruction: blr ip0. |
| 45 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); | 30 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); |
| 46 InstructionPattern::DecodeLoadWordFromPool( | 31 InstructionPattern::DecodeLoadWordFromPool( |
| 47 end_ - Instr::kInstrSize, ®_, &index_); | 32 end_ - Instr::kInstrSize, ®_, &index_); |
| 48 } | 33 } |
| 49 | 34 |
| 50 int32_t pp_offset() const { | 35 intptr_t pp_index() const { |
| 51 return InstructionPattern::OffsetFromPPIndex(index_); | 36 return index_; |
| 52 } | 37 } |
| 53 | 38 |
| 54 void set_pp_offset(int32_t offset) const { | 39 uword Target() const { |
| 55 InstructionPattern::EncodeLoadWordFromPoolFixed( | 40 return reinterpret_cast<uword>(object_pool_.At(pp_index())); |
| 56 end_ - Instr::kInstrSize, offset); | 41 } |
| 57 CPU::FlushICache(end_ - kCallPatternSize, kCallPatternSize); | 42 |
| 43 void SetTarget(uword target) const { |
| 44 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target)); |
| 45 object_pool_.SetAt(pp_index(), smi); |
| 46 // No need to flush the instruction cache, since the code is not modified. |
| 58 } | 47 } |
| 59 | 48 |
| 60 private: | 49 private: |
| 61 static const int kCallPatternSize = 3 * Instr::kInstrSize; | 50 static const int kCallPatternSize = 3 * Instr::kInstrSize; |
| 62 uword end_; | 51 uword end_; |
| 52 const Array& object_pool_; |
| 63 Register reg_; | 53 Register reg_; |
| 64 intptr_t index_; | 54 intptr_t index_; |
| 65 DISALLOW_IMPLICIT_CONSTRUCTORS(PoolPointerCall); | 55 DISALLOW_IMPLICIT_CONSTRUCTORS(PoolPointerCall); |
| 66 }; | 56 }; |
| 67 | 57 |
| 68 | 58 |
| 69 int32_t CodePatcher::GetPoolOffsetAt(uword return_address) { | 59 uword CodePatcher::GetStaticCallTargetAt(uword return_address, |
| 70 PoolPointerCall call(return_address); | 60 const Code& code) { |
| 71 return call.pp_offset(); | 61 ASSERT(code.ContainsInstructionAt(return_address)); |
| 62 PoolPointerCall call(return_address, code); |
| 63 return call.Target(); |
| 72 } | 64 } |
| 73 | 65 |
| 74 | 66 |
| 75 void CodePatcher::SetPoolOffsetAt(uword return_address, int32_t offset) { | 67 void CodePatcher::PatchStaticCallAt(uword return_address, |
| 76 PoolPointerCall call(return_address); | 68 const Code& code, |
| 77 call.set_pp_offset(offset); | 69 uword new_target) { |
| 70 PatchPoolPointerCallAt(return_address, code, new_target); |
| 78 } | 71 } |
| 79 | 72 |
| 80 | 73 |
| 74 void CodePatcher::PatchPoolPointerCallAt(uword return_address, |
| 75 const Code& code, |
| 76 uword new_target) { |
| 77 ASSERT(code.ContainsInstructionAt(return_address)); |
| 78 PoolPointerCall call(return_address, code); |
| 79 call.SetTarget(new_target); |
| 80 } |
| 81 |
| 82 |
| 81 void CodePatcher::InsertCallAt(uword start, uword target) { | 83 void CodePatcher::InsertCallAt(uword start, uword target) { |
| 82 // The inserted call should not overlap the lazy deopt jump code. | 84 // The inserted call should not overlap the lazy deopt jump code. |
| 83 ASSERT(start + CallPattern::kLengthInBytes <= target); | 85 ASSERT(start + CallPattern::kLengthInBytes <= target); |
| 84 CallPattern::InsertAt(start, target); | 86 CallPattern::InsertAt(start, target); |
| 85 } | 87 } |
| 86 | 88 |
| 87 | 89 |
| 88 uword CodePatcher::GetInstanceCallAt(uword return_address, | 90 uword CodePatcher::GetInstanceCallAt(uword return_address, |
| 89 const Code& code, | 91 const Code& code, |
| 90 ICData* ic_data) { | 92 ICData* ic_data) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 155 |
| 154 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { | 156 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { |
| 155 ASSERT(code.ContainsInstructionAt(pc)); | 157 ASSERT(code.ContainsInstructionAt(pc)); |
| 156 EdgeCounter counter(pc, code); | 158 EdgeCounter counter(pc, code); |
| 157 return counter.edge_counter(); | 159 return counter.edge_counter(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 } // namespace dart | 162 } // namespace dart |
| 161 | 163 |
| 162 #endif // defined TARGET_ARCH_ARM64 | 164 #endif // defined TARGET_ARCH_ARM64 |
| OLD | NEW |