29 * @build HandshakeWalkSuspendExitTest
30 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
31 * sun.hotspot.WhiteBox$WhiteBoxPermission
32 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI HandshakeWalkSuspendExitTest
33 */
34
35 import jdk.test.lib.Asserts;
36 import sun.hotspot.WhiteBox;
37
38 public class HandshakeWalkSuspendExitTest implements Runnable {
39
40 static final int _test_threads = 8;
41 static final int _test_exit_threads = 128;
42 static Thread[] _threads = new Thread[_test_threads];
43 static volatile boolean exit_now = false;
44 static java.util.concurrent.Semaphore _sem = new java.util.concurrent.Semaphore(0);
45
46 @Override
47 public void run() {
48 WhiteBox wb = WhiteBox.getWhiteBox();
49 while(!exit_now) {
50 _sem.release();
51 for (int i = 0; i < _threads.length; i+=2) {
52 wb.handshakeWalkStack(null, true);
53 if (Thread.currentThread() != _threads[i]) {
54 _threads[i].suspend();
55 _threads[i].resume();
56 }
57 }
58 for (int i = 0; i < _threads.length; i+=2) {
59 wb.handshakeWalkStack(_threads[i], false);
60 if (Thread.currentThread() != _threads[i]) {
61 _threads[i].suspend();
62 _threads[i].resume();
63 }
64 }
65 }
66 }
67
68 public static void main(String... args) throws Exception {
69 HandshakeWalkSuspendExitTest test = new HandshakeWalkSuspendExitTest();
70
71 for (int i = 0; i < _threads.length; i++) {
72 _threads[i] = new Thread(test);
73 _threads[i].start();
74 }
75 for (int i = 0; i < _test_threads; i++) {
76 _sem.acquire();
77 }
78 for (int i = 0; i < _test_exit_threads; i++) {
79 new Thread(new Runnable() { public void run() {} }).start();
80 }
81 exit_now = true;
82 for (int i = 0; i < _threads.length; i++) {
83 _threads[i].join();
84 }
85 }
86 }
|
29 * @build HandshakeWalkSuspendExitTest
30 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
31 * sun.hotspot.WhiteBox$WhiteBoxPermission
32 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI HandshakeWalkSuspendExitTest
33 */
34
35 import jdk.test.lib.Asserts;
36 import sun.hotspot.WhiteBox;
37
38 public class HandshakeWalkSuspendExitTest implements Runnable {
39
40 static final int _test_threads = 8;
41 static final int _test_exit_threads = 128;
42 static Thread[] _threads = new Thread[_test_threads];
43 static volatile boolean exit_now = false;
44 static java.util.concurrent.Semaphore _sem = new java.util.concurrent.Semaphore(0);
45
46 @Override
47 public void run() {
48 WhiteBox wb = WhiteBox.getWhiteBox();
49 while (!exit_now) {
50 _sem.release();
51 // We only suspend threads on even index and not ourself.
52 // Otherwise we can accidentially suspend all threads.
53 for (int i = 0; i < _threads.length; i += 2) {
54 wb.handshakeWalkStack(null /* ignored */, true /* stackwalk all threads */);
55 if (Thread.currentThread() != _threads[i]) {
56 _threads[i].suspend();
57 _threads[i].resume();
58 }
59 }
60 for (int i = 0; i < _threads.length; i += 2) {
61 wb.handshakeWalkStack(_threads[i] /* thread to stackwalk */, false /* stackwalk one thread */);
62 if (Thread.currentThread() != _threads[i]) {
63 _threads[i].suspend();
64 _threads[i].resume();
65 }
66 }
67 }
68 }
69
70 public static void main(String... args) throws Exception {
71 HandshakeWalkSuspendExitTest test = new HandshakeWalkSuspendExitTest();
72
73 for (int i = 0; i < _threads.length; i++) {
74 _threads[i] = new Thread(test);
75 _threads[i].start();
76 }
77 for (int i = 0; i < _test_threads; i++) {
78 _sem.acquire();
79 }
80 Thread[] exit_threads = new Thread[_test_exit_threads];
81 for (int i = 0; i < _test_exit_threads; i++) {
82 exit_threads[i] = new Thread(new Runnable() { public void run() {} });
83 exit_threads[i].start();
84 }
85 exit_now = true;
86 for (int i = 0; i < _threads.length; i++) {
87 _threads[i].join();
88 }
89 for (int i = 0; i < exit_threads.length; i++) {
90 exit_threads[i].join();
91 }
92 }
93 }
|