diff options
| author | 2021-04-16 13:27:20 +0100 | |
|---|---|---|
| committer | 2021-04-19 16:04:21 +0000 | |
| commit | 511392f151143f7d8bf2f82d5201ffa6d5d051de (patch) | |
| tree | 90b099b337432e8671f47c8eac6b1d5021db3293 | |
| parent | ae3aa6ca3e1bb29845da8844ab72ae2dc76d7793 (diff) | |
Add hooks in palette for reporting JNI invocations.
Test: test.py
Change-Id: I909fc720fe5b891da6919fe20ad162ec12524f02
| -rw-r--r-- | libartpalette/Android.bp | 5 | ||||
| -rw-r--r-- | libartpalette/include/palette/palette_hooks.h | 15 | ||||
| -rw-r--r-- | runtime/entrypoints/quick/quick_jni_entrypoints.cc | 10 |
3 files changed, 29 insertions, 1 deletions
diff --git a/libartpalette/Android.bp b/libartpalette/Android.bp index 66e8bda876..e8b7fd82d6 100644 --- a/libartpalette/Android.bp +++ b/libartpalette/Android.bp @@ -54,7 +54,10 @@ art_cc_library { // 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 14e7b3f912..90dc4a75d9 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 @@ typedef struct paletteHooksInterface_ { // 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 @@ struct PaletteHooks { 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 7d55817407..139225d0e0 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 @@ extern uint32_t JniMethodStart(Thread* self) { 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 @@ static void GoToRunnable(Thread* self) NO_THREAD_SAFETY_ANALYSIS { } self->TransitionFromSuspendedToRunnable(); + PaletteHooks* hooks = nullptr; + if (PaletteGetHooks(&hooks) == PALETTE_STATUS_OK) { + hooks->NotifyEndJniInvocation(self->GetJniEnv()); + } } ALWAYS_INLINE static inline void GoToRunnableFast(Thread* self) { |