35 import java.lang.reflect.Method;
36 import java.util.regex.Matcher;
37 import java.util.regex.Pattern;
38
39 public class CodeCacheTest {
40
41 /**
42 * This test calls Jcmd (diagnostic command tool) Compiler.codecache and then parses the output,
43 * making sure that all numbers look ok
44 *
45 *
46 * Expected output without code cache segmentation:
47 *
48 * CodeCache: size=245760Kb used=4680Kb max_used=4680Kb free=241079Kb
49 * bounds [0x00007f5bd9000000, 0x00007f5bd94a0000, 0x00007f5be8000000]
50 * total_blobs=575 nmethods=69 adapters=423
51 * compilation: enabled
52 *
53 * Expected output with code cache segmentation (number of segments may change):
54 *
55 * CodeHeap 'non-methods': size=5696Kb used=2236Kb max_used=2238Kb free=3459Kb
56 * bounds [0x00007fa0f0ffe000, 0x00007fa0f126e000, 0x00007fa0f158e000]
57 * CodeHeap 'profiled nmethods': size=120036Kb used=8Kb max_used=8Kb free=120027Kb
58 * bounds [0x00007fa0f158e000, 0x00007fa0f17fe000, 0x00007fa0f8ac7000]
59 * CodeHeap 'non-profiled nmethods': size=120036Kb used=2Kb max_used=2Kb free=120034Kb
60 * bounds [0x00007fa0f8ac7000, 0x00007fa0f8d37000, 0x00007fa100000000]
61 * total_blobs=486 nmethods=8 adapters=399
62 * compilation: enabled
63 */
64
65 static Pattern line1 = Pattern.compile("(CodeCache|CodeHeap.*): size=(\\p{Digit}*)Kb used=(\\p{Digit}*)Kb max_used=(\\p{Digit}*)Kb free=(\\p{Digit}*)Kb");
66 static Pattern line2 = Pattern.compile(" bounds \\[0x(\\p{XDigit}*), 0x(\\p{XDigit}*), 0x(\\p{XDigit}*)\\]");
67 static Pattern line3 = Pattern.compile(" total_blobs=(\\p{Digit}*) nmethods=(\\p{Digit}*) adapters=(\\p{Digit}*)");
68 static Pattern line4 = Pattern.compile(" compilation: (.*)");
69
70 private static boolean getFlagBool(String flag, String where) {
71 Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where);
72 if (!m.find()) {
73 throw new RuntimeException("Could not find value for flag " + flag + " in output string");
74 }
75 return m.group(1).equals("true");
78 private static int getFlagInt(String flag, String where) {
79 Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
80 if (!m.find()) {
81 throw new RuntimeException("Could not find value for flag " + flag + " in output string");
82 }
83 String match = m.group();
84 return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));
85 }
86
87 public static void main(String arg[]) throws Exception {
88 // Get number of code cache segments
89 int segmentsCount = 0;
90 String flags = DcmdUtil.executeDcmd("VM.flags", "-all");
91 if (!getFlagBool("SegmentedCodeCache", flags) || !getFlagBool("UseCompiler", flags)) {
92 // No segmentation
93 segmentsCount = 1;
94 } else if (getFlagBool("TieredCompilation", flags) && getFlagInt("TieredStopAtLevel", flags) > 1) {
95 // Tiered compilation: use all segments
96 segmentsCount = 3;
97 } else {
98 // No TieredCompilation: only non-method and non-profiled segment
99 segmentsCount = 2;
100 }
101
102 // Get output from dcmd (diagnostic command)
103 String result = DcmdUtil.executeDcmd("Compiler.codecache");
104 BufferedReader r = new BufferedReader(new StringReader(result));
105
106 // Validate code cache segments
107 String line;
108 Matcher m;
109 for (int s = 0; s < segmentsCount; ++s) {
110 // Validate first line
111 line = r.readLine();
112 m = line1.matcher(line);
113 if (m.matches()) {
114 for (int i = 2; i <= 5; i++) {
115 int val = Integer.parseInt(m.group(i));
116 if (val < 0) {
117 throw new Exception("Failed parsing dcmd codecache output");
118 }
|
35 import java.lang.reflect.Method;
36 import java.util.regex.Matcher;
37 import java.util.regex.Pattern;
38
39 public class CodeCacheTest {
40
41 /**
42 * This test calls Jcmd (diagnostic command tool) Compiler.codecache and then parses the output,
43 * making sure that all numbers look ok
44 *
45 *
46 * Expected output without code cache segmentation:
47 *
48 * CodeCache: size=245760Kb used=4680Kb max_used=4680Kb free=241079Kb
49 * bounds [0x00007f5bd9000000, 0x00007f5bd94a0000, 0x00007f5be8000000]
50 * total_blobs=575 nmethods=69 adapters=423
51 * compilation: enabled
52 *
53 * Expected output with code cache segmentation (number of segments may change):
54 *
55 * CodeHeap 'non-nmethods': size=5696Kb used=2236Kb max_used=2238Kb free=3459Kb
56 * bounds [0x00007fa0f0ffe000, 0x00007fa0f126e000, 0x00007fa0f158e000]
57 * CodeHeap 'profiled nmethods': size=120036Kb used=8Kb max_used=8Kb free=120027Kb
58 * bounds [0x00007fa0f158e000, 0x00007fa0f17fe000, 0x00007fa0f8ac7000]
59 * CodeHeap 'non-profiled nmethods': size=120036Kb used=2Kb max_used=2Kb free=120034Kb
60 * bounds [0x00007fa0f8ac7000, 0x00007fa0f8d37000, 0x00007fa100000000]
61 * total_blobs=486 nmethods=8 adapters=399
62 * compilation: enabled
63 */
64
65 static Pattern line1 = Pattern.compile("(CodeCache|CodeHeap.*): size=(\\p{Digit}*)Kb used=(\\p{Digit}*)Kb max_used=(\\p{Digit}*)Kb free=(\\p{Digit}*)Kb");
66 static Pattern line2 = Pattern.compile(" bounds \\[0x(\\p{XDigit}*), 0x(\\p{XDigit}*), 0x(\\p{XDigit}*)\\]");
67 static Pattern line3 = Pattern.compile(" total_blobs=(\\p{Digit}*) nmethods=(\\p{Digit}*) adapters=(\\p{Digit}*)");
68 static Pattern line4 = Pattern.compile(" compilation: (.*)");
69
70 private static boolean getFlagBool(String flag, String where) {
71 Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where);
72 if (!m.find()) {
73 throw new RuntimeException("Could not find value for flag " + flag + " in output string");
74 }
75 return m.group(1).equals("true");
78 private static int getFlagInt(String flag, String where) {
79 Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
80 if (!m.find()) {
81 throw new RuntimeException("Could not find value for flag " + flag + " in output string");
82 }
83 String match = m.group();
84 return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));
85 }
86
87 public static void main(String arg[]) throws Exception {
88 // Get number of code cache segments
89 int segmentsCount = 0;
90 String flags = DcmdUtil.executeDcmd("VM.flags", "-all");
91 if (!getFlagBool("SegmentedCodeCache", flags) || !getFlagBool("UseCompiler", flags)) {
92 // No segmentation
93 segmentsCount = 1;
94 } else if (getFlagBool("TieredCompilation", flags) && getFlagInt("TieredStopAtLevel", flags) > 1) {
95 // Tiered compilation: use all segments
96 segmentsCount = 3;
97 } else {
98 // No TieredCompilation: only non-nmethod and non-profiled segment
99 segmentsCount = 2;
100 }
101
102 // Get output from dcmd (diagnostic command)
103 String result = DcmdUtil.executeDcmd("Compiler.codecache");
104 BufferedReader r = new BufferedReader(new StringReader(result));
105
106 // Validate code cache segments
107 String line;
108 Matcher m;
109 for (int s = 0; s < segmentsCount; ++s) {
110 // Validate first line
111 line = r.readLine();
112 m = line1.matcher(line);
113 if (m.matches()) {
114 for (int i = 2; i <= 5; i++) {
115 int val = Integer.parseInt(m.group(i));
116 if (val < 0) {
117 throw new Exception("Failed parsing dcmd codecache output");
118 }
|