8303773: Replace "main.wrapper" with "test.thread.factory" property in test code

Reviewed-by: cjplummer, amenkov
This commit is contained in:
Leonid Mesnik 2023-10-03 15:03:47 +00:00
parent 0e501f66df
commit 89987dbf87
21 changed files with 62 additions and 63 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -152,7 +152,7 @@ public class monitor001 extends JdbTest {
// check 'threads', searching for "java.lang.Thread" followed by the main thread name.
v.add("java.lang.Thread");
if (System.getProperty("main.wrapper") != null) {
if (System.getProperty("test.thread.factory") != null) {
v.add(nsk.share.MainWrapper.OLD_MAIN_THREAD_NAME);
} else {
v.add("main");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -90,7 +90,7 @@ public class threads003 extends JdbTest {
int count;
Vector v;
String[] threads;
boolean vthreadMode = "Virtual".equals(System.getProperty("main.wrapper"));
boolean vthreadMode = "Virtual".equals(System.getProperty("test.thread.factory"));
if (!vthreadMode) {
// This test is only meant to be run in vthread mode.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -186,7 +186,7 @@ public class unmonitor001 extends JdbTest {
// check 'threads', searching for "java.lang.Thread" followed by the main thread name.
v.add("java.lang.Thread");
if (System.getProperty("main.wrapper") != null) {
if (System.getProperty("test.thread.factory") != null) {
v.add(nsk.share.MainWrapper.OLD_MAIN_THREAD_NAME);
} else {
v.add("main");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -191,7 +191,7 @@ public class bounds002 {
complain("Unexpected " + e);
exitStatus = Consts.TEST_FAILED;
}
boolean vthreadMode = "Virtual".equals(System.getProperty("main.wrapper"));
boolean vthreadMode = "Virtual".equals(System.getProperty("test.thread.factory"));
display("vthreadMode: " + vthreadMode + ", isTopmostFrame: " + isTopmostFrame);
try {
stackFrame.setValue(var, null);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -134,8 +134,8 @@ public class threads001 {
private int runThis (String argv[], PrintStream out) {
Debugee debuggee;
boolean usingWrapper = System.getProperty("main.wrapper") != null;
boolean usingVThreadWrapper = "Virtual".equals(System.getProperty("main.wrapper"));
boolean usingTTF = System.getProperty("test.thread.factory") != null;
boolean usingVirtualTTF = "Virtual".equals(System.getProperty("test.thread.factory"));
argsHandler = new ArgumentHandler(argv);
logHandler = new Log(out, argsHandler);
@ -253,10 +253,10 @@ public class threads001 {
* the "VirtualThreads" ThreadGroup, and threfore do not show up in group1.
*/
int expectedNumThreads;
if (usingVThreadWrapper) {
if (usingVirtualTTF) {
expectedNumThreads = 1;
} else {
expectedNumThreads = usingWrapper ? 3 : 2;
expectedNumThreads = usingTTF ? 3 : 2;
}
if (threads.size() < expectedNumThreads) {
log3("ERROR: threads.size() < 2 for group1 : " + threads.size() );
@ -277,7 +277,7 @@ public class threads001 {
if (s1.equals("Thread2"))
nThread2 += 1;
}
if (nMain != 1 && !usingVThreadWrapper) {
if (nMain != 1 && !usingVirtualTTF) {
log3("ERROR: # of 'main' threads != 1 : " + nMain);
expresult = 1;
}

View File

@ -69,7 +69,7 @@ public class stop001 {
static final int PASSED = 0;
static final int FAILED = 2;
static final int PASS_BASE = 95;
static final boolean vthreadMode = "Virtual".equals(System.getProperty("main.wrapper"));
static final boolean vthreadMode = "Virtual".equals(System.getProperty("test.thread.factory"));
//----------------------------------------------------- templete parameters
static final String

View File

@ -189,7 +189,7 @@ class Threadstop001a extends NamedTask {
public static Object lockingObject2 = new Object();
static final boolean vthreadMode = "Virtual".equals(System.getProperty("main.wrapper"));
static final boolean vthreadMode = "Virtual".equals(System.getProperty("test.thread.factory"));
private int i1 = 0, i2 = 10;

View File

@ -75,7 +75,7 @@ public class stop002 {
static final String COMMAND_GO = "go";
static final String COMMAND_QUIT = "quit";
static final boolean vthreadMode = "Virtual".equals(System.getProperty("main.wrapper"));
static final boolean vthreadMode = "Virtual".equals(System.getProperty("test.thread.factory"));
private ArgumentHandler argHandler;
private Log log;

View File

@ -38,7 +38,7 @@ public class stop002t {
volatile boolean stopLooping1 = false;
volatile boolean stopLooping2 = false;
volatile static int testNumReady = 0;
static final boolean vthreadMode = "Virtual".equals(System.getProperty("main.wrapper"));
static final boolean vthreadMode = "Virtual".equals(System.getProperty("test.thread.factory"));
public static void main(String args[]) {
System.exit(run(args) + Consts.JCK_STATUS_BASE);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -251,7 +251,7 @@ public class thread001 {
// debug agent has already generated the THREAD_START event for the
// original "main", so we end up with two THREAD_START events for "main".
// We need to allow for this.
if ((System.getProperty("main.wrapper") != null) &&
if ((System.getProperty("test.thread.factory") != null) &&
checkedThreads[i][0].equals("main") &&
checkedThreads[i][1].equals("1")) {
checkedThreads[i][1] = "2";

View File

@ -47,7 +47,7 @@ public final class MainWrapper {
finalizableObject.registerCleanup();
// Some tests use this property to understand if virtual threads are used
System.setProperty("main.wrapper", wrapperName);
System.setProperty("test.thread.factory", wrapperName);
Runnable task = () -> {
try {

View File

@ -163,7 +163,7 @@ public class Launcher extends DebugeeBinder {
args.add(jdbExecPath.trim());
if (argumentHandler.isLaunchingConnector()) {
boolean vthreadMode = "Virtual".equals(System.getProperty("main.wrapper"));
boolean vthreadMode = "Virtual".equals(System.getProperty("test.thread.factory"));
if (vthreadMode) {
/* Some tests need more carrier threads than the default provided. */
args.add("-R-Djdk.virtualThreadScheduler.parallelism=15");
@ -230,8 +230,8 @@ public class Launcher extends DebugeeBinder {
if (argumentHandler.verbose()) {
cmdline += " -verbose";
}
if (System.getProperty("main.wrapper") != null) {
cmdline = MainWrapper.class.getName() + " " + System.getProperty("main.wrapper") + " " + cmdline;
if (System.getProperty("test.thread.factory") != null) {
cmdline = MainWrapper.class.getName() + " " + System.getProperty("test.thread.factory") + " " + cmdline;
}
connect.append(",main=" + cmdline.trim());

View File

@ -708,8 +708,8 @@ public class Binder extends DebugeeBinder {
String cmdline = classToExecute + " " + ArgumentHandler.joinArguments(rawArgs, quote);
if(System.getProperty("main.wrapper") != null) {
cmdline = MainWrapper.class.getName() + " " + System.getProperty("main.wrapper") + " " + cmdline;
if (System.getProperty("test.thread.factory") != null) {
cmdline = MainWrapper.class.getName() + " " + System.getProperty("test.thread.factory") + " " + cmdline;
}
arg = (Connector.StringArgument) arguments.get("main");
@ -749,7 +749,7 @@ public class Binder extends DebugeeBinder {
vmArgs = vmUserArgs;
}
boolean vthreadMode = "Virtual".equals(System.getProperty("main.wrapper"));
boolean vthreadMode = "Virtual".equals(System.getProperty("test.thread.factory"));
if (vthreadMode) {
/* Some tests need more carrier threads than the default provided. */
vmArgs += " -Djdk.virtualThreadScheduler.parallelism=15";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -251,7 +251,7 @@ abstract public class Debugee extends DebugeeProcess {
if (thread.name().equals(name))
return thread;
}
if ("Virtual".equals(System.getProperty("main.wrapper"))) {
if ("Virtual".equals(System.getProperty("test.thread.factory"))) {
return null;
}
throw new JDITestRuntimeException("** Thread IS NOT found ** : " + name);

View File

@ -31,7 +31,7 @@ import java.util.concurrent.ThreadFactory;
public class JDIThreadFactory {
private static ThreadFactory threadFactory = "Virtual".equals(System.getProperty("main.wrapper"))
private static ThreadFactory threadFactory = "Virtual".equals(System.getProperty("test.thread.factory"))
? virtualThreadFactory() : platformThreadFactory();
public static Thread newThread(NamedTask task) {

View File

@ -350,9 +350,9 @@ public class DebugeeBinder extends Log.Logger implements Finalizable {
args.add(jdwpArgs);
if(System.getProperty("main.wrapper") != null) {
if (System.getProperty("test.thread.factory") != null) {
args.add(MainWrapper.class.getName());
args.add(System.getProperty("main.wrapper"));
args.add(System.getProperty("test.thread.factory"));
}
if (classToExecute != null) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -225,7 +225,7 @@ public class RunParams {
iterations = Integer.parseInt(args[++i]);
}
// Allow to force using vthreads using wrapper property
if(System.getProperty("main.wrapper") != null && System.getProperty("main.wrapper").equals("Virtual")) {
if ("Virtual".equals(System.getProperty("test.thread.factory"))) {
useVirtualThreads = true;
}
printConfig(System.out);

View File

@ -26,20 +26,20 @@ import java.util.concurrent.ThreadFactory;
public class DebuggeeWrapper {
public static String PROPERTY_NAME = "main.wrapper";
public static String PROPERTY_NAME = "test.thread.factory";
private static final String OLD_MAIN_THREAD_NAME = "old-m-a-i-n";
private static ThreadFactory threadFactory = r -> new Thread(r);
private static final String wrapperName = System.getProperty(PROPERTY_NAME);
private static final String testThreadFactoryName = System.getProperty(PROPERTY_NAME);
public static String getWrapperName() {
return wrapperName;
public static String getTestThreadFactoryName() {
return testThreadFactoryName;
}
public static boolean isVirtual() {
return "Virtual".equals(wrapperName);
return "Virtual".equals(testThreadFactoryName);
}
public static Thread newThread(Runnable task) {
@ -85,7 +85,7 @@ public class DebuggeeWrapper {
tg.uncaughtThrowable.printStackTrace(System.out);
System.exit(1);
}
} else if (getWrapperName().equals("Kernel")) {
} else if (getTestThreadFactoryName().equals("Kernel")) {
MainThreadGroup tg = new MainThreadGroup();
Thread t = new Thread(tg, () -> {
try {

View File

@ -512,7 +512,7 @@ abstract public class TestScaffold extends TargetAdapter {
// argInfo.targetVMArgs : -Xss4M
// The result with wrapper enabled:
// argInfo.targetAppCommandLine : DebuggeeWrapper Frames2Targ
// argInfo.targetVMArgs : -Xss4M -Dmain.wrapper=Virtual
// argInfo.targetVMArgs : -Xss4M -Dtest.thread.factory=Virtual
boolean classNameParsed = false;
for (int i = 0; i < args.length; i++) {
String arg = args[i].trim();
@ -548,10 +548,10 @@ abstract public class TestScaffold extends TargetAdapter {
}
// Need to change args to run wrapper using command like 'DebuggeeWrapper <app-name>'
// and set property 'main.wrapper' so test could use DebuggeeWrapper.isVirtual() method
String mainWrapper = DebuggeeWrapper.getWrapperName();
if (mainWrapper != null && !argInfo.targetAppCommandLine.isEmpty()) {
argInfo.targetVMArgs += "-D" + DebuggeeWrapper.PROPERTY_NAME + "=" + mainWrapper;
// and set property 'test.thread.factory' so test could use DebuggeeWrapper.isVirtual() method
String testThreadFactoryName = DebuggeeWrapper.getTestThreadFactoryName();
if (testThreadFactoryName != null && !argInfo.targetAppCommandLine.isEmpty()) {
argInfo.targetVMArgs += "-D" + DebuggeeWrapper.PROPERTY_NAME + "=" + testThreadFactoryName;
argInfo.targetAppCommandLine = DebuggeeWrapper.class.getName() + ' ' + argInfo.targetAppCommandLine;
} else if ("true".equals(System.getProperty("test.enable.preview"))) {
// the test specified @enablePreview.

View File

@ -28,7 +28,7 @@ public class Virtual implements ThreadFactory {
static {
// This property is used by ProcessTools and some tests
try {
System.setProperty("main.wrapper", "Virtual");
System.setProperty("test.thread.factory", "Virtual");
} catch (Throwable t) {
// might be thrown by security manager
}

View File

@ -33,7 +33,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.Thread.State;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
@ -388,14 +387,14 @@ public final class ProcessTools {
}
/*
Convert arguments for tests running with virtual threads main wrapper
When test is executed with process wrapper the line is changed from
Convert arguments for tests running with virtual threads test thread factory.
When test is executed with test thread factory the line is changed from
java <jvm-args> <test-class> <test-args>
to
java <jvm-args> -Dmain.wrapper=<wrapper-name> jdk.test.lib.process.ProcessTools <wrapper-name> <test-class> <test-args>
java <jvm-args> -Dtest.thread.factory=<test-thread-factory-name> jdk.test.lib.process.ProcessTools <test-thread-factory-name> <test-class> <test-args>
*/
private static List<String> addMainWrapperArgs(String mainWrapper, List<String> command) {
private static List<String> addTestThreadFactoryArgs(String testThreadFactoryName, List<String> command) {
final List<String> unsupportedArgs = List.of(
"-jar", "-cp", "-classpath", "--class-path", "--describe-module", "-d",
@ -408,9 +407,9 @@ public final class ProcessTools {
ArrayList<String> args = new ArrayList<>();
boolean expectSecondArg = false;
boolean isWrapperClassAdded = false;
boolean isTestThreadFactoryAdded = false;
for (String cmd : command) {
if (isWrapperClassAdded) {
if (isTestThreadFactoryAdded) {
args.add(cmd);
continue;
}
@ -443,10 +442,10 @@ public final class ProcessTools {
}
// Some tests might check property to understand
// if virtual threads are tested
args.add("-Dmain.wrapper=" + mainWrapper);
args.add("-Dtest.thread.factory=" + testThreadFactoryName);
args.add("jdk.test.lib.process.ProcessTools");
args.add(mainWrapper);
isWrapperClassAdded = true;
args.add(testThreadFactoryName);
isTestThreadFactoryAdded = true;
args.add(cmd);
}
return args;
@ -471,9 +470,9 @@ public final class ProcessTools {
args.add(System.getProperty("java.class.path"));
}
String mainWrapper = System.getProperty("main.wrapper");
if (mainWrapper != null) {
args.addAll(addMainWrapperArgs(mainWrapper, Arrays.asList(command)));
String testThreadFactoryName = System.getProperty("test.thread.factory");
if (testThreadFactoryName != null) {
args.addAll(addTestThreadFactoryArgs(testThreadFactoryName, Arrays.asList(command)));
} else {
Collections.addAll(args, command);
}
@ -881,10 +880,10 @@ public final class ProcessTools {
public static final String OLD_MAIN_THREAD_NAME = "old-m-a-i-n";
// ProcessTools as a wrapper
// ProcessTools as a wrapper for test execution
// It executes method main in a separate virtual or platform thread
public static void main(String[] args) throws Throwable {
String wrapper = args[0];
String testThreadFactoryName = args[0];
String className = args[1];
String[] classArgs = new String[args.length - 2];
System.arraycopy(args, 2, classArgs, 0, args.length - 2);
@ -892,7 +891,7 @@ public final class ProcessTools {
Method mainMethod = c.getMethod("main", new Class[] { String[].class });
mainMethod.setAccessible(true);
if (wrapper.equals("Virtual")) {
if (testThreadFactoryName.equals("Virtual")) {
// MainThreadGroup used just as a container for exceptions
// when main is executed in virtual thread
MainThreadGroup tg = new MainThreadGroup();
@ -912,7 +911,7 @@ public final class ProcessTools {
if (tg.uncaughtThrowable != null) {
throw tg.uncaughtThrowable;
}
} else if (wrapper.equals("Kernel")) {
} else if (testThreadFactoryName.equals("Kernel")) {
MainThreadGroup tg = new MainThreadGroup();
Thread t = new Thread(tg, () -> {
try {