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 { |