author | cjplummer |
Wed, 11 Feb 2015 15:22:43 -0800 | |
changeset 29071 | 73f45d04ad7a |
child 29678 | dd2f3932c21e |
permissions | -rw-r--r-- |
29071
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
1 |
/* |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
4 |
* |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
8 |
* |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
13 |
* accompanied this code). |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
14 |
* |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
18 |
* |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
21 |
* questions. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
22 |
*/ |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
23 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
24 |
/* |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
25 |
* @test |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
26 |
* @summary Test of diagnostic command VM.class_hierarchy |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
27 |
* @library /testlibrary |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
28 |
* @build com.oracle.java.testlibrary.* |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
29 |
* @build com.oracle.java.testlibrary.dcmd.* |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
30 |
* @run testng ClassHierarchyTest |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
31 |
*/ |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
32 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
33 |
import org.testng.annotations.Test; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
34 |
import org.testng.Assert; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
35 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
36 |
import com.oracle.java.testlibrary.OutputAnalyzer; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
37 |
import com.oracle.java.testlibrary.dcmd.CommandExecutor; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
38 |
import com.oracle.java.testlibrary.dcmd.JMXExecutor; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
39 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
40 |
import java.io.File; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
41 |
import java.io.FileInputStream; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
42 |
import java.io.IOException; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
43 |
import java.nio.ByteBuffer; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
44 |
import java.nio.channels.FileChannel; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
45 |
import java.util.Iterator; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
46 |
import java.util.regex.Matcher; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
47 |
import java.util.regex.Pattern; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
48 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
49 |
public class ClassHierarchyTest { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
50 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
51 |
// $> jcmd DcmdTestClass VM.class_hierarchy DcmdTestClass | grep DcmdTestClass\$\$Lambda |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
52 |
// |--DcmdTestClass$$Lambda$1/4081552/0xa529fbb0 |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
53 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
54 |
// > VM.class_hierarchy DcmdBaseClass |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
55 |
// java.lang.Object/null |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
56 |
// |--DcmdBaseClass/0xa4abcd48 |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
57 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
58 |
// > VM.class_hierarchy DcmdBaseClass -s |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
59 |
// java.lang.Object/null |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
60 |
// |--DcmdBaseClass/0xa4abcd48 |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
61 |
// | |--DcmdTestClass/0xa4abcd48 |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
62 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
63 |
// > VM.class_hierarchy DcmdBaseClass -i -s |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
64 |
// java.lang.Object/null |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
65 |
// |--DcmdBaseClass/0xa4abcd48 |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
66 |
// | implements Intf2/0xa4abcd48 (declared intf) |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
67 |
// | implements Intf1/0xa4abcd48 (inherited intf) |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
68 |
// | |--DcmdTestClass/0xa4abcd48 |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
69 |
// | | implements Intf1/0xa4abcd48 (inherited intf) |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
70 |
// | | implements Intf2/0xa4abcd48 (inherited intf) |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
71 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
72 |
static Pattern expected_lambda_line = |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
73 |
Pattern.compile("\\|--DcmdTestClass\\$\\$Lambda.*"); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
74 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
75 |
static Pattern expected_lines[] = { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
76 |
Pattern.compile("java.lang.Object/null"), |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
77 |
Pattern.compile("\\|--DcmdBaseClass/0x(\\p{XDigit}*)"), |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
78 |
Pattern.compile("\\| implements Intf2/0x(\\p{XDigit}*) \\(declared intf\\)"), |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
79 |
Pattern.compile("\\| implements Intf1/0x(\\p{XDigit}*) \\(inherited intf\\)"), |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
80 |
Pattern.compile("\\| \\|--DcmdTestClass/0x(\\p{XDigit}*)"), |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
81 |
Pattern.compile("\\| \\| implements Intf1/0x(\\p{XDigit}*) \\(inherited intf\\)"), |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
82 |
Pattern.compile("\\| \\| implements Intf2/0x(\\p{XDigit}*) \\(inherited intf\\)") |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
83 |
}; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
84 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
85 |
public void run(CommandExecutor executor) throws ClassNotFoundException { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
86 |
OutputAnalyzer output; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
87 |
Iterator<String> lines; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
88 |
int i; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
89 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
90 |
// Load our test class whose hierarchy we will print. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
91 |
Class<?> c = Class.forName("DcmdTestClass"); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
92 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
93 |
// Verify the presence of the lamba anonymous class |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
94 |
output = executor.execute("VM.class_hierarchy"); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
95 |
lines = output.asLines().iterator(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
96 |
Boolean foundMatch = false; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
97 |
while (lines.hasNext()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
98 |
String line = lines.next(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
99 |
Matcher m = expected_lambda_line.matcher(line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
100 |
if (m.matches()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
101 |
foundMatch = true; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
102 |
break; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
103 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
104 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
105 |
if (!foundMatch) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
106 |
Assert.fail("Failed to find lamda class"); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
107 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
108 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
109 |
// Verify the output for the simple hierachry of just DcmdBaseClass. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
110 |
output = executor.execute("VM.class_hierarchy DcmdBaseClass"); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
111 |
lines = output.asLines().iterator(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
112 |
i = 0; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
113 |
while (lines.hasNext()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
114 |
String line = lines.next(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
115 |
Matcher m = expected_lines[i].matcher(line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
116 |
i++; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
117 |
if (!m.matches()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
118 |
Assert.fail("Failed to match line #" + i + ": " + line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
119 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
120 |
// Should only be two lines of output in this form. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
121 |
if (i == 2) break; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
122 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
123 |
if (lines.hasNext()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
124 |
String line = lines.next(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
125 |
Assert.fail("Unexpected dcmd output: " + line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
126 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
127 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
128 |
// Verify the output for the full hierarchy of DcmdBaseClass, but without interfaces. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
129 |
output = executor.execute("VM.class_hierarchy DcmdBaseClass -s"); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
130 |
lines = output.asLines().iterator(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
131 |
i = 0; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
132 |
while (lines.hasNext()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
133 |
String line = lines.next(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
134 |
Matcher m = expected_lines[i].matcher(line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
135 |
i++; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
136 |
if (!m.matches()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
137 |
Assert.fail("Failed to match line #" + i + ": " + line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
138 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
139 |
// "implements" lines should not be in this output. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
140 |
if (i == 2 || i == 4) i += 2; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
141 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
142 |
if (lines.hasNext()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
143 |
String line = lines.next(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
144 |
Assert.fail("Unexpected dcmd output: " + line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
145 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
146 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
147 |
// Verify the output for the full hierarchy of DcmdBaseClass, including interfaces. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
148 |
output = executor.execute("VM.class_hierarchy DcmdBaseClass -i -s"); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
149 |
lines = output.asLines().iterator(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
150 |
i = 0; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
151 |
String classLoaderAddr = null; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
152 |
while (lines.hasNext()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
153 |
String line = lines.next(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
154 |
Matcher m = expected_lines[i].matcher(line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
155 |
i++; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
156 |
if (!m.matches()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
157 |
Assert.fail("Failed to match line #" + i + ": " + line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
158 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
159 |
if (i == 2) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
160 |
// Fetch the ClassLoader address, which should be the same in |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
161 |
// subsequent lines. |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
162 |
classLoaderAddr = m.group(1); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
163 |
System.out.println(classLoaderAddr); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
164 |
} else if (i > 2) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
165 |
if (!classLoaderAddr.equals(m.group(1))) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
166 |
Assert.fail("Classloader address didn't match on line #" |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
167 |
+ i + ": " + line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
168 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
169 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
170 |
if (i == expected_lines.length) break; |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
171 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
172 |
if (lines.hasNext()) { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
173 |
String line = lines.next(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
174 |
Assert.fail("Unexpected dcmd output: " + line); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
175 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
176 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
177 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
178 |
@Test |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
179 |
public void jmx() throws ClassNotFoundException { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
180 |
run(new JMXExecutor()); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
181 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
182 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
183 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
184 |
interface Intf1 { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
185 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
186 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
187 |
interface Intf2 extends Intf1 { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
188 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
189 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
190 |
class DcmdBaseClass implements Intf2 { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
191 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
192 |
|
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
193 |
class DcmdTestClass extends DcmdBaseClass { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
194 |
static { |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
195 |
// Force creation of anonymous class (for the lambdaform). |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
196 |
Runnable r = () -> System.out.println("Hello"); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
197 |
r.run(); |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
198 |
} |
73f45d04ad7a
8054888: Runtime: Add Diagnostic Command that prints the class hierarchy
cjplummer
parents:
diff
changeset
|
199 |
} |