Skip to content

Commit

Permalink
8303773: Replace "main.wrapper" with "test.thread.factory" property i…
Browse files Browse the repository at this point in the history
…n test code

Backport-of: 89987dbf8789f166fe24e7facf5b8cc9a3c292c2
  • Loading branch information
GoeLin committed Apr 5, 2024
1 parent b80fb5e commit ccaa6d7
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -152,7 +152,7 @@ private boolean checkCommands(String[] reply) {

// 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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -90,7 +90,7 @@ protected void runCases() {
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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -186,7 +186,7 @@ private boolean checkCommands(String[] reply) {

// 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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -191,7 +191,7 @@ private void execTest() {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -134,8 +134,8 @@ private static void log3(String message) {
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);
Expand Down Expand Up @@ -253,10 +253,10 @@ private int runThis (String argv[], PrintStream out) {
* 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() );
Expand All @@ -277,7 +277,7 @@ private int runThis (String argv[], PrintStream out) {
if (s1.equals("Thread2"))
nThread2 += 1;
}
if (nMain != 1 && !usingVThreadWrapper) {
if (nMain != 1 && !usingVirtualTTF) {
log3("ERROR: # of 'main' threads != 1 : " + nMain);
expresult = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public Threadstop001a(String threadName) {

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -251,7 +251,7 @@ public void run() {
// 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";
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void main(String[] args) throws Throwable {
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 {
Expand Down
6 changes: 3 additions & 3 deletions test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private String[] makeJdbCmdLine (String classToExecute) {
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");
Expand Down Expand Up @@ -230,8 +230,8 @@ private String[] makeJdbCmdLine (String classToExecute) {
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());

Expand Down
6 changes: 3 additions & 3 deletions test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Binder.java
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ private Map<String,? extends Argument> setupLaunchingConnector(LaunchingConnecto

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");
Expand Down Expand Up @@ -749,7 +749,7 @@ private Map<String,? extends Argument> setupLaunchingConnector(LaunchingConnecto
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";
Expand Down
4 changes: 2 additions & 2 deletions test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Debugee.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -251,7 +251,7 @@ public ThreadReference threadByNameOrThrow(String name) throws JDITestRuntimeExc
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ public String[] makeCommandLineArgs(String classToExecute, String transportAddre

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) {
Expand Down
4 changes: 2 additions & 2 deletions test/hotspot/jtreg/vmTestbase/nsk/share/runner/RunParams.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -225,7 +225,7 @@ else if (args[i].equals("-iterations"))
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);
Expand Down
12 changes: 6 additions & 6 deletions test/jdk/com/sun/jdi/DebuggeeWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@

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) {
Expand Down Expand Up @@ -85,7 +85,7 @@ public static void main(String[] args) throws Throwable {
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 {
Expand Down
10 changes: 5 additions & 5 deletions test/jdk/com/sun/jdi/TestScaffold.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ private ArgInfo parseArgs(String args[]) {
// 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();
Expand Down Expand Up @@ -548,10 +548,10 @@ private ArgInfo parseArgs(String args[]) {
}

// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading

1 comment on commit ccaa6d7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.