| 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) { |
| 131 ASSERT(code.ContainsInstructionAt(return_address)); |
| 130 StaticCall call(return_address); | 132 StaticCall call(return_address); |
| 131 return call.target(); | 133 return call.target(); |
| 132 } | 134 } |
| 133 | 135 |
| 134 | 136 |
| 135 void CodePatcher::PatchStaticCallAt(uword return_address, uword new_target) { | 137 void CodePatcher::PatchStaticCallAt(uword return_address, |
| 138 const Code& code, |
| 139 uword new_target) { |
| 140 ASSERT(code.ContainsInstructionAt(return_address)); |
| 136 StaticCall call(return_address); | 141 StaticCall call(return_address); |
| 137 call.set_target(new_target); | 142 call.set_target(new_target); |
| 138 } | 143 } |
| 139 | 144 |
| 140 | 145 |
| 141 void CodePatcher::PatchInstanceCallAt(uword return_address, uword new_target) { | 146 void CodePatcher::PatchInstanceCallAt(uword return_address, |
| 147 const Code& code, |
| 148 uword new_target) { |
| 149 ASSERT(code.ContainsInstructionAt(return_address)); |
| 142 InstanceCall call(return_address); | 150 InstanceCall call(return_address); |
| 143 call.set_target(new_target); | 151 call.set_target(new_target); |
| 144 } | 152 } |
| 145 | 153 |
| 146 | 154 |
| 147 bool CodePatcher::IsDartCall(uword return_address) { | |
| 148 return DartCallPattern::IsValid(return_address); | |
| 149 } | |
| 150 | |
| 151 | |
| 152 uword CodePatcher::GetInstanceCallAt(uword return_address, | 155 uword CodePatcher::GetInstanceCallAt(uword return_address, |
| 156 const Code& code, |
| 153 ICData* ic_data, | 157 ICData* ic_data, |
| 154 Array* arguments_descriptor) { | 158 Array* arguments_descriptor) { |
| 159 ASSERT(code.ContainsInstructionAt(return_address)); |
| 155 InstanceCall call(return_address); | 160 InstanceCall call(return_address); |
| 156 if (ic_data != NULL) { | 161 if (ic_data != NULL) { |
| 157 *ic_data ^= call.ic_data(); | 162 *ic_data ^= call.ic_data(); |
| 158 } | 163 } |
| 159 if (arguments_descriptor != NULL) { | 164 if (arguments_descriptor != NULL) { |
| 160 *arguments_descriptor ^= call.arguments_descriptor(); | 165 *arguments_descriptor ^= call.arguments_descriptor(); |
| 161 } | 166 } |
| 162 return call.target(); | 167 return call.target(); |
| 163 } | 168 } |
| 164 | 169 |
| 165 | 170 |
| 166 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 171 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
| 167 return DartCallPattern::kCallPatternSize; | 172 return DartCallPattern::kCallPatternSize; |
| 168 } | 173 } |
| 169 | 174 |
| 170 | 175 |
| 171 void CodePatcher::InsertCallAt(uword start, uword target) { | 176 void CodePatcher::InsertCallAt(uword start, uword target) { |
| 172 *reinterpret_cast<uint8_t*>(start) = 0xE8; | 177 *reinterpret_cast<uint8_t*>(start) = 0xE8; |
| 173 ShortCallPattern call(start); | 178 ShortCallPattern call(start); |
| 174 call.SetTargetAddress(target); | 179 call.SetTargetAddress(target); |
| 175 CPU::FlushICache(start, ShortCallPattern::InstructionLength()); | 180 CPU::FlushICache(start, ShortCallPattern::InstructionLength()); |
| 176 } | 181 } |
| 177 | 182 |
| 178 | 183 |
| 179 } // namespace dart | 184 } // namespace dart |
| 180 | 185 |
| 181 #endif // defined TARGET_ARCH_X64 | 186 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |