blob: cd38ead2c3505950affb12dbd04c86c4a2e9907a [file] [log] [blame]
Andreas Gampe04bbb5b2017-01-19 17:49:03 +00001/*
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
Andreas Gampea5814f92017-01-18 21:43:16 -080021#include "base/macros.h"
Andreas Gampe0f01b582017-01-18 15:22:37 -080022#include "class_linker.h"
Andreas Gampe04bbb5b2017-01-19 17:49:03 +000023#include "thread.h"
24
25namespace art {
26
27void RuntimeCallbacks::AddThreadLifecycleCallback(ThreadLifecycleCallback* cb) {
28 thread_callbacks_.push_back(cb);
29}
30
Andreas Gampea5814f92017-01-18 21:43:16 -080031template <typename T>
32ALWAYS_INLINE
33static inline void Remove(T* cb, std::vector<T*>* data) {
34 auto it = std::find(data->begin(), data->end(), cb);
35 if (it != data->end()) {
36 data->erase(it);
Andreas Gampe04bbb5b2017-01-19 17:49:03 +000037 }
38}
39
Andreas Gampea5814f92017-01-18 21:43:16 -080040void RuntimeCallbacks::RemoveThreadLifecycleCallback(ThreadLifecycleCallback* cb) {
41 Remove(cb, &thread_callbacks_);
42}
43
Andreas Gampe04bbb5b2017-01-19 17:49:03 +000044void RuntimeCallbacks::ThreadStart(Thread* self) {
45 for (ThreadLifecycleCallback* cb : thread_callbacks_) {
46 cb->ThreadStart(self);
47 }
48}
49
50void RuntimeCallbacks::ThreadDeath(Thread* self) {
51 for (ThreadLifecycleCallback* cb : thread_callbacks_) {
52 cb->ThreadDeath(self);
53 }
54}
55
Andreas Gampe0f01b582017-01-18 15:22:37 -080056void RuntimeCallbacks::AddClassLoadCallback(ClassLoadCallback* cb) {
57 class_callbacks_.push_back(cb);
58}
59
60void RuntimeCallbacks::RemoveClassLoadCallback(ClassLoadCallback* cb) {
Andreas Gampea5814f92017-01-18 21:43:16 -080061 Remove(cb, &class_callbacks_);
Andreas Gampe0f01b582017-01-18 15:22:37 -080062}
63
64void RuntimeCallbacks::ClassLoad(Handle<mirror::Class> klass) {
65 for (ClassLoadCallback* cb : class_callbacks_) {
66 cb->ClassLoad(klass);
67 }
68}
69
70void RuntimeCallbacks::ClassPrepare(Handle<mirror::Class> temp_klass, Handle<mirror::Class> klass) {
71 for (ClassLoadCallback* cb : class_callbacks_) {
72 cb->ClassPrepare(temp_klass, klass);
73 }
74}
75
Andreas Gampea5814f92017-01-18 21:43:16 -080076void RuntimeCallbacks::AddRuntimeSigQuitCallback(RuntimeSigQuitCallback* cb) {
77 sigquit_callbacks_.push_back(cb);
78}
79
80void RuntimeCallbacks::RemoveRuntimeSigQuitCallback(RuntimeSigQuitCallback* cb) {
81 Remove(cb, &sigquit_callbacks_);
82}
83
84void RuntimeCallbacks::SigQuit() {
85 for (RuntimeSigQuitCallback* cb : sigquit_callbacks_) {
86 cb->SigQuit();
87 }
88}
89
Andreas Gampe04bbb5b2017-01-19 17:49:03 +000090} // namespace art