--- old/test/hotspot/jtreg/runtime/handshake/HandshakeWalkSuspendExitTest.java 2018-10-28 21:03:56.881708779 +0100 +++ new/test/hotspot/jtreg/runtime/handshake/HandshakeWalkSuspendExitTest.java 2018-10-28 21:03:56.588698929 +0100 @@ -46,17 +46,19 @@ @Override public void run() { WhiteBox wb = WhiteBox.getWhiteBox(); - while(!exit_now) { + while (!exit_now) { _sem.release(); - for (int i = 0; i < _threads.length; i+=2) { - wb.handshakeWalkStack(null, true); + // We only suspend threads on even index and not ourself. + // Otherwise we can accidentially suspend all threads. + for (int i = 0; i < _threads.length; i += 2) { + wb.handshakeWalkStack(null /* ignored */, true /* stackwalk all threads */); if (Thread.currentThread() != _threads[i]) { _threads[i].suspend(); _threads[i].resume(); } } - for (int i = 0; i < _threads.length; i+=2) { - wb.handshakeWalkStack(_threads[i], false); + for (int i = 0; i < _threads.length; i += 2) { + wb.handshakeWalkStack(_threads[i] /* thread to stackwalk */, false /* stackwalk one thread */); if (Thread.currentThread() != _threads[i]) { _threads[i].suspend(); _threads[i].resume(); @@ -75,12 +77,17 @@ for (int i = 0; i < _test_threads; i++) { _sem.acquire(); } + Thread[] exit_threads = new Thread[_test_exit_threads]; for (int i = 0; i < _test_exit_threads; i++) { - new Thread(new Runnable() { public void run() {} }).start(); + exit_threads[i] = new Thread(new Runnable() { public void run() {} }); + exit_threads[i].start(); } exit_now = true; for (int i = 0; i < _threads.length; i++) { _threads[i].join(); } + for (int i = 0; i < exit_threads.length; i++) { + exit_threads[i].join(); + } } }