< prev index next >

test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java

Print this page
*** 26,25 ***
   * @bug 8322818
   * @summary Stress test Thread.getStackTrace on a virtual thread that is pinned
   * @requires vm.debug != true
   * @modules java.base/java.lang:+open
   * @library /test/lib
!  * @run main/othervm GetStackTraceALotWhenPinned 500000
   */
  
  /*
   * @test
   * @requires vm.debug == true
   * @modules java.base/java.lang:+open
   * @library /test/lib
!  * @run main/othervm/timeout=300 GetStackTraceALotWhenPinned 200000
   */
  
  import java.time.Instant;
  import java.util.concurrent.atomic.AtomicInteger;
  import java.util.concurrent.locks.LockSupport;
  import jdk.test.lib.thread.VThreadRunner;
  
  public class GetStackTraceALotWhenPinned {
  
      public static void main(String[] args) throws Exception {
          // need at least two carrier threads when main thread is a virtual thread
--- 26,26 ---
   * @bug 8322818
   * @summary Stress test Thread.getStackTrace on a virtual thread that is pinned
   * @requires vm.debug != true
   * @modules java.base/java.lang:+open
   * @library /test/lib
!  * @run main/othervm --enable-native-access=ALL-UNNAMED GetStackTraceALotWhenPinned 500000
   */
  
  /*
   * @test
   * @requires vm.debug == true
   * @modules java.base/java.lang:+open
   * @library /test/lib
!  * @run main/othervm/timeout=300 --enable-native-access=ALL-UNNAMED GetStackTraceALotWhenPinned 200000
   */
  
  import java.time.Instant;
  import java.util.concurrent.atomic.AtomicInteger;
  import java.util.concurrent.locks.LockSupport;
  import jdk.test.lib.thread.VThreadRunner;
+ import jdk.test.lib.thread.VThreadPinner;
  
  public class GetStackTraceALotWhenPinned {
  
      public static void main(String[] args) throws Exception {
          // need at least two carrier threads when main thread is a virtual thread

*** 63,17 ***
              for (int i = 0; i < iterations; i++) {
                  // wait for main thread to arrive
                  barrier.await();
  
                  Thread.yield();
!                 synchronized (GetStackTraceALotWhenPinned.class) {
!                     if (timed) {
                          LockSupport.parkNanos(Long.MAX_VALUE);
                      } else {
                          LockSupport.park();
                      }
!                 }
                  timed = !timed;
              }
          });
  
          long lastTimestamp = System.currentTimeMillis();
--- 64,18 ---
              for (int i = 0; i < iterations; i++) {
                  // wait for main thread to arrive
                  barrier.await();
  
                  Thread.yield();
!                 boolean b = timed;
!                 VThreadPinner.runPinned(() -> {
+                     if (b) {
                          LockSupport.parkNanos(Long.MAX_VALUE);
                      } else {
                          LockSupport.park();
                      }
!                 });
                  timed = !timed;
              }
          });
  
          long lastTimestamp = System.currentTimeMillis();
< prev index next >