OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_DBC. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_DBC. |
6 #if defined(TARGET_ARCH_DBC) | 6 #if defined(TARGET_ARCH_DBC) |
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 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.TargetCode(); | 20 return call.TargetCode(); |
21 } | 21 } |
22 | 22 |
23 | |
24 void CodePatcher::PatchStaticCallAt(uword return_address, | 23 void CodePatcher::PatchStaticCallAt(uword return_address, |
25 const Code& code, | 24 const Code& code, |
26 const Code& new_target) { | 25 const Code& new_target) { |
27 ASSERT(code.ContainsInstructionAt(return_address)); | 26 ASSERT(code.ContainsInstructionAt(return_address)); |
28 CallPattern call(return_address, code); | 27 CallPattern call(return_address, code); |
29 call.SetTargetCode(new_target); | 28 call.SetTargetCode(new_target); |
30 } | 29 } |
31 | 30 |
32 | |
33 void CodePatcher::InsertDeoptimizationCallAt(uword start) { | 31 void CodePatcher::InsertDeoptimizationCallAt(uword start) { |
34 CallPattern::InsertDeoptCallAt(start); | 32 CallPattern::InsertDeoptCallAt(start); |
35 } | 33 } |
36 | 34 |
37 | |
38 RawCode* CodePatcher::GetInstanceCallAt(uword return_address, | 35 RawCode* CodePatcher::GetInstanceCallAt(uword return_address, |
39 const Code& code, | 36 const Code& code, |
40 ICData* ic_data) { | 37 ICData* ic_data) { |
41 ASSERT(code.ContainsInstructionAt(return_address)); | 38 ASSERT(code.ContainsInstructionAt(return_address)); |
42 CallPattern call(return_address, code); | 39 CallPattern call(return_address, code); |
43 if (ic_data != NULL) { | 40 if (ic_data != NULL) { |
44 *ic_data = call.IcData(); | 41 *ic_data = call.IcData(); |
45 } | 42 } |
46 return call.TargetCode(); | 43 return call.TargetCode(); |
47 } | 44 } |
48 | 45 |
49 | |
50 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 46 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
51 UNREACHABLE(); | 47 UNREACHABLE(); |
52 return 0; | 48 return 0; |
53 } | 49 } |
54 | 50 |
55 | |
56 RawFunction* CodePatcher::GetUnoptimizedStaticCallAt(uword return_address, | 51 RawFunction* CodePatcher::GetUnoptimizedStaticCallAt(uword return_address, |
57 const Code& code, | 52 const Code& code, |
58 ICData* ic_data_result) { | 53 ICData* ic_data_result) { |
59 ASSERT(code.ContainsInstructionAt(return_address)); | 54 ASSERT(code.ContainsInstructionAt(return_address)); |
60 CallPattern static_call(return_address, code); | 55 CallPattern static_call(return_address, code); |
61 ICData& ic_data = ICData::Handle(); | 56 ICData& ic_data = ICData::Handle(); |
62 ic_data ^= static_call.IcData(); | 57 ic_data ^= static_call.IcData(); |
63 if (ic_data_result != NULL) { | 58 if (ic_data_result != NULL) { |
64 *ic_data_result = ic_data.raw(); | 59 *ic_data_result = ic_data.raw(); |
65 } | 60 } |
66 return ic_data.GetTargetAt(0); | 61 return ic_data.GetTargetAt(0); |
67 } | 62 } |
68 | 63 |
69 | |
70 void CodePatcher::PatchSwitchableCallAt(uword return_address, | 64 void CodePatcher::PatchSwitchableCallAt(uword return_address, |
71 const Code& caller_code, | 65 const Code& caller_code, |
72 const Object& data, | 66 const Object& data, |
73 const Code& target) { | 67 const Code& target) { |
74 ASSERT(caller_code.ContainsInstructionAt(return_address)); | 68 ASSERT(caller_code.ContainsInstructionAt(return_address)); |
75 SwitchableCallPattern call(return_address, caller_code); | 69 SwitchableCallPattern call(return_address, caller_code); |
76 call.SetData(data); | 70 call.SetData(data); |
77 call.SetTarget(target); | 71 call.SetTarget(target); |
78 } | 72 } |
79 | 73 |
80 | |
81 RawCode* CodePatcher::GetSwitchableCallTargetAt(uword return_address, | 74 RawCode* CodePatcher::GetSwitchableCallTargetAt(uword return_address, |
82 const Code& caller_code) { | 75 const Code& caller_code) { |
83 ASSERT(caller_code.ContainsInstructionAt(return_address)); | 76 ASSERT(caller_code.ContainsInstructionAt(return_address)); |
84 SwitchableCallPattern call(return_address, caller_code); | 77 SwitchableCallPattern call(return_address, caller_code); |
85 return call.target(); | 78 return call.target(); |
86 } | 79 } |
87 | 80 |
88 | |
89 RawObject* CodePatcher::GetSwitchableCallDataAt(uword return_address, | 81 RawObject* CodePatcher::GetSwitchableCallDataAt(uword return_address, |
90 const Code& caller_code) { | 82 const Code& caller_code) { |
91 ASSERT(caller_code.ContainsInstructionAt(return_address)); | 83 ASSERT(caller_code.ContainsInstructionAt(return_address)); |
92 SwitchableCallPattern call(return_address, caller_code); | 84 SwitchableCallPattern call(return_address, caller_code); |
93 return call.data(); | 85 return call.data(); |
94 } | 86 } |
95 | 87 |
96 | |
97 void CodePatcher::PatchNativeCallAt(uword return_address, | 88 void CodePatcher::PatchNativeCallAt(uword return_address, |
98 const Code& code, | 89 const Code& code, |
99 NativeFunction target, | 90 NativeFunction target, |
100 const Code& trampoline) { | 91 const Code& trampoline) { |
101 ASSERT(code.ContainsInstructionAt(return_address)); | 92 ASSERT(code.ContainsInstructionAt(return_address)); |
102 NativeCallPattern call(return_address, code); | 93 NativeCallPattern call(return_address, code); |
103 call.set_target(trampoline); | 94 call.set_target(trampoline); |
104 call.set_native_function(target); | 95 call.set_native_function(target); |
105 } | 96 } |
106 | 97 |
107 | |
108 RawCode* CodePatcher::GetNativeCallAt(uword return_address, | 98 RawCode* CodePatcher::GetNativeCallAt(uword return_address, |
109 const Code& code, | 99 const Code& code, |
110 NativeFunction* target) { | 100 NativeFunction* target) { |
111 ASSERT(code.ContainsInstructionAt(return_address)); | 101 ASSERT(code.ContainsInstructionAt(return_address)); |
112 NativeCallPattern call(return_address, code); | 102 NativeCallPattern call(return_address, code); |
113 *target = call.native_function(); | 103 *target = call.native_function(); |
114 return call.target(); | 104 return call.target(); |
115 } | 105 } |
116 | 106 |
117 } // namespace dart | 107 } // namespace dart |
118 | 108 |
119 #endif // defined TARGET_ARCH_DBC | 109 #endif // defined TARGET_ARCH_DBC |
OLD | NEW |