< prev index next > test/jdk/java/lang/Thread/virtual/stress/PinALot.java
Print this page
/*
* @test
* @summary Stress test timed park when pinned
* @requires vm.debug != true
! * @run main PinALot 500000
*/
/*
* @test
* @requires vm.debug == true
! * @run main/othervm/timeout=300 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 {
! static final Object lock = new Object();
public static void main(String[] args) throws Exception {
int iterations = 1_000_000;
if (args.length > 0) {
iterations = Integer.parseInt(args[0]);
/*
* @test
* @summary Stress test timed park when pinned
* @requires vm.debug != true
! * @library /test/lib
+ * @run main/othervm --enable-native-access=ALL-UNNAMED PinALot 500000
*/
/*
* @test
* @requires vm.debug == true
! * @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;
! import jdk.test.lib.thread.VThreadPinner;
! 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]);
final int ITERATIONS = iterations;
AtomicInteger count = new AtomicInteger();
Thread thread = Thread.ofVirtual().start(() -> {
! synchronized (lock) {
while (count.incrementAndGet() < ITERATIONS) {
LockSupport.parkNanos(1);
}
! }
});
boolean terminated;
do {
terminated = thread.join(Duration.ofSeconds(1));
final int ITERATIONS = iterations;
AtomicInteger count = new AtomicInteger();
Thread thread = Thread.ofVirtual().start(() -> {
! VThreadPinner.runPinned(() -> {
while (count.incrementAndGet() < ITERATIONS) {
LockSupport.parkNanos(1);
}
! });
});
boolean terminated;
do {
terminated = thread.join(Duration.ofSeconds(1));
< prev index next >