changeset 60854:49baadd53e06

8242162: convert clhsdb "sysprops" command from javascript to java Reviewed-by: sspitsyn, ysuenaga
author cjplummer
date Thu, 09 Apr 2020 07:13:49 -0700
parents be95ba8d08c4
children 695e3037028c
files src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CommandProcessor.java test/hotspot/jtreg/serviceability/sa/LingeredAppSysProps.java test/hotspot/jtreg/serviceability/sa/TestSysProps.java
diffstat 3 files changed, 64 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CommandProcessor.java	Thu Apr 09 10:55:01 2020 -0300
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/CommandProcessor.java	Thu Apr 09 07:13:49 2020 -0700
@@ -79,6 +79,7 @@
 import sun.jvm.hotspot.tools.PMap;
 import sun.jvm.hotspot.tools.PStack;
 import sun.jvm.hotspot.tools.StackTrace;
+import sun.jvm.hotspot.tools.SysPropsDumper;
 import sun.jvm.hotspot.tools.jcore.ClassDump;
 import sun.jvm.hotspot.tools.jcore.ClassFilter;
 import sun.jvm.hotspot.tools.jcore.ClassWriter;
@@ -1765,6 +1766,16 @@
                 }
             }
         },
+        new Command("sysprops", "sysprops", false) {
+            public void doit(Tokens t) {
+                if (t.countTokens() != 0) {
+                    usage();
+                    return;
+                }
+                SysPropsDumper sysProps = new SysPropsDumper();
+                sysProps.run();
+            }
+        },
         new Command("dumpheap", "dumpheap [filename]", false) {
             public void doit(Tokens t) {
                 if (t.countTokens() > 1) {
--- a/test/hotspot/jtreg/serviceability/sa/LingeredAppSysProps.java	Thu Apr 09 10:55:01 2020 -0300
+++ b/test/hotspot/jtreg/serviceability/sa/LingeredAppSysProps.java	Thu Apr 09 07:13:49 2020 -0700
@@ -27,6 +27,11 @@
 
 public class LingeredAppSysProps extends LingeredApp {
     public static void main(String args[]) {
+        // Make sure the user.timezone property gets created so we get consistent results.
+        // It's normally not created on startup, but it's creation is being trigger when
+        // "jinfo -syprops" is used. This way we force it to be created before then.
+        java.util.TimeZone.getDefault();
+
         // Print all the system properties first.
         System.getProperties().list(System.out);
 
--- a/test/hotspot/jtreg/serviceability/sa/TestSysProps.java	Thu Apr 09 10:55:01 2020 -0300
+++ b/test/hotspot/jtreg/serviceability/sa/TestSysProps.java	Thu Apr 09 07:13:49 2020 -0700
@@ -34,14 +34,38 @@
 
 /**
  * @test
- * @bug 8242165
- * @summary Test "jhsdb jinfo --sysprops" and "jinfo -sysprops" commands
+ * @bug 8242165 8242162
+ * @summary Test "jhsdb jinfo --sysprops", "jinfo -sysprops", and clhsdb "sysprops" commands
  * @requires vm.hasSA
  * @library /test/lib
  * @run main/othervm TestSysProps
  */
 
 public class TestSysProps {
+    public static void findProp(String[] propLines, String propname, String cmdName) {
+        boolean found = false;
+        for (String propLine : propLines) {
+            if (propLine.startsWith(propname)) {
+                found = true;
+                break;
+            }
+        }
+        if (!found) {
+            throw new RuntimeException("Could not find property in " + cmdName + " output: " + propname);
+        }
+    }
+
+    public static void countProps(String[] propLines, int expectedCount, String cmdName) {
+        int numProps = 0;
+        for (String propLine : propLines) {
+            if (propLine.indexOf("=") != -1) {
+                numProps++;
+            }
+        }
+        if (numProps != expectedCount) {
+            throw new RuntimeException("Wrong number of " + cmdName + " properties: " + numProps);
+        }
+    }
 
     public static void main (String... args) throws Exception {
         SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
@@ -52,7 +76,7 @@
             LingeredApp.startApp(app);
             System.out.println("Started LingeredAppSysProps with pid " + app.getPid());
 
-            // First get properties using the SA version of jinfo
+            // Get properties using the SA version of jinfo
 
             JDKToolLauncher jhsdbLauncher = JDKToolLauncher.createUsingTestJDK("jhsdb");
             jhsdbLauncher.addToolArg("jinfo");
@@ -72,7 +96,7 @@
 
             jhsdbOut.shouldMatch("Debugger attached successfully.");
 
-            // Now get properties using the Attach API version of jinfo
+            // Get the properties using the Attach API version of jinfo
 
             JDKToolLauncher jinfoLauncher = JDKToolLauncher.createUsingTestJDK("jinfo");
             jinfoLauncher.addToolArg("-sysprops");
@@ -91,8 +115,17 @@
 
             jinfoOut.shouldMatch("Java System Properties:");
 
+            // Get the properties using "clhsdb sysprops".
+
+            System.out.println("clhsdb sysprops output:");
+            ClhsdbLauncher test = new ClhsdbLauncher();
+            List<String> cmds = List.of("sysprops");
+            String output = test.run(app.getPid(), cmds, null, null);
+            OutputAnalyzer clhsdbOut = new OutputAnalyzer(output);
+            clhsdbOut.shouldMatch("java.specification.version");
+
             // Get the output from LingeredAppSysProps, which has printed all the
-            // system properties from java.
+            // system properties using java.
 
             app.stopApp();
             System.out.println("LingeredAppSysProps output:");
@@ -108,12 +141,11 @@
 
             String[] jhsdbLines = jhsdbOut.getStdout().split("\\R");
             String[] jinfoLines = jinfoOut.getStdout().split("\\R");
+            String[] clhsdbLines = clhsdbOut.getStdout().split("\\R");
             String[] appLines   = app.getOutput().getStdout().split("\\R");
             int numAppProps = 0;
             boolean foundStartOfList = false;
             for (String appProp : appLines) {
-                boolean found;
-
                 // Skip any output that occurs before the first property
                 if (!foundStartOfList) {
                     if (appProp.indexOf("-- listing properties --") != -1) {
@@ -129,33 +161,14 @@
                 System.out.println("Found prop " + propname);
                 numAppProps++;
 
-                // Find the same property in "jhsdb jinfo" output
-                found = false;
-                for (String jhsdbProp : jhsdbLines) {
-                    if (appProp.startsWith(jhsdbProp)) {
-                        found = true;
-                        break;
-                    }
-                }
-                if (!found) {
-                    throw new RuntimeException("Could not find property in jhsdb jinfo output: " + propname);
-                }
-
-                // Find the same property in "jinfo" output
-                found = false;
-                for (String jinfoProp : jinfoLines) {
-                    if (jinfoProp.startsWith(propname)) {
-                        found = true;
-                        break;
-                    }
-                }
-                if (!found) {
-                    throw new RuntimeException("Could not find property in jinfo output: " + propname);
-                }
+                // Make sure we can find the property in each of the other 3 lists
+                findProp(jhsdbLines, propname, "jhsdb jinfo");
+                findProp(jinfoLines, propname, "jinfo");
+                findProp(clhsdbLines, propname, "clhsdb sysprops");
             }
 
             // Make sure we found a reasonable number of properties in the app output. It should
-            // be close to 44, but the spec only mandates 29, so this is what we check for. The
+            // be close to 45, but the spec only mandates 29, so this is what we check for. The
             // main reason for this check is just to make sure something didn't go drastically
             // wrong, resulting in no properties in the app output, meaning that no comparison
             // was actually done with the other sets of output.
@@ -164,27 +177,10 @@
                 throw new RuntimeException("Did not find at least 29 properties: " + numAppProps);
             }
 
-            // Make sure jhsdb list has the same number of properties.
-            int numJhsdbProps = 0;
-            for (String jhsdbProp : jhsdbLines) {
-                if (jhsdbProp.indexOf("=") != -1) {
-                    numJhsdbProps++;
-                }
-            }
-            if (numJhsdbProps != numAppProps) {
-                throw new RuntimeException("Wrong number of jhsdb jinfo properties: " + numJhsdbProps);
-            }
-
-            // Make sure jinfo list has the same number of properties.
-            int numJinfoProps = 0;
-            for (String jinfoProp : jhsdbLines) {
-                if (jinfoProp.indexOf("=") != -1) {
-                    numJinfoProps++;
-                }
-            }
-            if (numJinfoProps != numAppProps) {
-                throw new RuntimeException("Wrong number of jinfo properties: " + numJhsdbProps);
-            }
+            // Make sure each list has the same number of properties.
+            countProps(jhsdbLines, numAppProps, "jhsdb jinfo");
+            countProps(jinfoLines, numAppProps, "jinfo");
+            countProps(clhsdbLines, numAppProps, "clhsdb sysprops");
 
             System.out.println("Test Completed");
         } finally {