OLD | NEW |
1 // Copyright (c) 2011, 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_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
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" |
11 #include "vm/ic_data.h" | 11 #include "vm/ic_data.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 *b = tmp; | 174 *b = tmp; |
175 a++; | 175 a++; |
176 b++; | 176 b++; |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 | 180 |
181 // The patch code buffer contains the jmp code which will be inserted at | 181 // The patch code buffer contains the jmp code which will be inserted at |
182 // entry point. | 182 // entry point. |
183 void CodePatcher::PatchEntry(const Code& code) { | 183 void CodePatcher::PatchEntry(const Code& code) { |
184 Jump jmp_entry(code.EntryPoint()); | 184 JumpPattern jmp_entry(code.EntryPoint()); |
185 ASSERT(!jmp_entry.IsValid()); | 185 ASSERT(!jmp_entry.IsValid()); |
186 const uword patch_buffer = code.GetPatchCodePc(); | 186 const uword patch_buffer = code.GetPatchCodePc(); |
187 ASSERT(patch_buffer != 0); | 187 ASSERT(patch_buffer != 0); |
188 Jump jmp_patch(patch_buffer); | 188 JumpPattern jmp_patch(patch_buffer); |
189 ASSERT(jmp_patch.IsValid()); | 189 ASSERT(jmp_patch.IsValid()); |
190 const uword jump_target = jmp_patch.TargetAddress(); | 190 const uword jump_target = jmp_patch.TargetAddress(); |
191 SwapCode(jmp_patch.pattern_length_in_bytes(), | 191 SwapCode(jmp_patch.pattern_length_in_bytes(), |
192 reinterpret_cast<char*>(code.EntryPoint()), | 192 reinterpret_cast<char*>(code.EntryPoint()), |
193 reinterpret_cast<char*>(patch_buffer)); | 193 reinterpret_cast<char*>(patch_buffer)); |
194 jmp_entry.SetTargetAddress(jump_target); | 194 jmp_entry.SetTargetAddress(jump_target); |
195 } | 195 } |
196 | 196 |
197 | 197 |
198 // The entry point is a jmp instruction, the patch code buffer contains | 198 // The entry point is a jmp instruction, the patch code buffer contains |
199 // original code, the entry point contains the jump instruction. | 199 // original code, the entry point contains the jump instruction. |
200 void CodePatcher::RestoreEntry(const Code& code) { | 200 void CodePatcher::RestoreEntry(const Code& code) { |
201 Jump jmp_entry(code.EntryPoint()); | 201 JumpPattern jmp_entry(code.EntryPoint()); |
202 ASSERT(jmp_entry.IsValid()); | 202 ASSERT(jmp_entry.IsValid()); |
203 const uword jump_target = jmp_entry.TargetAddress(); | 203 const uword jump_target = jmp_entry.TargetAddress(); |
204 const uword patch_buffer = code.GetPatchCodePc(); | 204 const uword patch_buffer = code.GetPatchCodePc(); |
205 ASSERT(patch_buffer != 0); | 205 ASSERT(patch_buffer != 0); |
206 // 'patch_buffer' contains original entry code. | 206 // 'patch_buffer' contains original entry code. |
207 Jump jmp_patch(patch_buffer); | 207 JumpPattern jmp_patch(patch_buffer); |
208 ASSERT(!jmp_patch.IsValid()); | 208 ASSERT(!jmp_patch.IsValid()); |
209 SwapCode(jmp_patch.pattern_length_in_bytes(), | 209 SwapCode(jmp_patch.pattern_length_in_bytes(), |
210 reinterpret_cast<char*>(code.EntryPoint()), | 210 reinterpret_cast<char*>(code.EntryPoint()), |
211 reinterpret_cast<char*>(patch_buffer)); | 211 reinterpret_cast<char*>(patch_buffer)); |
212 ASSERT(jmp_patch.IsValid()); | 212 ASSERT(jmp_patch.IsValid()); |
213 jmp_patch.SetTargetAddress(jump_target); | 213 jmp_patch.SetTargetAddress(jump_target); |
214 } | 214 } |
215 | 215 |
216 | 216 |
217 bool CodePatcher::CodeIsPatchable(const Code& code) { | 217 bool CodePatcher::CodeIsPatchable(const Code& code) { |
218 Jump jmp_entry(code.EntryPoint()); | 218 JumpPattern jmp_entry(code.EntryPoint()); |
219 if (code.Size() < (jmp_entry.pattern_length_in_bytes() * 2)) { | 219 if (code.Size() < (jmp_entry.pattern_length_in_bytes() * 2)) { |
220 return false; | 220 return false; |
221 } | 221 } |
222 uword limit = code.EntryPoint() + jmp_entry.pattern_length_in_bytes(); | 222 uword limit = code.EntryPoint() + jmp_entry.pattern_length_in_bytes(); |
223 for (intptr_t i = 0; i < code.pointer_offsets_length(); i++) { | 223 for (intptr_t i = 0; i < code.pointer_offsets_length(); i++) { |
224 const uword addr = code.GetPointerOffsetAt(i) + code.EntryPoint(); | 224 const uword addr = code.GetPointerOffsetAt(i) + code.EntryPoint(); |
225 if (addr < limit) { | 225 if (addr < limit) { |
226 return false; | 226 return false; |
227 } | 227 } |
228 } | 228 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 266 } |
267 | 267 |
268 | 268 |
269 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 269 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
270 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; | 270 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; |
271 } | 271 } |
272 | 272 |
273 } // namespace dart | 273 } // namespace dart |
274 | 274 |
275 #endif // defined TARGET_ARCH_IA32 | 275 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |