< prev index next >

test/hotspot/jtreg/serviceability/sa/TestUniverse.java

Print this page




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.util.ArrayList;
  25 import java.util.List;
  26 import java.io.IOException;
  27 import java.util.stream.Collectors;
  28 import java.io.OutputStream;
  29 import jdk.test.lib.apps.LingeredApp;
  30 import jdk.test.lib.JDKToolLauncher;
  31 import jdk.test.lib.Platform;
  32 import jdk.test.lib.process.OutputAnalyzer;
  33 
  34 /*
  35  * @test
  36  * @summary Test the 'universe' command of jhsdb clhsdb.

  37  * @bug 8190307
  38  * @library /test/lib
  39  * @build jdk.test.lib.apps.*
  40  * @run main/othervm TestUniverse










  41  */
  42 
  43 public class TestUniverse {
  44 
  45     private static void testClhsdbForUniverse(long lingeredAppPid,
  46                                               String gc) throws Exception {
  47 
  48         Process p;
  49         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
  50         launcher.addToolArg("clhsdb");
  51         launcher.addToolArg("--pid");
  52         launcher.addToolArg(Long.toString(lingeredAppPid));
  53 
  54         ProcessBuilder pb = new ProcessBuilder();
  55         pb.command(launcher.getCommand());
  56         System.out.println(
  57             pb.command().stream().collect(Collectors.joining(" ")));
  58 
  59         try {
  60             p = pb.start();


  85         System.out.println(output.getOutput());
  86 
  87         output.shouldContain("Heap Parameters");
  88         if (gc.contains("G1GC")) {
  89             output.shouldContain("garbage-first heap");
  90             output.shouldContain("region size");
  91             output.shouldContain("G1 Young Generation:");
  92             output.shouldContain("regions  =");
  93         }
  94         if (gc.contains("UseConcMarkSweepGC")) {
  95             output.shouldContain("Gen 1: concurrent mark-sweep generation");
  96         }
  97         if (gc.contains("UseSerialGC")) {
  98             output.shouldContain("Gen 1:   old");
  99         }
 100         if (gc.contains("UseParallelGC")) {
 101             output.shouldContain("ParallelScavengeHeap");
 102             output.shouldContain("PSYoungGen");
 103             output.shouldContain("eden");
 104         }



 105 
 106     }
 107 
 108     public static void test(String gc) throws Exception {
 109         LingeredApp app = null;
 110         try {
 111             List<String> vmArgs = new ArrayList<String>();



 112             vmArgs.add(gc);
 113             app = LingeredApp.startApp(vmArgs);
 114             System.out.println ("Started LingeredApp with the GC option " + gc +
 115                                 " and pid " + app.getPid());
 116             testClhsdbForUniverse(app.getPid(), gc);
 117         } finally {
 118             LingeredApp.stopApp(app);
 119         }
 120     }
 121 
 122 
 123     public static void main (String... args) throws Exception {
 124 
 125         if (!Platform.shouldSAAttach()) {
 126             System.out.println(
 127                "SA attach not expected to work - test skipped.");
 128             return;
 129         }
 130 
 131         try {
 132             test("-XX:+UseG1GC");
 133             test("-XX:+UseParallelGC");
 134             test("-XX:+UseSerialGC");
 135             test("-XX:+UseConcMarkSweepGC");




 136         } catch (Exception e) {
 137             throw new Error("Test failed with " + e);
 138         }
 139     }
 140 }


  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.util.ArrayList;
  25 import java.util.List;
  26 import java.io.IOException;
  27 import java.util.stream.Collectors;
  28 import java.io.OutputStream;
  29 import jdk.test.lib.apps.LingeredApp;
  30 import jdk.test.lib.JDKToolLauncher;
  31 import jdk.test.lib.Platform;
  32 import jdk.test.lib.process.OutputAnalyzer;
  33 
  34 /*
  35  * @test
  36  * @summary Test the 'universe' command of jhsdb clhsdb.
  37  * @requires vm.gc != "Z"
  38  * @bug 8190307
  39  * @library /test/lib
  40  * @build jdk.test.lib.apps.*
  41  * @run main/othervm TestUniverse withoutZ
  42  */
  43 
  44 /*
  45  * @test
  46  * @summary Test the 'universe' command of jhsdb clhsdb.
  47  * @requires vm.gc == "Z"
  48  * @bug 8190307
  49  * @library /test/lib
  50  * @build jdk.test.lib.apps.*
  51  * @run main/othervm TestUniverse withZ
  52  */
  53 
  54 public class TestUniverse {
  55 
  56     private static void testClhsdbForUniverse(long lingeredAppPid,
  57                                               String gc) throws Exception {
  58 
  59         Process p;
  60         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
  61         launcher.addToolArg("clhsdb");
  62         launcher.addToolArg("--pid");
  63         launcher.addToolArg(Long.toString(lingeredAppPid));
  64 
  65         ProcessBuilder pb = new ProcessBuilder();
  66         pb.command(launcher.getCommand());
  67         System.out.println(
  68             pb.command().stream().collect(Collectors.joining(" ")));
  69 
  70         try {
  71             p = pb.start();


  96         System.out.println(output.getOutput());
  97 
  98         output.shouldContain("Heap Parameters");
  99         if (gc.contains("G1GC")) {
 100             output.shouldContain("garbage-first heap");
 101             output.shouldContain("region size");
 102             output.shouldContain("G1 Young Generation:");
 103             output.shouldContain("regions  =");
 104         }
 105         if (gc.contains("UseConcMarkSweepGC")) {
 106             output.shouldContain("Gen 1: concurrent mark-sweep generation");
 107         }
 108         if (gc.contains("UseSerialGC")) {
 109             output.shouldContain("Gen 1:   old");
 110         }
 111         if (gc.contains("UseParallelGC")) {
 112             output.shouldContain("ParallelScavengeHeap");
 113             output.shouldContain("PSYoungGen");
 114             output.shouldContain("eden");
 115         }
 116         if (gc.contains("UseZGC")) {
 117             output.shouldContain("ZHeap");
 118         }
 119 
 120     }
 121 
 122     public static void test(String gc) throws Exception {
 123         LingeredApp app = null;
 124         try {
 125             List<String> vmArgs = new ArrayList<String>();
 126             if (gc.contains("UseZGC")) {
 127               vmArgs.add("-XX:+UnlockExperimentalVMOptions");
 128             }
 129             vmArgs.add(gc);
 130             app = LingeredApp.startApp(vmArgs);
 131             System.out.println ("Started LingeredApp with the GC option " + gc +
 132                                 " and pid " + app.getPid());
 133             testClhsdbForUniverse(app.getPid(), gc);
 134         } finally {
 135             LingeredApp.stopApp(app);
 136         }
 137     }
 138 
 139 
 140     public static void main (String... args) throws Exception {
 141 
 142         if (!Platform.shouldSAAttach()) {
 143             System.out.println(
 144                "SA attach not expected to work - test skipped.");
 145             return;
 146         }
 147 
 148         try {
 149             test("-XX:+UseG1GC");
 150             test("-XX:+UseParallelGC");
 151             test("-XX:+UseSerialGC");
 152             test("-XX:+UseConcMarkSweepGC");
 153             if (args[0].equals("withZ")) {
 154               test("-XX:+UseZGC");
 155             }
 156 
 157         } catch (Exception e) {
 158             throw new Error("Test failed with " + e);
 159         }
 160     }
 161 }
< prev index next >