The JStackStressTest.java, JShellHeapDumpTest, and HeapDumpTestWithActiveProcess launch the target JVM without any arguments. The end result is that we don't always get the testing we expect. For example, proper SA testing is heavily depending on the GC of the targetVM, but it will always end up being the default GC (G1). So when you run a test with -XX:+UseZGC, the test will be run with ZGC, jhsdb will be run with ZGC, but the JVM that jhsdb is debugging will use G1, and it is in fact the debuggee that we really want running with ZGC. We don't care so much about what GC is used for the test and jhsdb.
Using JStackStressTest.java as an example, we can see the problem here:
ProcessBuilder pb = new ProcessBuilder(JDKToolFinder.getTestJDKTool("jshell"));
jShellProcess = ProcessTools.startProcess("JShell", pb);
We should be using the JDKToolLauncher class. A working example can be found in ClhsdbLauncher.java:
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
launcher.addVMArgs(Utils.getTestJavaOpts());
launcher.addToolArg("clhsdb");
launcher.addToolArg("--core=" + coreFileName);
launcher.addToolArg("--exe=" + JDKToolFinder.getTestJDKTool("java"));
ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
I think what will work for JStackStressTest.java is (this is completely untested):
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jshell");
launcher.addVMArgs(Utils.getTestJavaOpts());
ProcessBuilder pb = new ProcessBuilder(launcher.getCommand());
jShellProcess = ProcessTools.startProcess("JShell", pb);
This will get -XX:+UseZGC passed to the debuggee process. Note if there are any options we want filtered out, we can do something like the following:
launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));