Skip to content
Permalink
Browse files
replace JVMTI GetThreadInfo/GetMethodName with get_thread_name/get_me…
…thod_name
  • Loading branch information
sspitsyn committed Mar 6, 2021
1 parent 92ab9a1 commit 66b2ab7c5c85f69e61890d53435904a973429ca8
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 728 deletions.
@@ -38,113 +38,100 @@ static int frame_pop_count = 0;

static void
print_frame_event_info(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method, const char* event_name) {
char* cname = NULL;
char* tname = get_thread_name(jvmti, jni, thread);
char* cname = get_method_class_name(jvmti, jni, method);
char* mname = NULL;
char* msign = NULL;
jvmtiThreadInfo thr_info;
jvmtiError err;

memset(&thr_info, 0, sizeof(thr_info));
err = jvmti->GetThreadInfo(thread, &thr_info);
check_jvmti_status(jni, err, "event handler: error in JVMTI GetThreadInfo call");
const char* thr_name = (thr_info.name == NULL) ? "<Unnamed thread>" : thr_info.name;

cname = get_method_class_name(jvmti, jni, method);

err = jvmti->GetMethodName(method, &mname, &msign, NULL);
check_jvmti_status(jni, err, "event handler: error in JVMTI GetMethodName call");

if (strcmp(event_name, "MethodEntry") == 0) {
printf("%s event #%d: thread: %s, method: %s: %s%s\n",
event_name, method_entry_count, thr_name, cname, mname, msign);
event_name, method_entry_count, tname, cname, mname, msign);
} else {
printf("%s event #%d: thread: %s, method: %s: %s%s\n",
event_name, frame_pop_count, thr_name, cname, mname, msign);
event_name, frame_pop_count, tname, cname, mname, msign);
}
fflush(0);
deallocate(jvmti, jni, (void*)tname);
deallocate(jvmti, jni, (void*)cname);
deallocate(jvmti, jni, (void*)mname);
deallocate(jvmti, jni, (void*)msign);
}

static void
print_cont_event_info(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jint frames_cnt, const char* event_name) {
jvmtiThreadInfo thr_info;
jvmtiError err;

memset(&thr_info, 0, sizeof(thr_info));
err = jvmti->GetThreadInfo(thread, &thr_info);
check_jvmti_status(jni, err, "event handler failed during JVMTI GetThreadInfo call");
char* tname = get_thread_name(jvmti, jni, thread);

const char* thr_name = (thr_info.name == NULL) ? "<Unnamed thread>" : thr_info.name;
printf("\n%s event: thread: %s, frames: %d\n\n", event_name, thr_name, frames_cnt);
printf("\n%s event: thread: %s, frames: %d\n\n", event_name, tname, frames_cnt);

print_current_stack_trace(jvmti, jni);

fflush(0);
deallocate(jvmti, jni, (void*)tname);
}

static void JNICALL
MethodEntry(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method) {
char* mname = NULL;
char* mname = get_method_name(jvmti, jni, method);
jvmtiError err;

RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "MethodEntry: error in JVMTI GetMethodName call");

if (strcmp(mname, "zzz") != 0) {
deallocate(jvmti, jni, (void*)mname);
return; // ignore any other MethodEntry events
}
++method_entry_count;
print_frame_event_info(jvmti, jni, thread, method, "MethodEntry");

printf("\nMethodEntry: Requesting FramePop notifications for top frame\n");
fflush(0);

err = jvmti->NotifyFramePop(thread, 0);
check_jvmti_status(jni, err, "MethodEntry: error in JVMTI NotifyFramePop");

print_method(jvmti, jni, method, 0);
fflush(0);

fflush(0);
deallocate(jvmti, jni, (void*)mname);
}

static void JNICALL
MethodExit(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
jboolean was_popped_by_exception, jvalue return_value) {
char* mname = NULL;
jvmtiError err;
char* mname = get_method_name(jvmti, jni, method);

RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "MethodExit: error in JVMTI GetMethodName call");

if (strcmp(mname, "zzz") != 0) {
deallocate(jvmti, jni, (void*)mname);
return; // ignore other MethodExit events
}
++method_exit_count;
print_frame_event_info(jvmti, jni, thread, method, "MethodExit");

deallocate(jvmti, jni, (void*)mname);
}

static void JNICALL
FramePop(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
jboolean was_popped_by_exception) {
char* mname = NULL;
jvmtiError err;
char* mname = get_method_name(jvmti, jni, method);

RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "FramePop: error in JVMTI GetMethodName call");

if (strcmp(mname, "zzz") != 0) {
// TBD: produce fatal error
deallocate(jvmti, jni, (void*)mname);
return;
}

frame_pop_count++;
print_frame_event_info(jvmti, jni, thread, method, "FramePop");

deallocate(jvmti, jni, (void*)mname);
}

JNIEXPORT jint JNICALL
@@ -40,58 +40,49 @@ static int single_step_count = 0;
static void
print_frame_event_info(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
const char* event_name, int event_count) {
char* cname = NULL;
char* tname = get_thread_name(jvmti, jni, thread);
char* cname = get_method_class_name(jvmti, jni, method);
char* mname = NULL;
char* msign = NULL;
jvmtiThreadInfo thr_info;
jvmtiError err;

memset(&thr_info, 0, sizeof(thr_info));
err = jvmti->GetThreadInfo(thread, &thr_info);
check_jvmti_status(jni, err, "event handler: error in JVMTI GetThreadInfo call");
const char* thr_name = (thr_info.name == NULL) ? "<Unnamed thread>" : thr_info.name;

cname = get_method_class_name(jvmti, jni, method);

err = jvmti->GetMethodName(method, &mname, &msign, NULL);
check_jvmti_status(jni, err, "event handler: error in JVMTI GetMethodName call");

printf("\n%s event #%d: thread: %s, method: %s: %s%s\n",
event_name, event_count, thr_name, cname, mname, msign);
event_name, event_count, tname, cname, mname, msign);

if (strcmp(event_name, "SingleStep") != 0) {
print_current_stack_trace(jvmti, jni);
}
fflush(0);
deallocate(jvmti, jni, (void*)tname);
deallocate(jvmti, jni, (void*)cname);
deallocate(jvmti, jni, (void*)mname);
deallocate(jvmti, jni, (void*)msign);
}

static void
print_cont_event_info(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jint frames_cnt, const char* event_name) {
jvmtiThreadInfo thr_info;
jvmtiError err;
char* tname = get_thread_name(jvmti, jni, thread);

memset(&thr_info, 0, sizeof(thr_info));
err = jvmti->GetThreadInfo(thread, &thr_info);
check_jvmti_status(jni, err, "event handler failed during JVMTI GetThreadInfo call");

const char* thr_name = (thr_info.name == NULL) ? "<Unnamed thread>" : thr_info.name;
printf("\n%s event: thread: %s, frames: %d\n\n", event_name, thr_name, frames_cnt);
printf("\n%s event: thread: %s, frames: %d\n\n", event_name, tname, frames_cnt);

print_current_stack_trace(jvmti, jni);

fflush(0);
deallocate(jvmti, jni, (void*)tname);
}

static void JNICALL
MethodEntry(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method) {
char* mname = NULL;
char* mname = get_method_name(jvmti, jni, method);
jvmtiError err;

RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "MethodEntry: error in JVMTI GetMethodName call");

if (strcmp(mname, "getNextFib") != 0) {
deallocate(jvmti, jni, (void*)mname);
return; // ignore unrelated events
}

@@ -109,20 +100,19 @@ MethodEntry(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method) {
print_frame_event_info(jvmti, jni, thread, method,
"MethodEntry", ++method_entry_count);

deallocate(jvmti, jni, (void*)mname);
}

static void JNICALL
MethodExit(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
jboolean was_popped_by_exception, jvalue return_value) {
char* mname = NULL;
char* mname = get_method_name(jvmti, jni, method);
jvmtiError err;

RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "MethodExit: error in JVMTI GetMethodName call");

if (strcmp(mname, "getNextFib") != 0) {
deallocate(jvmti, jni, (void*)mname);
return; // ignore unelated events
}
print_frame_event_info(jvmti, jni, thread, method,
@@ -131,20 +121,19 @@ MethodExit(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_METHOD_EXIT, thread);
check_jvmti_status(jni, err, "MethodExit: error in JVMTI SetEventNotificationMode: disable METHOD_EXIT");

deallocate(jvmti, jni, (void*)mname);
}

static void JNICALL
Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
jmethodID method, jlocation location) {
char* mname = NULL;
char* mname = get_method_name(jvmti, jni, method);
jvmtiError err;

RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "Breakpoint: error in JVMTI GetMethodName call");

if (strcmp(mname, "fibTest") != 0) {
deallocate(jvmti, jni, (void*)mname);
return; // ignore unrelated events
}
print_frame_event_info(jvmti, jni, thread, method,
@@ -154,41 +143,38 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
check_jvmti_status(jni, err, "Breakpoint: error in JVMTI SetEventNotificationMode: enable SINGLE_STEP");

err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, thread);
check_jvmti_status(jni, err, "enableEvents: error in JVMTI SetEventNotificationMode: enable METHOD_ENTRY");
check_jvmti_status(jni, err, "Breakpoint: error in JVMTI SetEventNotificationMode: enable METHOD_ENTRY");

deallocate(jvmti, jni, (void*)mname);
}

static void JNICALL
SingleStep(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
jmethodID method, jlocation location) {
char* mname = NULL;
jvmtiError err;
char* mname = get_method_name(jvmti, jni, method);

RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "SingleStep: error in JVMTI GetMethodName call");

if (strcmp(mname, "getNextFib") != 0) {
deallocate(jvmti, jni, (void*)mname);
return; // ignore unrelated events
}
print_frame_event_info(jvmti, jni, thread, method,
"SingleStep", ++single_step_count);

deallocate(jvmti, jni, (void*)mname);
}

static void JNICALL
FramePop(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
jmethodID method, jboolean was_popped_by_exception) {
char* mname = NULL;
char* mname = get_method_name(jvmti, jni, method);
jvmtiError err;

RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "FramePop: error in JVMTI GetMethodName call");

if (strcmp(mname, "getNextFib") != 0) {
deallocate(jvmti, jni, (void*)mname);
return; // ignore unrelated events
}

@@ -201,6 +187,7 @@ FramePop(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
err = jvmti->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_FRAME_POP, NULL);
check_jvmti_status(jni, err, "FramePop: error in JVMTI SetEventNotificationMode: disable FRAME_POP");

deallocate(jvmti, jni, (void*)mname);
}

JNIEXPORT jint JNICALL
@@ -263,16 +250,14 @@ Java_ContStackDepthTest_enableEvents(JNIEnv *jni, jclass klass, jthread thread)
// Find jmethodID of fibTest()
while (--method_count >= 0) {
jmethodID meth = methods[method_count];
char* mname = NULL;

err = jvmti->GetMethodName(meth, &mname, NULL, NULL);
check_jvmti_status(jni, err, "enableEvents: error in JVMTI GetMethodName call");
char* mname = get_method_name(jvmti, jni, meth);

if (strcmp(mname, "fibTest") == 0) {
printf("enableEvents: found method fibTest() to set a breakpoint\n");
fflush(0);
method = meth;
}
deallocate(jvmti, jni, (void*)mname);
}
if (method == NULL) {
jni->FatalError("Error in enableEvents: not found method fibTest()");

0 comments on commit 66b2ab7

Please sign in to comment.