From 3d29dc96b0c3f920b09957a257fba7a6ab25462f Mon Sep 17 00:00:00 2001 From: Staffan Larsen Date: Fri, 21 Feb 2014 16:26:22 +0100 Subject: [PATCH] 6952105: TEST_BUG: testcase failure, not very often, com/sun/jdi/SuspendThreadTest.java Reviewed-by: dholmes, sspitsyn, dsamersoff --- jdk/test/com/sun/jdi/SuspendThreadTest.java | 46 +++++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/jdk/test/com/sun/jdi/SuspendThreadTest.java b/jdk/test/com/sun/jdi/SuspendThreadTest.java index 3c84ac1a6e4..a2f647b4277 100644 --- a/jdk/test/com/sun/jdi/SuspendThreadTest.java +++ b/jdk/test/com/sun/jdi/SuspendThreadTest.java @@ -36,7 +36,6 @@ import com.sun.jdi.*; import com.sun.jdi.event.*; import com.sun.jdi.request.*; -import java.util.*; /********** target program **********/ @@ -78,7 +77,11 @@ public class SuspendThreadTest extends TestScaffold { // 1000 makes the test take over 2 mins on win32 static int maxBkpts = 200; - int bkptCount; + volatile int bkptCount; + // to guard against spurious wakeups from bkptSignal.wait() + boolean signalSent; + // signal that a breakpoint has happened + Object bkptSignal = new Object() {}; BreakpointRequest bkptRequest; Field debuggeeCountField; @@ -99,8 +102,12 @@ public class SuspendThreadTest extends TestScaffold { // The main thread watchs the bkptCount to // see if bkpts stop coming in. The // test _should_ fail well before maxBkpts bkpts. - if (bkptCount++ < maxBkpts) { - bkptRequest.enable(); + synchronized (bkptSignal) { + if (bkptCount++ < maxBkpts) { + bkptRequest.enable(); + } + signalSent = true; + bkptSignal.notifyAll(); } } @@ -130,29 +137,32 @@ public class SuspendThreadTest extends TestScaffold { debuggeeCountField = targetClass.fieldByName("count"); try { - addListener (this); } catch (Exception ex){ ex.printStackTrace(); failure("failure: Could not add listener"); - throw new Exception("SuspendThreadTest: failed"); + throw new Exception("SuspendThreadTest: failed", ex); } int prevBkptCount; vm().resume(); - while (bkptCount < maxBkpts) { - prevBkptCount = bkptCount; - // If we don't get a bkpt within 5 secs, - // the test fails - try { - Thread.sleep(5000); - } catch (InterruptedException ee) { + 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; + } } - if (prevBkptCount == bkptCount) { - failure("failure: test hung"); - break; - } - prevBkptCount = bkptCount; } println("done with loop"); bkptRequest.disable();