diff --git a/src/libagent/callback/MethodEntry.cpp b/src/libagent/callback/MethodEntry.cpp new file mode 100644 index 0000000..a9eb29d --- /dev/null +++ b/src/libagent/callback/MethodEntry.cpp @@ -0,0 +1,15 @@ +#include +#include + +void JNICALL MethodEntry(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method) { + auto& agent = JuiceAgent::Agent::instance(); + agent.get_eventbus().post(EventMethodEntry{ + .jvmti_env = jvmti_env, + .jni_env = jni_env, + .thread = thread, + .method = method + }); + } diff --git a/src/libagent/callback/MethodExit.cpp b/src/libagent/callback/MethodExit.cpp new file mode 100644 index 0000000..9223692 --- /dev/null +++ b/src/libagent/callback/MethodExit.cpp @@ -0,0 +1,19 @@ +#include +#include + +void JNICALL MethodExit(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jboolean was_popped_by_exception, + jvalue return_value) { + auto& agent = JuiceAgent::Agent::instance(); + agent.get_eventbus().post(EventMethodExit{ + .jvmti_env = jvmti_env, + .jni_env = jni_env, + .thread = thread, + .method = method, + .was_popped_by_exception = was_popped_by_exception, + .return_value = return_value + }); + } \ No newline at end of file diff --git a/src/libagent/includes/event/event_type.hpp b/src/libagent/includes/event/event_type.hpp index cbc2fd7..f7a20d6 100644 --- a/src/libagent/includes/event/event_type.hpp +++ b/src/libagent/includes/event/event_type.hpp @@ -16,6 +16,24 @@ struct EventClassFileLoadHook { unsigned char** new_classbytes; }; +// MethodEntry +struct EventMethodEntry { + jvmtiEnv* jvmti_env; + JNIEnv* jni_env; + jthread thread; + jmethodID method; +}; + +// MethodExit +struct EventMethodExit { + jvmtiEnv* jvmti_env; + JNIEnv* jni_env; + jthread thread; + jmethodID method; + jboolean was_popped_by_exception; + jvalue return_value; +}; + // JuiceAgent PreLoad/PostLoad struct EventPreLoad { JavaVM* jvm; diff --git a/src/libagent/includes/jni_impl.hpp b/src/libagent/includes/jni_impl.hpp index 238aaeb..42ebc10 100644 --- a/src/libagent/includes/jni_impl.hpp +++ b/src/libagent/includes/jni_impl.hpp @@ -23,4 +23,18 @@ void JNICALL ClassFileLoadHook( jint class_data_len, const unsigned char* classbytes, jint* new_class_data_len, - unsigned char** new_classbytes); \ No newline at end of file + unsigned char** new_classbytes); + +// See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#MethodEntry +void JNICALL MethodEntry(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method); + +// See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#MethodExit +void JNICALL MethodExit(jvmtiEnv *jvmti_env, + JNIEnv* jni_env, + jthread thread, + jmethodID method, + jboolean was_popped_by_exception, + jvalue return_value); \ No newline at end of file