8155091: Remove SA related functions from tmtools
authordsamersoff
Mon, 09 May 2016 23:41:59 +0300
changeset 38360 fb63be22ffa6
parent 38359 fd9b36598481
child 38361 8ea2d56bfdf3
8155091: Remove SA related functions from tmtools Summary: Remove options that enables support for non-cooperative mode Reviewed-by: alanb, mchung, sla
jdk/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java
jdk/src/jdk.jcmd/share/classes/jdk/internal/vm/agent/spi/ToolProvider.java
jdk/src/jdk.jcmd/share/classes/jdk/internal/vm/agent/spi/ToolProviderFinder.java
jdk/src/jdk.jcmd/share/classes/module-info.java
jdk/src/jdk.jcmd/share/classes/sun/tools/jinfo/JInfo.java
jdk/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java
jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java
jdk/test/sun/tools/jhsdb/heapconfig/JMapHeapConfigTest.java
jdk/test/sun/tools/jhsdb/heapconfig/TmtoolTestScenario.java
jdk/test/sun/tools/jinfo/BasicJInfoTest.java
jdk/test/sun/tools/jinfo/JInfoHelper.java
jdk/test/sun/tools/jinfo/JInfoLauncherTest.java
jdk/test/sun/tools/jinfo/JInfoRunningProcessFlagTest.java
jdk/test/sun/tools/jinfo/JInfoRunningProcessTest.java
jdk/test/sun/tools/jinfo/JInfoSanityTest.java
jdk/test/sun/tools/jmap/BasicJMapTest.java
jdk/test/sun/tools/jmap/heapconfig/JMapHeapConfigTest.java
jdk/test/sun/tools/jmap/heapconfig/TmtoolTestScenario.java
jdk/test/sun/tools/jstack/BasicJStackTest.java
jdk/test/sun/tools/jstack/DeadlockDetectionTest.java
--- a/jdk/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java	Mon May 09 13:12:48 2016 +0300
+++ b/jdk/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java	Mon May 09 23:41:59 2016 +0300
@@ -258,7 +258,7 @@
     /*
      * Convenience method for simple commands
      */
-    private InputStream executeCommand(String cmd, Object ... args) throws IOException {
+    public InputStream executeCommand(String cmd, Object ... args) throws IOException {
         try {
             return execute(cmd, args);
         } catch (AgentLoadException x) {
--- a/jdk/src/jdk.jcmd/share/classes/jdk/internal/vm/agent/spi/ToolProvider.java	Mon May 09 13:12:48 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2016, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.internal.vm.agent.spi;
-
-/**
- * Service interface for jdk.hotspot.agent to provide the tools that
- * jstack, jmap, jinfo will invoke, if present.
- */
-public interface ToolProvider {
-    /**
-     * Returns the name of the tool provider
-     */
-    String getName();
-
-    /**
-     * Invoke the tool provider with the given arguments
-     */
-    void run(String... arguments);
-}
--- a/jdk/src/jdk.jcmd/share/classes/jdk/internal/vm/agent/spi/ToolProviderFinder.java	Mon May 09 13:12:48 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2016, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package jdk.internal.vm.agent.spi;
-
-import java.lang.reflect.Layer;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.ServiceLoader;
-
-public final class ToolProviderFinder {
-    private static final Map<String, ToolProvider> providers = init();
-
-    public static ToolProvider find(String name) {
-        return providers.get(name);
-    }
-
-    private static Map<String, ToolProvider> init() {
-        Map<String, ToolProvider> providers = new HashMap<>();
-        ServiceLoader.load(Layer.boot(), ToolProvider.class)
-                     .forEach(p -> providers.putIfAbsent(p.getName(), p));
-        return providers;
-    }
-}
--- a/jdk/src/jdk.jcmd/share/classes/module-info.java	Mon May 09 13:12:48 2016 +0300
+++ b/jdk/src/jdk.jcmd/share/classes/module-info.java	Mon May 09 23:41:59 2016 +0300
@@ -26,9 +26,4 @@
 module jdk.jcmd {
     requires jdk.attach;
     requires jdk.jvmstat;
-
-    exports jdk.internal.vm.agent.spi to jdk.hotspot.agent;
-
-    uses jdk.internal.vm.agent.spi.ToolProvider;
 }
-
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jinfo/JInfo.java	Mon May 09 13:12:48 2016 +0300
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jinfo/JInfo.java	Mon May 09 23:41:59 2016 +0300
@@ -32,8 +32,6 @@
 import com.sun.tools.attach.VirtualMachine;
 
 import sun.tools.attach.HotSpotVirtualMachine;
-import jdk.internal.vm.agent.spi.ToolProvider;
-import jdk.internal.vm.agent.spi.ToolProviderFinder;
 
 /*
  * This class is the main class for the JInfo utility. It parses its arguments
@@ -41,157 +39,75 @@
  * or an SA tool.
  */
 final public class JInfo {
-    private static final String SA_JINFO_TOOL_NAME = "jinfo";
-    private boolean useSA = false;
-    private String[] args = null;
 
-    private JInfo(String[] args) throws IllegalArgumentException {
+    public static void main(String[] args) throws Exception {
         if (args.length == 0) {
-            throw new IllegalArgumentException();
+            usage(1); // no arguments
         }
+        checkForUnsupportedOptions(args);
 
-        int argCopyIndex = 0;
-        // First determine if we should launch SA or not
-        if (args[0].equals("-F")) {
-            // delete the -F
-            argCopyIndex = 1;
-            useSA = true;
-        } else if (args[0].equals("-flags")
-                   || args[0].equals("-sysprops"))
-        {
-            if (args.length == 2) {
-                if (!isPid(args[1])) {
-                    // If args[1] doesn't parse to a number then
-                    // it must be the SA debug server
-                    // (otherwise it is the pid)
-                    useSA = true;
-                }
-            } else if (args.length == 3) {
-                // arguments include an executable and a core file
-                useSA = true;
-            } else {
-                throw new IllegalArgumentException();
+        boolean doFlag = false;
+        boolean doFlags = false;
+        boolean doSysprops = false;
+
+        // Parse the options (arguments starting with "-" )
+        int optionCount = 0;
+        while (optionCount < args.length) {
+            String arg = args[optionCount];
+            if (!arg.startsWith("-")) {
+                break;
             }
-        } else if (!args[0].startsWith("-")) {
-            if (args.length == 2) {
-                // the only arguments are an executable and a core file
-                useSA = true;
-            } else if (args.length == 1) {
-                if (!isPid(args[0])) {
-                    // The only argument is not a PID; it must be SA debug
-                    // server
-                    useSA = true;
-                }
-            } else {
-                throw new IllegalArgumentException();
+
+            optionCount++;
+
+            if (arg.equals("-help") || arg.equals("-h")) {
+                usage(0);
             }
-        } else if (args[0].equals("-h") || args[0].equals("-help")) {
-            if (args.length > 1) {
-                throw new IllegalArgumentException();
+
+            if (arg.equals("-flag")) {
+                doFlag = true;
+                continue;
             }
-        } else if (args[0].equals("-flag")) {
-            if (args.length == 3) {
-                if (!isPid(args[2])) {
-                    throw new IllegalArgumentException();
-                }
-            } else {
-                throw new IllegalArgumentException();
+
+            if (arg.equals("-flags")) {
+                doFlags = true;
+                continue;
             }
-        } else {
-            throw new IllegalArgumentException();
-        }
 
-        this.args = Arrays.copyOfRange(args, argCopyIndex, args.length);
-    }
-
-    @SuppressWarnings("fallthrough")
-    private void execute() throws Exception {
-        if (args[0].equals("-h")
-            || args[0].equals("-help")) {
-            usage(0);
+            if (arg.equals("-sysprops")) {
+                doSysprops = true;
+                continue;
+            }
         }
 
-        if (useSA) {
-            // SA only supports -flags or -sysprops
-            if (args[0].startsWith("-")) {
-                if (!(args[0].equals("-flags") || args[0].equals("-sysprops"))) {
-                    usage(1);
-                }
-            }
-
-            // invoke SA which does it's own argument parsing
-            runTool();
-
-        } else {
-            // Now we can parse arguments for the non-SA case
-            String pid = null;
+        // Next we check the parameter count. -flag allows extra parameters
+        int paramCount = args.length - optionCount;
+        if ((doFlag && paramCount != 2) || (paramCount != 1)) {
+            usage(1);
+        }
 
-            switch(args[0]) {
-                case "-flag":
-                    if (args.length != 3) {
-                        usage(1);
-                    }
-                    String option = args[1];
-                    pid = args[2];
-                    flag(pid, option);
-                    break;
-                case "-flags":
-                    if (args.length != 2) {
-                        usage(1);
-                    }
-                    pid = args[1];
-                    flags(pid);
-                    break;
-                case "-sysprops":
-                    if (args.length != 2) {
-                        usage(1);
-                    }
-                    pid = args[1];
-                    sysprops(pid);
-                    break;
-                case "-help":
-                case "-h":
-                    usage(0);
-                    // Fall through
-                default:
-                    if (args.length == 1) {
-                        // no flags specified, we do -sysprops and -flags
-                        pid = args[0];
-                        sysprops(pid);
-                        System.out.println();
-                        flags(pid);
-                        System.out.println();
-                        commandLine(pid);
-                    } else {
-                        usage(1);
-                    }
+        if (!doFlag && !doFlags && !doSysprops) {
+            // Print flags and sysporps if no options given
+            sysprops(args[optionCount]);
+            System.out.println();
+            flags(args[optionCount]);
+            System.out.println();
+            commandLine(args[optionCount]);
+        }
+
+        if (doFlag) {
+            flag(args[optionCount+1], args[optionCount]);
+        }
+        else {
+            if (doFlags) {
+                flags(args[optionCount]);
+            }
+            else if (doSysprops) {
+                sysprops(args[optionCount]);
             }
         }
     }
 
-    public static void main(String[] args) throws Exception {
-        JInfo jinfo = null;
-        try {
-            jinfo = new JInfo(args);
-            jinfo.execute();
-        } catch (IllegalArgumentException e) {
-            usage(1);
-        }
-    }
-
-    private static boolean isPid(String arg) {
-        return arg.matches("[0-9]+");
-    }
-
-    // Invoke SA tool with the given arguments
-    private void runTool() throws Exception {
-        ToolProvider tool = ToolProviderFinder.find(SA_JINFO_TOOL_NAME);
-        if (tool == null) {
-            usage(1);
-        }
-        tool.run(args);
-    }
-
     private static void flag(String pid, String option) throws IOException {
         HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid);
         String flag;
@@ -274,46 +190,50 @@
         vm.detach();
     }
 
+    private static void checkForUnsupportedOptions(String[] args) {
+        // Check arguments for -F, and non-numeric value
+        // and warn the user that SA is not supported anymore
 
-    // print usage message
-    private static void usage(int exit) {
-        boolean usageSA = ToolProviderFinder.find(SA_JINFO_TOOL_NAME) != null;
+        int paramCount = 0;
 
-        System.err.println("Usage:");
-        if (usageSA) {
-            System.err.println("    jinfo [option] <pid>");
-            System.err.println("        (to connect to a running process)");
-            System.err.println("    jinfo -F [option] <pid>");
-            System.err.println("        (to connect to a hung process)");
-            System.err.println("    jinfo [option] <executable> <core>");
-            System.err.println("        (to connect to a core file)");
-            System.err.println("    jinfo [option] [server_id@]<remote server IP or hostname>");
-            System.err.println("        (to connect to remote debug server)");
-            System.err.println("");
-            System.err.println("where <option> is one of:");
-            System.err.println("  for running processes:");
-            System.err.println("    -flag <name>         to print the value of the named VM flag");
-            System.err.println("    -flag [+|-]<name>    to enable or disable the named VM flag");
-            System.err.println("    -flag <name>=<value> to set the named VM flag to the given value");
-            System.err.println("  for running or hung processes and core files:");
-            System.err.println("    -flags               to print VM flags");
-            System.err.println("    -sysprops            to print Java system properties");
-            System.err.println("    <no option>          to print both VM flags and system properties");
-            System.err.println("    -h | -help           to print this help message");
-        } else {
-            System.err.println("    jinfo <option> <pid>");
-            System.err.println("       (to connect to a running process)");
-            System.err.println("");
-            System.err.println("where <option> is one of:");
-            System.err.println("    -flag <name>         to print the value of the named VM flag");
-            System.err.println("    -flag [+|-]<name>    to enable or disable the named VM flag");
-            System.err.println("    -flag <name>=<value> to set the named VM flag to the given value");
-            System.err.println("    -flags               to print VM flags");
-            System.err.println("    -sysprops            to print Java system properties");
-            System.err.println("    <no option>          to print both VM flags and system properties");
-            System.err.println("    -h | -help           to print this help message");
+        for (String s : args) {
+            if (s.equals("-F")) {
+                SAOptionError("-F option used");
+            }
+
+            if (! s.startsWith("-")) {
+                if (! s.matches("[0-9]+")) {
+                   SAOptionError("non PID argument");
+                }
+                paramCount += 1;
+            }
         }
 
+        if (paramCount > 1) {
+            SAOptionError("More than one non-option argument");
+        }
+    }
+
+    private static void SAOptionError(String msg) {
+        System.err.println("Error: " + msg);
+        System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jinfo instead");
+        System.exit(1);
+    }
+
+     // print usage message
+    private static void usage(int exit) {
+        System.err.println("Usage:");
+        System.err.println("    jinfo <option> <pid>");
+        System.err.println("       (to connect to a running process)");
+        System.err.println("");
+        System.err.println("where <option> is one of:");
+        System.err.println("    -flag <name>         to print the value of the named VM flag");
+        System.err.println("    -flag [+|-]<name>    to enable or disable the named VM flag");
+        System.err.println("    -flag <name>=<value> to set the named VM flag to the given value");
+        System.err.println("    -flags               to print VM flags");
+        System.err.println("    -sysprops            to print Java system properties");
+        System.err.println("    <no option>          to print both VM flags and system properties");
+        System.err.println("    -h | -help           to print this help message");
         System.exit(exit);
     }
 }
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java	Mon May 09 13:12:48 2016 +0300
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java	Mon May 09 23:41:59 2016 +0300
@@ -28,12 +28,11 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
 
 import com.sun.tools.attach.VirtualMachine;
 import com.sun.tools.attach.AttachNotSupportedException;
 import sun.tools.attach.HotSpotVirtualMachine;
-import jdk.internal.vm.agent.spi.ToolProvider;
-import jdk.internal.vm.agent.spi.ToolProviderFinder;
 
 /*
  * This class is the main class for the JMap utility. It parses its arguments
@@ -44,34 +43,18 @@
  */
 public class JMap {
 
-    // Options handled by the attach mechanism
-    private static String HISTO_OPTION = "-histo";
-    private static String LIVE_HISTO_OPTION = "-histo:live";
-    private static String DUMP_OPTION_PREFIX = "-dump:";
-
-    // These options imply the use of a SA tool
-    private static String SA_TOOL_OPTIONS =
-      "-heap|-heap:format=b|-clstats|-finalizerinfo";
-
-    // The -F (force) option is currently not passed through to SA
-    private static String FORCE_SA_OPTION = "-F";
-
-    // Default option (if nothing provided)
-    private static String DEFAULT_OPTION = "-pmap";
-
     public static void main(String[] args) throws Exception {
         if (args.length == 0) {
             usage(1); // no arguments
         }
 
-        // used to indicate if we should use SA
-        boolean useSA = false;
+        checkForUnsupportedOptions(args);
 
-        // the chosen option (-heap, -dump:*, ... )
+        // the chosen option
         String option = null;
 
         // First iterate over the options (arguments starting with -).  There should be
-        // one (but maybe two if -F is also used).
+        // one.
         int optionCount = 0;
         while (optionCount < args.length) {
             String arg = args[optionCount];
@@ -80,8 +63,6 @@
             }
             if (arg.equals("-help") || arg.equals("-h")) {
                 usage(0);
-            } else if (arg.equals(FORCE_SA_OPTION)) {
-                useSA = true;
             } else {
                 if (option != null) {
                     usage(1);  // option already specified
@@ -93,123 +74,95 @@
 
         // if no option provided then use default.
         if (option == null) {
-            option = DEFAULT_OPTION;
-        }
-        if (option.matches(SA_TOOL_OPTIONS)) {
-            useSA = true;
+            usage(0);
         }
 
-        // Next we check the parameter count. For the SA tools there are
-        // one or two parameters. For the built-in -dump option there is
-        // only one parameter (the process-id)
+        // Next we check the parameter count.
         int paramCount = args.length - optionCount;
-        if (paramCount == 0 || paramCount > 2) {
+        if (paramCount != 1) {
             usage(1);
         }
 
-        if (optionCount == 0 || paramCount != 1) {
-            useSA = true;
+        String pid = args[1];
+        // Here we handle the built-in options
+        // As more options are added we should create an abstract tool class and
+        // have a table to map the options
+        if (option.equals("-histo")) {
+            histo(pid, "");
+        } else if (option.startsWith("-histo:")) {
+            histo(pid, option.substring("-histo:".length()));
+        } else if (option.startsWith("-dump:")) {
+            dump(pid, option.substring("-dump:".length()));
+        } else if (option.equals("-finalizerinfo")) {
+            executeCommandForPid(pid, "jcmd", "GC.finalizer_info");
+        } else if (option.equals("-clstats")) {
+            executeCommandForPid(pid, "jcmd", "GC.class_stats");
         } else {
-            // the parameter for the -dump option is a process-id.
-            // If it doesn't parse to a number then it must be SA
-            // debug server
-            if (!args[optionCount].matches("[0-9]+")) {
-                useSA = true;
-            }
-        }
-
-
-        // at this point we know if we are executing an SA tool or a built-in
-        // option.
-
-        if (useSA) {
-            // parameters (<pid> or <exe> <core>)
-            String params[] = new String[paramCount];
-            for (int i=optionCount; i<args.length; i++ ){
-                params[i-optionCount] = args[i];
-            }
-            runTool(option, params);
-
-        } else {
-            String pid = args[1];
-            // Here we handle the built-in options
-            // As more options are added we should create an abstract tool class and
-            // have a table to map the options
-            if (option.equals(HISTO_OPTION)) {
-                histo(pid, false);
-            } else if (option.equals(LIVE_HISTO_OPTION)) {
-                histo(pid, true);
-            } else if (option.startsWith(DUMP_OPTION_PREFIX)) {
-                dump(pid, option);
-            } else {
-                usage(1);
-            }
+          usage(1);
         }
     }
 
-    // Invoke SA tool  with the given arguments
-    private static void runTool(String option, String args[]) throws Exception {
-        String[][] tools = {
-            { "-pmap",          "pmap"             },
-            { "-heap",          "heapSummary"      },
-            { "-heap:format=b", "heapDumper"       },
-            { "-histo",         "objectHistogram"  },
-            { "-clstats",       "classLoaderStats" },
-            { "-finalizerinfo", "finalizerInfo"    },
-        };
-
-        String name = null;
-
-        // -dump option needs to be handled in a special way
-        if (option.startsWith(DUMP_OPTION_PREFIX)) {
-            // first check that the option can be parsed
-            String fn = parseDumpOptions(option);
-            if (fn == null) {
-                usage(1);
-            }
+    private static void executeCommandForPid(String pid, String command, Object ... args)
+        throws AttachNotSupportedException, IOException,
+               UnsupportedEncodingException {
+        VirtualMachine vm = VirtualMachine.attach(pid);
 
-            // tool for heap dumping
-            name = "heapDumper";
+        // Cast to HotSpotVirtualMachine as this is an
+        // implementation specific method.
+        HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
+        try (InputStream in = hvm.executeCommand(command, args)) {
+          // read to EOF and just print output
+          byte b[] = new byte[256];
+          int n;
+          do {
+              n = in.read(b);
+              if (n > 0) {
+                  String s = new String(b, 0, n, "UTF-8");
+                  System.out.print(s);
+              }
+          } while (n > 0);
+        }
+        vm.detach();
+    }
 
-            // HeapDumper -f <file>
-            args = prepend(fn, args);
-            args = prepend("-f", args);
-        } else {
-            int i=0;
-            while (i < tools.length) {
-                if (option.equals(tools[i][0])) {
-                    name = tools[i][1];
-                    break;
-                }
-                i++;
-            }
+    private static void histo(String pid, String options)
+        throws AttachNotSupportedException, IOException,
+               UnsupportedEncodingException {
+        String liveopt = "-all";
+        if (options.equals("") || options.equals("all")) {
+            //  pass
         }
-        if (name == null) {
-            usage(1);   // no mapping to tool
+        else if (options.equals("live")) {
+            liveopt = "-live";
         }
-
-        // Tool not available on this platform.
-        ToolProvider tool = ToolProviderFinder.find(name);
-        if (tool == null) {
+        else {
             usage(1);
         }
 
-        // invoke the main method with the arguments
-        tool.run(args);
+        // inspectHeap is not the same as jcmd GC.class_histogram
+        executeCommandForPid(pid, "inspectheap", liveopt);
     }
 
-    private static final String LIVE_OBJECTS_OPTION = "-live";
-    private static final String ALL_OBJECTS_OPTION = "-all";
-    private static void histo(String pid, boolean live) throws IOException {
-        VirtualMachine vm = attach(pid);
-        InputStream in = ((HotSpotVirtualMachine)vm).
-            heapHisto(live ? LIVE_OBJECTS_OPTION : ALL_OBJECTS_OPTION);
-        drain(vm, in);
-    }
+    private static void dump(String pid, String options)
+        throws AttachNotSupportedException, IOException,
+               UnsupportedEncodingException {
+
+        String subopts[] = options.split(",");
+        String filename = null;
+        String liveopt = "-all";
 
-    private static void dump(String pid, String options) throws IOException {
-        // parse the options to get the dump filename
-        String filename = parseDumpOptions(options);
+        for (int i = 0; i < subopts.length; i++) {
+            String subopt = subopts[i];
+            if (subopt.equals("live")) {
+                liveopt = "-live";
+            } else if (subopt.startsWith("file=")) {
+                // file=<file> - check that <file> is specified
+                if (subopt.length() > 5) {
+                    filename = subopt.substring(5);
+                }
+            }
+        }
+
         if (filename == null) {
             usage(1);  // invalid options or no filename
         }
@@ -219,156 +172,76 @@
         // working directory rather than the directory where jmap
         // is executed.
         filename = new File(filename).getCanonicalPath();
-
-        // dump live objects only or not
-        boolean live = isDumpLiveObjects(options);
-
-        VirtualMachine vm = attach(pid);
-        System.out.println("Dumping heap to " + filename + " ...");
-        InputStream in = ((HotSpotVirtualMachine)vm).
-            dumpHeap((Object)filename,
-                     (live ? LIVE_OBJECTS_OPTION : ALL_OBJECTS_OPTION));
-        drain(vm, in);
+        // dumpHeap is not the same as jcmd GC.heap_dump
+        executeCommandForPid(pid, "dumpheap", filename, liveopt);
     }
 
-    // Parse the options to the -dump option. Valid options are format=b and
-    // file=<file>. Returns <file> if provided. Returns null if <file> not
-    // provided, or invalid option.
-    private static String parseDumpOptions(String arg) {
-        assert arg.startsWith(DUMP_OPTION_PREFIX);
+    private static void checkForUnsupportedOptions(String[] args) {
+        // Check arguments for -F, -m, and non-numeric value
+        // and warn the user that SA is not supported anymore
+
+        int paramCount = 0;
 
-        String filename = null;
+        for (String s : args) {
+            if (s.equals("-F")) {
+                SAOptionError("-F option used");
+            }
 
-        // options are separated by comma (,)
-        String options[] = arg.substring(DUMP_OPTION_PREFIX.length()).split(",");
-
-        for (int i=0; i<options.length; i++) {
-            String option = options[i];
+            if (s.equals("-heap")) {
+                SAOptionError("-heap option used");
+            }
 
-            if (option.equals("format=b")) {
-                // ignore format (not needed at this time)
-            } else if (option.equals("live")) {
-                // a valid suboption
-            } else {
+            /* Reimplemented using jcmd, output format is different
+               from original one
+
+            if (s.equals("-clstats")) {
+                warnSA("-clstats option used");
+            }
 
-                // file=<file> - check that <file> is specified
-                if (option.startsWith("file=")) {
-                    filename = option.substring(5);
-                    if (filename.length() == 0) {
-                        return null;
-                    }
-                } else {
-                    return null;  // option not recognized
+            if (s.equals("-finalizerinfo")) {
+                warnSA("-finalizerinfo option used");
+            }
+            */
+
+            if (! s.startsWith("-")) {
+                if (! s.matches("[0-9]+")) {
+                    SAOptionError("non PID argument");
                 }
+                paramCount += 1;
             }
         }
-        return filename;
-    }
 
-    private static boolean isDumpLiveObjects(String arg) {
-        // options are separated by comma (,)
-        String options[] = arg.substring(DUMP_OPTION_PREFIX.length()).split(",");
-        for (String suboption : options) {
-            if (suboption.equals("live")) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    // Attach to <pid>, existing if we fail to attach
-    private static VirtualMachine attach(String pid) {
-        try {
-            return VirtualMachine.attach(pid);
-        } catch (Exception x) {
-            String msg = x.getMessage();
-            if (msg != null) {
-                System.err.println(pid + ": " + msg);
-            } else {
-                x.printStackTrace();
-            }
-            if ((x instanceof AttachNotSupportedException) && haveSA()) {
-                System.err.println("The -F option can be used when the " +
-                  "target process is not responding");
-            }
-            System.exit(1);
-            return null; // keep compiler happy
+        if (paramCount > 1) {
+            SAOptionError("More than one non-option argument");
         }
     }
 
-    // Read the stream from the target VM until EOF, then detach
-    private static void drain(VirtualMachine vm, InputStream in) throws IOException {
-        // read to EOF and just print output
-        byte b[] = new byte[256];
-        int n;
-        do {
-            n = in.read(b);
-            if (n > 0) {
-                String s = new String(b, 0, n, "UTF-8");
-                System.out.print(s);
-            }
-        } while (n > 0);
-        in.close();
-        vm.detach();
-    }
-
-    // return a new string array with arg as the first element
-    private static String[] prepend(String arg, String args[]) {
-        String[] newargs = new String[args.length+1];
-        newargs[0] = arg;
-        System.arraycopy(args, 0, newargs, 1, args.length);
-        return newargs;
-    }
-
-    // returns true if SA is available
-    private static boolean haveSA() {
-        return ToolProviderFinder.find("heapSummary") != null;
+    private static void SAOptionError(String msg) {
+        System.err.println("Error: " + msg);
+        System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jmap instead");
+        System.exit(1);
     }
 
     // print usage message
     private static void usage(int exit) {
         System.err.println("Usage:");
-        if (haveSA()) {
-            System.err.println("    jmap [option] <pid>");
-            System.err.println("        (to connect to running process)");
-            System.err.println("    jmap [option] <executable <core>");
-            System.err.println("        (to connect to a core file)");
-            System.err.println("    jmap [option] [server_id@]<remote server IP or hostname>");
-            System.err.println("        (to connect to remote debug server)");
-            System.err.println("");
-            System.err.println("where <option> is one of:");
-            System.err.println("    <none>               to print same info as Solaris pmap");
-            System.err.println("    -heap                to print java heap summary");
-            System.err.println("    -histo[:live]        to print histogram of java object heap; if the \"live\"");
-            System.err.println("                         suboption is specified, only count live objects");
-            System.err.println("    -clstats             to print class loader statistics");
-            System.err.println("    -finalizerinfo       to print information on objects awaiting finalization");
-            System.err.println("    -dump:<dump-options> to dump java heap in hprof binary format");
-            System.err.println("                         dump-options:");
-            System.err.println("                           live         dump only live objects; if not specified,");
-            System.err.println("                                        all objects in the heap are dumped.");
-            System.err.println("                           format=b     binary format");
-            System.err.println("                           file=<file>  dump heap to <file>");
-            System.err.println("                         Example: jmap -dump:live,format=b,file=heap.bin <pid>");
-            System.err.println("    -F                   force. Use with -dump:<dump-options> <pid> or -histo");
-            System.err.println("                         to force a heap dump or histogram when <pid> does not");
-            System.err.println("                         respond. The \"live\" suboption is not supported");
-            System.err.println("                         in this mode.");
-            System.err.println("    -h | -help           to print this help message");
-            System.err.println("    -J<flag>             to pass <flag> directly to the runtime system");
-        } else {
-            System.err.println("    jmap -histo <pid>");
-            System.err.println("      (to connect to running process and print histogram of java object heap");
-            System.err.println("    jmap -dump:<dump-options> <pid>");
-            System.err.println("      (to connect to running process and dump java heap)");
-            System.err.println("");
-            System.err.println("    dump-options:");
-            System.err.println("      format=b     binary default");
-            System.err.println("      file=<file>  dump heap to <file>");
-            System.err.println("");
-            System.err.println("    Example:       jmap -dump:format=b,file=heap.bin <pid>");
-        }
-
+        System.err.println("    jmap -clstats <pid>");
+        System.err.println("        to connect to running process and print class loader statistics");
+        System.err.println("    jmap -finalizerinfo <pid>");
+        System.err.println("        to connect to running process and print information on objects awaiting finalization");
+        System.err.println("    jmap -histo[:live] <pid>");
+        System.err.println("        to connect to running process and print histogram of java object heap");
+        System.err.println("        if the \"live\" suboption is specified, only count live objects");
+        System.err.println("    jmap -dump:<dump-options> <pid>");
+        System.err.println("        to connect to running process and dump java heap");
+        System.err.println("");
+        System.err.println("    dump-options:");
+        System.err.println("      live         dump only live objects; if not specified,");
+        System.err.println("                   all objects in the heap are dumped.");
+        System.err.println("      format=b     binary format");
+        System.err.println("      file=<file>  dump heap to <file>");
+        System.err.println("");
+        System.err.println("    Example: jmap -dump:live,format=b,file=heap.bin <pid>");
         System.exit(exit);
     }
 }
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java	Mon May 09 13:12:48 2016 +0300
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java	Mon May 09 23:41:59 2016 +0300
@@ -30,8 +30,6 @@
 import com.sun.tools.attach.VirtualMachine;
 import com.sun.tools.attach.AttachNotSupportedException;
 import sun.tools.attach.HotSpotVirtualMachine;
-import jdk.internal.vm.agent.spi.ToolProvider;
-import jdk.internal.vm.agent.spi.ToolProviderFinder;
 
 /*
  * This class is the main class for the JStack utility. It parses its arguments
@@ -39,15 +37,14 @@
  * obtained the thread dump from a target process using the VM attach mechanism
  */
 public class JStack {
-    private static final String SA_JSTACK_TOOL_NAME = "jstack";
 
     public static void main(String[] args) throws Exception {
         if (args.length == 0) {
             usage(1); // no arguments
         }
 
-        boolean useSA = false;
-        boolean mixed = false;
+        checkForUnsupportedOptions(args);
+
         boolean locks = false;
 
         // Parse the options (arguments starting with "-" )
@@ -60,87 +57,33 @@
             if (arg.equals("-help") || arg.equals("-h")) {
                 usage(0);
             }
-            else if (arg.equals("-F")) {
-                useSA = true;
-            }
             else {
-                if (arg.equals("-m")) {
-                    mixed = true;
+                if (arg.equals("-l")) {
+                    locks = true;
                 } else {
-                    if (arg.equals("-l")) {
-                       locks = true;
-                    } else {
-                        usage(1);
-                    }
+                    usage(1);
                 }
             }
             optionCount++;
         }
 
-        // mixed stack implies SA tool
-        if (mixed) {
-            useSA = true;
-        }
-
-        // Next we check the parameter count. If there are two parameters
-        // we assume core file and executable so we use SA.
+        // Next we check the parameter count.
         int paramCount = args.length - optionCount;
-        if (paramCount == 0 || paramCount > 2) {
+        if (paramCount != 1) {
             usage(1);
         }
-        if (paramCount == 2) {
-            useSA = true;
-        } else {
-            // If we can't parse it as a pid then it must be debug server
-            if (!args[optionCount].matches("[0-9]+")) {
-                useSA = true;
-            }
-        }
 
-        // now execute using the SA JStack tool or the built-in thread dumper
-        if (useSA) {
-            // parameters (<pid> or <exe> <core>
-            String params[] = new String[paramCount];
-            for (int i=optionCount; i<args.length; i++ ){
-                params[i-optionCount] = args[i];
-            }
-            runJStackTool(mixed, locks, params);
+        // pass -l to thread dump operation to get extra lock info
+        String pid = args[optionCount];
+        String params[];
+        if (locks) {
+            params = new String[] { "-l" };
         } else {
-            // pass -l to thread dump operation to get extra lock info
-            String pid = args[optionCount];
-            String params[];
-            if (locks) {
-                params = new String[] { "-l" };
-            } else {
-                params = new String[0];
-            }
-            runThreadDump(pid, params);
+            params = new String[0];
         }
+        runThreadDump(pid, params);
     }
 
-    // SA JStack tool
-    private static boolean isAgentToolPresent() {
-        return ToolProviderFinder.find(SA_JSTACK_TOOL_NAME) != null;
-    }
-
-    private static void runJStackTool(boolean mixed, boolean locks, String args[]) throws Exception {
-        ToolProvider tool = ToolProviderFinder.find(SA_JSTACK_TOOL_NAME);
-        if (tool == null) {
-            usage(1);            // SA not available
-        }
-
-        // JStack tool also takes -m and -l arguments
-        if (mixed) {
-            args = prepend("-m", args);
-        }
-        if (locks) {
-            args = prepend("-l", args);
-        }
-
-        tool.run(args);
-    }
-
-
     // Attach to pid and perform a thread dump
     private static void runThreadDump(String pid, String args[]) throws Exception {
         VirtualMachine vm = null;
@@ -153,10 +96,6 @@
             } else {
                 x.printStackTrace();
             }
-            if ((x instanceof AttachNotSupportedException) && isAgentToolPresent()) {
-                System.err.println("The -F option can be used when the target " +
-                    "process is not responding");
-            }
             System.exit(1);
         }
 
@@ -178,12 +117,38 @@
         vm.detach();
     }
 
-    // return a new string array with arg as the first element
-    private static String[] prepend(String arg, String args[]) {
-        String[] newargs = new String[args.length+1];
-        newargs[0] = arg;
-        System.arraycopy(args, 0, newargs, 1, args.length);
-        return newargs;
+    private static void checkForUnsupportedOptions(String[] args) {
+        // Check arguments for -F, -m, and non-numeric value
+        // and warn the user that SA is not supported anymore
+
+        int paramCount = 0;
+
+        for (String s : args) {
+            if (s.equals("-F")) {
+                SAOptionError("-F option used");
+            }
+
+            if (s.equals("-m")) {
+                SAOptionError("-m option used");
+            }
+
+            if (! s.startsWith("-")) {
+                if (! s.matches("[0-9]+")) {
+                    SAOptionError("non PID argument");
+                }
+                paramCount += 1;
+            }
+        }
+
+        if (paramCount > 1) {
+            SAOptionError("More than one non-option argument");
+        }
+    }
+
+    private static void SAOptionError(String msg) {
+        System.err.println("Error: " + msg);
+        System.err.println("Cannot connect to core dump or remote debug server. Use jhsdb jstack instead");
+        System.exit(1);
     }
 
     // print usage message
@@ -191,25 +156,8 @@
         System.err.println("Usage:");
         System.err.println("    jstack [-l] <pid>");
         System.err.println("        (to connect to running process)");
-
-        if (isAgentToolPresent()) {
-            System.err.println("    jstack -F [-m] [-l] <pid>");
-            System.err.println("        (to connect to a hung process)");
-            System.err.println("    jstack [-m] [-l] <executable> <core>");
-            System.err.println("        (to connect to a core file)");
-            System.err.println("    jstack [-m] [-l] [server_id@]<remote server IP or hostname>");
-            System.err.println("        (to connect to a remote debug server)");
-        }
-
         System.err.println("");
         System.err.println("Options:");
-
-        if (isAgentToolPresent()) {
-            System.err.println("    -F  to force a thread dump. Use when jstack <pid> does not respond" +
-                " (process is hung)");
-            System.err.println("    -m  to print both java and native frames (mixed mode)");
-        }
-
         System.err.println("    -l  long listing. Prints additional information about locks");
         System.err.println("    -h or -help to print this help message");
         System.exit(exit);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/tools/jhsdb/heapconfig/JMapHeapConfigTest.java	Mon May 09 23:41:59 2016 +0300
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import jdk.test.lib.apps.LingeredApp;
+import jdk.testlibrary.Utils;
+import jdk.testlibrary.Platform;
+
+/*
+ * @test
+ * @bug 8042397
+ * @summary Unit test for jmap utility test heap configuration reader
+ * @modules jdk.hotspot.agent/sun.jvm.hotspot
+ * @library /test/lib/share/classes
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.*
+ * @build jdk.test.lib.apps.*
+ * @build JMapHeapConfigTest TmtoolTestScenario
+ * @run main JMapHeapConfigTest
+ */
+public class JMapHeapConfigTest {
+
+    static final String expectedJMapValues[] = {
+        "MinHeapFreeRatio",
+        "MaxHeapFreeRatio",
+        "MaxHeapSize",
+        "NewSize",
+        "MaxNewSize",
+        "OldSize",
+        "NewRatio",
+        "SurvivorRatio",
+        "MetaspaceSize",
+        "CompressedClassSpaceSize",
+        "G1HeapRegionSize"};
+
+    // ignoring MaxMetaspaceSize
+
+    static final String desiredMaxHeapSize = "-Xmx128m";
+
+    private static Map<String, String> parseJMapOutput(List<String> jmapOutput) {
+        Map<String, String> heapConfigMap = new HashMap<String, String>();
+        boolean shouldParse = false;
+
+        for (String line : jmapOutput) {
+            line = line.trim();
+
+            if (line.startsWith("Heap Configuration:")) {
+                shouldParse = true;
+                continue;
+            }
+
+            if (line.startsWith("Heap Usage:")) {
+                shouldParse = false;
+                continue;
+            }
+
+            if (shouldParse && !line.equals("")) {
+                String[] lv = line.split("\\s+");
+                try {
+                    heapConfigMap.put(lv[0], lv[2]);
+                } catch (ArrayIndexOutOfBoundsException ex) {
+                    // Ignore mailformed lines
+                }
+            }
+        }
+        return heapConfigMap;
+    }
+
+    // Compare stored values
+    private static void compareValues(Map<String, String> parsedJMapOutput, Map<String, String> parsedVmOutput) {
+        for (String key : expectedJMapValues) {
+            try {
+                String jmapVal = parsedJMapOutput.get(key);
+                if (jmapVal == null) {
+                    throw new RuntimeException("Key '" + key + "' doesn't exists in jmap output");
+                }
+
+                String vmVal = parsedVmOutput.get(key);
+                if (vmVal == null) {
+                    throw new RuntimeException("Key '" + key + "' doesn't exists in vm output");
+                }
+
+                if (new BigDecimal(jmapVal).compareTo(new BigDecimal(vmVal)) != 0) {
+                    throw new RuntimeException(String.format("Key %s doesn't match %s vs %s", key, vmVal, jmapVal));
+                }
+            } catch (NumberFormatException ex) {
+                throw new RuntimeException("Unexpected key '" + key + "' value", ex);
+            }
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        System.out.println("Starting JMapHeapConfigTest");
+
+        if (!Platform.shouldSAAttach()) {
+            // Silently skip the test if we don't have enough permissions to attach
+            System.err.println("Error! Insufficient permissions to attach.");
+            return;
+        }
+
+        if (!LingeredApp.isLastModifiedWorking()) {
+            // Exact behaviour of the test depends to operating system and the test nature,
+            // so just print the warning and continue
+            System.err.println("Warning! Last modified time doesn't work.");
+        }
+
+        boolean mx_found = false;
+        List<String> jvmOptions = Utils.getVmOptions();
+        for (String option : jvmOptions) {
+            if (option.startsWith("-Xmx")) {
+               System.out.println("INFO: maximum heap size set by JTREG as " + option);
+               mx_found = true;
+               break;
+           }
+        }
+
+        // Forward vm options to LingeredApp
+        ArrayList<String> cmd = new ArrayList();
+        cmd.addAll(Utils.getVmOptions());
+        if (!mx_found) {
+            cmd.add(desiredMaxHeapSize);
+            System.out.println("INFO: maximum heap size set explicitly as " + desiredMaxHeapSize);
+        }
+        cmd.add("-XX:+PrintFlagsFinal");
+
+        TmtoolTestScenario tmt = TmtoolTestScenario.create("jmap", "--heap");
+        int exitcode = tmt.launch(cmd);
+        if (exitcode != 0) {
+            throw new RuntimeException("Test FAILED jmap exits with non zero exit code " + exitcode);
+        }
+
+        Map<String,String> parsedJmapOutput = parseJMapOutput(tmt.getToolOutput());
+        Map<String,String> parsedVMOutput = tmt.parseFlagsFinal();
+
+        compareValues(parsedJmapOutput, parsedVMOutput);
+
+        // If test fails it throws RuntimeException
+        System.out.println("Test PASSED");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/tools/jhsdb/heapconfig/TmtoolTestScenario.java	Mon May 09 23:41:59 2016 +0300
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import jdk.test.lib.apps.LingeredApp;
+import jdk.testlibrary.JDKToolLauncher;
+import jdk.testlibrary.Utils;
+
+public class TmtoolTestScenario {
+
+    private final ArrayList<String> toolOutput = new ArrayList<String>();
+    private LingeredApp theApp = null;
+    private final String toolName;
+    private final String[] toolArgs;
+
+    /**
+     *  @param toolName - name of tool to test
+     *  @param toolArgs - tool arguments
+     *  @return the object
+     */
+    public static TmtoolTestScenario create(String toolName, String... toolArgs) {
+        return new TmtoolTestScenario(toolName, toolArgs);
+    }
+
+    /**
+     * @return STDOUT of tool
+     */
+    public List<String> getToolOutput() {
+        return toolOutput;
+    }
+
+    /**
+     *
+     * @return STDOUT of test app
+     */
+    public List<String> getAppOutput() {
+        return theApp.getAppOutput();
+    }
+
+    /**
+     * @return Value of the app output with -XX:+PrintFlagsFinal as a map.
+     */
+    public Map<String, String>  parseFlagsFinal() {
+        List<String> astr = theApp.getAppOutput();
+        Map<String, String> vmMap = new HashMap<String, String>();
+
+        for (String line : astr) {
+            String[] lv = line.trim().split("\\s+");
+            try {
+                vmMap.put(lv[1], lv[3]);
+            } catch (ArrayIndexOutOfBoundsException ex) {
+                // ignore mailformed lines
+            }
+        }
+        return vmMap;
+    }
+
+    /**
+     *
+     * @param vmArgs  - vm and java arguments to launch test app
+     * @return exit code of tool
+     */
+    public int launch(List<String> vmArgs) {
+        System.out.println("Starting LingeredApp");
+        try {
+            try {
+                List<String> vmArgsExtended = new ArrayList<String>();
+                vmArgsExtended.add("-XX:+UsePerfData");
+                vmArgsExtended.addAll(vmArgs);
+                theApp = LingeredApp.startApp(vmArgsExtended);
+
+                System.out.println("Starting " + toolName + " against " + theApp.getPid());
+                JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
+                launcher.addToolArg(toolName);
+
+                for (String cmd : toolArgs) {
+                    launcher.addToolArg(cmd);
+                }
+                launcher.addToolArg("--pid");
+                launcher.addToolArg(Long.toString(theApp.getPid()));
+
+                ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
+                processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
+                Process toolProcess = processBuilder.start();
+
+                // By default child process output stream redirected to pipe, so we are reading it in foreground.
+                BufferedReader reader = new BufferedReader(new InputStreamReader(toolProcess.getInputStream()));
+
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    toolOutput.add(line.trim());
+                }
+
+                toolProcess.waitFor();
+
+                return toolProcess.exitValue();
+            } finally {
+                LingeredApp.stopApp(theApp);
+            }
+        } catch (IOException | InterruptedException ex) {
+            throw new RuntimeException("Test ERROR " + ex, ex);
+        }
+    }
+
+    public void launch(String... appArgs) throws IOException {
+        launch(Arrays.asList(appArgs));
+    }
+
+    private TmtoolTestScenario(String toolName, String[] toolArgs) {
+        this.toolName = toolName;
+        this.toolArgs = toolArgs;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/tools/jinfo/BasicJInfoTest.java	Mon May 09 23:41:59 2016 +0300
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2005, 2016, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.util.Arrays;
+
+import jdk.testlibrary.JDKToolLauncher;
+import jdk.testlibrary.OutputAnalyzer;
+import jdk.testlibrary.ProcessTools;
+
+/*
+ * @test
+ * @summary Unit test for jinfo utility
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.*
+ * @run main BasicJInfoTest
+ */
+public class BasicJInfoTest {
+
+    private static ProcessBuilder processBuilder = new ProcessBuilder();
+
+    public static void main(String[] args) throws Exception {
+        testJinfoNoArgs();
+        testJinfoFlags();
+        testJinfoProps();
+        testJinfoFlagInvalid();
+    }
+
+    private static void testJinfoNoArgs() throws Exception {
+        OutputAnalyzer output = jinfo();
+        output.shouldContain("-XX");
+        output.shouldContain("test.jdk=");
+        output.shouldHaveExitValue(0);
+    }
+
+    private static void testJinfoFlagInvalid() throws Exception {
+        OutputAnalyzer output = jinfo("-flag");
+        output.shouldHaveExitValue(1);
+    }
+
+    private static void testJinfoFlags() throws Exception {
+        OutputAnalyzer output = jinfo("-flags");
+        output.shouldContain("-XX");
+        output.shouldHaveExitValue(0);
+    }
+
+    private static void testJinfoProps() throws Exception {
+        OutputAnalyzer output = jinfo("-props");
+        output.shouldContain("test.jdk=");
+        output.shouldHaveExitValue(0);
+    }
+
+    private static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
+        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
+        if (toolArgs != null) {
+            for (String toolArg : toolArgs) {
+                launcher.addToolArg(toolArg);
+            }
+        }
+        launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
+
+        processBuilder.command(launcher.getCommand());
+        System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
+        OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
+        System.out.println(output.getOutput());
+
+        return output;
+    }
+
+}
--- a/jdk/test/sun/tools/jinfo/JInfoHelper.java	Mon May 09 13:12:48 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2014, 2015, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.util.Arrays;
-
-import jdk.testlibrary.JDKToolLauncher;
-import jdk.testlibrary.OutputAnalyzer;
-import jdk.testlibrary.ProcessTools;
-
-/**
- *  The helper class for running jinfo utility.
- */
-public final class JInfoHelper {
-
-    /**
-     * Print configuration information for the current process
-     *
-     * @param toolArgs List of jinfo options
-     */
-    public static OutputAnalyzer jinfo(String... toolArgs) throws Exception {
-        return jinfo(true, toolArgs);
-    }
-
-    /**
-     * Print usage information
-     *
-     * @param toolArgs List of jinfo options
-     */
-    public static OutputAnalyzer jinfoNoPid(String... toolArgs) throws Exception {
-        return jinfo(false, toolArgs);
-    }
-
-    private static OutputAnalyzer jinfo(boolean toPid, String... toolArgs) throws Exception {
-        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jinfo");
-        if (toolArgs != null) {
-            for (String toolArg : toolArgs) {
-                launcher.addToolArg(toolArg);
-            }
-        }
-        if (toPid) {
-            launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
-        }
-
-        ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
-        System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
-        OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
-        System.out.println(output.getOutput());
-
-        return output;
-    }
-
-}
--- a/jdk/test/sun/tools/jinfo/JInfoLauncherTest.java	Mon May 09 13:12:48 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,343 +0,0 @@
-/*
- * Copyright (c) 2014, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import org.testng.annotations.Test;
-import org.testng.annotations.BeforeClass;
-import sun.tools.jinfo.JInfo;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-
-import static org.testng.Assert.*;
-
-/**
- * @test
- * @bug 8039080
- * @modules jdk.jcmd/sun.tools.jinfo
- * @run testng JInfoLauncherTest
- * @summary Test JInfo launcher argument parsing
- */
-@Test
-public class JInfoLauncherTest {
-    public static final String VALIDATION_EXCEPTION_CLSNAME =
-                                IllegalArgumentException.class.getName();
-
-    private Constructor<JInfo> jInfoConstructor;
-    private Field fldUseSA;
-
-    @BeforeClass
-    public void setup() throws Exception {
-        jInfoConstructor = JInfo.class.getDeclaredConstructor(String[].class);
-        jInfoConstructor.setAccessible(true);
-        fldUseSA = JInfo.class.getDeclaredField("useSA");
-        fldUseSA.setAccessible(true);
-    }
-
-    private JInfo newJInfo(String[] args) throws Exception {
-        try {
-            return jInfoConstructor.newInstance((Object) args);
-        } catch (Exception e) {
-            if (isValidationException(e.getCause())) {
-                throw (Exception)e.getCause();
-            }
-            throw e;
-        }
-    }
-
-    private boolean getUseSA(JInfo jinfo) throws Exception {
-        return fldUseSA.getBoolean(jinfo);
-    }
-
-    private void cmdPID(String cmd, String ... params) throws Exception {
-        int offset = (cmd != null ? 1 : 0);
-        String[] args = new String[offset + params.length];
-        args[0] = cmd;
-        System.arraycopy(params, 0, args, offset, params.length);
-        JInfo j = newJInfo(args);
-        assertFalse(getUseSA(j), "Local jinfo must not forward to SA");
-    }
-
-    private void cmdCore(String cmd, String ... params) throws Exception {
-        int offset = (cmd != null ? 1 : 0);
-        String[] args = new String[offset + params.length];
-        args[0] = cmd;
-        System.arraycopy(params, 0, args, offset, params.length);
-        JInfo j = newJInfo(args);
-        assertTrue(getUseSA(j), "Core jinfo must forward to SA");
-    }
-
-    private void cmdRemote(String cmd, String ... params) throws Exception {
-        int offset = (cmd != null ? 1 : 0);
-        String[] args = new String[offset + params.length];
-        args[0] = cmd;
-        System.arraycopy(params, 0, args, offset, params.length);
-        JInfo j = newJInfo(args);
-        assertTrue(getUseSA(j), "Remote jinfo must forward to SA");
-    }
-
-    private void cmdExtraArgs(String cmd, int argsLen) throws Exception {
-        String[] args = new String[argsLen + 1 + (cmd != null ? 1 : 0)];
-        Arrays.fill(args, "a");
-        if (cmd != null) {
-            args[0] = cmd;
-        } else {
-            cmd = "default";
-        }
-        try {
-            JInfo j = newJInfo(args);
-            fail("\"" + cmd + "\" does not support more than " + argsLen +
-                 " arguments");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    private void cmdMissingArgs(String cmd, int reqArgs) throws Exception {
-        String[] args = new String[reqArgs - 1 + (cmd != null ? 1 : 0)];
-        Arrays.fill(args, "a");
-        if (cmd != null) {
-            args[0] = cmd;
-        } else {
-            cmd = "default";
-        }
-        try {
-            JInfo j = newJInfo(args);
-            fail("\"" + cmd + "\" requires at least " + reqArgs + " argument");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    public void testDefaultPID() throws Exception {
-        cmdPID(null, "1234");
-    }
-
-    public void testFlagsPID() throws Exception {
-        cmdPID("-flags", "1234");
-    }
-
-    public void testSyspropsPID() throws Exception {
-        cmdPID("-sysprops", "1234");
-    }
-
-    public void testReadFlagPID() throws Exception {
-        cmdPID("-flag", "SomeManagementFlag", "1234");
-    }
-
-    public void testSetFlag1PID() throws Exception {
-        cmdPID("-flag", "+SomeManagementFlag", "1234");
-    }
-
-    public void testSetFlag2PID() throws Exception {
-        cmdPID("-flag", "-SomeManagementFlag", "1234");
-    }
-
-    public void testSetFlag3PID() throws Exception {
-        cmdPID("-flag", "SomeManagementFlag=314", "1234");
-    }
-
-    public void testDefaultCore() throws Exception {
-        cmdCore(null, "myapp.exe", "my.core");
-    }
-
-    public void testFlagsCore() throws Exception {
-        cmdCore("-flags", "myapp.exe", "my.core");
-    }
-
-    public void testSyspropsCore() throws Exception {
-        cmdCore("-sysprops", "myapp.exe", "my.core");
-    }
-
-    public void testReadFlagCore() throws Exception {
-        try {
-            cmdCore("-flag", "SomeManagementFlag", "myapp.exe", "my.core");
-            fail("Flags can not be read from core files");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    public void testSetFlag1Core() throws Exception {
-        try {
-            cmdCore("-flag", "+SomeManagementFlag", "myapp.exe", "my.core");
-            fail("Flags can not be set in core files");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    public void testSetFlag2Core() throws Exception {
-        try {
-            cmdCore("-flag", "-SomeManagementFlag", "myapp.exe", "my.core");
-            fail("Flags can not be set in core files");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    public void testSetFlag3Core() throws Exception {
-        try {
-            cmdCore("-flag", "SomeManagementFlag=314", "myapp.exe", "my.core");
-            fail("Flags can not be set in core files");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    public void testDefaultRemote() throws Exception {
-        cmdRemote(null, "serverid@host");
-    }
-
-    public void testFlagsRemote() throws Exception {
-        cmdRemote("-flags", "serverid@host");
-    }
-
-    public void testSyspropsRemote() throws Exception {
-        cmdRemote("-sysprops", "serverid@host");
-    }
-
-    public void testReadFlagRemote() throws Exception {
-        try {
-            cmdCore("-flag", "SomeManagementFlag", "serverid@host");
-            fail("Flags can not be read from SA server");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    public void testSetFlag1Remote() throws Exception {
-        try {
-            cmdCore("-flag", "+SomeManagementFlag","serverid@host");
-            fail("Flags can not be set on SA server");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    public void testSetFlag2Remote() throws Exception {
-        try {
-            cmdCore("-flag", "-SomeManagementFlag", "serverid@host");
-            fail("Flags can not be read set on SA server");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    public void testSetFlag3Remote() throws Exception {
-        try {
-            cmdCore("-flag", "SomeManagementFlag=314", "serverid@host");
-            fail("Flags can not be read set on SA server");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    public void testDefaultExtraArgs() throws Exception {
-        cmdExtraArgs(null, 2);
-    }
-
-    public void testFlagsExtraArgs() throws Exception {
-        cmdExtraArgs("-flags", 2);
-    }
-
-    public void testSyspropsExtraArgs() throws Exception {
-        cmdExtraArgs("-sysprops", 2);
-    }
-
-    public void testFlagExtraArgs() throws Exception {
-        cmdExtraArgs("-flag", 2);
-    }
-
-    public void testHelp1ExtraArgs() throws Exception {
-        cmdExtraArgs("-h", 0);
-    }
-
-    public void testHelp2ExtraArgs() throws Exception {
-        cmdExtraArgs("-help", 0);
-    }
-
-    public void testDefaultMissingArgs() throws Exception {
-        cmdMissingArgs(null, 1);
-    }
-
-    public void testFlagsMissingArgs() throws Exception {
-        cmdMissingArgs("-flags", 1);
-    }
-
-    public void testSyspropsMissingArgs() throws Exception {
-        cmdMissingArgs("-sysprops", 1);
-    }
-
-    public void testFlagMissingArgs() throws Exception {
-        cmdMissingArgs("-flag", 2);
-    }
-
-    public void testUnknownCommand() throws Exception {
-        try {
-            JInfo j = newJInfo(new String[]{"-unknown_command"});
-            fail("JInfo accepts unknown commands");
-        } catch (Exception e) {
-            if (!isValidationException(e)) {
-                throw e;
-            }
-            // ignore
-        }
-    }
-
-    private static boolean isValidationException(Throwable e) {
-        return e.getClass().getName().equals(VALIDATION_EXCEPTION_CLSNAME);
-    }
-}
--- a/jdk/test/sun/tools/jinfo/JInfoRunningProcessFlagTest.java	Mon May 09 13:12:48 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2014, 2015, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.lang.management.ManagementFactory;
-import com.sun.management.HotSpotDiagnosticMXBean;
-import jdk.testlibrary.OutputAnalyzer;
-import static jdk.testlibrary.Platform.isSolaris;
-import static jdk.testlibrary.Asserts.assertEquals;
-import static jdk.testlibrary.Asserts.assertNotEquals;
-import static jdk.testlibrary.Asserts.assertTrue;
-
-/**
- * @test
- * @summary The test sanity checks 'jinfo -flag' option.
- * @library /lib/testlibrary
- * @modules java.management
- * @build jdk.testlibrary.* JInfoHelper
- * @run main/othervm -XX:+HeapDumpOnOutOfMemoryError JInfoRunningProcessFlagTest
- */
-public class JInfoRunningProcessFlagTest {
-
-    public static void main(String[] args) throws Exception {
-        testFlag();
-        testFlagPlus();
-        testFlagMinus();
-        testFlagEqual();
-
-        testInvalidFlag();
-
-        testSolarisSpecificFlag();
-    }
-
-    private static void testFlag() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError");
-        output.shouldHaveExitValue(0);
-        assertTrue(output.getStderr().isEmpty(), "'jinfo -flag HeapDumpOnOutOfMemoryError' stderr should be empty");
-        output.shouldContain("+HeapDumpOnOutOfMemoryError");
-    }
-
-    private static void testFlagPlus() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+HeapDumpOnOutOfMemoryError");
-        output.shouldHaveExitValue(0);
-        output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError");
-        output.shouldHaveExitValue(0);
-        output.shouldContain("+HeapDumpOnOutOfMemoryError");
-        verifyIsEnabled("HeapDumpOnOutOfMemoryError");
-    }
-
-    private static void testFlagMinus() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfo("-flag", "-HeapDumpOnOutOfMemoryError");
-        output.shouldHaveExitValue(0);
-        output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError");
-        output.shouldHaveExitValue(0);
-        output.shouldContain("-HeapDumpOnOutOfMemoryError");
-        verifyIsDisabled("HeapDumpOnOutOfMemoryError");
-    }
-
-    private static void testFlagEqual() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError=1");
-        output.shouldHaveExitValue(0);
-        output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError");
-        output.shouldHaveExitValue(0);
-        output.shouldContain("+HeapDumpOnOutOfMemoryError");
-        verifyIsEnabled("HeapDumpOnOutOfMemoryError");
-    }
-
-    private static void testInvalidFlag() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfo("-flag", "monkey");
-        assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid flag");
-    }
-
-    private static void testSolarisSpecificFlag() throws Exception {
-        if (!isSolaris())
-            return;
-
-        OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+ExtendedDTraceProbes");
-        output.shouldHaveExitValue(0);
-        output = JInfoHelper.jinfo();
-        output.shouldContain("+ExtendedDTraceProbes");
-        verifyIsEnabled("ExtendedDTraceProbes");
-
-        output = JInfoHelper.jinfo("-flag", "-ExtendedDTraceProbes");
-        output.shouldHaveExitValue(0);
-        output = JInfoHelper.jinfo();
-        output.shouldContain("-ExtendedDTraceProbes");
-        verifyIsDisabled("ExtendedDTraceProbes");
-
-        output = JInfoHelper.jinfo("-flag", "ExtendedDTraceProbes");
-        output.shouldContain("-ExtendedDTraceProbes");
-        output.shouldHaveExitValue(0);
-    }
-
-    private static void verifyIsEnabled(String flag) {
-        HotSpotDiagnosticMXBean hotspotDiagnostic =
-                ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
-        String flagValue = hotspotDiagnostic.getVMOption(flag).getValue();
-        assertEquals(flagValue, "true", "Expected '" + flag + "' flag be enabled");
-    }
-
-    private static void verifyIsDisabled(String flag) {
-        HotSpotDiagnosticMXBean hotspotDiagnostic =
-                ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
-        String flagValue = hotspotDiagnostic.getVMOption(flag).getValue();
-        assertEquals(flagValue, "false", "Expected '" + flag + "' flag be disabled");
-    }
-
-}
--- a/jdk/test/sun/tools/jinfo/JInfoRunningProcessTest.java	Mon May 09 13:12:48 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2014, 2015, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import jdk.testlibrary.OutputAnalyzer;
-import static jdk.testlibrary.Asserts.assertTrue;
-
-/**
- * @test
- * @summary The test sanity checks functionality of 'jinfo', 'jinfo -sysprops' and 'jinfo -flags'
- * @library /lib/testlibrary
- * @modules java.management
- * @build jdk.testlibrary.* JInfoHelper
- * @run main/othervm -XX:+HeapDumpOnOutOfMemoryError JInfoRunningProcessTest
- */
-public class JInfoRunningProcessTest {
-
-    public static void main(String[] args) throws Exception {
-        testNoOptions();
-        testSysprops();
-        testFlags();
-    }
-
-    private static void testNoOptions() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfo();
-        output.shouldHaveExitValue(0);
-        assertTrue(output.getStderr().isEmpty(), "'jinfo' stderr should be empty");
-        output.shouldContain("+HeapDumpOnOutOfMemoryError");
-    }
-
-    private static void testSysprops() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfo("-sysprops");
-        output.shouldHaveExitValue(0);
-        assertTrue(output.getStderr().isEmpty(), "'jinfo -sysprops' stderr should be empty");
-    }
-
-    private static void testFlags() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfo("-flags");
-        output.shouldHaveExitValue(0);
-        assertTrue(output.getStderr().isEmpty(), "'jinfo -flags' stderr should be empty");
-        output.shouldContain("+HeapDumpOnOutOfMemoryError");
-    }
-
-}
--- a/jdk/test/sun/tools/jinfo/JInfoSanityTest.java	Mon May 09 13:12:48 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2014, 2015, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import static jdk.testlibrary.Asserts.assertNotEquals;
-import static jdk.testlibrary.Asserts.assertTrue;
-import static jdk.testlibrary.Asserts.assertFalse;
-import jdk.testlibrary.OutputAnalyzer;
-
-/**
- * @test
- * @summary The test sanity checks functionality of 'jinfo -h', 'jinfo -help',
- *          and verifies jinfo exits abnormally if started with invalid options.
- * @library /lib/testlibrary
- * @modules java.management
- * @build jdk.testlibrary.* JInfoHelper
- * @run main JInfoSanityTest
- */
-public class JInfoSanityTest {
-
-    public static void main(String[] args) throws Exception {
-        test_h();
-        test_help();
-        testVersion();
-        testUnknownHost();
-    }
-
-    private static void test_h() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfoNoPid("-h");
-        output.shouldHaveExitValue(0);
-        assertFalse(output.getStderr().isEmpty(), "'jinfo -h' stderr should not be empty");
-        assertTrue(output.getStdout().isEmpty(), "'jinfo -h' stdout should be empty");
-    }
-
-    private static void test_help() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfoNoPid("-help");
-        output.shouldHaveExitValue(0);
-        assertFalse(output.getStderr().isEmpty(), "'jinfo -help' stderr should not be empty");
-        assertTrue(output.getStdout().isEmpty(), "'jinfo -help' stdout should be empty");
-    }
-
-    private static void testVersion() throws Exception {
-        OutputAnalyzer output = JInfoHelper.jinfoNoPid("-version");
-        output.shouldHaveExitValue(1);
-        assertFalse(output.getStderr().isEmpty(), "'jinfo -version' stderr should not be empty");
-        assertTrue(output.getStdout().isEmpty(), "'jinfo -version' stdout should be empty");
-    }
-
-    private static void testUnknownHost() throws Exception {
-        String unknownHost = "Oja781nh2ev7vcvbajdg-Sda1-C";
-        OutputAnalyzer output = JInfoHelper.jinfoNoPid("med@" + unknownHost);
-        assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid operation");
-        output.shouldMatch(".*(Connection refused to host\\:|UnknownHostException\\:) " + unknownHost + ".*");
-    }
-
-}
--- a/jdk/test/sun/tools/jmap/BasicJMapTest.java	Mon May 09 13:12:48 2016 +0300
+++ b/jdk/test/sun/tools/jmap/BasicJMapTest.java	Mon May 09 23:41:59 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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,12 +34,10 @@
 
 /*
  * @test
- * @bug 6321286
  * @summary Unit test for jmap utility
  * @key intermittent
  * @library /lib/testlibrary
  * @library /test/lib/share/classes
- * @modules java.management
  * @build jdk.testlibrary.*
  * @build jdk.test.lib.hprof.*
  * @build jdk.test.lib.hprof.model.*
@@ -54,6 +52,8 @@
     public static void main(String[] args) throws Exception {
         testHisto();
         testHistoLive();
+        testFinalizerInfo();
+        testClstats();
         testDump();
         testDumpLive();
     }
@@ -68,6 +68,16 @@
         output.shouldHaveExitValue(0);
     }
 
+    private static void testFinalizerInfo() throws Exception {
+        OutputAnalyzer output = jmap("-finalizerinfo");
+        output.shouldHaveExitValue(0);
+    }
+
+    private static void testClstats() throws Exception {
+        OutputAnalyzer output = jmap("-clstats");
+        output.shouldHaveExitValue(0);
+    }
+
     private static void testDump() throws Exception {
         dump(false);
     }
@@ -105,7 +115,6 @@
 
     private static OutputAnalyzer jmap(String... toolArgs) throws Exception {
         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jmap");
-        launcher.addVMArg("-XX:+UsePerfData");
         if (toolArgs != null) {
             for (String toolArg : toolArgs) {
                 launcher.addToolArg(toolArg);
--- a/jdk/test/sun/tools/jmap/heapconfig/JMapHeapConfigTest.java	Mon May 09 13:12:48 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,166 +0,0 @@
-/*
- * Copyright (c) 2015, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import jdk.test.lib.apps.LingeredApp;
-import jdk.testlibrary.Utils;
-import jdk.testlibrary.Platform;
-
-/*
- * @test
- * @bug 8042397
- * @summary Unit test for jmap utility test heap configuration reader
- * @library /test/lib/share/classes
- * @library /lib/testlibrary
- * @modules java.management
- * @build jdk.testlibrary.*
- * @build jdk.test.lib.apps.*
- * @build JMapHeapConfigTest TmtoolTestScenario
- * @run main JMapHeapConfigTest
- */
-public class JMapHeapConfigTest {
-
-    static final String expectedJMapValues[] = {
-        "MinHeapFreeRatio",
-        "MaxHeapFreeRatio",
-        "MaxHeapSize",
-        "NewSize",
-        "MaxNewSize",
-        "OldSize",
-        "NewRatio",
-        "SurvivorRatio",
-        "MetaspaceSize",
-        "CompressedClassSpaceSize",
-        "G1HeapRegionSize"};
-
-    // ignoring MaxMetaspaceSize
-
-    static final String desiredMaxHeapSize = "-Xmx128m";
-
-    private static Map<String, String> parseJMapOutput(List<String> jmapOutput) {
-        Map<String, String> heapConfigMap = new HashMap<String, String>();
-        boolean shouldParse = false;
-
-        for (String line : jmapOutput) {
-            line = line.trim();
-
-            if (line.startsWith("Heap Configuration:")) {
-                shouldParse = true;
-                continue;
-            }
-
-            if (line.startsWith("Heap Usage:")) {
-                shouldParse = false;
-                continue;
-            }
-
-            if (shouldParse && !line.equals("")) {
-                String[] lv = line.split("\\s+");
-                try {
-                    heapConfigMap.put(lv[0], lv[2]);
-                } catch (ArrayIndexOutOfBoundsException ex) {
-                    // Ignore mailformed lines
-                }
-            }
-        }
-        return heapConfigMap;
-    }
-
-    // Compare stored values
-    private static void compareValues(Map<String, String> parsedJMapOutput, Map<String, String> parsedVmOutput) {
-        for (String key : expectedJMapValues) {
-            try {
-                String jmapVal = parsedJMapOutput.get(key);
-                if (jmapVal == null) {
-                    throw new RuntimeException("Key '" + key + "' doesn't exists in jmap output");
-                }
-
-                String vmVal = parsedVmOutput.get(key);
-                if (vmVal == null) {
-                    throw new RuntimeException("Key '" + key + "' doesn't exists in vm output");
-                }
-
-                if (new BigDecimal(jmapVal).compareTo(new BigDecimal(vmVal)) != 0) {
-                    throw new RuntimeException(String.format("Key %s doesn't match %s vs %s", key, vmVal, jmapVal));
-                }
-            } catch (NumberFormatException ex) {
-                throw new RuntimeException("Unexpected key '" + key + "' value", ex);
-            }
-        }
-    }
-
-    public static void main(String[] args) throws Exception {
-        System.out.println("Starting JMapHeapConfigTest");
-
-        if (!Platform.shouldSAAttach()) {
-            // Silently skip the test if we don't have enough permissions to attach
-            System.err.println("Error! Insufficient permissions to attach.");
-            return;
-        }
-
-        if (!LingeredApp.isLastModifiedWorking()) {
-            // Exact behaviour of the test depends to operating system and the test nature,
-            // so just print the warning and continue
-            System.err.println("Warning! Last modified time doesn't work.");
-        }
-
-        boolean mx_found = false;
-        List<String> jvmOptions = Utils.getVmOptions();
-        for (String option : jvmOptions) {
-            if (option.startsWith("-Xmx")) {
-               System.out.println("INFO: maximum heap size set by JTREG as " + option);
-               mx_found = true;
-               break;
-           }
-        }
-
-        // Forward vm options to LingeredApp
-        ArrayList<String> cmd = new ArrayList();
-        cmd.addAll(Utils.getVmOptions());
-        if (!mx_found) {
-            cmd.add(desiredMaxHeapSize);
-            System.out.println("INFO: maximum heap size set explicitly as " + desiredMaxHeapSize);
-        }
-        cmd.add("-XX:+PrintFlagsFinal");
-
-        TmtoolTestScenario tmt = TmtoolTestScenario.create("jmap", "-heap");
-        int exitcode = tmt.launch(cmd);
-        if (exitcode != 0) {
-            throw new RuntimeException("Test FAILED jmap exits with non zero exit code " + exitcode);
-        }
-
-        Map<String,String> parsedJmapOutput = parseJMapOutput(tmt.getToolOutput());
-        Map<String,String> parsedVMOutput = tmt.parseFlagsFinal();
-
-        compareValues(parsedJmapOutput, parsedVMOutput);
-
-        // If test fails it throws RuntimeException
-        System.out.println("Test PASSED");
-    }
-}
--- a/jdk/test/sun/tools/jmap/heapconfig/TmtoolTestScenario.java	Mon May 09 13:12:48 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2015, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import jdk.test.lib.apps.LingeredApp;
-import jdk.testlibrary.JDKToolLauncher;
-import jdk.testlibrary.Utils;
-
-public class TmtoolTestScenario {
-
-    private final ArrayList<String> toolOutput = new ArrayList<String>();
-    private LingeredApp theApp = null;
-    private final String toolName;
-    private final String[] toolArgs;
-
-    /**
-     *  @param toolName - name of tool to test
-     *  @param toolArgs - tool arguments
-     *  @return the object
-     */
-    public static TmtoolTestScenario create(String toolName, String... toolArgs) {
-        return new TmtoolTestScenario(toolName, toolArgs);
-    }
-
-    /**
-     * @return STDOUT of tool
-     */
-    public List<String> getToolOutput() {
-        return toolOutput;
-    }
-
-    /**
-     *
-     * @return STDOUT of test app
-     */
-    public List<String> getAppOutput() {
-        return theApp.getAppOutput();
-    }
-
-    /**
-     * @return Value of the app output with -XX:+PrintFlagsFinal as a map.
-     */
-    public Map<String, String>  parseFlagsFinal() {
-        List<String> astr = theApp.getAppOutput();
-        Map<String, String> vmMap = new HashMap<String, String>();
-
-        for (String line : astr) {
-            String[] lv = line.trim().split("\\s+");
-            try {
-                vmMap.put(lv[1], lv[3]);
-            } catch (ArrayIndexOutOfBoundsException ex) {
-                // ignore mailformed lines
-            }
-        }
-        return vmMap;
-    }
-
-    /**
-     *
-     * @param vmArgs  - vm and java arguments to launch test app
-     * @return exit code of tool
-     */
-    public int launch(List<String> vmArgs) {
-        System.out.println("Starting LingeredApp");
-        try {
-            try {
-                List<String> vmArgsExtended = new ArrayList<String>();
-                vmArgsExtended.add("-XX:+UsePerfData");
-                vmArgsExtended.addAll(vmArgs);
-                theApp = LingeredApp.startApp(vmArgsExtended);
-
-                System.out.println("Starting " + toolName + " against " + theApp.getPid());
-                JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK(toolName);
-
-                for (String cmd : toolArgs) {
-                    launcher.addToolArg(cmd);
-                }
-                launcher.addToolArg(Long.toString(theApp.getPid()));
-
-                ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
-                processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
-                Process toolProcess = processBuilder.start();
-
-                // By default child process output stream redirected to pipe, so we are reading it in foreground.
-                BufferedReader reader = new BufferedReader(new InputStreamReader(toolProcess.getInputStream()));
-
-                String line;
-                while ((line = reader.readLine()) != null) {
-                    toolOutput.add(line.trim());
-                }
-
-                toolProcess.waitFor();
-
-                return toolProcess.exitValue();
-            } finally {
-                LingeredApp.stopApp(theApp);
-            }
-        } catch (IOException | InterruptedException ex) {
-            throw new RuntimeException("Test ERROR " + ex, ex);
-        }
-    }
-
-    public void launch(String... appArgs) throws IOException {
-        launch(Arrays.asList(appArgs));
-    }
-
-    private TmtoolTestScenario(String toolName, String[] toolArgs) {
-        this.toolName = toolName;
-        this.toolArgs = toolArgs;
-    }
-
-}
--- a/jdk/test/sun/tools/jstack/BasicJStackTest.java	Mon May 09 13:12:48 2016 +0300
+++ b/jdk/test/sun/tools/jstack/BasicJStackTest.java	Mon May 09 23:41:59 2016 +0300
@@ -29,10 +29,8 @@
 
 /*
  * @test
- * @bug 6260070
  * @summary Unit test for jstack utility
  * @library /lib/testlibrary
- * @modules java.management
  * @build jdk.testlibrary.*
  * @run main BasicJStackTest
  */
--- a/jdk/test/sun/tools/jstack/DeadlockDetectionTest.java	Mon May 09 13:12:48 2016 +0300
+++ b/jdk/test/sun/tools/jstack/DeadlockDetectionTest.java	Mon May 09 23:41:59 2016 +0300
@@ -39,7 +39,6 @@
  * @summary Test deadlock detection
  * @library /test/lib/share/classes
  * @library /lib/testlibrary
- * @modules java.management
  * @build jdk.testlibrary.*
  * @build jdk.test.lib.apps.*
  * @build DeadlockDetectionTest