< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp

Print this page
rev 52432 : 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,40 +332,41 @@
 
     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)) {
+    thrClass = jni->FindClass("java/lang/Thread", TRACE_JNI_CALL);
+    if (thrClass == NULL) {
         nsk_jvmti_setFailStatus();
         return result;
     }
 
-    cid = jni->GetMethodID(thrClass, "<init>", "()V");
-    if (!NSK_JNI_VERIFY(jni, cid != NULL)) {
+    cid = jni->GetMethodID(thrClass, "<init>", "()V", TRACE_JNI_CALL);
+    if (cid == NULL) {
         nsk_jvmti_setFailStatus();
         return result;
     }
 
-    result = jni->NewObject(thrClass, cid);
-    if (!NSK_JNI_VERIFY(jni, result != NULL)) {
+    result = jni->NewObject(thrClass, cid, TRACE_JNI_CALL);
+    if (result == NULL) {
         nsk_jvmti_setFailStatus();
         return result;
     }
 
     return result;
 }
 
 /***********************************************************************/
 
 /** 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);
 

@@ -379,15 +380,15 @@
     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 +432,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 +463,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 +494,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 +508,36 @@
         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)) {
+    root = jni->GetStaticObjectField(debugeeClass, rootFieldID, TRACE_JNI_CALL);
+    if (root == NULL) {
         NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n");
         nsk_jvmti_setFailStatus();
         return;
     }
 
-    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 +547,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,17 +560,19 @@
     if (debugeeClass == NULL) {
         nsk_jvmti_setFailStatus();
         return;
     }
 
-    debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass);
-    if (!NSK_JNI_VERIFY(jni, debugeeClass != NULL))
+    debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass, TRACE_JNI_CALL);
+    if (debugeeClass == NULL) {
         return;
+    }
 
     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)) {
+    rootFieldID = jni->GetStaticFieldID(debugeeClass, "root",
+                                        ROOT_SIGNATURE, TRACE_JNI_CALL);
+    if (rootFieldID == NULL) {
         nsk_jvmti_setFailStatus();
         return;
     }
 
     NSK_DISPLAY0("Let debugee to run test cases\n");

@@ -577,11 +581,11 @@
 
     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 >