1
1
/*
2
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
30
30
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:GuaranteedSafepointInterval=1 -XX:+HandshakeALot HandshakeSuspendExitTest
31
31
*/
32
32
33
+ import jvmti .JVMTIUtils ;
34
+
33
35
public class HandshakeSuspendExitTest implements Runnable {
34
36
35
37
static Thread [] _suspend_threads = new Thread [16 ];
36
38
static volatile boolean _exit_now = false ;
37
39
static java .util .concurrent .Semaphore _sem = new java .util .concurrent .Semaphore (0 );
38
40
41
+ static void suspendThread (Thread t ) {
42
+ try {
43
+ JVMTIUtils .suspendThread (t );
44
+ } catch (JVMTIUtils .JvmtiException e ) {
45
+ if (e .getCode () != JVMTIUtils .JVMTI_ERROR_THREAD_SUSPENDED
46
+ && e .getCode () != JVMTIUtils .JVMTI_ERROR_THREAD_NOT_ALIVE ) {
47
+ throw e ;
48
+ }
49
+ }
50
+ }
51
+
52
+ static void resumeThread (Thread t ) {
53
+ try {
54
+ JVMTIUtils .resumeThread (t );
55
+ } catch (JVMTIUtils .JvmtiException e ) {
56
+ if (e .getCode () != JVMTIUtils .JVMTI_ERROR_THREAD_NOT_SUSPENDED
57
+ && e .getCode () != JVMTIUtils .JVMTI_ERROR_THREAD_NOT_ALIVE ) {
58
+ throw e ;
59
+ }
60
+ }
61
+ }
62
+
39
63
@ Override
40
64
public void run () {
41
65
_sem .release ();
42
66
while (!_exit_now ) {
43
67
// Leave last 2 threads running.
44
68
for (int i = 0 ; i < _suspend_threads .length - 2 ; i ++) {
45
69
if (Thread .currentThread () != _suspend_threads [i ]) {
46
- _suspend_threads [i ]. suspend ( );
47
- _suspend_threads [i ]. resume ( );
70
+ suspendThread ( _suspend_threads [i ]);
71
+ resumeThread ( _suspend_threads [i ]);
48
72
}
49
73
}
50
74
}
51
75
_sem .release ();
52
76
}
53
77
78
+
54
79
public static void main (String ... args ) throws Exception {
55
80
HandshakeSuspendExitTest test = new HandshakeSuspendExitTest ();
56
81
// Fire-up suspend threads.
@@ -74,10 +99,10 @@ public static void main(String... args) throws Exception {
74
99
75
100
// Try to suspend them.
76
101
for (Thread thr : exit_threads ) {
77
- thr . suspend ( );
102
+ suspendThread ( thr );
78
103
}
79
104
for (Thread thr : exit_threads ) {
80
- thr . resume ( );
105
+ resumeThread ( thr );
81
106
}
82
107
83
108
// Start exit and join.
@@ -88,7 +113,7 @@ public static void main(String... args) throws Exception {
88
113
// each other at exactly the same time so they can see
89
114
// _exit_now and check in via the semaphore.
90
115
for (Thread thr : _suspend_threads ) {
91
- thr . resume ( );
116
+ resumeThread ( thr );
92
117
}
93
118
while (_sem .tryAcquire ()) {
94
119
--waiting ;
0 commit comments