Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "runtime_callbacks.h" |
| 18 | |
| 19 | #include <algorithm> |
| 20 | |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 21 | #include "art_method.h" |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame] | 22 | #include "base/macros.h" |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 23 | #include "base/mutex-inl.h" |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 24 | #include "class_linker.h" |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 25 | #include "monitor.h" |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 26 | #include "thread-current-inl.h" |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 30 | RuntimeCallbacks::RuntimeCallbacks() |
| 31 | : callback_lock_(new ReaderWriterMutex("Runtime callbacks lock", |
| 32 | LockLevel::kGenericBottomLock)) {} |
| 33 | |
| 34 | // We don't want to be holding any locks when the actual event is called so we use this to define a |
| 35 | // helper that gets a copy of the current event list and returns it. |
| 36 | #define COPY(T) \ |
| 37 | ([this]() -> decltype(this->T) { \ |
| 38 | ReaderMutexLock mu(Thread::Current(), *this->callback_lock_); \ |
| 39 | return std::vector<decltype(this->T)::value_type>(this->T); \ |
| 40 | })() |
| 41 | |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame] | 42 | template <typename T> |
| 43 | ALWAYS_INLINE |
| 44 | static inline void Remove(T* cb, std::vector<T*>* data) { |
| 45 | auto it = std::find(data->begin(), data->end(), cb); |
| 46 | if (it != data->end()) { |
| 47 | data->erase(it); |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 51 | void RuntimeCallbacks::AddDdmCallback(DdmCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 52 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 53 | ddm_callbacks_.push_back(cb); |
| 54 | } |
| 55 | |
| 56 | void RuntimeCallbacks::RemoveDdmCallback(DdmCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 57 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 58 | Remove(cb, &ddm_callbacks_); |
| 59 | } |
| 60 | |
| 61 | void RuntimeCallbacks::DdmPublishChunk(uint32_t type, const ArrayRef<const uint8_t>& data) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 62 | for (DdmCallback* cb : COPY(ddm_callbacks_)) { |
Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 63 | cb->DdmPublishChunk(type, data); |
| 64 | } |
| 65 | } |
| 66 | |
Alex Light | 4032071 | 2017-12-14 11:52:04 -0800 | [diff] [blame] | 67 | void RuntimeCallbacks::AddDebuggerControlCallback(DebuggerControlCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 68 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | 4032071 | 2017-12-14 11:52:04 -0800 | [diff] [blame] | 69 | debugger_control_callbacks_.push_back(cb); |
| 70 | } |
| 71 | |
| 72 | void RuntimeCallbacks::RemoveDebuggerControlCallback(DebuggerControlCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 73 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | 4032071 | 2017-12-14 11:52:04 -0800 | [diff] [blame] | 74 | Remove(cb, &debugger_control_callbacks_); |
| 75 | } |
| 76 | |
| 77 | bool RuntimeCallbacks::IsDebuggerConfigured() { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 78 | for (DebuggerControlCallback* cb : COPY(debugger_control_callbacks_)) { |
Alex Light | 4032071 | 2017-12-14 11:52:04 -0800 | [diff] [blame] | 79 | if (cb->IsDebuggerConfigured()) { |
| 80 | return true; |
| 81 | } |
| 82 | } |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | void RuntimeCallbacks::StartDebugger() { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 87 | for (DebuggerControlCallback* cb : COPY(debugger_control_callbacks_)) { |
Alex Light | 4032071 | 2017-12-14 11:52:04 -0800 | [diff] [blame] | 88 | cb->StartDebugger(); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | void RuntimeCallbacks::StopDebugger() { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 93 | for (DebuggerControlCallback* cb : COPY(debugger_control_callbacks_)) { |
Alex Light | 4032071 | 2017-12-14 11:52:04 -0800 | [diff] [blame] | 94 | cb->StopDebugger(); |
| 95 | } |
| 96 | } |
| 97 | |
Alex Light | 2161193 | 2017-09-26 13:07:39 -0700 | [diff] [blame] | 98 | void RuntimeCallbacks::AddMethodInspectionCallback(MethodInspectionCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 99 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | 2161193 | 2017-09-26 13:07:39 -0700 | [diff] [blame] | 100 | method_inspection_callbacks_.push_back(cb); |
| 101 | } |
| 102 | |
| 103 | void RuntimeCallbacks::RemoveMethodInspectionCallback(MethodInspectionCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 104 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | 2161193 | 2017-09-26 13:07:39 -0700 | [diff] [blame] | 105 | Remove(cb, &method_inspection_callbacks_); |
| 106 | } |
| 107 | |
| 108 | bool RuntimeCallbacks::IsMethodBeingInspected(ArtMethod* m) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 109 | for (MethodInspectionCallback* cb : COPY(method_inspection_callbacks_)) { |
Alex Light | 2161193 | 2017-09-26 13:07:39 -0700 | [diff] [blame] | 110 | if (cb->IsMethodBeingInspected(m)) { |
| 111 | return true; |
| 112 | } |
| 113 | } |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | void RuntimeCallbacks::AddThreadLifecycleCallback(ThreadLifecycleCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 118 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | 2161193 | 2017-09-26 13:07:39 -0700 | [diff] [blame] | 119 | thread_callbacks_.push_back(cb); |
| 120 | } |
| 121 | |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 122 | void RuntimeCallbacks::MonitorContendedLocking(Monitor* m) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 123 | for (MonitorCallback* cb : COPY(monitor_callbacks_)) { |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 124 | cb->MonitorContendedLocking(m); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | void RuntimeCallbacks::MonitorContendedLocked(Monitor* m) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 129 | for (MonitorCallback* cb : COPY(monitor_callbacks_)) { |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 130 | cb->MonitorContendedLocked(m); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void RuntimeCallbacks::ObjectWaitStart(Handle<mirror::Object> m, int64_t timeout) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 135 | for (MonitorCallback* cb : COPY(monitor_callbacks_)) { |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 136 | cb->ObjectWaitStart(m, timeout); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | void RuntimeCallbacks::MonitorWaitFinished(Monitor* m, bool timeout) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 141 | for (MonitorCallback* cb : COPY(monitor_callbacks_)) { |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 142 | cb->MonitorWaitFinished(m, timeout); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | void RuntimeCallbacks::AddMonitorCallback(MonitorCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 147 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 148 | monitor_callbacks_.push_back(cb); |
| 149 | } |
| 150 | |
| 151 | void RuntimeCallbacks::RemoveMonitorCallback(MonitorCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 152 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | 77fee87 | 2017-09-05 14:51:49 -0700 | [diff] [blame] | 153 | Remove(cb, &monitor_callbacks_); |
| 154 | } |
| 155 | |
Charles Munger | 5cc0e75 | 2018-11-09 12:30:46 -0800 | [diff] [blame] | 156 | void RuntimeCallbacks::ThreadParkStart(bool is_absolute, int64_t timeout) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 157 | for (ParkCallback * cb : COPY(park_callbacks_)) { |
Charles Munger | 5cc0e75 | 2018-11-09 12:30:46 -0800 | [diff] [blame] | 158 | cb->ThreadParkStart(is_absolute, timeout); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void RuntimeCallbacks::ThreadParkFinished(bool timeout) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 163 | for (ParkCallback * cb : COPY(park_callbacks_)) { |
Charles Munger | 5cc0e75 | 2018-11-09 12:30:46 -0800 | [diff] [blame] | 164 | cb->ThreadParkFinished(timeout); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | void RuntimeCallbacks::AddParkCallback(ParkCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 169 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Charles Munger | 5cc0e75 | 2018-11-09 12:30:46 -0800 | [diff] [blame] | 170 | park_callbacks_.push_back(cb); |
| 171 | } |
| 172 | |
| 173 | void RuntimeCallbacks::RemoveParkCallback(ParkCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 174 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Charles Munger | 5cc0e75 | 2018-11-09 12:30:46 -0800 | [diff] [blame] | 175 | Remove(cb, &park_callbacks_); |
| 176 | } |
| 177 | |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame] | 178 | void RuntimeCallbacks::RemoveThreadLifecycleCallback(ThreadLifecycleCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 179 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame] | 180 | Remove(cb, &thread_callbacks_); |
| 181 | } |
| 182 | |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 183 | void RuntimeCallbacks::ThreadStart(Thread* self) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 184 | for (ThreadLifecycleCallback* cb : COPY(thread_callbacks_)) { |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 185 | cb->ThreadStart(self); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | void RuntimeCallbacks::ThreadDeath(Thread* self) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 190 | for (ThreadLifecycleCallback* cb : COPY(thread_callbacks_)) { |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 191 | cb->ThreadDeath(self); |
| 192 | } |
| 193 | } |
| 194 | |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 195 | void RuntimeCallbacks::AddClassLoadCallback(ClassLoadCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 196 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 197 | class_callbacks_.push_back(cb); |
| 198 | } |
| 199 | |
| 200 | void RuntimeCallbacks::RemoveClassLoadCallback(ClassLoadCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 201 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame] | 202 | Remove(cb, &class_callbacks_); |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void RuntimeCallbacks::ClassLoad(Handle<mirror::Class> klass) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 206 | for (ClassLoadCallback* cb : COPY(class_callbacks_)) { |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 207 | cb->ClassLoad(klass); |
| 208 | } |
| 209 | } |
| 210 | |
Alex Light | 270db1c | 2019-12-03 12:20:01 +0000 | [diff] [blame] | 211 | void RuntimeCallbacks::EndDefineClass() { |
| 212 | for (ClassLoadCallback* cb : COPY(class_callbacks_)) { |
| 213 | cb->EndDefineClass(); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | void RuntimeCallbacks::BeginDefineClass() { |
| 218 | for (ClassLoadCallback* cb : COPY(class_callbacks_)) { |
| 219 | cb->BeginDefineClass(); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | |
Alex Light | b0f1192 | 2017-01-23 14:25:17 -0800 | [diff] [blame] | 224 | void RuntimeCallbacks::ClassPreDefine(const char* descriptor, |
| 225 | Handle<mirror::Class> temp_class, |
| 226 | Handle<mirror::ClassLoader> loader, |
| 227 | const DexFile& initial_dex_file, |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 228 | const dex::ClassDef& initial_class_def, |
Alex Light | b0f1192 | 2017-01-23 14:25:17 -0800 | [diff] [blame] | 229 | /*out*/DexFile const** final_dex_file, |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 230 | /*out*/dex::ClassDef const** final_class_def) { |
Alex Light | b0f1192 | 2017-01-23 14:25:17 -0800 | [diff] [blame] | 231 | DexFile const* current_dex_file = &initial_dex_file; |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 232 | dex::ClassDef const* current_class_def = &initial_class_def; |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 233 | for (ClassLoadCallback* cb : COPY(class_callbacks_)) { |
Alex Light | b0f1192 | 2017-01-23 14:25:17 -0800 | [diff] [blame] | 234 | DexFile const* new_dex_file = nullptr; |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 235 | dex::ClassDef const* new_class_def = nullptr; |
Alex Light | b0f1192 | 2017-01-23 14:25:17 -0800 | [diff] [blame] | 236 | cb->ClassPreDefine(descriptor, |
| 237 | temp_class, |
| 238 | loader, |
| 239 | *current_dex_file, |
| 240 | *current_class_def, |
| 241 | &new_dex_file, |
| 242 | &new_class_def); |
| 243 | if ((new_dex_file != nullptr && new_dex_file != current_dex_file) || |
| 244 | (new_class_def != nullptr && new_class_def != current_class_def)) { |
| 245 | DCHECK(new_dex_file != nullptr && new_class_def != nullptr); |
| 246 | current_dex_file = new_dex_file; |
| 247 | current_class_def = new_class_def; |
| 248 | } |
| 249 | } |
| 250 | *final_dex_file = current_dex_file; |
| 251 | *final_class_def = current_class_def; |
| 252 | } |
| 253 | |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 254 | void RuntimeCallbacks::ClassPrepare(Handle<mirror::Class> temp_klass, Handle<mirror::Class> klass) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 255 | for (ClassLoadCallback* cb : COPY(class_callbacks_)) { |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 256 | cb->ClassPrepare(temp_klass, klass); |
| 257 | } |
| 258 | } |
| 259 | |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame] | 260 | void RuntimeCallbacks::AddRuntimeSigQuitCallback(RuntimeSigQuitCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 261 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame] | 262 | sigquit_callbacks_.push_back(cb); |
| 263 | } |
| 264 | |
| 265 | void RuntimeCallbacks::RemoveRuntimeSigQuitCallback(RuntimeSigQuitCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 266 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame] | 267 | Remove(cb, &sigquit_callbacks_); |
| 268 | } |
| 269 | |
| 270 | void RuntimeCallbacks::SigQuit() { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 271 | for (RuntimeSigQuitCallback* cb : COPY(sigquit_callbacks_)) { |
Andreas Gampe | a5814f9 | 2017-01-18 21:43:16 -0800 | [diff] [blame] | 272 | cb->SigQuit(); |
| 273 | } |
| 274 | } |
| 275 | |
Andreas Gampe | 4886411 | 2017-01-19 17:23:17 -0800 | [diff] [blame] | 276 | void RuntimeCallbacks::AddRuntimePhaseCallback(RuntimePhaseCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 277 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Andreas Gampe | 4886411 | 2017-01-19 17:23:17 -0800 | [diff] [blame] | 278 | phase_callbacks_.push_back(cb); |
| 279 | } |
| 280 | |
| 281 | void RuntimeCallbacks::RemoveRuntimePhaseCallback(RuntimePhaseCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 282 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Andreas Gampe | 4886411 | 2017-01-19 17:23:17 -0800 | [diff] [blame] | 283 | Remove(cb, &phase_callbacks_); |
| 284 | } |
| 285 | |
| 286 | void RuntimeCallbacks::NextRuntimePhase(RuntimePhaseCallback::RuntimePhase phase) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 287 | for (RuntimePhaseCallback* cb : COPY(phase_callbacks_)) { |
Andreas Gampe | 4886411 | 2017-01-19 17:23:17 -0800 | [diff] [blame] | 288 | cb->NextRuntimePhase(phase); |
| 289 | } |
| 290 | } |
| 291 | |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 292 | void RuntimeCallbacks::AddMethodCallback(MethodCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 293 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 294 | method_callbacks_.push_back(cb); |
| 295 | } |
| 296 | |
| 297 | void RuntimeCallbacks::RemoveMethodCallback(MethodCallback* cb) { |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 298 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 299 | Remove(cb, &method_callbacks_); |
| 300 | } |
| 301 | |
| 302 | void RuntimeCallbacks::RegisterNativeMethod(ArtMethod* method, |
| 303 | const void* in_cur_method, |
| 304 | /*out*/void** new_method) { |
| 305 | void* cur_method = const_cast<void*>(in_cur_method); |
| 306 | *new_method = cur_method; |
Alex Light | 51d5a30 | 2019-04-09 11:22:17 -0700 | [diff] [blame] | 307 | for (MethodCallback* cb : COPY(method_callbacks_)) { |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 308 | cb->RegisterNativeMethod(method, cur_method, new_method); |
| 309 | if (*new_method != nullptr) { |
| 310 | cur_method = *new_method; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
Alex Light | c18eba3 | 2019-09-24 14:36:27 -0700 | [diff] [blame] | 315 | void RuntimeCallbacks::AddReflectiveValueVisitCallback(ReflectiveValueVisitCallback *cb) { |
| 316 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
| 317 | reflective_value_visit_callbacks_.push_back(cb); |
| 318 | } |
| 319 | |
| 320 | void RuntimeCallbacks::RemoveReflectiveValueVisitCallback(ReflectiveValueVisitCallback *cb) { |
| 321 | WriterMutexLock mu(Thread::Current(), *callback_lock_); |
| 322 | Remove(cb, &reflective_value_visit_callbacks_); |
| 323 | } |
| 324 | |
| 325 | void RuntimeCallbacks::VisitReflectiveTargets(ReflectiveValueVisitor *visitor) { |
| 326 | for (ReflectiveValueVisitCallback* cb : COPY(reflective_value_visit_callbacks_)) { |
| 327 | cb->VisitReflectiveTargets(visitor); |
| 328 | } |
| 329 | } |
| 330 | |
Andreas Gampe | 04bbb5b | 2017-01-19 17:49:03 +0000 | [diff] [blame] | 331 | } // namespace art |