feat: Implement MethodEntry and MethodExit callbacks with event posting

This commit is contained in:
xiaozhou233 committed 2026-04-24 15:50:43 +08:00
1 parent 4c940c848b
commit 5b253ddd5d
4 files changed
+67 -1

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
#include <jni_impl.hpp>
#include <event/event_type.hpp>
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
});
}
+19
View File
@@ -0,0 +1,19 @@
#include <jni_impl.hpp>
#include <event/event_type.hpp>
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
});
}
@@ -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;
+15 -1
View File
@@ -23,4 +23,18 @@ void JNICALL ClassFileLoadHook(
jint class_data_len,
const unsigned char* classbytes,
jint* new_class_data_len,
unsigned char** new_classbytes);
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);