Implement can_generate_native_method_bind capability
This capability lets one observe and even replace the implementations
of native methods when they are bound.
Test: ./test.py --host -j40
Bug: 37432636
Change-Id: I2432a8e4da1a677e8011ce495296f4ab9f42eb3e
diff --git a/runtime/runtime_callbacks.cc b/runtime/runtime_callbacks.cc
index 25324b5..16d6c13 100644
--- a/runtime/runtime_callbacks.cc
+++ b/runtime/runtime_callbacks.cc
@@ -18,6 +18,7 @@
#include <algorithm>
+#include "art_method.h"
#include "base/macros.h"
#include "class_linker.h"
#include "thread.h"
@@ -131,4 +132,25 @@
}
}
+void RuntimeCallbacks::AddMethodCallback(MethodCallback* cb) {
+ method_callbacks_.push_back(cb);
+}
+
+void RuntimeCallbacks::RemoveMethodCallback(MethodCallback* cb) {
+ Remove(cb, &method_callbacks_);
+}
+
+void RuntimeCallbacks::RegisterNativeMethod(ArtMethod* method,
+ const void* in_cur_method,
+ /*out*/void** new_method) {
+ void* cur_method = const_cast<void*>(in_cur_method);
+ *new_method = cur_method;
+ for (MethodCallback* cb : method_callbacks_) {
+ cb->RegisterNativeMethod(method, cur_method, new_method);
+ if (*new_method != nullptr) {
+ cur_method = *new_method;
+ }
+ }
+}
+
} // namespace art