< prev index next >

test/jdk/java/lang/Thread/virtual/VirtualThreadPinnedEventThrows.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -22,11 +22,11 @@
   */
  
  /**
   * @test
   * @summary Test parking when pinned and emitting the JFR VirtualThreadPinnedEvent throws
-  * @modules java.base/jdk.internal.event
+  * @modules java.base/java.lang:+open java.base/jdk.internal.event
   * @library /test/lib
   * @compile/module=java.base jdk/internal/event/VirtualThreadPinnedEvent.java
   * @run junit/othervm --enable-native-access=ALL-UNNAMED VirtualThreadPinnedEventThrows
   */
  

@@ -34,16 +34,26 @@
  import java.util.concurrent.atomic.AtomicBoolean;
  import java.util.concurrent.atomic.AtomicReference;
  import java.util.concurrent.locks.LockSupport;
  import jdk.internal.event.VirtualThreadPinnedEvent;
  
+ import jdk.test.lib.thread.VThreadRunner;
  import jdk.test.lib.thread.VThreadPinner;
  import org.junit.jupiter.api.Test;
+ import org.junit.jupiter.api.BeforeAll;
  import static org.junit.jupiter.api.Assertions.*;
  
  class VirtualThreadPinnedEventThrows {
  
+     @BeforeAll
+     static void setup() {
+         // need >=2 carriers for testing pinning when main thread is a virtual thread
+         if (Thread.currentThread().isVirtual()) {
+             VThreadRunner.ensureParallelism(2);
+         }
+     }
+ 
      /**
       * Test parking when pinned and creating the VirtualThreadPinnedEvent fails with OOME.
       */
      @Test
      void testVirtualThreadPinnedEventCreateThrows() throws Exception {
< prev index next >