From 5a8524c1f73a3ebe2975cba8705ab55516181482 Mon Sep 17 00:00:00 2001 From: Jack Lu Date: Thu, 7 Sep 2023 15:37:17 -0400 Subject: [PATCH 1/2] Add @Hidden annotation to Continuation enter/yield methods Signed-off-by: Jack Lu --- .../share/classes/jdk/internal/vm/Continuation.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jcl/src/java.base/share/classes/jdk/internal/vm/Continuation.java b/jcl/src/java.base/share/classes/jdk/internal/vm/Continuation.java index e0e4c611c51..a2e623bef31 100644 --- a/jcl/src/java.base/share/classes/jdk/internal/vm/Continuation.java +++ b/jcl/src/java.base/share/classes/jdk/internal/vm/Continuation.java @@ -28,6 +28,7 @@ import jdk.internal.access.JavaLangAccess; import jdk.internal.access.SharedSecrets; import jdk.internal.misc.Unsafe; +import jdk.internal.vm.annotation.Hidden; import jdk.internal.vm.annotation.JvmtiMountTransition; /** @@ -180,6 +181,7 @@ public void unlockAccess() { isAccessible = true; } + @Hidden private static void enter(Continuation cont) { try { cont.runnable.run(); @@ -226,6 +228,7 @@ public final void run() { * @param scope the scope to lookup/suspend * @return {@link true} or {@link false} based on success/failure */ + @Hidden public static boolean yield(ContinuationScope scope) { /* TODO find matching scope to yield */ Thread carrierThread = JLA.currentCarrierThread(); @@ -234,6 +237,7 @@ public static boolean yield(ContinuationScope scope) { return cont.yield0(); } + @Hidden private boolean yield0() { int rcPinned = isPinnedImpl(); if (rcPinned != 0) { @@ -285,9 +289,11 @@ public PreemptStatus tryPreempt(Thread t) { } /* Continuation Native APIs */ + @Hidden @JvmtiMountTransition private native boolean enterImpl(); + @Hidden @JvmtiMountTransition private static native boolean yieldImpl(boolean isFinished); } From 2ddda9d44e5941395f3fd6866ed3e456adddd1b5 Mon Sep 17 00:00:00 2001 From: Jack Lu Date: Mon, 11 Sep 2023 14:09:12 -0400 Subject: [PATCH 2/2] Update VirtualThreadTests to match StackTrace changes Signed-off-by: Jack Lu --- .../test/jep425/VirtualThreadTests.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/test/functional/Java21andUp/src/org/openj9/test/jep425/VirtualThreadTests.java b/test/functional/Java21andUp/src/org/openj9/test/jep425/VirtualThreadTests.java index d750097976a..70ebf2ddfe0 100644 --- a/test/functional/Java21andUp/src/org/openj9/test/jep425/VirtualThreadTests.java +++ b/test/functional/Java21andUp/src/org/openj9/test/jep425/VirtualThreadTests.java @@ -175,11 +175,9 @@ public void test_jniFromVirtualthread() { @Test public void test_YieldedVirtualThreadGetStackTrace() { - /* The expected frame count is based on test's callstack and OpenJ9's implementation of - * Continuation.yield(). - */ - int expectedFrames = 10; - String expectedMethodName = "yieldImpl"; + /* The expected frame count is based on test's callstack */ + int expectedFrames = 6; + String expectedMethodName = "park"; try { Thread t = Thread.ofVirtual().name("yielded-stackwalker").start(() -> { @@ -209,7 +207,7 @@ public void test_YieldedVirtualThreadGetStackTrace() { (expectedFrames == ste.length)); AssertJUnit.assertTrue( - "Expected top frame to be yieldImpl, got " + ste[0].getMethodName(), + "Expected top frame to be " + expectedMethodName + ", got " + ste[0].getMethodName(), ste[0].getMethodName().equals(expectedMethodName)); LockSupport.unpark(t); @@ -224,6 +222,10 @@ public void test_YieldedVirtualThreadGetStackTrace() { @Test public void test_RunningVirtualThreadGetStackTrace() { try { + /* The expected frame count is based on test's callstack */ + int expectedFrames = 2; + String expectedClassName = "org.openj9.test.jep425.VirtualThreadTests"; + Thread t = Thread.ofVirtual().name("running-stackwalker").start(() -> { testThread2_state = true; while (testThread2_state); @@ -233,8 +235,18 @@ public void test_RunningVirtualThreadGetStackTrace() { } StackTraceElement[] ste = t.getStackTrace(); - Assert.assertEquals(ste.length, 3); - Assert.assertEquals(ste[0].getClassName(), "org.openj9.test.jep425.VirtualThreadTests"); + + /* If the stacktrace doesn't match the expected result, then print out the stacktrace + * for debuggging. + */ + if ((expectedFrames != ste.length) || !ste[0].getClassName().equals(expectedClassName)) { + for (StackTraceElement st : ste) { + System.out.println(st); + } + } + + Assert.assertEquals(ste.length, expectedFrames); + Assert.assertEquals(ste[0].getClassName(), expectedClassName); testThread2_state = false; t.join();