< 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,21 +44,23 @@
static java.util.concurrent.Semaphore _sem = new java.util.concurrent.Semaphore(0);
@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();
}
}
@@ -73,14 +75,19 @@
_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++) {
- 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();
+ }
}
}
< prev index next >