| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 CPU::FlushICache(start_ + 10, 2 + 8); | 119 CPU::FlushICache(start_ + 10, 2 + 8); |
| 120 } | 120 } |
| 121 | 121 |
| 122 private: | 122 private: |
| 123 uword start_; | 123 uword start_; |
| 124 | 124 |
| 125 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); | 125 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 | 128 |
| 129 uword CodePatcher::GetStaticCallTargetAt(uword return_address) { | 129 uword CodePatcher::GetStaticCallTargetAt(uword return_address, |
| 130 const Code& code) { |
| 130 StaticCall call(return_address); | 131 StaticCall call(return_address); |
| 131 return call.target(); | 132 return call.target(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 | 135 |
| 135 void CodePatcher::PatchStaticCallAt(uword return_address, uword new_target) { | 136 void CodePatcher::PatchStaticCallAt(uword return_address, |
| 137 const Code& code, |
| 138 uword new_target) { |
| 136 StaticCall call(return_address); | 139 StaticCall call(return_address); |
| 137 call.set_target(new_target); | 140 call.set_target(new_target); |
| 138 } | 141 } |
| 139 | 142 |
| 140 | 143 |
| 141 void CodePatcher::PatchInstanceCallAt(uword return_address, uword new_target) { | 144 void CodePatcher::PatchInstanceCallAt(uword return_address, |
| 145 const Code& code, |
| 146 uword new_target) { |
| 142 InstanceCall call(return_address); | 147 InstanceCall call(return_address); |
| 143 call.set_target(new_target); | 148 call.set_target(new_target); |
| 144 } | 149 } |
| 145 | 150 |
| 146 | 151 |
| 147 bool CodePatcher::IsDartCall(uword return_address) { | |
| 148 return DartCallPattern::IsValid(return_address); | |
| 149 } | |
| 150 | |
| 151 | |
| 152 uword CodePatcher::GetInstanceCallAt(uword return_address, | 152 uword CodePatcher::GetInstanceCallAt(uword return_address, |
| 153 const Code& code, |
| 153 ICData* ic_data, | 154 ICData* ic_data, |
| 154 Array* arguments_descriptor) { | 155 Array* arguments_descriptor) { |
| 155 InstanceCall call(return_address); | 156 InstanceCall call(return_address); |
| 156 if (ic_data != NULL) { | 157 if (ic_data != NULL) { |
| 157 *ic_data ^= call.ic_data(); | 158 *ic_data ^= call.ic_data(); |
| 158 } | 159 } |
| 159 if (arguments_descriptor != NULL) { | 160 if (arguments_descriptor != NULL) { |
| 160 *arguments_descriptor ^= call.arguments_descriptor(); | 161 *arguments_descriptor ^= call.arguments_descriptor(); |
| 161 } | 162 } |
| 162 return call.target(); | 163 return call.target(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 | 166 |
| 166 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 167 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
| 167 return DartCallPattern::kCallPatternSize; | 168 return DartCallPattern::kCallPatternSize; |
| 168 } | 169 } |
| 169 | 170 |
| 170 | 171 |
| 171 void CodePatcher::InsertCallAt(uword start, uword target) { | 172 void CodePatcher::InsertCallAt(uword start, uword target) { |
| 172 *reinterpret_cast<uint8_t*>(start) = 0xE8; | 173 *reinterpret_cast<uint8_t*>(start) = 0xE8; |
| 173 ShortCallPattern call(start); | 174 ShortCallPattern call(start); |
| 174 call.SetTargetAddress(target); | 175 call.SetTargetAddress(target); |
| 175 CPU::FlushICache(start, ShortCallPattern::InstructionLength()); | 176 CPU::FlushICache(start, ShortCallPattern::InstructionLength()); |
| 176 } | 177 } |
| 177 | 178 |
| 178 | 179 |
| 179 } // namespace dart | 180 } // namespace dart |
| 180 | 181 |
| 181 #endif // defined TARGET_ARCH_X64 | 182 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |