From 89987dbf8789f166fe24e7facf5b8cc9a3c292c2 Mon Sep 17 00:00:00 2001 From: Leonid Mesnik Date: Tue, 3 Oct 2023 15:03:47 +0000 Subject: [PATCH] 8303773: Replace "main.wrapper" with "test.thread.factory" property in test code Reviewed-by: cjplummer, amenkov --- .../jdb/monitor/monitor001/monitor001.java | 4 +-- .../jdb/threads/threads003/threads003.java | 4 +-- .../unmonitor/unmonitor001/unmonitor001.java | 4 +-- .../jdi/StackFrame/_bounds_/bounds002.java | 4 +-- .../threads/threads001.java | 12 +++---- .../nsk/jdi/ThreadReference/stop/stop001.java | 2 +- .../jdi/ThreadReference/stop/stop001a.java | 2 +- .../nsk/jdi/ThreadReference/stop/stop002.java | 2 +- .../jdi/ThreadReference/stop/stop002t.java | 2 +- .../ThreadStartEvent/thread/thread001.java | 4 +-- .../vmTestbase/nsk/share/MainWrapper.java | 2 +- .../vmTestbase/nsk/share/jdb/Launcher.java | 6 ++-- .../vmTestbase/nsk/share/jdi/Binder.java | 6 ++-- .../vmTestbase/nsk/share/jdi/Debugee.java | 4 +-- .../nsk/share/jdi/JDIThreadFactory.java | 2 +- .../nsk/share/jpda/DebugeeBinder.java | 4 +-- .../nsk/share/runner/RunParams.java | 4 +-- test/jdk/com/sun/jdi/DebuggeeWrapper.java | 12 +++---- test/jdk/com/sun/jdi/TestScaffold.java | 10 +++--- .../src/share/classes/Virtual.java | 2 +- .../jdk/test/lib/process/ProcessTools.java | 33 +++++++++---------- 21 files changed, 62 insertions(+), 63 deletions(-) diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor001/monitor001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor001/monitor001.java index e3486a81b82..1fd1f8c328b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor001/monitor001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/monitor/monitor001/monitor001.java @@ -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"); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads003/threads003.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads003/threads003.java index e9caa83388c..4332eb69cf9 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads003/threads003.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/threads/threads003/threads003.java @@ -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. diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdb/unmonitor/unmonitor001/unmonitor001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdb/unmonitor/unmonitor001/unmonitor001.java index 3d53fc159ca..7d98824be73 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdb/unmonitor/unmonitor001/unmonitor001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdb/unmonitor/unmonitor001/unmonitor001.java @@ -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"); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/_bounds_/bounds002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/_bounds_/bounds002.java index 16308834cba..b4971ee03a2 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/_bounds_/bounds002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/StackFrame/_bounds_/bounds002.java @@ -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); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadGroupReference/threads/threads001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadGroupReference/threads/threads001.java index 09124c038e8..d8b773faf4d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadGroupReference/threads/threads001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadGroupReference/threads/threads001.java @@ -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; } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop001.java index dd451dc3007..5c04f30145c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop001.java @@ -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 diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop001a.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop001a.java index 9fb5a61113f..bd0136e55e2 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop001a.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop001a.java @@ -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; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop002.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop002.java index 55788e323b1..de8ee1df617 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop002.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop002.java @@ -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; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop002t.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop002t.java index 0b544905cb4..694485e608e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop002t.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadReference/stop/stop002t.java @@ -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); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadStartEvent/thread/thread001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadStartEvent/thread/thread001.java index 34c05b6cd04..0ec0b83b304 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadStartEvent/thread/thread001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ThreadStartEvent/thread/thread001.java @@ -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"; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java b/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java index c24ca5e813e..b84c975ffaa 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java @@ -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 { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Launcher.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Launcher.java index 3df8b11027d..0db3a6f718e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Launcher.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdb/Launcher.java @@ -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()); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Binder.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Binder.java index 46a115bbb4c..8897d07459c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Binder.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Binder.java @@ -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"; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Debugee.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Debugee.java index 81b15af1cac..dd6c8a1b82d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Debugee.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/Debugee.java @@ -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); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIThreadFactory.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIThreadFactory.java index 08b36dd55a1..4d8802ba1d2 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIThreadFactory.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIThreadFactory.java @@ -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) { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java index 79192149409..89a048a17cb 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java @@ -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) { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/runner/RunParams.java b/test/hotspot/jtreg/vmTestbase/nsk/share/runner/RunParams.java index a0bc096802c..e627816a6fc 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/runner/RunParams.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/runner/RunParams.java @@ -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); diff --git a/test/jdk/com/sun/jdi/DebuggeeWrapper.java b/test/jdk/com/sun/jdi/DebuggeeWrapper.java index 4904e3a394d..58563fb225a 100644 --- a/test/jdk/com/sun/jdi/DebuggeeWrapper.java +++ b/test/jdk/com/sun/jdi/DebuggeeWrapper.java @@ -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 { diff --git a/test/jdk/com/sun/jdi/TestScaffold.java b/test/jdk/com/sun/jdi/TestScaffold.java index b4b30855acc..e410ae2c76d 100644 --- a/test/jdk/com/sun/jdi/TestScaffold.java +++ b/test/jdk/com/sun/jdi/TestScaffold.java @@ -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 ' - // 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. diff --git a/test/jtreg_test_thread_factory/src/share/classes/Virtual.java b/test/jtreg_test_thread_factory/src/share/classes/Virtual.java index 80b0b59fa1a..174e36bf65a 100644 --- a/test/jtreg_test_thread_factory/src/share/classes/Virtual.java +++ b/test/jtreg_test_thread_factory/src/share/classes/Virtual.java @@ -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 } diff --git a/test/lib/jdk/test/lib/process/ProcessTools.java b/test/lib/jdk/test/lib/process/ProcessTools.java index e49b17febf6..b97d93bb476 100644 --- a/test/lib/jdk/test/lib/process/ProcessTools.java +++ b/test/lib/jdk/test/lib/process/ProcessTools.java @@ -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 to - java -Dmain.wrapper= jdk.test.lib.process.ProcessTools + java -Dtest.thread.factory= jdk.test.lib.process.ProcessTools */ - private static List addMainWrapperArgs(String mainWrapper, List command) { + private static List addTestThreadFactoryArgs(String testThreadFactoryName, List command) { final List unsupportedArgs = List.of( "-jar", "-cp", "-classpath", "--class-path", "--describe-module", "-d", @@ -408,9 +407,9 @@ public final class ProcessTools { ArrayList 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 {