Skip to content

Commit

Permalink
Merge pull request #18096 from fengxue-IS/hide-cont
Browse files Browse the repository at this point in the history
Add @hidden annotation to Continuation enter/yield methods
  • Loading branch information
babsingh authored Sep 12, 2023
2 parents dce0276 + 2ddda9d commit 1dfb607
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
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

0 comments on commit 1dfb607

Please sign in to comment.