< prev index next >

test/hotspot/jtreg/runtime/handshake/HandshakeWalkSuspendExitTest.java

Print this page
rev 52283 : [mq]: 8212933
rev 52284 : 8212933: Thread-SMR: requesting a VM operation whilst holding a ThreadsListHandle can cause deadlocks
Reviewed-by: eosterlund, dcubed, sspitsyn

*** 44,64 **** static java.util.concurrent.Semaphore _sem = new java.util.concurrent.Semaphore(0); @Override public void run() { WhiteBox wb = WhiteBox.getWhiteBox(); ! while(!exit_now) { _sem.release(); ! for (int i = 0; i < _threads.length; i+=2) { ! wb.handshakeWalkStack(null, true); 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); if (Thread.currentThread() != _threads[i]) { _threads[i].suspend(); _threads[i].resume(); } } --- 44,66 ---- static java.util.concurrent.Semaphore _sem = new java.util.concurrent.Semaphore(0); @Override public void run() { WhiteBox wb = WhiteBox.getWhiteBox(); ! while (!exit_now) { _sem.release(); ! // 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] /* thread to stackwalk */, false /* stackwalk one thread */); if (Thread.currentThread() != _threads[i]) { _threads[i].suspend(); _threads[i].resume(); } }
*** 73,86 **** _threads[i].start(); } for (int i = 0; i < _test_threads; i++) { _sem.acquire(); } for (int i = 0; i < _test_exit_threads; i++) { ! new Thread(new Runnable() { public void run() {} }).start(); } exit_now = true; for (int i = 0; i < _threads.length; i++) { _threads[i].join(); } } } --- 75,93 ---- _threads[i].start(); } 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++) { ! 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(); + } } }
< prev index next >