< prev index next >

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

Print this page
@@ -23,27 +23,29 @@
  
  /*
   * @test
   * @summary Stress test timed park when pinned
   * @requires vm.debug != true
-  * @run main PinALot 500000
+  * @library /test/lib
+  * @run main/othervm --enable-native-access=ALL-UNNAMED PinALot 500000
   */
  
  /*
   * @test
   * @requires vm.debug == true
-  * @run main/othervm/timeout=300 PinALot 200000
+  * @library /test/lib
+  * @run main/othervm/timeout=300 --enable-native-access=ALL-UNNAMED PinALot 200000
   */
  
  import java.time.Duration;
  import java.time.Instant;
  import java.util.concurrent.atomic.AtomicInteger;
  import java.util.concurrent.locks.LockSupport;
  
- public class PinALot {
+ import jdk.test.lib.thread.VThreadPinner;
  
-     static final Object lock = new Object();
+ public class PinALot {
  
      public static void main(String[] args) throws Exception {
          int iterations = 1_000_000;
          if (args.length > 0) {
              iterations = Integer.parseInt(args[0]);

@@ -51,15 +53,15 @@
          final int ITERATIONS = iterations;
  
          AtomicInteger count = new AtomicInteger();
  
          Thread thread = Thread.ofVirtual().start(() -> {
-             synchronized (lock) {
+             VThreadPinner.runPinned(() -> {
                  while (count.incrementAndGet() < ITERATIONS) {
                      LockSupport.parkNanos(1);
                  }
-             }
+             });
          });
  
          boolean terminated;
          do {
              terminated = thread.join(Duration.ofSeconds(1));
< prev index next >