OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_ARM. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. |
6 #if defined(TARGET_ARCH_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
7 | 7 |
8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
9 | 9 |
10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
11 #include "vm/instructions.h" | 11 #include "vm/instructions.h" |
12 #include "vm/object.h" | 12 #include "vm/object.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 RawCode* CodePatcher::GetStaticCallTargetAt(uword return_address, | 16 uword CodePatcher::GetStaticCallTargetAt(uword return_address, |
17 const Code& code) { | 17 const Code& code) { |
18 ASSERT(code.ContainsInstructionAt(return_address)); | 18 ASSERT(code.ContainsInstructionAt(return_address)); |
19 CallPattern call(return_address, code); | 19 CallPattern call(return_address, code); |
20 return call.TargetCode(); | 20 return call.TargetAddress(); |
21 } | 21 } |
22 | 22 |
23 | 23 |
24 void CodePatcher::PatchStaticCallAt(uword return_address, | 24 void CodePatcher::PatchStaticCallAt(uword return_address, |
25 const Code& code, | 25 const Code& code, |
26 const Code& new_target) { | 26 uword new_target) { |
27 ASSERT(code.ContainsInstructionAt(return_address)); | 27 ASSERT(code.ContainsInstructionAt(return_address)); |
28 CallPattern call(return_address, code); | 28 CallPattern call(return_address, code); |
29 call.SetTargetCode(new_target); | 29 call.SetTargetAddress(new_target); |
30 } | 30 } |
31 | 31 |
32 | 32 |
33 void CodePatcher::InsertDeoptimizationCallAt(uword start, uword target) { | 33 void CodePatcher::PatchInstanceCallAt(uword return_address, |
34 // The inserted call should not overlap the lazy deopt jump code. | 34 const Code& code, |
35 ASSERT(start + CallPattern::DeoptCallPatternLengthInBytes() <= target); | 35 uword new_target) { |
36 CallPattern::InsertDeoptCallAt(start, target); | 36 ASSERT(code.ContainsInstructionAt(return_address)); |
| 37 CallPattern call(return_address, code); |
| 38 call.SetTargetAddress(new_target); |
37 } | 39 } |
38 | 40 |
39 | 41 |
40 RawCode* CodePatcher::GetInstanceCallAt(uword return_address, | 42 void CodePatcher::InsertCallAt(uword start, uword target) { |
41 const Code& code, | 43 // The inserted call should not overlap the lazy deopt jump code. |
42 ICData* ic_data) { | 44 ASSERT(start + CallPattern::LengthInBytes() <= target); |
| 45 CallPattern::InsertAt(start, target); |
| 46 } |
| 47 |
| 48 |
| 49 uword CodePatcher::GetInstanceCallAt(uword return_address, |
| 50 const Code& code, |
| 51 ICData* ic_data) { |
43 ASSERT(code.ContainsInstructionAt(return_address)); | 52 ASSERT(code.ContainsInstructionAt(return_address)); |
44 CallPattern call(return_address, code); | 53 CallPattern call(return_address, code); |
45 if (ic_data != NULL) { | 54 if (ic_data != NULL) { |
46 *ic_data = call.IcData(); | 55 *ic_data = call.IcData(); |
47 } | 56 } |
48 return call.TargetCode(); | 57 return call.TargetAddress(); |
49 } | 58 } |
50 | 59 |
51 | 60 |
52 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 61 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
53 // The instance call instruction sequence has a variable size on ARM. | 62 // The instance call instruction sequence has a variable size on ARM. |
54 UNREACHABLE(); | 63 UNREACHABLE(); |
55 return 0; | 64 return 0; |
56 } | 65 } |
57 | 66 |
58 | 67 |
59 RawFunction* CodePatcher::GetUnoptimizedStaticCallAt( | 68 RawFunction* CodePatcher::GetUnoptimizedStaticCallAt( |
60 uword return_address, const Code& code, ICData* ic_data_result) { | 69 uword return_address, const Code& code, ICData* ic_data_result) { |
61 ASSERT(code.ContainsInstructionAt(return_address)); | 70 ASSERT(code.ContainsInstructionAt(return_address)); |
62 CallPattern static_call(return_address, code); | 71 CallPattern static_call(return_address, code); |
63 ICData& ic_data = ICData::Handle(); | 72 ICData& ic_data = ICData::Handle(); |
64 ic_data ^= static_call.IcData(); | 73 ic_data ^= static_call.IcData(); |
65 if (ic_data_result != NULL) { | 74 if (ic_data_result != NULL) { |
66 *ic_data_result = ic_data.raw(); | 75 *ic_data_result = ic_data.raw(); |
67 } | 76 } |
68 return ic_data.GetTargetAt(0); | 77 return ic_data.GetTargetAt(0); |
69 } | 78 } |
70 | 79 |
71 | 80 |
72 void CodePatcher::PatchNativeCallAt(uword return_address, | 81 void CodePatcher::PatchNativeCallAt(uword return_address, |
73 const Code& code, | 82 const Code& code, |
74 NativeFunction target, | 83 NativeFunction target, |
75 const Code& trampoline) { | 84 const Code& trampoline) { |
76 ASSERT(code.ContainsInstructionAt(return_address)); | 85 ASSERT(code.ContainsInstructionAt(return_address)); |
77 NativeCallPattern call(return_address, code); | 86 NativeCallPattern call(return_address, code); |
78 call.set_target(trampoline); | 87 call.set_target(trampoline.EntryPoint()); |
79 call.set_native_function(target); | 88 call.set_native_function(target); |
80 } | 89 } |
81 | 90 |
82 | 91 |
83 RawCode* CodePatcher::GetNativeCallAt(uword return_address, | 92 uword CodePatcher::GetNativeCallAt(uword return_address, |
84 const Code& code, | 93 const Code& code, |
85 NativeFunction* target) { | 94 NativeFunction* target) { |
86 ASSERT(code.ContainsInstructionAt(return_address)); | 95 ASSERT(code.ContainsInstructionAt(return_address)); |
87 NativeCallPattern call(return_address, code); | 96 NativeCallPattern call(return_address, code); |
88 *target = call.native_function(); | 97 *target = call.native_function(); |
89 return call.target(); | 98 return call.target(); |
90 } | 99 } |
91 | 100 |
92 | 101 |
93 // This class pattern matches on a load from the object pool. Loading on | 102 // This class pattern matches on a load from the object pool. Loading on |
94 // ARM is complicated because it can take four possible different forms. We | 103 // ARM is complicated because it can take four possible different forms. We |
95 // match backwards from the end of the sequence so we can reuse the code for | 104 // match backwards from the end of the sequence so we can reuse the code for |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 136 |
128 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { | 137 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { |
129 ASSERT(code.ContainsInstructionAt(pc)); | 138 ASSERT(code.ContainsInstructionAt(pc)); |
130 EdgeCounter counter(pc, code); | 139 EdgeCounter counter(pc, code); |
131 return counter.edge_counter(); | 140 return counter.edge_counter(); |
132 } | 141 } |
133 | 142 |
134 } // namespace dart | 143 } // namespace dart |
135 | 144 |
136 #endif // defined TARGET_ARCH_ARM | 145 #endif // defined TARGET_ARCH_ARM |
OLD | NEW |