Flutter Engine
The Flutter Engine
code_patcher_arm.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM.
6#if defined(TARGET_ARCH_ARM)
7
8#include "vm/code_patcher.h"
9
10#include "vm/instructions.h"
11#include "vm/object.h"
12
13namespace dart {
14
15CodePtr CodePatcher::GetStaticCallTargetAt(uword return_address,
16 const Code& code) {
17 ASSERT(code.ContainsInstructionAt(return_address));
18 CallPattern call(return_address, code);
19 return call.TargetCode();
20}
21
22void CodePatcher::PatchStaticCallAt(uword return_address,
23 const Code& code,
24 const Code& new_target) {
25 ASSERT(code.ContainsInstructionAt(return_address));
26 CallPattern call(return_address, code);
27 call.SetTargetCode(new_target);
28}
29
32}
33
34CodePtr CodePatcher::GetInstanceCallAt(uword return_address,
35 const Code& caller_code,
36 Object* data) {
37 ASSERT(caller_code.ContainsInstructionAt(return_address));
38 ICCallPattern call(return_address, caller_code);
39 if (data != nullptr) {
40 *data = call.Data();
41 }
42 return call.TargetCode();
43}
44
45void CodePatcher::PatchInstanceCallAt(uword return_address,
46 const Code& caller_code,
47 const Object& data,
48 const Code& target) {
49 auto thread = Thread::Current();
50 thread->isolate_group()->RunWithStoppedMutators([&]() {
51 PatchInstanceCallAtWithMutatorsStopped(thread, return_address, caller_code,
52 data, target);
53 });
54}
55
57 Thread* thread,
58 uword return_address,
59 const Code& caller_code,
60 const Object& data,
61 const Code& target) {
62 ASSERT(caller_code.ContainsInstructionAt(return_address));
63 ICCallPattern call(return_address, caller_code);
64 call.SetData(data);
65 call.SetTargetCode(target);
66}
67
68FunctionPtr CodePatcher::GetUnoptimizedStaticCallAt(uword return_address,
69 const Code& caller_code,
70 ICData* ic_data_result) {
71 ASSERT(caller_code.ContainsInstructionAt(return_address));
72 ICCallPattern static_call(return_address, caller_code);
73 ICData& ic_data = ICData::Handle();
74 ic_data ^= static_call.Data();
75 if (ic_data_result != nullptr) {
76 *ic_data_result = ic_data.ptr();
77 }
78 return ic_data.GetTargetAt(0);
79}
80
82 const Code& caller_code,
83 const Object& data,
84 const Code& target) {
85 auto thread = Thread::Current();
86 // Ensure all threads are suspended as we update data and target pair.
87 thread->isolate_group()->RunWithStoppedMutators([&]() {
88 PatchSwitchableCallAtWithMutatorsStopped(thread, return_address,
89 caller_code, data, target);
90 });
91}
92
94 Thread* thread,
95 uword return_address,
96 const Code& caller_code,
97 const Object& data,
98 const Code& target) {
99 if (FLAG_precompiled_mode) {
100 BareSwitchableCallPattern call(return_address);
101 call.SetData(data);
102 call.SetTarget(target);
103 } else {
104 SwitchableCallPattern call(return_address, caller_code);
105 call.SetData(data);
106 call.SetTarget(target);
107 }
108}
109
111 const Code& caller_code) {
112 if (FLAG_precompiled_mode) {
113 BareSwitchableCallPattern call(return_address);
114 return call.target_entry();
115 } else {
116 SwitchableCallPattern call(return_address, caller_code);
117 return call.target_entry();
118 }
119}
120
121ObjectPtr CodePatcher::GetSwitchableCallDataAt(uword return_address,
122 const Code& caller_code) {
123 if (FLAG_precompiled_mode) {
124 BareSwitchableCallPattern call(return_address);
125 return call.data();
126 } else {
127 SwitchableCallPattern call(return_address, caller_code);
128 return call.data();
129 }
130}
131
132void CodePatcher::PatchNativeCallAt(uword return_address,
133 const Code& code,
135 const Code& trampoline) {
137 ASSERT(code.ContainsInstructionAt(return_address));
138 NativeCallPattern call(return_address, code);
139 call.set_target(trampoline);
140 call.set_native_function(target);
141 });
142}
143
144CodePtr CodePatcher::GetNativeCallAt(uword return_address,
145 const Code& code,
147 ASSERT(code.ContainsInstructionAt(return_address));
148 NativeCallPattern call(return_address, code);
149 *target = call.native_function();
150 return call.target();
151}
152
153} // namespace dart
154
155#endif // defined TARGET_ARCH_ARM
#define UNREACHABLE()
Definition: assert.h:248
static void PatchInstanceCallAt(uword return_address, const Code &caller_code, const Object &data, const Code &target)
static CodePtr GetStaticCallTargetAt(uword return_address, const Code &code)
static void PatchSwitchableCallAtWithMutatorsStopped(Thread *thread, uword return_address, const Code &caller_code, const Object &data, const Code &target)
static void PatchInstanceCallAtWithMutatorsStopped(Thread *thread, uword return_address, const Code &caller_code, const Object &data, const Code &target)
static void PatchSwitchableCallAt(uword return_address, const Code &caller_code, const Object &data, const Code &target)
static FunctionPtr GetUnoptimizedStaticCallAt(uword return_address, const Code &code, ICData *ic_data)
static uword GetSwitchableCallTargetEntryAt(uword return_address, const Code &caller_code)
static ObjectPtr GetSwitchableCallDataAt(uword return_address, const Code &caller_code)
static void InsertDeoptimizationCallAt(uword start)
static CodePtr GetInstanceCallAt(uword return_address, const Code &caller_code, Object *data)
static CodePtr GetNativeCallAt(uword return_address, const Code &caller_code, NativeFunction *target)
static void PatchStaticCallAt(uword return_address, const Code &code, const Code &new_target)
static void PatchNativeCallAt(uword return_address, const Code &caller_code, NativeFunction target, const Code &trampoline)
void RunWithStoppedMutators(T single_current_mutator, S otherwise, bool use_force_growth_in_otherwise=false)
Definition: isolate.h:611
static Object & Handle()
Definition: object.h:407
static Thread * Current()
Definition: thread.h:362
IsolateGroup * isolate_group() const
Definition: thread.h:541
#define ASSERT(E)
uint32_t * target
Definition: dart_vm.cc:33
uintptr_t uword
Definition: globals.h:501
static int8_t data[kExtLength]
void(* NativeFunction)(NativeArguments *arguments)
def call(args)
Definition: dom.py:159