< prev index next >
test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp
Print this page
rev 52828 : 8213501: Deploy ExceptionJniWrapper for a few tests
Summary:
Reviewed-by:
@@ -23,11 +23,11 @@
#include <stdio.h>
#include <string.h>
#include <jvmti.h>
#include "agent_common.h"
-
+#include "ExceptionCheckingJniEnv.hpp"
#include "nsk_tools.h"
#include "jni_tools.h"
#include "JVMTITools.h"
#include "jvmti_tools.h"
@@ -303,11 +303,11 @@
NSK_DISPLAY0("Agent thread: finished.\n");
}
/***********************************************************************/
-static int startThread(JNIEnv* jni, jthread threadObj) {
+static int startThread(jthread threadObj) {
int success = NSK_TRUE;
/* enter startLock */
if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(startLock))) {
nsk_jvmti_setFailStatus();
@@ -332,62 +332,43 @@
return success;
}
/** Create thread object for new agent thread. */
-static jthread newThreadObj(JNIEnv* jni) {
+static jthread newThreadObj(JNIEnv* jni_env) {
+ ExceptionCheckingJniEnvPtr jni(jni_env);
jclass thrClass;
jmethodID cid;
jthread result = NULL;
- thrClass = jni->FindClass("java/lang/Thread");
- if (!NSK_JNI_VERIFY(jni, thrClass != NULL)) {
- nsk_jvmti_setFailStatus();
- return result;
- }
-
- cid = jni->GetMethodID(thrClass, "<init>", "()V");
- if (!NSK_JNI_VERIFY(jni, cid != NULL)) {
- nsk_jvmti_setFailStatus();
- return result;
- }
-
- result = jni->NewObject(thrClass, cid);
- if (!NSK_JNI_VERIFY(jni, result != NULL)) {
- nsk_jvmti_setFailStatus();
- return result;
- }
-
- return result;
+ thrClass = jni->FindClass("java/lang/Thread", TRACE_JNI_CALL);
+ cid = jni->GetMethodID(thrClass, "<init>", "()V", TRACE_JNI_CALL);
+ return jni->NewObject(thrClass, cid, TRACE_JNI_CALL);
}
/***********************************************************************/
/** Clean counters and start new agent thread with agent_start() body. */
-static int prepareToIteration (JNIEnv* jni) {
+static int prepareToIteration(JNIEnv* jni) {
jthread threadObj = NULL;
setCounter(&iterationCount, 0);
setCounter(&objectCount, 0);
threadObj = newThreadObj(jni);
- if (!NSK_VERIFY(threadObj != NULL)) {
- nsk_jvmti_setFailStatus();
- return NSK_FALSE;
- }
/* enter endLock */
if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(endLock))) {
nsk_jvmti_setFailStatus();
}
NSK_DISPLAY0("Starting new agent thread...\n");
- return startThread(jni, threadObj);
+ return startThread(threadObj);
}
/** Wait for new agent thread to complete. */
-static void afterIteration (JNIEnv* jni) {
+static void afterIteration() {
/* notify new agent thread (in case if not yet notified) */
notifyThread();
NSK_DISPLAY0("Wait for new agent thread to complete\n");
@@ -431,11 +412,11 @@
NULL /*user_data*/))) {
nsk_jvmti_setFailStatus();
}
NSK_DISPLAY0("IterateOverHeap finished.\n");
- afterIteration(jni);
+ afterIteration();
found = getCounter(&objectCount);
NSK_DISPLAY1("Found tagged objects: %d\n", found);
modified = OBJ_MAX_COUNT - found;
@@ -462,11 +443,11 @@
NULL /*user_data*/))) {
nsk_jvmti_setFailStatus();
}
NSK_DISPLAY0("IterateOverReachableObjects finished.\n");
- afterIteration(jni);
+ afterIteration();
found = getCounter(&objectCount);
NSK_DISPLAY1("Found tagged objects: %d\n", found);
modified = OBJ_MAX_COUNT - found;
@@ -493,11 +474,11 @@
NULL /*user_data*/))) {
nsk_jvmti_setFailStatus();
}
NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n");
- afterIteration(jni);
+ afterIteration();
found = getCounter(&objectCount);
NSK_DISPLAY1("Found tagged objects: %d\n", found);
modified = OBJ_MAX_COUNT - found;
@@ -507,35 +488,31 @@
nsk_jvmti_setFailStatus();
}
}
JNIEXPORT void JNICALL
-Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject(JNIEnv* jni,
+Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject(JNIEnv* jni_env,
jclass klass) {
+ ExceptionCheckingJniEnvPtr jni(jni_env);
jobject root = NULL;
int modified = 0;
int found = 0;
- root = jni->GetStaticObjectField(debugeeClass, rootFieldID);
- if (!NSK_JNI_VERIFY(jni, root != NULL)) {
- NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n");
- nsk_jvmti_setFailStatus();
- return;
- }
+ root = jni->GetStaticObjectField(debugeeClass, rootFieldID, TRACE_JNI_CALL);
- if (!prepareToIteration(jni))
+ if (!prepareToIteration(jni_env))
return;
NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n");
if (!NSK_JVMTI_VERIFY(jvmti->IterateOverObjectsReachableFromObject(root,
objectReferenceCallback,
NULL /*user_data*/))) {
nsk_jvmti_setFailStatus();
}
NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n");
- afterIteration(jni);
+ afterIteration();
found = getCounter(&objectCount);
NSK_DISPLAY1("Found tagged objects: %d\n", found);
modified = OBJ_MAX_COUNT - found;
@@ -545,12 +522,12 @@
nsk_jvmti_setFailStatus();
}
}
static void JNICALL
-agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
-
+agentProc(jvmtiEnv* jvmti, JNIEnv* jni_env, void* arg) {
+ ExceptionCheckingJniEnvPtr jni(jni_env);
NSK_DISPLAY0("Wait for debugee start\n\n");
if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
return;
NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE);
@@ -558,30 +535,25 @@
if (debugeeClass == NULL) {
nsk_jvmti_setFailStatus();
return;
}
- debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass);
- if (!NSK_JNI_VERIFY(jni, debugeeClass != NULL))
- return;
+ debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass, TRACE_JNI_CALL);
NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE);
- rootFieldID = jni->GetStaticFieldID(debugeeClass, "root", ROOT_SIGNATURE);
- if (!NSK_JNI_VERIFY(jni, rootFieldID != NULL)) {
- nsk_jvmti_setFailStatus();
- return;
- }
+ rootFieldID = jni->GetStaticFieldID(debugeeClass, "root",
+ ROOT_SIGNATURE, TRACE_JNI_CALL);
NSK_DISPLAY0("Let debugee to run test cases\n");
if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
return;
NSK_DISPLAY0("Wait for completion of test cases\n\n");
if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
return;
- NSK_TRACE(jni->DeleteGlobalRef(debugeeClass));
+ jni->DeleteGlobalRef(debugeeClass, TRACE_JNI_CALL);
NSK_TRACE(jvmti->DestroyRawMonitor(counterMonitor_ptr));
NSK_TRACE(jvmti->DestroyRawMonitor(startLock));
NSK_TRACE(jvmti->DestroyRawMonitor(runLock));
NSK_TRACE(jvmti->DestroyRawMonitor(endLock));
< prev index next >