author | mchung |
Tue, 17 Jan 2012 15:55:40 -0800 | |
changeset 11530 | a9d059c15b80 |
parent 5506 | 202f599c92aa |
child 14342 | 8435a30053c1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.management; |
|
27 |
||
28 |
import java.util.regex.*; |
|
29 |
import java.util.List; |
|
30 |
import java.util.ListIterator; |
|
31 |
import java.util.Iterator; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.Map; |
|
34 |
import java.util.TreeMap; |
|
35 |
import sun.management.counter.*; |
|
36 |
||
37 |
/** |
|
38 |
* Implementation class of HotspotCompilationMBean interface. |
|
39 |
* |
|
40 |
* Internal, uncommitted management interface for Hotspot compilation |
|
41 |
* system. |
|
42 |
* |
|
43 |
*/ |
|
44 |
class HotspotCompilation |
|
45 |
implements HotspotCompilationMBean { |
|
46 |
||
47 |
private VMManagement jvm; |
|
48 |
||
49 |
/** |
|
50 |
* Constructor of HotspotRuntime class. |
|
51 |
*/ |
|
52 |
HotspotCompilation(VMManagement vm) { |
|
53 |
jvm = vm; |
|
54 |
initCompilerCounters(); |
|
55 |
} |
|
56 |
||
57 |
// Performance counter support |
|
58 |
private static final String JAVA_CI = "java.ci."; |
|
59 |
private static final String COM_SUN_CI = "com.sun.ci."; |
|
60 |
private static final String SUN_CI = "sun.ci."; |
|
61 |
private static final String CI_COUNTER_NAME_PATTERN = |
|
62 |
JAVA_CI + "|" + COM_SUN_CI + "|" + SUN_CI; |
|
63 |
||
64 |
private LongCounter compilerThreads; |
|
65 |
private LongCounter totalCompiles; |
|
66 |
private LongCounter totalBailouts; |
|
67 |
private LongCounter totalInvalidates; |
|
68 |
private LongCounter nmethodCodeSize; |
|
69 |
private LongCounter nmethodSize; |
|
70 |
private StringCounter lastMethod; |
|
71 |
private LongCounter lastSize; |
|
72 |
private LongCounter lastType; |
|
73 |
private StringCounter lastFailedMethod; |
|
74 |
private LongCounter lastFailedType; |
|
75 |
private StringCounter lastInvalidatedMethod; |
|
76 |
private LongCounter lastInvalidatedType; |
|
77 |
||
78 |
private class CompilerThreadInfo { |
|
79 |
int index; |
|
80 |
String name; |
|
81 |
StringCounter method; |
|
82 |
LongCounter type; |
|
83 |
LongCounter compiles; |
|
84 |
LongCounter time; |
|
85 |
CompilerThreadInfo(String bname, int index) { |
|
86 |
String basename = bname + "." + index + "."; |
|
87 |
this.name = bname + "-" + index; |
|
88 |
this.method = (StringCounter) lookup(basename + "method"); |
|
89 |
this.type = (LongCounter) lookup(basename + "type"); |
|
90 |
this.compiles = (LongCounter) lookup(basename + "compiles"); |
|
91 |
this.time = (LongCounter) lookup(basename + "time"); |
|
92 |
} |
|
93 |
CompilerThreadInfo(String bname) { |
|
94 |
String basename = bname + "."; |
|
95 |
this.name = bname; |
|
96 |
this.method = (StringCounter) lookup(basename + "method"); |
|
97 |
this.type = (LongCounter) lookup(basename + "type"); |
|
98 |
this.compiles = (LongCounter) lookup(basename + "compiles"); |
|
99 |
this.time = (LongCounter) lookup(basename + "time"); |
|
100 |
} |
|
101 |
||
102 |
CompilerThreadStat getCompilerThreadStat() { |
|
103 |
MethodInfo minfo = new MethodInfo(method.stringValue(), |
|
104 |
(int) type.longValue(), |
|
105 |
-1); |
|
106 |
return new CompilerThreadStat(name, |
|
107 |
compiles.longValue(), |
|
108 |
time.longValue(), |
|
109 |
minfo); |
|
110 |
} |
|
111 |
} |
|
112 |
private CompilerThreadInfo[] threads; |
|
113 |
private int numActiveThreads; // number of active compiler threads |
|
114 |
||
115 |
private Map<String, Counter> counters; |
|
116 |
private Counter lookup(String name) { |
|
117 |
Counter c = null; |
|
118 |
||
119 |
// Only one counter exists with the specified name in the |
|
120 |
// current implementation. We first look up in the SUN_CI namespace |
|
121 |
// since most counters are in SUN_CI namespace. |
|
122 |
||
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
123 |
if ((c = counters.get(SUN_CI + name)) != null) { |
2 | 124 |
return c; |
125 |
} |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
126 |
if ((c = counters.get(COM_SUN_CI + name)) != null) { |
2 | 127 |
return c; |
128 |
} |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
129 |
if ((c = counters.get(JAVA_CI + name)) != null) { |
2 | 130 |
return c; |
131 |
} |
|
132 |
||
133 |
// FIXME: should tolerate if counter doesn't exist |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
134 |
throw new AssertionError("Counter " + name + " does not exist"); |
2 | 135 |
} |
136 |
||
137 |
private void initCompilerCounters() { |
|
138 |
// Build a tree map of the current list of performance counters |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
139 |
counters = new TreeMap<>(); |
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
140 |
for (Counter c: getInternalCompilerCounters()) { |
2 | 141 |
counters.put(c.getName(), c); |
142 |
} |
|
143 |
||
144 |
compilerThreads = (LongCounter) lookup("threads"); |
|
145 |
totalCompiles = (LongCounter) lookup("totalCompiles"); |
|
146 |
totalBailouts = (LongCounter) lookup("totalBailouts"); |
|
147 |
totalInvalidates = (LongCounter) lookup("totalInvalidates"); |
|
148 |
nmethodCodeSize = (LongCounter) lookup("nmethodCodeSize"); |
|
149 |
nmethodSize = (LongCounter) lookup("nmethodSize"); |
|
150 |
lastMethod = (StringCounter) lookup("lastMethod"); |
|
151 |
lastSize = (LongCounter) lookup("lastSize"); |
|
152 |
lastType = (LongCounter) lookup("lastType"); |
|
153 |
lastFailedMethod = (StringCounter) lookup("lastFailedMethod"); |
|
154 |
lastFailedType = (LongCounter) lookup("lastFailedType"); |
|
155 |
lastInvalidatedMethod = (StringCounter) lookup("lastInvalidatedMethod"); |
|
156 |
lastInvalidatedType = (LongCounter) lookup("lastInvalidatedType"); |
|
157 |
||
158 |
numActiveThreads = (int) compilerThreads.longValue(); |
|
159 |
||
160 |
// Allocate CompilerThreadInfo for compilerThread and adaptorThread |
|
161 |
threads = new CompilerThreadInfo[numActiveThreads+1]; |
|
162 |
||
163 |
// AdaptorThread has index 0 |
|
164 |
if (counters.containsKey(SUN_CI + "adapterThread.compiles")) { |
|
165 |
threads[0] = new CompilerThreadInfo("adapterThread", 0); |
|
166 |
numActiveThreads++; |
|
167 |
} else { |
|
168 |
threads[0] = null; |
|
169 |
} |
|
170 |
||
171 |
for (int i = 1; i < threads.length; i++) { |
|
172 |
threads[i] = new CompilerThreadInfo("compilerThread", i-1); |
|
173 |
} |
|
174 |
} |
|
175 |
||
176 |
public int getCompilerThreadCount() { |
|
177 |
return numActiveThreads; |
|
178 |
} |
|
179 |
||
180 |
public long getTotalCompileCount() { |
|
181 |
return totalCompiles.longValue(); |
|
182 |
} |
|
183 |
||
184 |
public long getBailoutCompileCount() { |
|
185 |
return totalBailouts.longValue(); |
|
186 |
} |
|
187 |
||
188 |
public long getInvalidatedCompileCount() { |
|
189 |
return totalInvalidates.longValue(); |
|
190 |
} |
|
191 |
||
192 |
public long getCompiledMethodCodeSize() { |
|
193 |
return nmethodCodeSize.longValue(); |
|
194 |
} |
|
195 |
||
196 |
public long getCompiledMethodSize() { |
|
197 |
return nmethodSize.longValue(); |
|
198 |
} |
|
199 |
||
200 |
public java.util.List<CompilerThreadStat> getCompilerThreadStats() { |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
201 |
List<CompilerThreadStat> list = new ArrayList<>(threads.length); |
2 | 202 |
int i = 0; |
203 |
if (threads[0] == null) { |
|
204 |
// no adaptor thread |
|
205 |
i = 1; |
|
206 |
} |
|
207 |
for (; i < threads.length; i++) { |
|
208 |
list.add(threads[i].getCompilerThreadStat()); |
|
209 |
} |
|
210 |
return list; |
|
211 |
} |
|
212 |
||
213 |
public MethodInfo getLastCompile() { |
|
214 |
return new MethodInfo(lastMethod.stringValue(), |
|
215 |
(int) lastType.longValue(), |
|
216 |
(int) lastSize.longValue()); |
|
217 |
} |
|
218 |
||
219 |
public MethodInfo getFailedCompile() { |
|
220 |
return new MethodInfo(lastFailedMethod.stringValue(), |
|
221 |
(int) lastFailedType.longValue(), |
|
222 |
-1); |
|
223 |
} |
|
224 |
||
225 |
public MethodInfo getInvalidatedCompile() { |
|
226 |
return new MethodInfo(lastInvalidatedMethod.stringValue(), |
|
227 |
(int) lastInvalidatedType.longValue(), |
|
228 |
-1); |
|
229 |
} |
|
230 |
||
231 |
public java.util.List<Counter> getInternalCompilerCounters() { |
|
232 |
return jvm.getInternalCounters(CI_COUNTER_NAME_PATTERN); |
|
233 |
} |
|
234 |
} |