changeset 13315:27e200792297

8144308: com/sun/jdi/SuspendThreadTest.java failed with "transport error 202: send failed: Broken pipe" Reviewed-by: sla
author jbachorik
date Mon, 07 Dec 2015 12:31:25 +0100
parents ddb52d0fc6ff
children 7a67f71d3645
files test/com/sun/jdi/SuspendThreadTest.java
diffstat 1 files changed, 60 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/test/com/sun/jdi/SuspendThreadTest.java	Fri Nov 06 14:32:34 2015 +0100
+++ b/test/com/sun/jdi/SuspendThreadTest.java	Mon Dec 07 12:31:25 2015 +0100
@@ -42,6 +42,7 @@
 
 class SuspendThreadTarg {
     public static long count;
+    public static boolean active = true;
 
     public static void bkpt() {
         count++;
@@ -53,7 +54,7 @@
         // We need this to be running so the bkpt
         // can be hit immediately when it is enabled
         // in the back-end.
-        while(count >= 0) {
+        while(active) {
             bkpt();
         }
         System.out.println("Goodbye from SuspendThreadTarg, count = " + count);
@@ -82,9 +83,9 @@
     // to guard against spurious wakeups from bkptSignal.wait()
     boolean signalSent;
     // signal that a breakpoint has happened
-    Object bkptSignal = new Object() {};
+    final private Object bkptSignal = new Object() {};
     BreakpointRequest bkptRequest;
-    Field debuggeeCountField;
+    Field debuggeeCountField, debuggeeActiveField;
 
     // When we get a bkpt we want to disable the request,
     // resume the debuggee, and then re-enable the request
@@ -119,65 +120,71 @@
     /********** test core **********/
 
     protected void runTests() throws Exception {
-        /*
-         * Get to the top of main()
-         * to determine targetClass and mainThread
-         */
-        BreakpointEvent bpe = startToMain("SuspendThreadTarg");
-        targetClass = (ClassType)bpe.location().declaringType();
-        mainThread = bpe.thread();
-        EventRequestManager erm = vm().eventRequestManager();
+        try {
+            /*
+             * Get to the top of main()
+             * to determine targetClass and mainThread
+             */
+            BreakpointEvent bpe = startToMain("SuspendThreadTarg");
+            targetClass = (ClassType)bpe.location().declaringType();
+            mainThread = bpe.thread();
+            EventRequestManager erm = vm().eventRequestManager();
 
-        Location loc1 = findMethod(targetClass, "bkpt", "()V").location();
+            Location loc1 = findMethod(targetClass, "bkpt", "()V").location();
 
-        bkptRequest = erm.createBreakpointRequest(loc1);
+            bkptRequest = erm.createBreakpointRequest(loc1);
 
-        // Without this, it is a SUSPEND_ALL bkpt and the test will pass
-        bkptRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
-        bkptRequest.enable();
+            // Without this, it is a SUSPEND_ALL bkpt and the test will pass
+            bkptRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
+            bkptRequest.enable();
 
-        debuggeeCountField = targetClass.fieldByName("count");
-        try {
-            addListener (this);
-        } catch (Exception ex){
-            ex.printStackTrace();
-            failure("failure: Could not add listener");
-            throw new Exception("SuspendThreadTest: failed", ex);
-        }
+            debuggeeCountField = targetClass.fieldByName("count");
+            debuggeeActiveField = targetClass.fieldByName("active");
+            try {
+                addListener (this);
+            } catch (Exception ex){
+                ex.printStackTrace();
+                failure("failure: Could not add listener");
+                throw new Exception("SuspendThreadTest: failed", ex);
+            }
 
-        int prevBkptCount;
-        vm().resume();
-        synchronized (bkptSignal) {
-            while (bkptCount < maxBkpts) {
-                prevBkptCount = bkptCount;
-                // If we don't get a bkpt within 5 secs,
-                // the test fails
-                signalSent = false;
-                do {
-                    try {
-                        bkptSignal.wait(5000);
-                    } catch (InterruptedException ee) {
+            int prevBkptCount;
+            vm().resume();
+            synchronized (bkptSignal) {
+                while (bkptCount < maxBkpts) {
+                    prevBkptCount = bkptCount;
+                    // If we don't get a bkpt within 5 secs,
+                    // the test fails
+                    signalSent = false;
+                    do {
+                        try {
+                            bkptSignal.wait(5000);
+                        } catch (InterruptedException ee) {
+                        }
+                    } while (signalSent == false);
+                    if (prevBkptCount == bkptCount) {
+                        failure("failure: test hung");
+                        break;
                     }
-                } while (signalSent == false);
-                if (prevBkptCount == bkptCount) {
-                    failure("failure: test hung");
-                    break;
                 }
             }
-        }
-        println("done with loop");
-        bkptRequest.disable();
-        removeListener(this);
+            println("done with loop");
+            bkptRequest.disable();
+            removeListener(this);
 
-
-        /*
-         * deal with results of test
-         * if anything has called failure("foo") testFailed will be true
-         */
-        if (!testFailed) {
-            println("SuspendThreadTest: passed");
-        } else {
-            throw new Exception("SuspendThreadTest: failed");
+            /*
+             * deal with results of test
+             * if anything has called failure("foo") testFailed will be true
+             */
+            if (!testFailed) {
+                println("SuspendThreadTest: passed");
+            } else {
+                throw new Exception("SuspendThreadTest: failed");
+            }
+        } finally {
+            if (targetClass != null && debuggeeActiveField != null) {
+                targetClass.setValue(debuggeeActiveField, vm().mirrorOf(false));
+            }
         }
     }
 }