< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/jni_interception/JI06/ji06t001/ji06t001.c

Print this page

        

@@ -60,10 +60,22 @@
 #define STATUS_FAILED  2
 
 #define TRIES 30
 #define MAX_THREADS 5
 
+// Helper for thread detach and terminate
+#define THREAD_return(status) \
+  do { \
+      int res = JNI_ENV_PTR(vm)->DetachCurrentThread(JNI_ENV_ARG1(vm)); \
+      if (res != 0) \
+          NSK_COMPLAIN1("TEST WARNING: DetachCurrentThread() returns: %d\n", res); \
+      else \
+          NSK_DISPLAY0("Detaching thread ...\n"); \
+      return status; \
+  } while (0)
+
+
 static const char *javaField = "_ji06t001a";
 static const char *classSig =
     "Lnsk/jvmti/scenarios/jni_interception/JI06/ji06t001a;";
 
 static JavaVM *vm;

@@ -223,20 +235,20 @@
        indx);
 
     thrStarted[indx-1] = 1; /* the thread is started */
 
     if (enterMonitor(env, "waitingThread") == STATUS_FAILED)
-        return STATUS_FAILED;
+        THREAD_return(STATUS_FAILED);
     if (verbose)
         printf("waitingThread: thread #%d entered the monitor\n",
             indx);
     if (exitMonitor(env, "waitingThread") == STATUS_FAILED)
-        return STATUS_FAILED;
+        THREAD_return(STATUS_FAILED);
 
     NSK_DISPLAY2("waitingThread: thread #%d exits the monitor\n\treturning %d\n",
         indx, exitCode);
-    return exitCode;
+    THREAD_return(exitCode);
 }
 
 static int ownerThread(void *context) {
     JNIEnv *env;
     int exitCode = PASSED;

@@ -252,11 +264,11 @@
         return STATUS_FAILED;
     }
 
     NSK_DISPLAY0("ownerThread: trying to enter the monitor ...\n");
     if (enterMonitor(env, "ownerThread") == STATUS_FAILED)
-        return STATUS_FAILED;
+        THREAD_return(STATUS_FAILED);
 
     monEntered = 1; /* the monitor has been entered */
     NSK_DISPLAY1("ownerThread: entered the monitor: monEntered=%d\n\
 \twaiting ...\n",
         monEntered);

@@ -270,16 +282,16 @@
                 "ownerThread: time exceed"));
         }
     } while(releaseMon != 1);
 
     if (exitMonitor(env, "ownerThread") == STATUS_FAILED)
-        return STATUS_FAILED;
+        THREAD_return(STATUS_FAILED);
 
     NSK_DISPLAY1("ownerThread: exits the monitor\n\treturning %d\n",
         exitCode);
 
-    return exitCode;
+    THREAD_return(exitCode);
 }
 
 static int redirectorThread(void *context) {
     JNIEnv *env;
     int exitCode = PASSED;

@@ -299,11 +311,11 @@
     doRedirect(env);
 
     NSK_DISPLAY1("redirectorThread: the MonitorEnter() redirected\n\treturning %d\n",
         exitCode);
 
-    return exitCode;
+    THREAD_return(exitCode);
 }
 /*********************/
 
 static jobject getObjectFromField(JNIEnv *env, jobject obj) {
     jfieldID fid;
< prev index next >