4903717: nsk/jdi/ThreadReference/isSuspended/issuspended002 failing
authorgadams
Mon, 04 Mar 2019 08:45:05 -0500
changeset 53988 efa9bc147d50
parent 53987 e1f707ed0757
child 53989 247f1a85d736
4903717: nsk/jdi/ThreadReference/isSuspended/issuspended002 failing Reviewed-by: amenkov, sspitsyn
test/hotspot/jtreg/ProblemList.txt
test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/isSuspended/issuspended002a.java
--- a/test/hotspot/jtreg/ProblemList.txt	Mon Mar 04 11:49:16 2019 +0100
+++ b/test/hotspot/jtreg/ProblemList.txt	Mon Mar 04 08:45:05 2019 -0500
@@ -157,7 +157,6 @@
 vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded005/TestDescription.java 8153598 generic-all
 vmTestbase/nsk/monitoring/ThreadMXBean/ThreadInfo/Deadlock/JavaDeadlock001/TestDescription.java 8060733 generic-all
 
-vmTestbase/nsk/jdi/ThreadReference/isSuspended/issuspended002/TestDescription.java 4903717 generic-all
 vmTestbase/nsk/jdi/ThreadReference/resume/resume001/TestDescription.java 8072701 generic-all
 vmTestbase/nsk/jdi/ThreadReference/stop/stop001/TestDescription.java 7034630 generic-all
 vmTestbase/nsk/jdi/BScenarios/hotswap/tc10x001/TestDescription.java 8013728 generic-all
--- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/isSuspended/issuspended002a.java	Mon Mar 04 11:49:16 2019 +0100
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/isSuspended/issuspended002a.java	Mon Mar 04 08:45:05 2019 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -63,8 +63,8 @@
 
     public static void main (String argv[]) {
 
-        for (int i=0; i<argv.length; i++) {
-            if ( argv[i].equals("-vbs") || argv[i].equals("-verbose") ) {
+        for (int i = 0; i < argv.length; i++) {
+            if (argv[i].equals("-vbs") || argv[i].equals("-verbose")) {
                 verbMode = true;
                 break;
             }
@@ -76,10 +76,8 @@
         IOPipe pipe = argHandler.createDebugeeIOPipe();
         pipe.println("ready");
 
-
         int exitCode = PASSED;
         for (int i = 0; ; i++) {
-
             String instruction;
 
             log1("waiting for an instruction from the debugger ...");
@@ -94,53 +92,70 @@
     //------------------------------------------------------  section tested
 
                 case 0:
-                         Threadissuspended002a test_thread =
-                             new Threadissuspended002a("testedThread");
-                         log1("       thread2 is created");
-
-                         label:
-                         synchronized (Threadissuspended002a.lockingObject) {
-                             synchronized (Threadissuspended002a.waitnotifyObj) {
-                                 log1("       synchronized (waitnotifyObj) { enter");
-                                 log1("       before: test_thread.start()");
-                                 test_thread.start();
+                    Threadissuspended002a test_thread =
+                        new Threadissuspended002a("testedThread");
+                    log1("       thread2 is created");
+                label:
+                    synchronized (Threadissuspended002a.lockingObject) {
+                        synchronized (Threadissuspended002a.waitnotifyObj) {
+                            log1("       synchronized (waitnotifyObj) { enter");
+                            log1("       before: test_thread.start()");
+                            test_thread.start();
 
-                                 try {
-                                     log1("       before:   waitnotifyObj.wait();");
-                                     Threadissuspended002a.waitnotifyObj.wait();
-                                     log1("       after:    waitnotifyObj.wait();");
-                                     pipe.println("checkready");
-                                     instruction = pipe.readln();
-                                     if (!instruction.equals("continue")) {
-                                         logErr("ERROR: unexpected instruction: " + instruction);
-                                         exitCode = FAILED;
-                                         break label;
-                                     }
-                                     pipe.println("docontinue");
-                                 } catch ( Exception e2) {
-                                     log1("       Exception e2 exception: " + e2 );
-                                     pipe.println("waitnotifyerr");
-                                 }
-                             }
-                         }
-                         log1("mainThread is out of: synchronized (lockingObject) {");
+                            try {
+                                log1("       before:   waitnotifyObj.wait();");
+                                Threadissuspended002a.waitnotifyObj.wait();
+                                log1("       after:    waitnotifyObj.wait();");
+                                pipe.println("checkready");
+                                instruction = pipe.readln();
+                                if (!instruction.equals("continue")) {
+                                    logErr("ERROR: unexpected instruction: " + instruction);
+                                    exitCode = FAILED;
+                                    break label;
+                                }
+                            } catch ( Exception e2) {
+                                log1("       Exception e2 exception: " + e2 );
+                                pipe.println("waitnotifyerr");
+                            }
+                        }
+                    }
+                    log1("mainThread is out of: synchronized (lockingObject) {");
 
-                         break ;
+                    // To avoid contention for the logging print stream lock
+                    // the main thread will wait until the debuggee test thread
+                    // has completed to the breakpoint.
+                    // If the debugger suspends the main thread while it is holding
+                    // the logging lock, the test is deadlocked on the test thread log
+                    // calls.
+                    synchronized (Threadissuspended002a.waitnotifyObj) {
+                        try {
+                            // Main debuggee thread is out of synchronized(lockingObject)
+                            // so the test thread will continue.
+                            // Send the debugger the "docontinue" command
+                            // so it will enable the breakpoint in the test thread.
+                            pipe.println("docontinue");
+
+                            Threadissuspended002a.waitnotifyObj.wait();
+                        } catch (Exception e3) {
+                            pipe.println("waitnotifyerr");
+                        }
+                    }
+
+                    break ;
 
     //-------------------------------------------------    standard end section
 
                 default:
-                                pipe.println("checkend");
-                                break ;
+                    pipe.println("checkend");
+                    break ;
                 }
 
             } else {
-                logErr("ERRROR: unexpected instruction: " + instruction);
+                logErr("ERROR: unexpected instruction: " + instruction);
                 exitCode = FAILED;
                 break ;
             }
         }
-
         System.exit(exitCode + PASS_BASE);
     }
 }
@@ -158,12 +173,14 @@
 
     public void run() {
         log("method 'run' enter");
-        synchronized (waitnotifyObj)                    {
+        synchronized (waitnotifyObj) {
             log("entered into block:  synchronized (waitnotifyObj)");
-            waitnotifyObj.notify();                     }
+            waitnotifyObj.notify();
+        }
         log("exited from block:  synchronized (waitnotifyObj)");
-        synchronized (lockingObject)                    {
-            log("entered into block:  synchronized (lockingObject)");   }
+        synchronized (lockingObject) {
+            log("entered into block:  synchronized (lockingObject)");
+        }
         log("exited from block:  synchronized (lockingObject)");
         i1++;
         i2--;
@@ -171,6 +188,11 @@
         runt1();
         log("returned from the method 'runt1'");
         log("method 'run' exit");
+
+        // Allow the main thread to continue
+        synchronized (waitnotifyObj) {
+            waitnotifyObj.notify();
+        }
         return;
     }