7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test id=default
26 * @summary Test SuspendAllVirtualThreads/ResumeAllVirtualThreads
27 * @library /test/lib
28 * @compile SuspendResume2.java
29 * @run driver jdk.test.lib.FileInstaller . .
30 * @run main/othervm/native
31 * -Djdk.virtualThreadScheduler.maxPoolSize=1
32 * -agentlib:SuspendResume2
33 * SuspendResume2
34 */
35
36 /*
37 * @test id=no-vmcontinuations
38 * @requires vm.continuations
39 * @library /test/lib
40 * @compile SuspendResume2.java
41 * @run driver jdk.test.lib.FileInstaller . .
42 * @run main/othervm/native
43 * -agentlib:SuspendResume2
44 * -XX:+UnlockExperimentalVMOptions
45 * -XX:-VMContinuations
46 * SuspendResume2
47 */
48
49 import java.io.PrintStream;
50 import java.util.concurrent.*;
51 import jdk.test.lib.jvmti.DebugeeClass;
52
53 public class SuspendResume2 extends DebugeeClass {
54
55 // load native library if required
131
132 // class for tested threads
133 class TestedThread extends Thread {
134 private volatile boolean threadReady = false;
135 private volatile boolean shouldFinish = false;
136
137 // make thread with specific name
138 public TestedThread(String name) {
139 super(name);
140 }
141
142 // run thread continuously
143 public void run() {
144 // run in a loop
145 threadReady = true;
146 int i = 0;
147 int n = 1000;
148 while (!shouldFinish) {
149 if (n <= 0) {
150 n = 1000;
151 SuspendResume2.sleep(1);
152 }
153 if (i > n) {
154 i = 0;
155 n = n - 1;
156 }
157 i = i + 1;
158 }
159 }
160
161 // ensure thread is ready
162 public void ensureReady() {
163 try {
164 while (!threadReady) {
165 sleep(1);
166 }
167 } catch (InterruptedException e) {
168 throw new RuntimeException("Interruption while preparing tested thread: \n\t" + e);
169 }
170 }
171
172 // let thread to finish
173 public void letFinish() {
174 shouldFinish = true;
175 }
176 }
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test id=default
26 * @summary Test SuspendAllVirtualThreads/ResumeAllVirtualThreads
27 * @requires vm.debug != true
28 * @library /test/lib
29 * @compile SuspendResume2.java
30 * @run driver jdk.test.lib.FileInstaller . .
31 * @run main/othervm/native
32 * -Djdk.virtualThreadScheduler.maxPoolSize=1
33 * -agentlib:SuspendResume2
34 * SuspendResume2
35 */
36
37 /*
38 * @test id=debug
39 * @requires vm.debug == true
40 * @library /test/lib
41 * @compile SuspendResume2.java
42 * @run driver jdk.test.lib.FileInstaller . .
43 * @run main/othervm/native
44 * -Djdk.virtualThreadScheduler.maxPoolSize=1
45 * -agentlib:SuspendResume2
46 * -XX:-VerifyContinuations
47 * SuspendResume2
48 */
49
50 /*
51 * @test id=no-vmcontinuations
52 * @requires vm.continuations
53 * @library /test/lib
54 * @compile SuspendResume2.java
55 * @run driver jdk.test.lib.FileInstaller . .
56 * @run main/othervm/native
57 * -agentlib:SuspendResume2
58 * -XX:+UnlockExperimentalVMOptions
59 * -XX:-VMContinuations
60 * SuspendResume2
61 */
62
63 import java.io.PrintStream;
64 import java.util.concurrent.*;
65 import jdk.test.lib.jvmti.DebugeeClass;
66
67 public class SuspendResume2 extends DebugeeClass {
68
69 // load native library if required
145
146 // class for tested threads
147 class TestedThread extends Thread {
148 private volatile boolean threadReady = false;
149 private volatile boolean shouldFinish = false;
150
151 // make thread with specific name
152 public TestedThread(String name) {
153 super(name);
154 }
155
156 // run thread continuously
157 public void run() {
158 // run in a loop
159 threadReady = true;
160 int i = 0;
161 int n = 1000;
162 while (!shouldFinish) {
163 if (n <= 0) {
164 n = 1000;
165 SuspendResume2.sleep(10);
166 }
167 if (i > n) {
168 i = 0;
169 n = n - 1;
170 }
171 i = i + 1;
172 }
173 }
174
175 // ensure thread is ready
176 public void ensureReady() {
177 try {
178 while (!threadReady) {
179 sleep(100);
180 }
181 } catch (InterruptedException e) {
182 throw new RuntimeException("Interruption while preparing tested thread: \n\t" + e);
183 }
184 }
185
186 // let thread to finish
187 public void letFinish() {
188 shouldFinish = true;
189 }
190 }
|