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