Skip to content
Permalink
Browse files
jvmti/vthread tests fixed to use RawMonitorLocker.
  • Loading branch information
lmesnik committed Mar 1, 2021
1 parent 0803957 commit 5d1acba6cd8e3fa3458152c766607bfa95009ecb
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 182 deletions.
@@ -37,16 +37,6 @@ static jboolean received_method_exit_event = JNI_FALSE;
static jboolean passed = JNI_TRUE;


static void
lock_events() {
jvmti->RawMonitorEnter(event_mon);
}

static void
unlock_events() {
jvmti->RawMonitorExit(event_mon);
}

static void
print_frame_event_info(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
const char* event_name, int event_count) {
@@ -123,15 +113,14 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread cthread,
return;
}

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

printf("Breakpoint: %s: Stack Trace of %s thread: %p\n",
mname, virt, (void*)cthread);

print_frame_event_info(jvmti, jni, cthread, method,
"Breakpoint", ++breakpoint_count);
fflush(0);
unlock_events();
}

static void JNICALL
@@ -143,11 +132,10 @@ ThreadStart(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread) {
err = jvmti->GetThreadInfo(thread, &thr_info);
check_jvmti_status(jni, err, "ThreadStart: error in JVMTI GetThreadInfo call");

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

printf("\nThreadStart: thread: %p, name: %s\n", (void*)thread, thr_info.name);
fflush(0);
unlock_events();
}

static void JNICALL
@@ -159,11 +147,10 @@ VirtualThreadScheduled(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread) {
err = jvmti->GetThreadInfo(thread, &thr_info);
check_jvmti_status(jni, err, "VirtualThreadScheduled: error in JVMTI GetThreadInfo call");

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

printf("\nVirtualThreadScheduled: thread: %p, name: %s\n",(void*)thread, thr_info.name);
fflush(0);
unlock_events();
}

#if 0
@@ -259,11 +246,7 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
callbacks.ContinuationYield = &ContinuationYield;
#endif

err = jvmti->CreateRawMonitor("Events Monitor", &event_mon);
if (err != JVMTI_ERROR_NONE) {
printf("Agent_OnLoad: Error in JVMTI CreateRawMonitor: %d\n", err);
return JNI_ERR;
}
event_mon = create_raw_monitor(jvmti, "Events Monitor");

err = jvmti->AddCapabilities(&caps);
if (err != JVMTI_ERROR_NONE) {
@@ -36,17 +36,6 @@ static int method_entry_count = 0;
static int method_exit_count = 0;
static int frame_pop_count = 0;

static void
lock_events() {
jvmti->RawMonitorEnter(event_mon);
}

static void
unlock_events() {
jvmti->RawMonitorExit(event_mon);
}


static void
print_frame_event_info(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method, const char* event_name) {
char* cname = NULL;
@@ -96,7 +85,7 @@ MethodEntry(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method) {
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "MethodEntry: error in JVMTI GetMethodName call");
@@ -116,7 +105,6 @@ MethodEntry(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method) {
print_method(jvmti, jni, method, 0);
fflush(0);

unlock_events();
}

static void JNICALL
@@ -125,7 +113,7 @@ MethodExit(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "MethodExit: error in JVMTI GetMethodName call");
@@ -136,7 +124,6 @@ MethodExit(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
++method_exit_count;
print_frame_event_info(jvmti, jni, thread, method, "MethodExit");

unlock_events();
}

static void JNICALL
@@ -145,7 +132,7 @@ FramePop(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "FramePop: error in JVMTI GetMethodName call");
@@ -158,7 +145,6 @@ FramePop(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
frame_pop_count++;
print_frame_event_info(jvmti, jni, thread, method, "FramePop");

unlock_events();
}

JNIEXPORT jint JNICALL
@@ -192,10 +178,7 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
printf("Agent_OnLoad: Error in JVMTI SetEventCallbacks: %d\n", err);
}

err = jvmti->CreateRawMonitor("Events Monitor", &event_mon);
if (err != JVMTI_ERROR_NONE) {
printf("Agent_OnLoad: Error in JVMTI CreateRawMonitor: %d\n", err);
}
event_mon = create_raw_monitor(jvmti, "Events Monitor");

printf("Agent_OnLoad finished\n");
fflush(0);
@@ -37,16 +37,6 @@ static int method_entry_count = 0;
static int method_exit_count = 0;
static int single_step_count = 0;

static void
lock_events() {
jvmti->RawMonitorEnter(event_mon);
}

static void
unlock_events() {
jvmti->RawMonitorExit(event_mon);
}

static void
print_frame_event_info(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
const char* event_name, int event_count) {
@@ -96,7 +86,7 @@ MethodEntry(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method) {
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "MethodEntry: error in JVMTI GetMethodName call");
@@ -119,7 +109,6 @@ MethodEntry(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method) {
print_frame_event_info(jvmti, jni, thread, method,
"MethodEntry", ++method_entry_count);

unlock_events();
}

static void JNICALL
@@ -128,7 +117,7 @@ MethodExit(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "MethodExit: error in JVMTI GetMethodName call");
@@ -142,7 +131,6 @@ 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");

unlock_events();
}

static void JNICALL
@@ -151,7 +139,7 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "Breakpoint: error in JVMTI GetMethodName call");
@@ -168,7 +156,6 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY, thread);
check_jvmti_status(jni, err, "enableEvents: error in JVMTI SetEventNotificationMode: enable METHOD_ENTRY");

unlock_events();
}

static void JNICALL
@@ -177,7 +164,7 @@ SingleStep(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "SingleStep: error in JVMTI GetMethodName call");
@@ -188,7 +175,6 @@ SingleStep(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
print_frame_event_info(jvmti, jni, thread, method,
"SingleStep", ++single_step_count);

unlock_events();
}

static void JNICALL
@@ -197,7 +183,7 @@ FramePop(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "FramePop: error in JVMTI GetMethodName call");
@@ -215,7 +201,6 @@ 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");

unlock_events();
}

JNIEXPORT jint JNICALL
@@ -253,10 +238,7 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
printf("Agent_OnLoad: Error in JVMTI SetEventCallbacks: %d\n", err);
}

err = jvmti->CreateRawMonitor("Events Monitor", &event_mon);
if (err != JVMTI_ERROR_NONE) {
printf("Agent_OnLoad: Error in JVMTI CreateRawMonitor: %d\n", err);
}
event_mon = create_raw_monitor(jvmti, "Events Monitor");

printf("Agent_OnLoad finished\n");
fflush(0);
@@ -34,16 +34,6 @@ static jrawMonitorID event_mon = NULL;
static int breakpoint_count = 0;
static int single_step_count = 0;

static void
lock_events() {
jvmti->RawMonitorEnter(event_mon);
}

static void
unlock_events() {
jvmti->RawMonitorExit(event_mon);
}

static void
print_frame_event_info(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, jmethodID method,
const char* event_name, int event_count) {
@@ -94,7 +84,7 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "Breakpoint: error in JVMTI GetMethodName call");
@@ -107,8 +97,6 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,

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

unlock_events();
}

static void JNICALL
@@ -117,7 +105,7 @@ SingleStep(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
char* mname = NULL;
jvmtiError err;

lock_events();
RawMonitorLocker rml(jvmti, jni, event_mon);

err = jvmti->GetMethodName(method, &mname, NULL, NULL);
check_jvmti_status(jni, err, "SingleStep: error in JVMTI GetMethodName call");
@@ -127,8 +115,6 @@ SingleStep(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
}
print_frame_event_info(jvmti, jni, thread, method,
"SingleStep", ++single_step_count);

unlock_events();
}


@@ -161,10 +147,7 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
printf("Agent_OnLoad: Error in JVMTI SetEventCallbacks: %d\n", err);
}

err = jvmti->CreateRawMonitor("Events Monitor", &event_mon);
if (err != JVMTI_ERROR_NONE) {
printf("Agent_OnLoad: Error in JVMTI CreateRawMonitor: %d\n", err);
}
event_mon = create_raw_monitor(jvmti, "Events Monitor");

printf("Agent_OnLoad finished\n");
fflush(0);

0 comments on commit 5d1acba

Please sign in to comment.