Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @Hidden annotation to Continuation enter/yield methods #18096

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -180,6 +181,7 @@ public void unlockAccess() {
isAccessible = true;
}

@Hidden
private static void enter(Continuation cont) {
try {
cont.runnable.run();
Expand Down Expand Up @@ -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();
Expand All @@ -234,6 +237,7 @@ public static boolean yield(ContinuationScope scope) {
return cont.yield0();
}

@Hidden
private boolean yield0() {
int rcPinned = isPinnedImpl();
if (rcPinned != 0) {
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(() -> {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand Down