From a726aca6de59f038bd1a10ab07f585ee5962de4c Mon Sep 17 00:00:00 2001
From: Daniil Titov <dtitov@openjdk.org>
Date: Tue, 12 May 2020 09:45:24 -0700
Subject: [PATCH] 8242009: Review setting test.java/vm.opts in jcmd/jhsdb and
 debugger in serviceability tests

Reviewed-by: cjplummer
---
 .../serviceability/attach/ConcAttachTest.java |  4 +-
 .../attach/RemovingUnixDomainSocketTest.java  |  6 +-
 .../serviceability/sa/CDSJMapClstats.java     |  5 +-
 .../serviceability/sa/ClhsdbDumpclass.java    |  4 +-
 .../sa/ClhsdbJstackXcompStress.java           |  6 +-
 .../serviceability/sa/ClhsdbLauncher.java     |  6 +-
 .../sa/DeadlockDetectionTest.java             |  3 +-
 .../sa/JhsdbThreadInfoTest.java               | 19 +----
 .../sa/TestHeapDumpForInvokeDynamic.java      |  9 +--
 .../sa/TestJhsdbJstackLock.java               | 25 +-----
 .../sa/TestJhsdbJstackMixed.java              |  1 +
 .../jtreg/serviceability/sa/TestJmapCore.java |  3 +-
 .../jtreg/serviceability/sa/TestSysProps.java |  8 +-
 .../sa/jmap-hprof/JMapHProfLargeHeapTest.java |  3 +-
 .../sa/sadebugd/DebugdConnectTest.java        | 11 +--
 .../sa/sadebugd/DebugdUtils.java              |  4 +-
 .../sa/sadebugd/SADebugDTest.java             |  1 +
 .../tmtools/jstack/JstackThreadTest.java      |  3 +-
 test/jdk/sun/tools/jcmd/JcmdBase.java         |  4 +-
 .../tools/jcmd/JcmdOutputEncodingTest.java    |  4 +-
 test/jdk/sun/tools/jcmd/TestJcmdDefaults.java |  4 +-
 test/jdk/sun/tools/jcmd/TestJcmdSanity.java   |  4 +-
 .../sun/tools/jhsdb/BasicLauncherTest.java    |  2 +-
 test/jdk/sun/tools/jhsdb/HeapDumpTest.java    |  2 +
 .../sun/tools/jhsdb/JShellHeapDumpTest.java   |  2 +
 test/jdk/sun/tools/jinfo/BasicJInfoTest.java  |  4 +-
 test/jdk/sun/tools/jinfo/JInfoTest.java       |  2 +
 test/jdk/sun/tools/jmap/BasicJMapTest.java    |  4 +-
 test/jdk/sun/tools/jps/JpsHelper.java         |  1 +
 .../jdk/sun/tools/jstack/BasicJStackTest.java |  4 +-
 .../tools/jstack/DeadlockDetectionTest.java   |  1 +
 test/jdk/sun/tools/jstat/JStatInterval.java   |  4 +-
 test/jdk/sun/tools/jstatd/JstatdTest.java     |  8 +-
 .../jdk/sun/tools/jstatd/TestJstatdUsage.java |  2 +
 test/lib/jdk/test/lib/JDKToolLauncher.java    | 21 ++++-
 .../jdk/test/lib/process/OutputAnalyzer.java  | 76 ++++++++++++++-----
 36 files changed, 161 insertions(+), 109 deletions(-)

diff --git a/test/hotspot/jtreg/serviceability/attach/ConcAttachTest.java b/test/hotspot/jtreg/serviceability/attach/ConcAttachTest.java
index 53ac66b2db5..db2ea216b35 100644
--- a/test/hotspot/jtreg/serviceability/attach/ConcAttachTest.java
+++ b/test/hotspot/jtreg/serviceability/attach/ConcAttachTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2020, 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
@@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit;
 import com.sun.tools.attach.VirtualMachine;
 import com.sun.tools.attach.AttachNotSupportedException;
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.apps.LingeredApp;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.JDKToolLauncher;
@@ -80,6 +81,7 @@ public class ConcAttachTest implements Runnable {
 
     private static void checkAttachListenerThread() throws InterruptedException, IOException {
         JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");
+        jcmd.addVMArgs(Utils.getTestJavaOpts());
         jcmd.addToolArg(strPID);
         jcmd.addToolArg("Thread.print");
 
diff --git a/test/hotspot/jtreg/serviceability/attach/RemovingUnixDomainSocketTest.java b/test/hotspot/jtreg/serviceability/attach/RemovingUnixDomainSocketTest.java
index fafbf6e4d84..2fd36be8840 100644
--- a/test/hotspot/jtreg/serviceability/attach/RemovingUnixDomainSocketTest.java
+++ b/test/hotspot/jtreg/serviceability/attach/RemovingUnixDomainSocketTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2020, 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
@@ -32,6 +32,7 @@
 import java.io.IOException;
 import java.nio.file.Path;
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.apps.LingeredApp;
 import jdk.test.lib.JDKToolLauncher;
 import jdk.test.lib.process.OutputAnalyzer;
@@ -40,6 +41,7 @@ public class RemovingUnixDomainSocketTest {
 
     private static void runJCmd(long pid) throws InterruptedException, IOException {
         JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");
+        jcmd.addVMArgs(Utils.getTestJavaOpts());
         jcmd.addToolArg(Long.toString(pid));
         jcmd.addToolArg("VM.version");
 
@@ -53,7 +55,7 @@ public class RemovingUnixDomainSocketTest {
         System.out.println(out.getStdout());
         System.err.println(out.getStderr());
 
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
     }
 
     public static void main(String... args) throws Exception {
diff --git a/test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java b/test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java
index 88fd334dcae..8273132963d 100644
--- a/test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java
+++ b/test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java
@@ -30,9 +30,9 @@
  * @run main/othervm/timeout=2400 CDSJMapClstats
  */
 
-import java.util.List;
-import java.util.Arrays;
 import java.util.stream.Collectors;
+
+import jdk.test.lib.Utils;
 import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.cds.CDSOptions;
 import jdk.test.lib.apps.LingeredApp;
@@ -46,6 +46,7 @@ public class CDSJMapClstats {
     private static void runClstats(long lingeredAppPid) throws Exception {
 
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addToolArg("jmap");
         launcher.addToolArg("--clstats");
         launcher.addToolArg("--pid");
diff --git a/test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java b/test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java
index 635161020fd..801a8646e8b 100644
--- a/test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java
+++ b/test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java
@@ -27,11 +27,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.apps.LingeredApp;
 import jdk.test.lib.JDKToolLauncher;
-import jdk.test.lib.JDKToolFinder;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.SA.SATestUtils;
 import jtreg.SkippedException;
 
 /**
@@ -70,6 +69,7 @@ public class ClhsdbDumpclass {
 
             // Run javap on the generated class file to make sure it's valid.
             JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("javap");
+            launcher.addVMArgs(Utils.getTestJavaOpts());
             launcher.addToolArg(APP_DOT_CLASSNAME);
             System.out.println("> javap " + APP_DOT_CLASSNAME);
             List<String> cmdStringList = Arrays.asList(launcher.getCommand());
diff --git a/test/hotspot/jtreg/serviceability/sa/ClhsdbJstackXcompStress.java b/test/hotspot/jtreg/serviceability/sa/ClhsdbJstackXcompStress.java
index 05a6bfcf24a..385a4c56bda 100644
--- a/test/hotspot/jtreg/serviceability/sa/ClhsdbJstackXcompStress.java
+++ b/test/hotspot/jtreg/serviceability/sa/ClhsdbJstackXcompStress.java
@@ -22,11 +22,8 @@
  * questions.
  */
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 import jdk.test.lib.JDKToolLauncher;
@@ -61,6 +58,7 @@ public class ClhsdbJstackXcompStress {
         for (int i = 0; i < MAX_ITERATIONS; i++) {
             JDKToolLauncher launcher = JDKToolLauncher
                     .createUsingTestJDK("jhsdb");
+            launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
             launcher.addToolArg("jstack");
             launcher.addToolArg("--pid");
             launcher.addToolArg(Long.toString(app.getPid()));
@@ -76,7 +74,7 @@ public class ClhsdbJstackXcompStress {
                 System.err.println(out.getStderr());
             }
 
-            out.stderrShouldBeEmpty(); // NPE's are reported on the err stream
+            out.stderrShouldBeEmptyIgnoreVMWarnings();
             out.stdoutShouldNotContain("Error occurred during stack walking:");
             out.stdoutShouldContain(LingeredAppWithRecComputation.THREAD_NAME);
             List<String> stdoutList = Arrays.asList(out.getStdout().split("\\R"));
diff --git a/test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java b/test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java
index 787293db15d..49388f5d526 100644
--- a/test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java
+++ b/test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java
@@ -25,10 +25,8 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
 import java.util.Map;
-import java.util.Arrays;
 
-import jdk.test.lib.apps.LingeredApp;
-import jdk.test.lib.Platform;
+import jdk.test.lib.Utils;
 import jdk.test.lib.JDKToolLauncher;
 import jdk.test.lib.JDKToolFinder;
 import jdk.test.lib.process.OutputAnalyzer;
@@ -56,6 +54,7 @@ public class ClhsdbLauncher {
     private void attach(long lingeredAppPid)
         throws IOException {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addToolArg("clhsdb");
         if (lingeredAppPid != -1) {
             launcher.addToolArg("--pid=" + Long.toString(lingeredAppPid));
@@ -75,6 +74,7 @@ public class ClhsdbLauncher {
         throws IOException {
 
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addToolArg("clhsdb");
         launcher.addToolArg("--core=" + coreFileName);
         launcher.addToolArg("--exe=" + JDKToolFinder.getTestJDKTool("java"));
diff --git a/test/hotspot/jtreg/serviceability/sa/DeadlockDetectionTest.java b/test/hotspot/jtreg/serviceability/sa/DeadlockDetectionTest.java
index 95c4a2fd152..969c366ed3a 100644
--- a/test/hotspot/jtreg/serviceability/sa/DeadlockDetectionTest.java
+++ b/test/hotspot/jtreg/serviceability/sa/DeadlockDetectionTest.java
@@ -31,8 +31,6 @@
  * @run main DeadlockDetectionTest
  */
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.stream.Collectors;
 
 import jdk.test.lib.apps.LingeredApp;
@@ -51,6 +49,7 @@ public class DeadlockDetectionTest {
 
     private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addToolArg("jstack");
         if (toolArgs != null) {
             for (String toolArg : toolArgs) {
diff --git a/test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java b/test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java
index 9e683cf62d9..a5cdb6fb177 100644
--- a/test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java
+++ b/test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java
@@ -21,14 +21,8 @@
  * questions.
  */
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 import jdk.test.lib.apps.LingeredApp;
 import jdk.test.lib.JDKToolLauncher;
-import jdk.test.lib.Platform;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.SA.SATestUtils;
 import jdk.test.lib.Utils;
@@ -50,6 +44,7 @@ public class JhsdbThreadInfoTest {
             System.out.println("Started LingeredApp with pid " + app.getPid());
 
             JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+            jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());
 
             jhsdbLauncher.addToolArg("jstack");
             jhsdbLauncher.addToolArg("--pid");
@@ -73,17 +68,7 @@ public class JhsdbThreadInfoTest {
             out.shouldNotContain(" prio=0 ");
             out.shouldNotContain("   java.lang.Thread.State: UNKNOWN");
 
-            // stderr should be empty except for VM warnings.
-            if (!out.getStderr().isEmpty()) {
-                List<String> lines = Arrays.asList(out.getStderr().split("(\\r\\n|\\n|\\r)"));
-                Pattern p = Pattern.compile(".*VM warning.*");
-                for (String line : lines) {
-                    Matcher m = p.matcher(line);
-                    if (!m.matches()) {
-                        throw new RuntimeException("Stderr has output other than VM warnings");
-                    }
-                }
-            }
+            out.stderrShouldBeEmptyIgnoreVMWarnings();
 
             System.out.println("Test Completed");
         } catch (Exception ex) {
diff --git a/test/hotspot/jtreg/serviceability/sa/TestHeapDumpForInvokeDynamic.java b/test/hotspot/jtreg/serviceability/sa/TestHeapDumpForInvokeDynamic.java
index 80571f7dc21..028e25fd7e4 100644
--- a/test/hotspot/jtreg/serviceability/sa/TestHeapDumpForInvokeDynamic.java
+++ b/test/hotspot/jtreg/serviceability/sa/TestHeapDumpForInvokeDynamic.java
@@ -21,28 +21,20 @@
  * questions.
  */
 
-import java.util.ArrayList;
-import java.util.List;
 import java.io.File;
-import java.nio.file.Files;
 import java.io.IOException;
 import java.io.BufferedInputStream;
 import java.util.stream.Collectors;
 import java.io.FileInputStream;
 
-import sun.jvm.hotspot.HotSpotAgent;
-import sun.jvm.hotspot.debugger.*;
 
 import jdk.test.lib.apps.LingeredApp;
 import jdk.test.lib.Asserts;
 import jdk.test.lib.JDKToolLauncher;
-import jdk.test.lib.JDKToolFinder;
-import jdk.test.lib.Platform;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.SA.SATestUtils;
 import jdk.test.lib.Utils;
-import jdk.test.lib.hprof.HprofParser;
 import jdk.test.lib.hprof.parser.HprofReader;
 import jdk.test.lib.hprof.parser.PositionDataInputStream;
 import jdk.test.lib.hprof.model.Snapshot;
@@ -91,6 +83,7 @@ public class TestHeapDumpForInvokeDynamic {
                                             long lingeredAppPid) throws Exception {
 
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addToolArg("jmap");
         launcher.addToolArg("--binaryheap");
         launcher.addToolArg("--dumpfile");
diff --git a/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java
index 9f9dc61703c..60d990d76fe 100644
--- a/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java
+++ b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java
@@ -21,20 +21,9 @@
  * questions.
  */
 
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 import jdk.test.lib.apps.LingeredApp;
-import jdk.test.lib.Asserts;
 import jdk.test.lib.JDKToolLauncher;
-import jdk.test.lib.Platform;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.SA.SATestUtils;
 import jdk.test.lib.Utils;
 
@@ -57,6 +46,7 @@ public class TestJhsdbJstackLock {
             System.out.println ("Started LingeredApp with pid " + app.getPid());
 
             JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+            launcher.addVMArgs(Utils.getTestJavaOpts());
             launcher.addToolArg("jstack");
             launcher.addToolArg("--pid");
             launcher.addToolArg(Long.toString(app.getPid()));
@@ -75,18 +65,7 @@ public class TestJhsdbJstackLock {
             out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Thread\\)$");
             out.shouldMatch("^\\s+- locked <0x[0-9a-f]+> \\(a java\\.lang\\.Class for int\\)$");
 
-            // stderr should be empty except for VM warnings.
-            if (!out.getStderr().isEmpty()) {
-                List<String> lines = Arrays.asList(out.getStderr().split("(\\r\\n|\\n|\\r)"));
-                Pattern p = Pattern.compile(".*VM warning.*");
-                for (String line : lines) {
-                    Matcher m = p.matcher(line);
-                    if (!m.matches()) {
-                        throw new RuntimeException("Stderr has output other than VM warnings");
-                    }
-                }
-            }
-
+            out.stderrShouldBeEmptyIgnoreVMWarnings();
 
             System.out.println("Test Completed");
         } finally {
diff --git a/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java
index e5db380e1fb..149a7028be8 100644
--- a/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java
+++ b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java
@@ -132,6 +132,7 @@ public class TestJhsdbJstackMixed {
         for (int i = 0; i < MAX_ITERATIONS; i++) {
             JDKToolLauncher launcher = JDKToolLauncher
                     .createUsingTestJDK("jhsdb");
+            launcher.addVMArgs(Utils.getTestJavaOpts());
             launcher.addToolArg("jstack");
             launcher.addToolArg("--mixed");
             launcher.addToolArg("--pid");
diff --git a/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java b/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java
index e236db618d7..1c5780a1957 100644
--- a/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java
+++ b/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, 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
@@ -120,6 +120,7 @@ public class TestJmapCore {
 
         File dumpFile = new File("heap.hprof");
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addToolArg("jmap");
         launcher.addToolArg("--binaryheap");
         launcher.addToolArg("--dumpfile=" + dumpFile);
diff --git a/test/hotspot/jtreg/serviceability/sa/TestSysProps.java b/test/hotspot/jtreg/serviceability/sa/TestSysProps.java
index 524a9c8dfc0..0f8e05bb994 100644
--- a/test/hotspot/jtreg/serviceability/sa/TestSysProps.java
+++ b/test/hotspot/jtreg/serviceability/sa/TestSysProps.java
@@ -21,10 +21,10 @@
  * questions.
  */
 
-import java.io.OutputStream;
 import java.util.Arrays;
 import java.util.List;
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.apps.LingeredApp;
 import jdk.test.lib.JDKToolLauncher;
 import jdk.test.lib.Platform;
@@ -58,7 +58,9 @@ public class TestSysProps {
     public static void countProps(String[] propLines, int expectedCount, String cmdName) {
         int numProps = 0;
         for (String propLine : propLines) {
-            if (propLine.indexOf("=") != -1) {
+            // Ignore the debug output lines (they start with '[' and printed
+            // in the output when the test is run with -Xlog VM option).
+            if (!propLine.startsWith("[") && propLine.indexOf("=") != -1) {
                 numProps++;
             }
         }
@@ -79,6 +81,7 @@ public class TestSysProps {
             // Get properties using the SA version of jinfo
 
             JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+            jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());
             jhsdbLauncher.addToolArg("jinfo");
             jhsdbLauncher.addToolArg("--sysprops");
             jhsdbLauncher.addToolArg("--pid");
@@ -99,6 +102,7 @@ public class TestSysProps {
             // Get the properties using the Attach API version of jinfo
 
             JDKToolLauncher jinfoLauncher = JDKToolLauncher.createUsingTestJDK("jinfo");
+            jinfoLauncher.addVMArgs(Utils.getTestJavaOpts());
             jinfoLauncher.addToolArg("-sysprops");
             jinfoLauncher.addToolArg(Long.toString(app.getPid()));
 
diff --git a/test/hotspot/jtreg/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java b/test/hotspot/jtreg/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java
index 7f0bc7c21ef..ecadb102909 100644
--- a/test/hotspot/jtreg/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java
+++ b/test/hotspot/jtreg/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java
@@ -33,7 +33,7 @@ import java.util.Scanner;
 
 import jdk.test.lib.Asserts;
 import jdk.test.lib.JDKToolLauncher;
-import jdk.test.lib.Platform;
+import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.SA.SATestUtils;
@@ -98,6 +98,7 @@ public class JMapHProfLargeHeapTest {
 
             JDKToolLauncher jMapLauncher = JDKToolLauncher
                     .createUsingTestJDK("jhsdb");
+            jMapLauncher.addVMArgs(Utils.getTestJavaOpts());
             jMapLauncher.addToolArg("jmap");
             jMapLauncher.addToolArg("--binaryheap");
             jMapLauncher.addToolArg("--pid");
diff --git a/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdConnectTest.java b/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdConnectTest.java
index 4de2281f134..75d12e59e50 100644
--- a/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdConnectTest.java
+++ b/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdConnectTest.java
@@ -37,6 +37,7 @@ import java.io.IOException;
 
 import jdk.test.lib.JDKToolLauncher;
 import jdk.test.lib.SA.SATestUtils;
+import jdk.test.lib.Utils;
 import jdk.test.lib.apps.LingeredApp;
 import jdk.test.lib.process.OutputAnalyzer;
 
@@ -45,6 +46,7 @@ public class DebugdConnectTest {
 
     private static OutputAnalyzer runJHSDB(String command, String id) throws IOException, InterruptedException {
         JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        jhsdbLauncher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
         jhsdbLauncher.addToolArg(command);
         jhsdbLauncher.addToolArg("--connect");
         if (id != null) {
@@ -68,7 +70,7 @@ public class DebugdConnectTest {
         OutputAnalyzer out = runJHSDB("jstack", id);
 
         out.shouldContain("LingeredApp");
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
         out.shouldHaveExitValue(0);
     }
 
@@ -76,7 +78,7 @@ public class DebugdConnectTest {
         OutputAnalyzer out = runJHSDB("jmap", id);
 
         out.shouldContain("JVM version is");
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
         out.shouldHaveExitValue(0);
     }
 
@@ -84,7 +86,7 @@ public class DebugdConnectTest {
         OutputAnalyzer out = runJHSDB("jinfo", id);
 
         out.shouldContain("Java System Properties:");
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
         out.shouldHaveExitValue(0);
     }
 
@@ -92,7 +94,7 @@ public class DebugdConnectTest {
         OutputAnalyzer out = runJHSDB("jsnap", id);
 
         out.shouldContain("java.vm.name=");
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
         out.shouldHaveExitValue(0);
     }
 
@@ -128,5 +130,4 @@ public class DebugdConnectTest {
         }
 
     }
-
 }
diff --git a/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdUtils.java b/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdUtils.java
index 39bcf023843..7c6c4d8c749 100644
--- a/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdUtils.java
+++ b/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdUtils.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2020, 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
@@ -26,6 +26,7 @@ import java.io.InputStreamReader;
 import java.io.IOException;
 
 import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Utils;
 
 
 public class DebugdUtils {
@@ -43,6 +44,7 @@ public class DebugdUtils {
 
     public void attach(long pid) throws IOException {
         JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        jhsdbLauncher.addVMArgs(Utils.getTestJavaOpts());
         jhsdbLauncher.addToolArg("debugd");
         jhsdbLauncher.addToolArg("--pid");
         jhsdbLauncher.addToolArg(Long.toString(pid));
diff --git a/test/hotspot/jtreg/serviceability/sa/sadebugd/SADebugDTest.java b/test/hotspot/jtreg/serviceability/sa/sadebugd/SADebugDTest.java
index 89117c690c3..eb488c957d2 100644
--- a/test/hotspot/jtreg/serviceability/sa/sadebugd/SADebugDTest.java
+++ b/test/hotspot/jtreg/serviceability/sa/sadebugd/SADebugDTest.java
@@ -94,6 +94,7 @@ public class SADebugDTest {
                 testResult = false;
                 portInUse = false;
                 JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+                jhsdbLauncher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
                 jhsdbLauncher.addToolArg("debugd");
                 jhsdbLauncher.addToolArg("--pid");
                 jhsdbLauncher.addToolArg(Long.toString(app.getPid()));
diff --git a/test/hotspot/jtreg/serviceability/tmtools/jstack/JstackThreadTest.java b/test/hotspot/jtreg/serviceability/tmtools/jstack/JstackThreadTest.java
index 2de069b1b21..e09dfd45dad 100644
--- a/test/hotspot/jtreg/serviceability/tmtools/jstack/JstackThreadTest.java
+++ b/test/hotspot/jtreg/serviceability/tmtools/jstack/JstackThreadTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2020, 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
@@ -69,6 +69,7 @@ public class JstackThreadTest {
     thread.start();
     ProcessBuilder processBuilder = new ProcessBuilder();
     JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
+    launcher.addVMArgs(jdk.test.lib.Utils.getTestJavaOpts());
     launcher.addToolArg("-l");
     launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
     processBuilder.command(launcher.getCommand());
diff --git a/test/jdk/sun/tools/jcmd/JcmdBase.java b/test/jdk/sun/tools/jcmd/JcmdBase.java
index 2e4c8eaa1eb..b0315673133 100644
--- a/test/jdk/sun/tools/jcmd/JcmdBase.java
+++ b/test/jdk/sun/tools/jcmd/JcmdBase.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2020, 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
@@ -23,6 +23,7 @@
 
 import java.util.Arrays;
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.JDKToolLauncher;
@@ -95,6 +96,7 @@ public final class JcmdBase {
     private static final OutputAnalyzer jcmd(boolean requestToCurrentProcess,
             String[] vmArgs, String[] jcmdArgs) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         if (vmArgs != null) {
             for (String vmArg : vmArgs) {
                 launcher.addVMArg(vmArg);
diff --git a/test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java b/test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java
index e5c267d11ea..45ba91f2f7e 100644
--- a/test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java
+++ b/test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2020, 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
@@ -25,6 +25,7 @@ import java.util.Arrays;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.JDKToolLauncher;
@@ -48,6 +49,7 @@ public class JcmdOutputEncodingTest {
         Thread.currentThread().setName(marker);
 
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addVMArg("-Dfile.encoding=" + cs);
         launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
         launcher.addToolArg("Thread.print");
diff --git a/test/jdk/sun/tools/jcmd/TestJcmdDefaults.java b/test/jdk/sun/tools/jcmd/TestJcmdDefaults.java
index 6e57ddeac34..b0f369b55e3 100644
--- a/test/jdk/sun/tools/jcmd/TestJcmdDefaults.java
+++ b/test/jdk/sun/tools/jcmd/TestJcmdDefaults.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2020, 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 TestJcmdDefaults {
      * @param output The generated output from the jcmd.
      */
     private static void matchListedProcesses(OutputAnalyzer output) {
-        output.shouldMatchByLine(JCMD_LIST_REGEX);
+        output.shouldMatchByLineIgnoreVMWarnings(JCMD_LIST_REGEX);
     }
 
     private static void verifyOutputAgainstFile(OutputAnalyzer output) throws IOException {
diff --git a/test/jdk/sun/tools/jcmd/TestJcmdSanity.java b/test/jdk/sun/tools/jcmd/TestJcmdSanity.java
index d3806fbfd2b..6e2343ee08a 100644
--- a/test/jdk/sun/tools/jcmd/TestJcmdSanity.java
+++ b/test/jdk/sun/tools/jcmd/TestJcmdSanity.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2020, 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 TestJcmdSanity {
      * @throws Exception
      */
     private static void matchPerfCounters(OutputAnalyzer output) {
-        output.shouldMatchByLineFrom(PERF_COUNTER_REGEX,
+        output.shouldMatchByLineIgnoreVMWarnings(PERF_COUNTER_REGEX, null,
                 PERF_COUNTER_REGEX);
     }
 
diff --git a/test/jdk/sun/tools/jhsdb/BasicLauncherTest.java b/test/jdk/sun/tools/jhsdb/BasicLauncherTest.java
index 06a239735d1..401dfe6ca31 100644
--- a/test/jdk/sun/tools/jhsdb/BasicLauncherTest.java
+++ b/test/jdk/sun/tools/jhsdb/BasicLauncherTest.java
@@ -63,7 +63,7 @@ public class BasicLauncherTest {
         else {
             launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
         }
-
+        launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
         return launcher;
     }
 
diff --git a/test/jdk/sun/tools/jhsdb/HeapDumpTest.java b/test/jdk/sun/tools/jhsdb/HeapDumpTest.java
index 3222685f14f..69b46b684a3 100644
--- a/test/jdk/sun/tools/jhsdb/HeapDumpTest.java
+++ b/test/jdk/sun/tools/jhsdb/HeapDumpTest.java
@@ -38,6 +38,7 @@ import java.io.File;
 import java.util.List;
 import java.util.Arrays;
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.apps.LingeredApp;
 import jdk.test.lib.hprof.parser.HprofReader;
 import jdk.test.lib.JDKToolLauncher;
@@ -65,6 +66,7 @@ public class HeapDumpTest {
             System.out.println(theApp.\u00CB);
             System.out.println("Starting " + toolArgs.get(0) + " against " + theApp.getPid());
             JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+            launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
 
             for (String cmd : toolArgs) {
                 launcher.addToolArg(cmd);
diff --git a/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java b/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java
index 78cb35be400..6c16ec2d293 100644
--- a/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java
+++ b/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java
@@ -38,6 +38,7 @@ import java.util.List;
 import java.util.Arrays;
 import java.util.Map;
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.hprof.parser.HprofReader;
 import jdk.test.lib.JDKToolLauncher;
 import jdk.test.lib.JDKToolFinder;
@@ -61,6 +62,7 @@ public class JShellHeapDumpTest {
 
             System.out.println("Starting " + toolArgs.get(0) + " against " + jShellPID);
             JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+            launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
 
             for (String cmd : toolArgs) {
                 launcher.addToolArg(cmd);
diff --git a/test/jdk/sun/tools/jinfo/BasicJInfoTest.java b/test/jdk/sun/tools/jinfo/BasicJInfoTest.java
index b1ddf8b8f6b..ae1124982c2 100644
--- a/test/jdk/sun/tools/jinfo/BasicJInfoTest.java
+++ b/test/jdk/sun/tools/jinfo/BasicJInfoTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2020, 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
@@ -24,6 +24,7 @@
 import java.util.Arrays;
 
 import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 
@@ -70,6 +71,7 @@ public class BasicJInfoTest {
 
     private static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         if (toolArgs != null) {
             for (String toolArg : toolArgs) {
                 launcher.addToolArg(toolArg);
diff --git a/test/jdk/sun/tools/jinfo/JInfoTest.java b/test/jdk/sun/tools/jinfo/JInfoTest.java
index 0534843cdb9..bea0e4b796c 100644
--- a/test/jdk/sun/tools/jinfo/JInfoTest.java
+++ b/test/jdk/sun/tools/jinfo/JInfoTest.java
@@ -29,6 +29,7 @@ import java.util.regex.Pattern;
 import java.io.IOException;
 
 import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.apps.LingeredApp;
@@ -114,6 +115,7 @@ public class JInfoTest {
 
     private static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         if (toolArgs != null) {
             for (String toolArg : toolArgs) {
                 launcher.addToolArg(toolArg);
diff --git a/test/jdk/sun/tools/jmap/BasicJMapTest.java b/test/jdk/sun/tools/jmap/BasicJMapTest.java
index 88d95164087..a4c240a6bf6 100644
--- a/test/jdk/sun/tools/jmap/BasicJMapTest.java
+++ b/test/jdk/sun/tools/jmap/BasicJMapTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2020, 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
@@ -28,6 +28,7 @@ import java.io.File;
 import java.util.Arrays;
 
 import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Utils;
 import jdk.test.lib.hprof.HprofParser;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
@@ -179,6 +180,7 @@ public class BasicJMapTest {
 
     private static OutputAnalyzer jmap(String... toolArgs) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jmap");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         if (toolArgs != null) {
             for (String toolArg : toolArgs) {
                 launcher.addToolArg(toolArg);
diff --git a/test/jdk/sun/tools/jps/JpsHelper.java b/test/jdk/sun/tools/jps/JpsHelper.java
index a186c0d80b2..c70b3790182 100644
--- a/test/jdk/sun/tools/jps/JpsHelper.java
+++ b/test/jdk/sun/tools/jps/JpsHelper.java
@@ -152,6 +152,7 @@ public final class JpsHelper {
      */
     public static OutputAnalyzer jps(List<String> vmArgs, List<String> toolArgs) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
+        launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-XX:+UsePerfData"));
         launcher.addVMArg("-XX:+UsePerfData");
         if (vmArgs != null) {
             for (String vmArg : vmArgs) {
diff --git a/test/jdk/sun/tools/jstack/BasicJStackTest.java b/test/jdk/sun/tools/jstack/BasicJStackTest.java
index aeadedcfa54..23559f85700 100644
--- a/test/jdk/sun/tools/jstack/BasicJStackTest.java
+++ b/test/jdk/sun/tools/jstack/BasicJStackTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2020, 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
@@ -25,6 +25,7 @@ import java.util.Arrays;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.JDKToolLauncher;
@@ -70,6 +71,7 @@ public class BasicJStackTest {
         Charset cs = StandardCharsets.UTF_8;
         Thread.currentThread().setName(marker);
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
+        launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-XX:+UsePerfData"));
         launcher.addVMArg("-XX:+UsePerfData");
         launcher.addVMArg("-Dfile.encoding=" + cs);
         if (toolArgs != null) {
diff --git a/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java b/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java
index 7761474bab3..80eda6fc091 100644
--- a/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java
+++ b/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java
@@ -50,6 +50,7 @@ public class DeadlockDetectionTest {
 
     private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
+        launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-XX:+UsePerfData"));
         launcher.addVMArg("-XX:+UsePerfData");
         if (toolArgs != null) {
             for (String toolArg : toolArgs) {
diff --git a/test/jdk/sun/tools/jstat/JStatInterval.java b/test/jdk/sun/tools/jstat/JStatInterval.java
index edd7a788752..c3ff9404745 100644
--- a/test/jdk/sun/tools/jstat/JStatInterval.java
+++ b/test/jdk/sun/tools/jstat/JStatInterval.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2020, 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
@@ -34,6 +34,7 @@
  */
 
 import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Utils;
 import jdk.test.lib.process.ProcessTools;
 
 import java.util.concurrent.TimeUnit;
@@ -87,6 +88,7 @@ public class JStatInterval {
 
         String pidStr = String.valueOf(app.pid());
         JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jstat");
+        l.addVMArgs(Utils.getTestJavaOpts());
         l.addToolArg("-compiler");
         l.addToolArg(pidStr);
         l.addToolArg("100");
diff --git a/test/jdk/sun/tools/jstatd/JstatdTest.java b/test/jdk/sun/tools/jstatd/JstatdTest.java
index 2925a223098..56c86cbfa07 100644
--- a/test/jdk/sun/tools/jstatd/JstatdTest.java
+++ b/test/jdk/sun/tools/jstatd/JstatdTest.java
@@ -27,6 +27,7 @@ import java.rmi.RemoteException;
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
 import java.util.Arrays;
+import java.util.List;
 
 import static jdk.test.lib.Asserts.*;
 import jdk.test.lib.Utils;
@@ -127,6 +128,7 @@ public final class JstatdTest {
      */
     private OutputAnalyzer runJps() throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jps");
+        launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-XX:+UsePerfData"));
         launcher.addVMArg("-XX:+UsePerfData");
         launcher.addToolArg(getDestination());
 
@@ -156,7 +158,7 @@ public final class JstatdTest {
         assertFalse(output.getOutput().isEmpty(), "Output should not be empty");
 
         boolean foundFirstLineWithPid = false;
-        String[] lines = output.getOutput().split(Utils.NEW_LINE);
+        List<String> lines = output.asLinesWithoutVMWarnings();
         for (String line : lines) {
             if (!foundFirstLineWithPid) {
                 foundFirstLineWithPid = line.matches(JPS_OUTPUT_REGEX);
@@ -353,9 +355,7 @@ public final class JstatdTest {
 
         // Verify output from jstatd
         OutputAnalyzer output = jstatdThread.getOutput();
-        assertTrue(output.getOutput().isEmpty(),
-                "jstatd should get an empty output, got: "
-                + Utils.NEW_LINE + output.getOutput());
+        output.shouldBeEmptyIgnoreVMWarnings();
         assertNotEquals(output.getExitValue(), 0,
                 "jstatd process exited with unexpected exit code");
     }
diff --git a/test/jdk/sun/tools/jstatd/TestJstatdUsage.java b/test/jdk/sun/tools/jstatd/TestJstatdUsage.java
index d80fe952f45..345cf8357b7 100644
--- a/test/jdk/sun/tools/jstatd/TestJstatdUsage.java
+++ b/test/jdk/sun/tools/jstatd/TestJstatdUsage.java
@@ -22,6 +22,7 @@
  */
 
 import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
 import jdk.test.lib.process.ProcessTools;
 
@@ -42,6 +43,7 @@ public class TestJstatdUsage {
 
     private static void testUsage(String option) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstatd");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addToolArg(option);
         ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
         OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
diff --git a/test/lib/jdk/test/lib/JDKToolLauncher.java b/test/lib/jdk/test/lib/JDKToolLauncher.java
index 6c264700215..0dae2dabfaf 100644
--- a/test/lib/jdk/test/lib/JDKToolLauncher.java
+++ b/test/lib/jdk/test/lib/JDKToolLauncher.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2020, 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
@@ -25,6 +25,7 @@ package jdk.test.lib;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Stream;
 
 /**
  * A utility for constructing command lines for starting JDK tool processes.
@@ -102,6 +103,24 @@ public class JDKToolLauncher {
         return this;
     }
 
+    /**
+     * Adds arguments to the JVM running the tool.
+     *
+     * The JVM arguments are passed to the underlying JVM running the tool.
+     * Arguments will automatically be prepended with "-J".
+     *
+     * Any platform specific arguments required for running the tool are
+     * automatically added.
+     *
+     * @param args
+     *            The arguments to VM running the tool
+     * @return The JDKToolLauncher instance
+     */
+    public JDKToolLauncher addVMArgs(String[] args) {
+        Stream.of(args).forEach(vmArgs::add);
+        return this;
+    }
+
     /**
      * Adds an argument to the tool.
      *
diff --git a/test/lib/jdk/test/lib/process/OutputAnalyzer.java b/test/lib/jdk/test/lib/process/OutputAnalyzer.java
index a2af1a914d3..c8653ea9bb2 100644
--- a/test/lib/jdk/test/lib/process/OutputAnalyzer.java
+++ b/test/lib/jdk/test/lib/process/OutputAnalyzer.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2020, 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
@@ -38,6 +38,15 @@ import java.util.regex.Pattern;
 
 public final class OutputAnalyzer {
 
+    private static final String JVM_WARNING_MSG = ".* VM warning:.*";
+    private static final String JAVA_VERSION_MSG = "^java version .*|^Java\\(TM\\).*|^Java HotSpot\\(TM\\).*|" +
+            "^openjdk version .*|^OpenJDK .*";
+    private static final String JAVA_WARNINGS_AND_VERSION = JVM_WARNING_MSG + "|" + JAVA_VERSION_MSG;
+    private static final Pattern JAVA_WARNINGS_AND_VERSION_PATTERN =
+            Pattern.compile(JAVA_WARNINGS_AND_VERSION.replaceAll("\\|", "\\\\R|") + "\\R",
+                    Pattern.MULTILINE);
+
+
     private final OutputBuffer buffer;
     /**
      * Create an OutputAnalyzer, a utility class for verifying output and exit
@@ -132,13 +141,13 @@ public final class OutputAnalyzer {
 
     /**
      * Verify that the stderr contents of output buffer is empty,
-     * after filtering out the Hotspot warning messages
+     * after filtering out the HotSpot warning and Java version messages.
      *
      * @throws RuntimeException
      *             If stderr was not empty
      */
     public OutputAnalyzer stderrShouldBeEmptyIgnoreVMWarnings() {
-        if (!getStderr().replaceAll(jvmwarningmsg + "\\R", "").isEmpty()) {
+        if (!JAVA_WARNINGS_AND_VERSION_PATTERN.matcher(getStderr()).replaceAll("").isEmpty()) {
             reportDiagnosticSummary();
             throw new RuntimeException("stderr was not empty");
         }
@@ -561,12 +570,15 @@ public final class OutputAnalyzer {
         return Arrays.asList(buffer.split("\\R"));
     }
 
-
-    private static final String jvmwarningmsg = ".* VM warning:.*";
+    private List<String> asLinesWithoutVMWarnings(String buffer) {
+        return Arrays.stream(buffer.split("\\R"))
+                .filter(Pattern.compile(JAVA_WARNINGS_AND_VERSION).asPredicate().negate())
+                .collect(Collectors.toList());
+    }
 
     /**
      * Verifies that the stdout and stderr contents of output buffer are empty, after
-     * filtering out the HotSpot warning messages.
+     * filtering out the HotSpot warning and Java version messages.
      *
      * @throws RuntimeException If the stdout and stderr are not empty
      */
@@ -577,22 +589,19 @@ public final class OutputAnalyzer {
             reportDiagnosticSummary();
             throw new RuntimeException("stdout was not empty");
         }
-        if (!stderr.replaceAll(jvmwarningmsg + "\\R", "").isEmpty()) {
-            reportDiagnosticSummary();
-            throw new RuntimeException("stderr was not empty");
-        }
+        stderrShouldBeEmptyIgnoreVMWarnings();
         return this;
     }
 
     /**
      * Verify that the stderr contents of output buffer matches the pattern,
-     * after filtering out the Hotespot warning messages
+     * after filtering out the HotSpot warning and Java version messages.
      *
      * @param pattern
      * @throws RuntimeException If the pattern was not found
      */
     public OutputAnalyzer stderrShouldMatchIgnoreVMWarnings(String pattern) {
-        String stderr = getStderr().replaceAll(jvmwarningmsg + "\\R", "");
+        String stderr = JAVA_WARNINGS_AND_VERSION_PATTERN.matcher(getStderr()).replaceAll("");
         Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
         if (!matcher.find()) {
             reportDiagnosticSummary();
@@ -604,16 +613,28 @@ public final class OutputAnalyzer {
 
     /**
      * Returns the contents of the output buffer (stdout and stderr), without those
-     * JVM warning msgs, as list of strings. Output is split by newlines.
+     * JVM warning and Java version messages, as list of strings. Output is split
+     * by newlines.
      *
      * @return Contents of the output buffer as list of strings
      */
     public List<String> asLinesWithoutVMWarnings() {
         return Arrays.stream(getOutput().split("\\R"))
-                     .filter(Pattern.compile(jvmwarningmsg).asPredicate().negate())
+                     .filter(Pattern.compile(JAVA_WARNINGS_AND_VERSION).asPredicate().negate())
                      .collect(Collectors.toList());
     }
 
+    /**
+     * Verify that the stdout and stderr contents of output buffer match the
+     * {@code pattern} line by line ignoring HotSpot warning and version messages.
+     *
+     * @param pattern
+     *            Matching pattern
+     */
+    public OutputAnalyzer shouldMatchByLineIgnoreVMWarnings(String pattern) {
+        return shouldMatchByLine(getOutput(), null, null, pattern, true);
+    }
+
     /**
      * @see #shouldMatchByLine(String, String, String)
      */
@@ -657,7 +678,25 @@ public final class OutputAnalyzer {
      *            Matching pattern
      */
     public OutputAnalyzer shouldMatchByLine(String from, String to, String pattern) {
-        return shouldMatchByLine(getOutput(), from, to, pattern);
+        return shouldMatchByLine(getOutput(), from, to, pattern, false);
+    }
+
+    /**
+     * Verify that the stdout and stderr contents of output buffer match the
+     * {@code pattern} line by line ignoring HotSpot warnings and version messages.
+     * The whole output could be matched or just a subset of it.
+     *
+     * @param from
+     *            The line (excluded) from where output will be matched.
+     *            Set {@code from} to null for matching from the first line.
+     * @param to
+     *            The line (excluded) until where output will be matched.
+     *            Set {@code to} to null for matching until the last line.
+     * @param pattern
+     *            Matching pattern
+     */
+    public OutputAnalyzer shouldMatchByLineIgnoreVMWarnings(String from, String to, String pattern) {
+        return shouldMatchByLine(getOutput(), from, to, pattern, true);
     }
 
     /**
@@ -675,11 +714,12 @@ public final class OutputAnalyzer {
      *            Matching pattern
      */
     public OutputAnalyzer stdoutShouldMatchByLine(String from, String to, String pattern) {
-        return shouldMatchByLine(getStdout(), from, to, pattern);
+        return shouldMatchByLine(getStdout(), from, to, pattern, false);
     }
 
-    private OutputAnalyzer shouldMatchByLine(String buffer, String from, String to, String pattern) {
-        List<String> lines = asLines(buffer);
+    private OutputAnalyzer shouldMatchByLine(String buffer, String from, String to, String pattern,
+                                             boolean ignoreVMWarnings) {
+        List<String> lines = ignoreVMWarnings ? asLinesWithoutVMWarnings() : asLines(buffer);
 
         int fromIndex = 0;
         if (from != null) {