test/hotspot/jtreg/serviceability/sa/TestUniverse.java
changeset 53635 247e5ca412f5
parent 50791 b1e90a8a876c
child 54300 1b85f55c9aa2
equal deleted inserted replaced
53634:f57b943a1a22 53635:247e5ca412f5
     1 /*
     1 /*
     2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    23 
    23 
    24 import sun.hotspot.code.Compiler;
    24 import sun.hotspot.code.Compiler;
    25 
    25 
    26 import java.util.ArrayList;
    26 import java.util.ArrayList;
    27 import java.util.List;
    27 import java.util.List;
    28 import java.io.IOException;
    28 import java.util.Map;
    29 import java.util.stream.Collectors;
    29 import java.util.HashMap;
    30 import java.io.OutputStream;
       
    31 import jdk.test.lib.apps.LingeredApp;
    30 import jdk.test.lib.apps.LingeredApp;
    32 import jdk.test.lib.JDKToolLauncher;
    31 import jtreg.SkippedException;
    33 import jdk.test.lib.Platform;
       
    34 import jdk.test.lib.process.OutputAnalyzer;
       
    35 
    32 
    36 /**
    33 /**
    37  * @test
    34  * @test
    38  * @summary Test the 'universe' command of jhsdb clhsdb.
    35  * @summary Test the 'universe' command of jhsdb clhsdb.
    39  * @requires vm.hasSAandCanAttach & vm.gc != "Z"
    36  * @requires vm.hasSAandCanAttach & vm.gc != "Z"
    60 public class TestUniverse {
    57 public class TestUniverse {
    61 
    58 
    62     private static void testClhsdbForUniverse(long lingeredAppPid,
    59     private static void testClhsdbForUniverse(long lingeredAppPid,
    63                                               String gc) throws Exception {
    60                                               String gc) throws Exception {
    64 
    61 
    65         Process p;
    62         ClhsdbLauncher launcher = new ClhsdbLauncher();
    66         JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
    63         List<String> cmds = List.of("universe");
    67         launcher.addToolArg("clhsdb");
    64         Map<String, List<String>> expStrMap = new HashMap<>();
    68         launcher.addToolArg("--pid");
    65         List<String> expStrings = new ArrayList<String>();
    69         launcher.addToolArg(Long.toString(lingeredAppPid));
    66         expStrings.add("Heap Parameters");
    70 
    67 
    71         ProcessBuilder pb = new ProcessBuilder();
    68         if (gc.contains("UseZGC")) {
    72         pb.command(launcher.getCommand());
    69             expStrings.add("ZHeap");
    73         System.out.println(
       
    74             pb.command().stream().collect(Collectors.joining(" ")));
       
    75 
       
    76         try {
       
    77             p = pb.start();
       
    78         } catch (Exception attachE) {
       
    79             throw new Error("Couldn't start jhsdb or attach to LingeredApp : " + attachE);
       
    80         }
    70         }
    81 
       
    82         // Issue the 'universe' command at the clhsdb prompt.
       
    83         OutputStream input = p.getOutputStream();
       
    84         try {
       
    85             input.write("universe\n".getBytes());
       
    86             input.write("quit\n".getBytes());
       
    87             input.flush();
       
    88         } catch (IOException ioe) {
       
    89             throw new Error("Problem issuing the 'universe' command ", ioe);
       
    90         }
       
    91 
       
    92         OutputAnalyzer output = new OutputAnalyzer(p);
       
    93 
       
    94         try {
       
    95             p.waitFor();
       
    96         } catch (InterruptedException ie) {
       
    97             p.destroyForcibly();
       
    98             throw new Error("Problem awaiting the child process: " + ie, ie);
       
    99         }
       
   100         if (gc.contains("UseZGC")) {
       
   101             output.shouldContain("ZHeap");
       
   102         }
       
   103 
       
   104         output.shouldHaveExitValue(0);
       
   105         System.out.println(output.getOutput());
       
   106 
       
   107         output.shouldContain("Heap Parameters");
       
   108         if (gc.contains("G1GC")) {
    71         if (gc.contains("G1GC")) {
   109             output.shouldContain("garbage-first heap");
    72             expStrings.add("garbage-first heap");
   110             output.shouldContain("region size");
    73             expStrings.add("region size");
   111             output.shouldContain("G1 Young Generation:");
    74             expStrings.add("G1 Young Generation:");
   112             output.shouldContain("regions  =");
    75             expStrings.add("regions  =");
   113         }
    76         }
   114         if (gc.contains("UseConcMarkSweepGC")) {
    77         if (gc.contains("UseConcMarkSweepGC")) {
   115             output.shouldContain("Gen 1: concurrent mark-sweep generation");
    78             expStrings.add("Gen 1: concurrent mark-sweep generation");
   116         }
    79         }
   117         if (gc.contains("UseSerialGC")) {
    80         if (gc.contains("UseSerialGC")) {
   118             output.shouldContain("Gen 1:   old");
    81             expStrings.add("Gen 1:   old");
   119         }
    82         }
   120         if (gc.contains("UseParallelGC")) {
    83         if (gc.contains("UseParallelGC")) {
   121             output.shouldContain("ParallelScavengeHeap");
    84             expStrings.add("ParallelScavengeHeap");
   122             output.shouldContain("PSYoungGen");
    85             expStrings.add("PSYoungGen");
   123             output.shouldContain("eden");
    86             expStrings.add("eden");
   124         }
    87         }
   125         if (gc.contains("UseEpsilonGC")) {
    88         if (gc.contains("UseEpsilonGC")) {
   126             output.shouldContain("Epsilon heap");
    89             expStrings.add("Epsilon heap");
   127             output.shouldContain("reserved");
    90             expStrings.add("reserved");
   128             output.shouldContain("committed");
    91             expStrings.add("committed");
   129             output.shouldContain("used");
    92             expStrings.add("used");
   130         }
    93         }
       
    94         expStrMap.put("universe", expStrings);
       
    95         launcher.run(lingeredAppPid, cmds, expStrMap, null);
   131     }
    96     }
   132 
    97 
   133     public static void test(String gc) throws Exception {
    98     public static void test(String gc) throws Exception {
   134         LingeredApp app = null;
    99         LingeredApp app = null;
   135         try {
   100         try {
   143         } finally {
   108         } finally {
   144             LingeredApp.stopApp(app);
   109             LingeredApp.stopApp(app);
   145         }
   110         }
   146     }
   111     }
   147 
   112 
   148 
       
   149     public static void main (String... args) throws Exception {
   113     public static void main (String... args) throws Exception {
       
   114         System.out.println("Starting TestUniverse test");
   150         try {
   115         try {
   151             test("-XX:+UseG1GC");
   116             test("-XX:+UseG1GC");
   152             test("-XX:+UseParallelGC");
   117             test("-XX:+UseParallelGC");
   153             test("-XX:+UseSerialGC");
   118             test("-XX:+UseSerialGC");
   154             if (!Compiler.isGraalEnabled()) { // Graal does not support all GCs
   119             if (!Compiler.isGraalEnabled()) { // Graal does not support all GCs
   156                 if (args[0].equals("withZ")) {
   121                 if (args[0].equals("withZ")) {
   157                     test("-XX:+UseZGC");
   122                     test("-XX:+UseZGC");
   158                 }
   123                 }
   159                 test("-XX:+UseEpsilonGC");
   124                 test("-XX:+UseEpsilonGC");
   160             }
   125             }
       
   126         } catch (SkippedException se) {
       
   127             throw se;
   161         } catch (Exception e) {
   128         } catch (Exception e) {
       
   129             System.out.println(e.getMessage());
       
   130             e.printStackTrace();
   162             throw new Error("Test failed with " + e);
   131             throw new Error("Test failed with " + e);
   163         }
   132         }
   164     }
   133     }
   165 }
   134 }