Skip to content
Permalink
Browse files
Refactored RawMonitor usage in jvmti/events tests.
  • Loading branch information
lmesnik committed Mar 1, 2021
1 parent 0126360 commit 0803957137742addfaeaf30ee366cc4847a787a3
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 296 deletions.
@@ -89,7 +89,7 @@ ClassLoad(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread, jclass klass) {
char *sig, *generic;
jvmtiError err;

RawMonitorMark rmm(jni, jvmti, agent_lock);
RawMonitorLocker rml(jvmti, jni, agent_lock);
if (callbacksEnabled) {
// GetClassSignature may be called only during the start or the live phase
err = jvmti->GetClassSignature(klass, &sig, &generic);
@@ -210,13 +210,13 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread, jmethodID method, jloca

void JNICALL
VMStart(jvmtiEnv *jvmti, JNIEnv *jni) {
RawMonitorMark rmm(jni, jvmti, agent_lock);
RawMonitorLocker rml(jvmti, jni, agent_lock);
callbacksEnabled = NSK_TRUE;
}

void JNICALL
VMDeath(jvmtiEnv *jvmti, JNIEnv *jni) {
RawMonitorMark rmm(jni, jvmti, agent_lock);
RawMonitorLocker rml(jvmti, jni, agent_lock);
callbacksEnabled = NSK_FALSE;
}
/************************/
@@ -300,7 +300,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
return JNI_ERR;
printf("enabling the events done\n\n");

agent_lock = CreateRawMonitor(jvmti, "agent_lock");
agent_lock = create_raw_monitor(jvmti, "agent_lock");

if (agent_lock == NULL) {
return JNI_ERR;
@@ -77,7 +77,7 @@ static volatile int primClsEvents[UNEXP_SIG_NUM];
static jint result = PASSED;
static jvmtiEnv *jvmti = NULL;
static jvmtiEventCallbacks callbacks;
static jrawMonitorID countLock;
static jrawMonitorID counter_lock;

static void initCounters() {
size_t i;
@@ -110,13 +110,12 @@ ClassLoad(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread, jclass klass) {
char *sig, *generic;
jvmtiError err;

RawMonitorEnter(jni, jvmti, countLock);
RawMonitorLocker rml(jvmti, jni, counter_lock);

err = jvmti->GetClassSignature(klass, &sig, &generic);
if (err != JVMTI_ERROR_NONE) {
result = STATUS_FAILED;
printf("TEST FAILURE: unable to obtain a class signature. Error %d\n", err);
RawMonitorExit(jni, jvmti, countLock);
return;
}

@@ -142,8 +141,6 @@ ClassLoad(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread, jclass klass) {
sig);
}
}

RawMonitorExit(jni, jvmti, countLock);
}
/************************/

@@ -210,11 +207,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {

initCounters();

countLock = CreateRawMonitor(jvmti, "_counter_lock");
if (countLock == nullptr) {
printf("Error in CreateRawMonitor %d/n", err);
return JNI_ERR;
}
counter_lock = create_raw_monitor(jvmti, "_counter_lock");

printf("setting event callbacks ...\n");
(void) memset(&callbacks, 0, sizeof(callbacks));
@@ -215,10 +215,9 @@ void JNICALL MethodEntry(jvmtiEnv *jvmti, JNIEnv *jni,

if (watch_events == JNI_FALSE) return;

jvmti->RawMonitorEnter(agent_lock);
RawMonitorLocker rml(jvmti, jni, agent_lock);

if (!callbacksEnabled) {
jvmti->RawMonitorExit(agent_lock);
return;
}

@@ -228,7 +227,6 @@ void JNICALL MethodEntry(jvmtiEnv *jvmti, JNIEnv *jni,
TranslateError(err), err);
printInfo(jvmti, thr, method, frameCount);
result = STATUS_FAILED;
jvmti->RawMonitorExit(agent_lock);
return;
}

@@ -247,21 +245,8 @@ void JNICALL MethodEntry(jvmtiEnv *jvmti, JNIEnv *jni,
printInfo(jvmti, thr, method, frameCount);
}
if (isNative == JNI_FALSE) {
err = jvmti->RawMonitorEnter(event_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorEnter) unexpected error: %s (%d)\n",
TranslateError(err), err);
printInfo(jvmti, thr, method, frameCount);
result = STATUS_FAILED;
}
RawMonitorLocker rml(jvmti, jni, event_lock);
push((JNIEnv *)jni, thr, method, frameCount);
err = jvmti->RawMonitorExit(event_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorExit) unexpected error: %s (%d)\n",
TranslateError(err), err);
printInfo(jvmti, thr, method, frameCount);
result = STATUS_FAILED;
}
err = jvmti->NotifyFramePop(thr, 0);
if (err != JVMTI_ERROR_NONE) {
printf("(NotifyFramePop) unexpected error: %s (%d)\n",
@@ -271,36 +256,27 @@ void JNICALL MethodEntry(jvmtiEnv *jvmti, JNIEnv *jni,
}
}
}

jvmti->RawMonitorExit(agent_lock);
}

void JNICALL VMStart(jvmtiEnv *jvmti, JNIEnv* jni) {
jvmti->RawMonitorEnter(agent_lock);

RawMonitorLocker rml(jvmti, jni, agent_lock);
callbacksEnabled = NSK_TRUE;

jvmti->RawMonitorExit(agent_lock);
}


void JNICALL VMDeath(jvmtiEnv *jvmti, JNIEnv* jni) {
jvmti->RawMonitorEnter(agent_lock);

RawMonitorLocker rml(jvmti, jni, agent_lock);
callbacksEnabled = NSK_FALSE;

jvmti->RawMonitorExit(agent_lock);
}

void JNICALL FramePop(jvmtiEnv *jvmti, JNIEnv *jni,
jthread thr, jmethodID method, jboolean wasPopedByException) {
jvmtiError err;
jint frameCount;

jvmti->RawMonitorEnter(agent_lock);
RawMonitorLocker rml(jvmti, jni, agent_lock);

if (!callbacksEnabled) {
jvmti->RawMonitorExit(agent_lock);
return;
}
err = jvmti->GetFrameCount(thr, &frameCount);
@@ -309,7 +285,6 @@ void JNICALL FramePop(jvmtiEnv *jvmti, JNIEnv *jni,
TranslateError(err), err);
printInfo(jvmti, thr, method, frameCount);
result = STATUS_FAILED;
jvmti->RawMonitorExit(agent_lock);
return;
}

@@ -318,24 +293,9 @@ void JNICALL FramePop(jvmtiEnv *jvmti, JNIEnv *jni,
printf(">>> Frame Pop\n>>>");
printInfo(jvmti, thr, method, frameCount);
}
err = jvmti->RawMonitorEnter(event_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorEnter) unexpected error: %s (%d)\n",
TranslateError(err), err);
printInfo(jvmti, thr, method, frameCount);
result = STATUS_FAILED;
}
RawMonitorLocker rml(jvmti, jni, event_lock);
pop(jvmti, (JNIEnv *)jni, thr, method, frameCount);
err = jvmti->RawMonitorExit(event_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(RawMonitorExit) unexpected error: %s (%d)\n",
TranslateError(err), err);
printInfo(jvmti, thr, method, frameCount);
result = STATUS_FAILED;
}
}

jvmti->RawMonitorExit(agent_lock);
}

#ifdef STATIC_BUILD
@@ -364,12 +324,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
return JNI_ERR;
}

err = jvmti->CreateRawMonitor("_event_lock", &event_lock);
if (err != JVMTI_ERROR_NONE) {
printf("(CreateRawMonitor) unexpected error: %s (%d)\n",
TranslateError(err), err);
return JNI_ERR;
}
event_lock = create_raw_monitor(jvmti, "_event_lock");

memset(&caps, 0, sizeof(jvmtiCapabilities));
caps.can_generate_frame_pop_events = 1;
@@ -413,9 +368,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
return JNI_ERR;
}

if (jvmti->CreateRawMonitor("agent_lock", &agent_lock) != JVMTI_ERROR_NONE) {
return JNI_ERR;
}
agent_lock = create_raw_monitor(jvmti, "agent_lock");

} else {
printf("Warning: FramePop or MethodEntry event is not implemented\n");
@@ -51,7 +51,7 @@ static const char *CLASS_SIG =
static volatile jint result = PASSED;
static jvmtiEnv *jvmti = NULL;
static jvmtiEventCallbacks callbacks;
static jrawMonitorID countLock;
static jrawMonitorID counter_lock;

/** callback functions **/
void JNICALL
@@ -62,28 +62,25 @@ NativeMethodBind(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
int i;
jvmtiError err;

RawMonitorEnter(jni, jvmti, countLock);
RawMonitorLocker rml(jvmti, jni, counter_lock);

printf(">>>> NativeMethodBind event received\n");

err = jvmti->GetPhase(&phase);
if (err != JVMTI_ERROR_NONE) {
printf(">>>> Error getting phase\n");
result = STATUS_FAILED;
RawMonitorExit(jni, jvmti, countLock);
return;
}

if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) {
RawMonitorExit(jni, jvmti, countLock);
return;
}

err = jvmti->GetMethodName(method, &methNam, &methSig, NULL);
if (err != JVMTI_ERROR_NONE) {
result = STATUS_FAILED;
printf("TEST FAILED: unable to get method name during NativeMethodBind callback\n\n");
RawMonitorExit(jni, jvmti, countLock);
return;
}

@@ -114,8 +111,6 @@ NativeMethodBind(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
}

printf("<<<<\n\n");

RawMonitorExit(jni, jvmti, countLock);
}
/************************/

@@ -203,10 +198,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
}

/* create a raw monitor */
err = jvmti->CreateRawMonitor("_counter_lock", &countLock);
if (err != JVMTI_ERROR_NONE) {
return JNI_ERR;
}
counter_lock = create_raw_monitor(jvmti, "_counter_lock");

/* add capability to generate compiled method events */
memset(&caps, 0, sizeof(jvmtiCapabilities));
@@ -38,7 +38,7 @@ static volatile int wrongBindEv = 0;
static volatile jint result = PASSED;
static jvmtiEnv *jvmti = NULL;
static jvmtiEventCallbacks callbacks;
static jrawMonitorID countLock;
static jrawMonitorID counter_lock;

/** callback functions **/
void JNICALL
@@ -48,17 +48,15 @@ NativeMethodBind(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread,
jvmtiError err;
char *methNam = NULL, *methSig = NULL;

RawMonitorEnter(jni, jvmti, countLock);
RawMonitorLocker rml(jvmti, jni, counter_lock);
err = jvmti->GetPhase(&phase);
if (err != JVMTI_ERROR_NONE) {
printf(">>>> Error getting phase\n");
result = STATUS_FAILED;
RawMonitorExit(jni, jvmti, countLock);
return;
}

if (phase != JVMTI_PHASE_LIVE && phase != JVMTI_PHASE_START) {
RawMonitorExit(jni, jvmti, countLock);
return;
}

@@ -67,7 +65,6 @@ NativeMethodBind(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread,
if (err != JVMTI_ERROR_NONE) {
result = STATUS_FAILED;
printf("TEST FAILED: unable to get method name during NativeMethodBind callback\n\n");
RawMonitorExit(jni, jvmti, countLock);
return;
} else {
printf("NativeMethodBind received for \"%s %s\"\n",
@@ -90,7 +87,6 @@ NativeMethodBind(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread,
}
}

RawMonitorExit(jni, jvmti, countLock);
}

void JNICALL
@@ -142,10 +138,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {


/* create a raw monitor */
err = jvmti->CreateRawMonitor("_counter_lock", &countLock);
if (err != JVMTI_ERROR_NONE) {
return JNI_ERR;
}
counter_lock = create_raw_monitor(jvmti, "_counter_lock");

/* add capability to generate compiled method events */
memset(&caps, 0, sizeof(jvmtiCapabilities));
@@ -48,7 +48,7 @@ static const char *CLASS_SIG =
static volatile jint result = PASSED;
static jvmtiEnv *jvmti = NULL;
static jvmtiEventCallbacks callbacks;
static jrawMonitorID countLock;
static jrawMonitorID counter_lock;

/** callback functions **/
void JNICALL
@@ -58,28 +58,25 @@ NativeMethodBind(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread,
jvmtiError err;
char *methNam, *methSig;

RawMonitorEnter(jni, jvmti, countLock);
RawMonitorLocker rml(jvmti, jni, counter_lock);

printf(">>>> NativeMethodBind event received\n");

err = jvmti->GetPhase(&phase);
if (err != JVMTI_ERROR_NONE) {
printf(">>>> Error getting phase\n");
result = STATUS_FAILED;
RawMonitorExit(jni, jvmti, countLock);
return;
}

if (phase != JVMTI_PHASE_LIVE && phase != JVMTI_PHASE_START) {
RawMonitorExit(jni, jvmti, countLock);
return;
}

err = jvmti->GetMethodName(method, &methNam, &methSig, NULL);
if (err != JVMTI_ERROR_NONE) {
result = STATUS_FAILED;
NSK_COMPLAIN0("TEST FAILED: unable to get method name during NativeMethodBind callback\n\n");
RawMonitorExit(jni, jvmti, countLock);
return;
}

@@ -108,7 +105,6 @@ NativeMethodBind(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread,

printf("<<<<\n\n");

RawMonitorExit(jni, jvmti, countLock);
}

void JNICALL
@@ -205,11 +201,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {


/* create a raw monitor */
err = jvmti->CreateRawMonitor("_counter_lock", &countLock);
if (err != JVMTI_ERROR_NONE) {
return JNI_ERR;
}

counter_lock = create_raw_monitor(jvmti, "_counter_lock");

/* add capability to generate compiled method events */
memset(&caps, 0, sizeof(jvmtiCapabilities));

0 comments on commit 0803957

Please sign in to comment.