< prev index next >

test/hotspot/jtreg/serviceability/jvmti/vthread/SuspendResume1/SuspendResume1.java

Print this page

  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 SuspendThread/ResumeThread, SuspendThreadList/ResumeThreadList
 27  *          for virtual threads.

 28  * @library /test/lib
 29  * @compile SuspendResume1.java
 30  * @run driver jdk.test.lib.FileInstaller . .
 31  * @run main/othervm/native/timeout=600
 32  *      -Djdk.virtualThreadScheduler.maxPoolSize=1
 33  *      -agentlib:SuspendResume1
 34  *      SuspendResume1
 35  */
 36 













 37  /*
 38  * @test id=no-vmcontinuations
 39  * @requires vm.continuations
 40  * @library /test/lib
 41  * @compile SuspendResume1.java
 42  * @run driver jdk.test.lib.FileInstaller . .
 43  * @run main/othervm/native/timeout=600
 44  *      -agentlib:SuspendResume1
 45  *      -XX:+UnlockExperimentalVMOptions
 46  *      -XX:-VMContinuations
 47  *      SuspendResume1
 48  */
 49 
 50 import java.io.PrintStream;
 51 import java.util.concurrent.*;
 52 import jdk.test.lib.jvmti.DebugeeClass;
 53 
 54 public class SuspendResume1 extends DebugeeClass {
 55 
 56     // load native library if required

151         threadReady = true;
152         int i = 0;
153         int n = 1000;
154         while (!shouldFinish) {
155             if (n <= 0) {
156                 n = 1000;
157                 SuspendResume1.sleep(10);
158             }
159             if (i > n) {
160                 i = 0;
161                 n = n - 1;
162             }
163             i = i + 1;
164         }
165     }
166 
167     // ensure thread is ready
168     public void ensureReady() {
169         try {
170             while (!threadReady) {
171                 sleep(1000);
172             }
173         } catch (InterruptedException e) {
174             throw new RuntimeException("Interruption while preparing tested thread: \n\t" + e);
175         }
176     }
177 
178     // let thread to finish
179     public void letFinish() {
180         shouldFinish = true;
181     }
182 }

  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 SuspendThread/ResumeThread, SuspendThreadList/ResumeThreadList
 27  *          for virtual threads.
 28  * @requires vm.debug != true
 29  * @library /test/lib
 30  * @compile SuspendResume1.java
 31  * @run driver jdk.test.lib.FileInstaller . .
 32  * @run main/othervm/native/timeout=600
 33  *      -Djdk.virtualThreadScheduler.maxPoolSize=1
 34  *      -agentlib:SuspendResume1
 35  *      SuspendResume1
 36  */
 37 
 38 /*
 39  * @test id=debug
 40  * @requires vm.debug == true
 41  * @library /test/lib
 42  * @compile SuspendResume1.java
 43  * @run driver jdk.test.lib.FileInstaller . .
 44  * @run main/othervm/native/timeout=600
 45  *      -Djdk.virtualThreadScheduler.maxPoolSize=1
 46  *      -agentlib:SuspendResume1
 47  *      -XX:-VerifyContinuations
 48  *      SuspendResume1
 49  */
 50 
 51  /*
 52  * @test id=no-vmcontinuations
 53  * @requires vm.continuations
 54  * @library /test/lib
 55  * @compile SuspendResume1.java
 56  * @run driver jdk.test.lib.FileInstaller . .
 57  * @run main/othervm/native/timeout=600
 58  *      -agentlib:SuspendResume1
 59  *      -XX:+UnlockExperimentalVMOptions
 60  *      -XX:-VMContinuations
 61  *      SuspendResume1
 62  */
 63 
 64 import java.io.PrintStream;
 65 import java.util.concurrent.*;
 66 import jdk.test.lib.jvmti.DebugeeClass;
 67 
 68 public class SuspendResume1 extends DebugeeClass {
 69 
 70     // load native library if required

165         threadReady = true;
166         int i = 0;
167         int n = 1000;
168         while (!shouldFinish) {
169             if (n <= 0) {
170                 n = 1000;
171                 SuspendResume1.sleep(10);
172             }
173             if (i > n) {
174                 i = 0;
175                 n = n - 1;
176             }
177             i = i + 1;
178         }
179     }
180 
181     // ensure thread is ready
182     public void ensureReady() {
183         try {
184             while (!threadReady) {
185                 sleep(100);
186             }
187         } catch (InterruptedException e) {
188             throw new RuntimeException("Interruption while preparing tested thread: \n\t" + e);
189         }
190     }
191 
192     // let thread to finish
193     public void letFinish() {
194         shouldFinish = true;
195     }
196 }
< prev index next >