Details
-
Bug
-
Resolution: Fixed
-
P4
-
21
-
b26
Description
Normally when a virtual thread wrapper is used to run a test, the main thread is renamed to "old-m-a-i-n" and the new virtual thread that will act as the main thread is named "main". Neither is being done by `ProcessTools.main()`. This can cause problems for tests that expect the main thread that the test is running in to be called "main".
diff --git a/test/lib/jdk/test/lib/process/ProcessTools.java b/test/lib/jdk/test/lib/process/ProcessTools.java
index 115f2e96fc0..ed30efbb6fb 100644
--- a/test/lib/jdk/test/lib/process/ProcessTools.java
+++ b/test/lib/jdk/test/lib/process/ProcessTools.java
@@ -879,6 +879,8 @@ public final class ProcessTools {
}
}
+ public static final String OLD_MAIN_THREAD_NAME = "old-m-a-i-n";
+
// ProcessTools as a wrapper
// It executes method main in a separate virtual or platform thread
public static void main(String[] args) throws Throwable {
@@ -894,7 +896,7 @@ public final class ProcessTools {
// MainThreadGroup used just as a container for exceptions
// when main is executed in virtual thread
MainThreadGroup tg = new MainThreadGroup();
- Thread vthread = startVirtualThread(() -> {
+ Thread vthread = createVirtualThread(() -> {
try {
mainMethod.invoke(null, new Object[] { classArgs });
} catch (InvocationTargetException e) {
@@ -903,6 +905,9 @@ public final class ProcessTools {
tg.uncaughtThrowable = error;
}
});
+ Thread.currentThread().setName(OLD_MAIN_THREAD_NAME);
+ vthread.setName("main");
+ vthread.start();
vthread.join();
if (tg.uncaughtThrowable != null) {
throw tg.uncaughtThrowable;
@@ -940,12 +945,12 @@ public final class ProcessTools {
Throwable uncaughtThrowable = null;
}
- static Thread startVirtualThread(Runnable task) {
+ static Thread createVirtualThread(Runnable task) {
try {
Object builder = Thread.class.getMethod("ofVirtual").invoke(null);
Class<?> clazz = Class.forName("java.lang.Thread$Builder");
- Method start = clazz.getMethod("start", Runnable.class);
- return (Thread) start.invoke(builder, task);
+ Method unstarted = clazz.getMethod("unstarted", Runnable.class);
+ return (Thread) unstarted.invoke(builder, task);
} catch (RuntimeException | Error e) {
throw e;
} catch (Exception e) {
diff --git a/test/lib/jdk/test/lib/process/ProcessTools.java b/test/lib/jdk/test/lib/process/ProcessTools.java
index 115f2e96fc0..ed30efbb6fb 100644
--- a/test/lib/jdk/test/lib/process/ProcessTools.java
+++ b/test/lib/jdk/test/lib/process/ProcessTools.java
@@ -879,6 +879,8 @@ public final class ProcessTools {
}
}
+ public static final String OLD_MAIN_THREAD_NAME = "old-m-a-i-n";
+
// ProcessTools as a wrapper
// It executes method main in a separate virtual or platform thread
public static void main(String[] args) throws Throwable {
@@ -894,7 +896,7 @@ public final class ProcessTools {
// MainThreadGroup used just as a container for exceptions
// when main is executed in virtual thread
MainThreadGroup tg = new MainThreadGroup();
- Thread vthread = startVirtualThread(() -> {
+ Thread vthread = createVirtualThread(() -> {
try {
mainMethod.invoke(null, new Object[] { classArgs });
} catch (InvocationTargetException e) {
@@ -903,6 +905,9 @@ public final class ProcessTools {
tg.uncaughtThrowable = error;
}
});
+ Thread.currentThread().setName(OLD_MAIN_THREAD_NAME);
+ vthread.setName("main");
+ vthread.start();
vthread.join();
if (tg.uncaughtThrowable != null) {
throw tg.uncaughtThrowable;
@@ -940,12 +945,12 @@ public final class ProcessTools {
Throwable uncaughtThrowable = null;
}
- static Thread startVirtualThread(Runnable task) {
+ static Thread createVirtualThread(Runnable task) {
try {
Object builder = Thread.class.getMethod("ofVirtual").invoke(null);
Class<?> clazz = Class.forName("java.lang.Thread$Builder");
- Method start = clazz.getMethod("start", Runnable.class);
- return (Thread) start.invoke(builder, task);
+ Method unstarted = clazz.getMethod("unstarted", Runnable.class);
+ return (Thread) unstarted.invoke(builder, task);
} catch (RuntimeException | Error e) {
throw e;
} catch (Exception e) {
Attachments
Issue Links
- relates to
-
JDK-8309397 com/sun/jdi/JdbXXX tests fail due to not being run with -Djdk.trackAllThreads
-
- Closed
-
-
JDK-8285422 [LOOM] Some com/sun/jdi test are failing with the vthread wrapper
-
- Resolved
-
-
JDK-8309396 com/sun/jdi/JdbMethodExitTest.java fails with virtual threads due to a bug in determining the main thread id
-
- Resolved
-