< prev index next >

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

Print this page
@@ -298,14 +298,14 @@
              assertContainsPinnedEvent(recording, vthread);
          }
      }
  
      /**
-      * Test jdk.VirtualThreadPinned event when waiting for a class initializer.
+      * Test jdk.VirtualThreadPinned event when waiting for a class initializer while pinned.
       */
      @Test
-     void testWaitingForClassInitializer() throws Exception {
+     void testWaitingForClassInitializerWhenPinned() throws Exception {
          class TestClass {
              static {
                  LockSupport.park();
              }
              static void m() {

@@ -324,11 +324,13 @@
                  started1.set(true);
                  TestClass.m();
              });
              Thread vthread2 = Thread.ofVirtual().unstarted(() -> {
                  started2.set(true);
-                 TestClass.m();
+                 VThreadPinner.runPinned(() -> {
+                     TestClass.m();
+                 });
              });
  
              try {
                  // start first virtual thread and wait for it to start + park
                  vthread1.start();

@@ -337,11 +339,11 @@
  
                  // start second virtual thread and wait for it to start
                  vthread2.start();
                  awaitTrue(started2);
  
-                 // give time for second virtual thread to wait on the MutexLocker
+                 // give time for second virtual thread to wait in VM
                  Thread.sleep(3000);
  
              } finally {
                  LockSupport.unpark(vthread1);
                  vthread1.join();
< prev index next >