changeset 59257:697257d168ff

8242009: Review setting test.java/vm.opts in jcmd/jhsdb and debugger in serviceability tests Reviewed-by: cjplummer
author dtitov
date Tue, 12 May 2020 09:45:24 -0700
parents bae14e11d1fe
children bd06e64b05db
files test/hotspot/jtreg/serviceability/attach/ConcAttachTest.java test/hotspot/jtreg/serviceability/attach/RemovingUnixDomainSocketTest.java test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java test/hotspot/jtreg/serviceability/sa/ClhsdbJstackXcompStress.java test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java test/hotspot/jtreg/serviceability/sa/DeadlockDetectionTest.java test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java test/hotspot/jtreg/serviceability/sa/TestHeapDumpForInvokeDynamic.java test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java test/hotspot/jtreg/serviceability/sa/TestJmapCore.java test/hotspot/jtreg/serviceability/sa/TestSysProps.java test/hotspot/jtreg/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdConnectTest.java test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdUtils.java test/hotspot/jtreg/serviceability/sa/sadebugd/SADebugDTest.java test/hotspot/jtreg/serviceability/tmtools/jstack/JstackThreadTest.java test/jdk/sun/tools/jcmd/JcmdBase.java test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java test/jdk/sun/tools/jcmd/TestJcmdDefaults.java test/jdk/sun/tools/jcmd/TestJcmdSanity.java test/jdk/sun/tools/jhsdb/BasicLauncherTest.java test/jdk/sun/tools/jhsdb/HeapDumpTest.java test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java test/jdk/sun/tools/jinfo/BasicJInfoTest.java test/jdk/sun/tools/jinfo/JInfoTest.java test/jdk/sun/tools/jmap/BasicJMapTest.java test/jdk/sun/tools/jps/JpsHelper.java test/jdk/sun/tools/jstack/BasicJStackTest.java test/jdk/sun/tools/jstack/DeadlockDetectionTest.java test/jdk/sun/tools/jstat/JStatInterval.java test/jdk/sun/tools/jstatd/JstatdTest.java test/jdk/sun/tools/jstatd/TestJstatdUsage.java test/lib/jdk/test/lib/JDKToolLauncher.java test/lib/jdk/test/lib/process/OutputAnalyzer.java
diffstat 36 files changed, 161 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/serviceability/attach/ConcAttachTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/attach/ConcAttachTest.java	Tue May 12 09:45:24 2020 -0700
@@ -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 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 @@
 
     private static void checkAttachListenerThread() throws InterruptedException, IOException {
         JDKToolLauncher jcmd = JDKToolLauncher.createUsingTestJDK("jcmd");
+        jcmd.addVMArgs(Utils.getTestJavaOpts());
         jcmd.addToolArg(strPID);
         jcmd.addToolArg("Thread.print");
 
--- a/test/hotspot/jtreg/serviceability/attach/RemovingUnixDomainSocketTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/attach/RemovingUnixDomainSocketTest.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
 
     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 @@
         System.out.println(out.getStdout());
         System.err.println(out.getStderr());
 
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
     }
 
     public static void main(String... args) throws Exception {
--- a/test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/CDSJMapClstats.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
     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");
--- a/test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/ClhsdbDumpclass.java	Tue May 12 09:45:24 2020 -0700
@@ -27,11 +27,10 @@
 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 @@
 
             // 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());
--- a/test/hotspot/jtreg/serviceability/sa/ClhsdbJstackXcompStress.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/ClhsdbJstackXcompStress.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
         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 @@
                 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"));
--- a/test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/ClhsdbLauncher.java	Tue May 12 09:45:24 2020 -0700
@@ -25,10 +25,8 @@
 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 @@
     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 @@
         throws IOException {
 
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addToolArg("clhsdb");
         launcher.addToolArg("--core=" + coreFileName);
         launcher.addToolArg("--exe=" + JDKToolFinder.getTestJDKTool("java"));
--- a/test/hotspot/jtreg/serviceability/sa/DeadlockDetectionTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/DeadlockDetectionTest.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
 
     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) {
--- a/test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/JhsdbThreadInfoTest.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
             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 @@
             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) {
--- a/test/hotspot/jtreg/serviceability/sa/TestHeapDumpForInvokeDynamic.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/TestHeapDumpForInvokeDynamic.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
                                             long lingeredAppPid) throws Exception {
 
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+        launcher.addVMArgs(Utils.getTestJavaOpts());
         launcher.addToolArg("jmap");
         launcher.addToolArg("--binaryheap");
         launcher.addToolArg("--dumpfile");
--- a/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackLock.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
             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 @@
             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 {
--- a/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/TestJhsdbJstackMixed.java	Tue May 12 09:45:24 2020 -0700
@@ -132,6 +132,7 @@
         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");
--- a/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/TestJmapCore.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
 
         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);
--- a/test/hotspot/jtreg/serviceability/sa/TestSysProps.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/TestSysProps.java	Tue May 12 09:45:24 2020 -0700
@@ -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 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 @@
             // 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 @@
             // 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()));
 
--- a/test/hotspot/jtreg/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/jmap-hprof/JMapHProfLargeHeapTest.java	Tue May 12 09:45:24 2020 -0700
@@ -33,7 +33,7 @@
 
 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 @@
 
             JDKToolLauncher jMapLauncher = JDKToolLauncher
                     .createUsingTestJDK("jhsdb");
+            jMapLauncher.addVMArgs(Utils.getTestJavaOpts());
             jMapLauncher.addToolArg("jmap");
             jMapLauncher.addToolArg("--binaryheap");
             jMapLauncher.addToolArg("--pid");
--- a/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdConnectTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdConnectTest.java	Tue May 12 09:45:24 2020 -0700
@@ -37,6 +37,7 @@
 
 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 @@
 
     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 @@
         OutputAnalyzer out = runJHSDB("jstack", id);
 
         out.shouldContain("LingeredApp");
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
         out.shouldHaveExitValue(0);
     }
 
@@ -76,7 +78,7 @@
         OutputAnalyzer out = runJHSDB("jmap", id);
 
         out.shouldContain("JVM version is");
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
         out.shouldHaveExitValue(0);
     }
 
@@ -84,7 +86,7 @@
         OutputAnalyzer out = runJHSDB("jinfo", id);
 
         out.shouldContain("Java System Properties:");
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
         out.shouldHaveExitValue(0);
     }
 
@@ -92,7 +94,7 @@
         OutputAnalyzer out = runJHSDB("jsnap", id);
 
         out.shouldContain("java.vm.name=");
-        out.stderrShouldBeEmpty();
+        out.stderrShouldBeEmptyIgnoreVMWarnings();
         out.shouldHaveExitValue(0);
     }
 
@@ -128,5 +130,4 @@
         }
 
     }
-
 }
--- a/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdUtils.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/sadebugd/DebugdUtils.java	Tue May 12 09:45:24 2020 -0700
@@ -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.IOException;
 
 import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.Utils;
 
 
 public class DebugdUtils {
@@ -43,6 +44,7 @@
 
     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));
--- a/test/hotspot/jtreg/serviceability/sa/sadebugd/SADebugDTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/sa/sadebugd/SADebugDTest.java	Tue May 12 09:45:24 2020 -0700
@@ -94,6 +94,7 @@
                 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()));
--- a/test/hotspot/jtreg/serviceability/tmtools/jstack/JstackThreadTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/hotspot/jtreg/serviceability/tmtools/jstack/JstackThreadTest.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
     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());
--- a/test/jdk/sun/tools/jcmd/JcmdBase.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jcmd/JcmdBase.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
     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);
--- a/test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jcmd/JcmdOutputEncodingTest.java	Tue May 12 09:45:24 2020 -0700
@@ -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.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 @@
         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");
--- a/test/jdk/sun/tools/jcmd/TestJcmdDefaults.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jcmd/TestJcmdDefaults.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
      * @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 {
--- a/test/jdk/sun/tools/jcmd/TestJcmdSanity.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jcmd/TestJcmdSanity.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
      * @throws Exception
      */
     private static void matchPerfCounters(OutputAnalyzer output) {
-        output.shouldMatchByLineFrom(PERF_COUNTER_REGEX,
+        output.shouldMatchByLineIgnoreVMWarnings(PERF_COUNTER_REGEX, null,
                 PERF_COUNTER_REGEX);
     }
 
--- a/test/jdk/sun/tools/jhsdb/BasicLauncherTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jhsdb/BasicLauncherTest.java	Tue May 12 09:45:24 2020 -0700
@@ -63,7 +63,7 @@
         else {
             launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
         }
-
+        launcher.addVMArgs(Utils.getFilteredTestJavaOpts("-Xcomp"));
         return launcher;
     }
 
--- a/test/jdk/sun/tools/jhsdb/HeapDumpTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jhsdb/HeapDumpTest.java	Tue May 12 09:45:24 2020 -0700
@@ -38,6 +38,7 @@
 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 @@
             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);
--- a/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jhsdb/JShellHeapDumpTest.java	Tue May 12 09:45:24 2020 -0700
@@ -38,6 +38,7 @@
 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 @@
 
             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);
--- a/test/jdk/sun/tools/jinfo/BasicJInfoTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jinfo/BasicJInfoTest.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
 
     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);
--- a/test/jdk/sun/tools/jinfo/JInfoTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jinfo/JInfoTest.java	Tue May 12 09:45:24 2020 -0700
@@ -29,6 +29,7 @@
 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 @@
 
     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);
--- a/test/jdk/sun/tools/jmap/BasicJMapTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jmap/BasicJMapTest.java	Tue May 12 09:45:24 2020 -0700
@@ -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.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 @@
 
     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);
--- a/test/jdk/sun/tools/jps/JpsHelper.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jps/JpsHelper.java	Tue May 12 09:45:24 2020 -0700
@@ -152,6 +152,7 @@
      */
     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) {
--- a/test/jdk/sun/tools/jstack/BasicJStackTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jstack/BasicJStackTest.java	Tue May 12 09:45:24 2020 -0700
@@ -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.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 @@
         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) {
--- a/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java	Tue May 12 09:45:24 2020 -0700
@@ -50,6 +50,7 @@
 
     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) {
--- a/test/jdk/sun/tools/jstat/JStatInterval.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jstat/JStatInterval.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
 
         String pidStr = String.valueOf(app.pid());
         JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jstat");
+        l.addVMArgs(Utils.getTestJavaOpts());
         l.addToolArg("-compiler");
         l.addToolArg(pidStr);
         l.addToolArg("100");
--- a/test/jdk/sun/tools/jstatd/JstatdTest.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jstatd/JstatdTest.java	Tue May 12 09:45:24 2020 -0700
@@ -27,6 +27,7 @@
 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 @@
      */
     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 @@
         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 @@
 
         // 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");
     }
--- a/test/jdk/sun/tools/jstatd/TestJstatdUsage.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/jdk/sun/tools/jstatd/TestJstatdUsage.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
 
     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);
--- a/test/lib/jdk/test/lib/JDKToolLauncher.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/lib/jdk/test/lib/JDKToolLauncher.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Stream;
 
 /**
  * A utility for constructing command lines for starting JDK tool processes.
@@ -103,6 +104,24 @@
     }
 
     /**
+     * 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.
      *
      * @param arg
--- a/test/lib/jdk/test/lib/process/OutputAnalyzer.java	Tue May 12 16:35:58 2020 +0200
+++ b/test/lib/jdk/test/lib/process/OutputAnalyzer.java	Tue May 12 09:45:24 2020 -0700
@@ -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 @@
 
 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 @@
 
     /**
      * 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 @@
         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 @@
             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,17 +613,29 @@
 
     /**
      * 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)
      */
     public OutputAnalyzer shouldMatchByLine(String pattern) {
@@ -657,7 +678,25 @@
      *            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 @@
      *            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) {