37 |
38 |
38 public class CodeCacheTest { |
39 public class CodeCacheTest { |
39 |
40 |
40 /** |
41 /** |
41 * This test calls Jcmd (diagnostic command tool) Compiler.codecache and then parses the output, |
42 * This test calls Jcmd (diagnostic command tool) Compiler.codecache and then parses the output, |
42 * making sure that all number look ok |
43 * making sure that all numbers look ok |
43 * |
44 * |
44 * |
45 * |
45 * Expected output: |
46 * Expected output without code cache segmentation: |
46 * |
47 * |
47 * CodeCache: size=245760Kb used=4680Kb max_used=4680Kb free=241079Kb |
48 * CodeCache: size=245760Kb used=4680Kb max_used=4680Kb free=241079Kb |
48 * bounds [0x00007f5bd9000000, 0x00007f5bd94a0000, 0x00007f5be8000000] |
49 * bounds [0x00007f5bd9000000, 0x00007f5bd94a0000, 0x00007f5be8000000] |
49 * total_blobs=575 nmethods=69 adapters=423 |
50 * total_blobs=575 nmethods=69 adapters=423 |
50 * compilation: enabled |
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 |
51 */ |
63 */ |
52 |
64 |
53 static Pattern line1 = Pattern.compile("CodeCache: size=(\\p{Digit}*)Kb used=(\\p{Digit}*)Kb max_used=(\\p{Digit}*)Kb free=(\\p{Digit}*)Kb"); |
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"); |
54 static Pattern line2 = Pattern.compile(" bounds \\[0x(\\p{XDigit}*), 0x(\\p{XDigit}*), 0x(\\p{XDigit}*)\\]"); |
66 static Pattern line2 = Pattern.compile(" bounds \\[0x(\\p{XDigit}*), 0x(\\p{XDigit}*), 0x(\\p{XDigit}*)\\]"); |
55 static Pattern line3 = Pattern.compile(" total_blobs=(\\p{Digit}*) nmethods=(\\p{Digit}*) adapters=(\\p{Digit}*)"); |
67 static Pattern line3 = Pattern.compile(" total_blobs=(\\p{Digit}*) nmethods=(\\p{Digit}*) adapters=(\\p{Digit}*)"); |
56 static Pattern line4 = Pattern.compile(" compilation: (\\w*)"); |
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"); |
|
76 } |
|
77 |
|
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 } |
57 |
86 |
58 public static void main(String arg[]) throws Exception { |
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 } |
59 |
101 |
60 // Get output from dcmd (diagnostic command) |
102 // Get output from dcmd (diagnostic command) |
61 String result = DcmdUtil.executeDcmd("Compiler.codecache"); |
103 String result = DcmdUtil.executeDcmd("Compiler.codecache"); |
62 BufferedReader r = new BufferedReader(new StringReader(result)); |
104 BufferedReader r = new BufferedReader(new StringReader(result)); |
63 |
105 |
64 // Validate first line |
106 // Validate code cache segments |
65 String line; |
107 String line; |
66 line = r.readLine(); |
108 Matcher m; |
67 Matcher m = line1.matcher(line); |
109 for (int s = 0; s < segmentsCount; ++s) { |
68 if (m.matches()) { |
110 // Validate first line |
69 for(int i = 1; i <= 4; i++) { |
111 line = r.readLine(); |
70 int val = Integer.parseInt(m.group(i)); |
112 m = line1.matcher(line); |
71 if (val < 0) { |
113 if (m.matches()) { |
72 throw new Exception("Failed parsing dcmd codecache output"); |
114 for (int i = 2; i <= 5; i++) { |
73 } |
115 int val = Integer.parseInt(m.group(i)); |
74 } |
116 if (val < 0) { |
75 } else { |
117 throw new Exception("Failed parsing dcmd codecache output"); |
76 throw new Exception("Regexp 1 failed"); |
118 } |
77 } |
119 } |
|
120 } else { |
|
121 throw new Exception("Regexp 1 failed"); |
|
122 } |
78 |
123 |
79 // Validate second line |
124 // Validate second line |
80 line = r.readLine(); |
125 line = r.readLine(); |
81 m = line2.matcher(line); |
126 m = line2.matcher(line); |
82 if (m.matches()) { |
127 if (m.matches()) { |
83 String start = m.group(1); |
128 String start = m.group(1); |
84 String mark = m.group(2); |
129 String mark = m.group(2); |
85 String top = m.group(3); |
130 String top = m.group(3); |
86 |
131 |
87 // Lexical compare of hex numbers to check that they look sane. |
132 // Lexical compare of hex numbers to check that they look sane. |
88 if (start.compareTo(mark) > 1) { |
133 if (start.compareTo(mark) > 1) { |
89 throw new Exception("Failed parsing dcmd codecache output"); |
134 throw new Exception("Failed parsing dcmd codecache output"); |
90 } |
135 } |
91 if (mark.compareTo(top) > 1) { |
136 if (mark.compareTo(top) > 1) { |
92 throw new Exception("Failed parsing dcmd codecache output"); |
137 throw new Exception("Failed parsing dcmd codecache output"); |
93 } |
138 } |
94 } else { |
139 } else { |
95 throw new Exception("Regexp 2 failed line: " + line); |
140 throw new Exception("Regexp 2 failed line: " + line); |
|
141 } |
96 } |
142 } |
97 |
143 |
98 // Validate third line |
144 // Validate third line |
99 line = r.readLine(); |
145 line = r.readLine(); |
100 m = line3.matcher(line); |
146 m = line3.matcher(line); |