Add hooks in palette for reporting JNI invocations.
Test: test.py
Change-Id: I909fc720fe5b891da6919fe20ad162ec12524f02
diff --git a/libartpalette/Android.bp b/libartpalette/Android.bp
index 66e8bda..e8b7fd8 100644
--- a/libartpalette/Android.bp
+++ b/libartpalette/Android.bp
@@ -54,7 +54,10 @@
// support both prebuilts and sources present simultaneously.
"//prebuilts/module_sdk/art/current/host-exports",
],
- header_libs: ["libbase_headers"],
+ header_libs: [
+ "libbase_headers",
+ "jni_headers",
+ ],
target: {
// Targets supporting dlopen build the client library which loads
// and binds the methods in the libartpalette-system library.
diff --git a/libartpalette/include/palette/palette_hooks.h b/libartpalette/include/palette/palette_hooks.h
index 14e7b3f..90dc4a7 100644
--- a/libartpalette/include/palette/palette_hooks.h
+++ b/libartpalette/include/palette/palette_hooks.h
@@ -19,6 +19,8 @@
#include "palette_types.h"
+#include "jni.h"
+
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
@@ -39,6 +41,13 @@
// Notify the Hooks object that the runtime is loading a .oat file.
void (*NotifyOatFileLoaded)(const char* path);
+
+ // Notify the Hooks object that a native call is starting.
+ void (*NotifyBeginJniInvocation)(JNIEnv* env);
+
+
+ // Notify the Hooks object that a native call is ending.
+ void (*NotifyEndJniInvocation)(JNIEnv* env);
} paletteHooksInterface;
struct PaletteHooks {
@@ -56,6 +65,12 @@
void NotifyOatFileLoaded(const char* path) {
return functions->NotifyOatFileLoaded(path);
}
+ void NotifyBeginJniInvocation(JNIEnv* env) {
+ return functions->NotifyBeginJniInvocation(env);
+ }
+ void NotifyEndJniInvocation(JNIEnv* env) {
+ return functions->NotifyEndJniInvocation(env);
+ }
#endif
};
diff --git a/runtime/entrypoints/quick/quick_jni_entrypoints.cc b/runtime/entrypoints/quick/quick_jni_entrypoints.cc
index 7d55817..139225d 100644
--- a/runtime/entrypoints/quick/quick_jni_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_jni_entrypoints.cc
@@ -21,6 +21,8 @@
#include "entrypoints/entrypoint_utils-inl.h"
#include "indirect_reference_table.h"
#include "mirror/object-inl.h"
+#include "palette/palette.h"
+#include "palette/palette_hooks.h"
#include "thread-inl.h"
#include "verify_object.h"
@@ -74,6 +76,10 @@
CHECK(!native_method->IsFastNative()) << native_method->PrettyMethod();
}
+ PaletteHooks* hooks = nullptr;
+ if (PaletteGetHooks(&hooks) == PALETTE_STATUS_OK) {
+ hooks->NotifyBeginJniInvocation(env);
+ }
// Transition out of runnable.
self->TransitionFromRunnableToSuspended(kNative);
return saved_local_ref_cookie;
@@ -92,6 +98,10 @@
}
self->TransitionFromSuspendedToRunnable();
+ PaletteHooks* hooks = nullptr;
+ if (PaletteGetHooks(&hooks) == PALETTE_STATUS_OK) {
+ hooks->NotifyEndJniInvocation(self->GetJniEnv());
+ }
}
ALWAYS_INLINE static inline void GoToRunnableFast(Thread* self) {