author | jgeorge |
Fri, 01 Dec 2017 18:19:39 +0530 | |
changeset 48181 | 61a14b5cb1c6 |
parent 47900 | 75d365bfc2e6 |
child 50791 | b1e90a8a876c |
permissions | -rw-r--r-- |
47900
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
1 |
/* |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
4 |
* |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
8 |
* |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
13 |
* accompanied this code). |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
14 |
* |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
18 |
* |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
21 |
* questions. |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
22 |
*/ |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
23 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
24 |
import java.util.ArrayList; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
25 |
import java.util.List; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
26 |
import java.io.IOException; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
27 |
import java.util.stream.Collectors; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
28 |
import java.io.OutputStream; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
29 |
import jdk.test.lib.apps.LingeredApp; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
30 |
import jdk.test.lib.JDKToolLauncher; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
31 |
import jdk.test.lib.Platform; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
32 |
import jdk.test.lib.process.OutputAnalyzer; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
33 |
import jdk.test.lib.Utils; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
34 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
35 |
/* |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
36 |
* @test |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
37 |
* @summary Test the 'type' command of jhsdb clhsdb. |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
38 |
* @bug 8190307 |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
39 |
* @library /test/lib |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
40 |
* @build jdk.test.lib.apps.* |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
41 |
* @run main/othervm TestType |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
42 |
*/ |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
43 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
44 |
public class TestType { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
45 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
46 |
private static void testClhsdbForType( |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
47 |
long lingeredAppPid, |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
48 |
String commandString, |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
49 |
String[] expectedOutputStrings) throws Exception { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
50 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
51 |
Process p; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
52 |
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb"); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
53 |
launcher.addToolArg("clhsdb"); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
54 |
launcher.addToolArg("--pid"); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
55 |
launcher.addToolArg(Long.toString(lingeredAppPid)); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
56 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
57 |
ProcessBuilder pb = new ProcessBuilder(); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
58 |
pb.command(launcher.getCommand()); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
59 |
System.out.println( |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
60 |
pb.command().stream().collect(Collectors.joining(" "))); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
61 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
62 |
try { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
63 |
p = pb.start(); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
64 |
} catch (Exception attachE) { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
65 |
throw new Error("Couldn't start jhsdb or attach to LingeredApp : " + attachE); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
66 |
} |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
67 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
68 |
// Issue the 'type' commands at the clhsdb prompt. |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
69 |
OutputStream input = p.getOutputStream(); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
70 |
try { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
71 |
input.write((commandString + "\n").getBytes()); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
72 |
input.write("quit\n".getBytes()); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
73 |
input.flush(); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
74 |
} catch (IOException ioe) { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
75 |
throw new Error("Problem issuing the 'type' command ", ioe); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
76 |
} |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
77 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
78 |
OutputAnalyzer output = new OutputAnalyzer(p); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
79 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
80 |
try { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
81 |
p.waitFor(); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
82 |
} catch (InterruptedException ie) { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
83 |
p.destroyForcibly(); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
84 |
throw new Error("Problem awaiting the child process: " + ie); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
85 |
} |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
86 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
87 |
output.shouldHaveExitValue(0); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
88 |
System.out.println(output.getOutput()); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
89 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
90 |
for (String expectedOutputString: expectedOutputStrings) { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
91 |
output.shouldContain(expectedOutputString); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
92 |
} |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
93 |
} |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
94 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
95 |
public static void main (String... args) throws Exception { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
96 |
LingeredApp app = null; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
97 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
98 |
if (!Platform.shouldSAAttach()) { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
99 |
System.out.println( |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
100 |
"SA attach not expected to work - test skipped."); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
101 |
return; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
102 |
} |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
103 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
104 |
try { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
105 |
List<String> vmArgs = new ArrayList<String>(); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
106 |
vmArgs.addAll(Utils.getVmOptions()); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
107 |
// Strings to check for in the output of 'type'. The 'type' |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
108 |
// command prints out entries from 'gHotSpotVMTypes', which |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
109 |
// is a table containing the hotspot types, their supertypes, |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
110 |
// sizes, etc, which are of interest to the SA. |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
111 |
String[] defaultOutputStrings = |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
112 |
{"type G1CollectedHeap CollectedHeap", |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
113 |
"type ConstantPoolCache MetaspaceObj", |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
114 |
"type ConstantPool Metadata", |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
115 |
"type CompilerThread JavaThread", |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
116 |
"type CardGeneration Generation", |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
117 |
"type ArrayKlass Klass", |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
118 |
"type InstanceKlass Klass"}; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
119 |
// String to check for in the output of "type InstanceKlass" |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
120 |
String[] instanceKlassOutputString = {"type InstanceKlass Klass"}; |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
121 |
|
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
122 |
app = LingeredApp.startApp(vmArgs); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
123 |
System.out.println ("Started LingeredApp with pid " + app.getPid()); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
124 |
testClhsdbForType(app.getPid(), "type", defaultOutputStrings); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
125 |
testClhsdbForType(app.getPid(), |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
126 |
"type InstanceKlass", |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
127 |
instanceKlassOutputString); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
128 |
} finally { |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
129 |
LingeredApp.stopApp(app); |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
130 |
} |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
131 |
} |
75d365bfc2e6
8190307: SA tests for the clhsdb commands: universe, intconstant, type
jgeorge
parents:
diff
changeset
|
132 |
} |