author | amurillo |
Fri, 01 May 2015 03:56:04 -0700 | |
changeset 30365 | 551470085a1d |
parent 30042 | jdk/src/java.management/share/classes/com/sun/management/GcInfo.java@4728ebcf8fd0 |
parent 30355 | jdk/src/java.management/share/classes/com/sun/management/GcInfo.java@e37c7eba132f |
child 34894 | 3248b89d1921 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, 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 com.sun.management; |
|
27 |
||
28 |
import java.lang.management.MemoryUsage; |
|
29 |
import javax.management.openmbean.CompositeData; |
|
30 |
import javax.management.openmbean.CompositeDataView; |
|
31 |
import javax.management.openmbean.CompositeType; |
|
32 |
import java.util.Collection; |
|
33 |
import java.util.Collections; |
|
34 |
import java.util.HashMap; |
|
35 |
import java.util.Map; |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
36 |
import com.sun.management.internal.GcInfoCompositeData; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
37 |
import com.sun.management.internal.GcInfoBuilder; |
2 | 38 |
|
39 |
/** |
|
40 |
* Garbage collection information. It contains the following |
|
41 |
* information for one garbage collection as well as GC-specific |
|
42 |
* attributes: |
|
43 |
* <blockquote> |
|
44 |
* <ul> |
|
45 |
* <li>Start time</li> |
|
46 |
* <li>End time</li> |
|
47 |
* <li>Duration</li> |
|
48 |
* <li>Memory usage before the collection starts</li> |
|
49 |
* <li>Memory usage after the collection ends</li> |
|
50 |
* </ul> |
|
51 |
* </blockquote> |
|
52 |
* |
|
53 |
* <p> |
|
30042 | 54 |
* {@code GcInfo} is a {@link CompositeData CompositeData} |
2 | 55 |
* The GC-specific attributes can be obtained via the CompositeData |
56 |
* interface. This is a historical relic, and other classes should |
|
57 |
* not copy this pattern. Use {@link CompositeDataView} instead. |
|
58 |
* |
|
59 |
* <h4>MXBean Mapping</h4> |
|
30042 | 60 |
* {@code GcInfo} is mapped to a {@link CompositeData CompositeData} |
2 | 61 |
* with attributes as specified in the {@link #from from} method. |
62 |
* |
|
63 |
* @author Mandy Chung |
|
64 |
* @since 1.5 |
|
65 |
*/ |
|
20742
4ae78e8060d6
8008662: Add @jdk.Exported to JDK-specific/exported APIs
alanb
parents:
5506
diff
changeset
|
66 |
@jdk.Exported |
2 | 67 |
public class GcInfo implements CompositeData, CompositeDataView { |
68 |
private final long index; |
|
69 |
private final long startTime; |
|
70 |
private final long endTime; |
|
71 |
private final Map<String, MemoryUsage> usageBeforeGc; |
|
72 |
private final Map<String, MemoryUsage> usageAfterGc; |
|
73 |
private final Object[] extAttributes; |
|
74 |
private final CompositeData cdata; |
|
75 |
private final GcInfoBuilder builder; |
|
76 |
||
77 |
private GcInfo(GcInfoBuilder builder, |
|
78 |
long index, long startTime, long endTime, |
|
79 |
MemoryUsage[] muBeforeGc, |
|
80 |
MemoryUsage[] muAfterGc, |
|
81 |
Object[] extAttributes) { |
|
82 |
this.builder = builder; |
|
83 |
this.index = index; |
|
84 |
this.startTime = startTime; |
|
85 |
this.endTime = endTime; |
|
86 |
String[] poolNames = builder.getPoolNames(); |
|
87 |
this.usageBeforeGc = new HashMap<String, MemoryUsage>(poolNames.length); |
|
88 |
this.usageAfterGc = new HashMap<String, MemoryUsage>(poolNames.length); |
|
89 |
for (int i = 0; i < poolNames.length; i++) { |
|
90 |
this.usageBeforeGc.put(poolNames[i], muBeforeGc[i]); |
|
91 |
this.usageAfterGc.put(poolNames[i], muAfterGc[i]); |
|
92 |
} |
|
93 |
this.extAttributes = extAttributes; |
|
94 |
this.cdata = new GcInfoCompositeData(this, builder, extAttributes); |
|
95 |
} |
|
96 |
||
97 |
private GcInfo(CompositeData cd) { |
|
98 |
GcInfoCompositeData.validateCompositeData(cd); |
|
99 |
||
100 |
this.index = GcInfoCompositeData.getId(cd); |
|
101 |
this.startTime = GcInfoCompositeData.getStartTime(cd); |
|
102 |
this.endTime = GcInfoCompositeData.getEndTime(cd); |
|
103 |
this.usageBeforeGc = GcInfoCompositeData.getMemoryUsageBeforeGc(cd); |
|
104 |
this.usageAfterGc = GcInfoCompositeData.getMemoryUsageAfterGc(cd); |
|
105 |
this.extAttributes = null; |
|
106 |
this.builder = null; |
|
107 |
this.cdata = cd; |
|
108 |
} |
|
109 |
||
110 |
/** |
|
111 |
* Returns the identifier of this garbage collection which is |
|
112 |
* the number of collections that this collector has done. |
|
113 |
* |
|
114 |
* @return the identifier of this garbage collection which is |
|
115 |
* the number of collections that this collector has done. |
|
116 |
*/ |
|
117 |
public long getId() { |
|
118 |
return index; |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* Returns the start time of this GC in milliseconds |
|
123 |
* since the Java virtual machine was started. |
|
124 |
* |
|
125 |
* @return the start time of this GC. |
|
126 |
*/ |
|
127 |
public long getStartTime() { |
|
128 |
return startTime; |
|
129 |
} |
|
130 |
||
131 |
/** |
|
132 |
* Returns the end time of this GC in milliseconds |
|
133 |
* since the Java virtual machine was started. |
|
134 |
* |
|
135 |
* @return the end time of this GC. |
|
136 |
*/ |
|
137 |
public long getEndTime() { |
|
138 |
return endTime; |
|
139 |
} |
|
140 |
||
141 |
/** |
|
142 |
* Returns the elapsed time of this GC in milliseconds. |
|
143 |
* |
|
144 |
* @return the elapsed time of this GC in milliseconds. |
|
145 |
*/ |
|
146 |
public long getDuration() { |
|
147 |
return endTime - startTime; |
|
148 |
} |
|
149 |
||
150 |
/** |
|
151 |
* Returns the memory usage of all memory pools |
|
152 |
* at the beginning of this GC. |
|
153 |
* This method returns |
|
30042 | 154 |
* a {@code Map} of the name of a memory pool |
2 | 155 |
* to the memory usage of the corresponding |
156 |
* memory pool before GC starts. |
|
157 |
* |
|
30042 | 158 |
* @return a {@code Map} of memory pool names to the memory |
2 | 159 |
* usage of a memory pool before GC starts. |
160 |
*/ |
|
161 |
public Map<String, MemoryUsage> getMemoryUsageBeforeGc() { |
|
162 |
return Collections.unmodifiableMap(usageBeforeGc); |
|
163 |
} |
|
164 |
||
165 |
/** |
|
166 |
* Returns the memory usage of all memory pools |
|
167 |
* at the end of this GC. |
|
168 |
* This method returns |
|
30042 | 169 |
* a {@code Map} of the name of a memory pool |
2 | 170 |
* to the memory usage of the corresponding |
171 |
* memory pool when GC finishes. |
|
172 |
* |
|
30042 | 173 |
* @return a {@code Map} of memory pool names to the memory |
2 | 174 |
* usage of a memory pool when GC finishes. |
175 |
*/ |
|
176 |
public Map<String, MemoryUsage> getMemoryUsageAfterGc() { |
|
177 |
return Collections.unmodifiableMap(usageAfterGc); |
|
178 |
} |
|
179 |
||
180 |
/** |
|
30042 | 181 |
* Returns a {@code GcInfo} object represented by the |
182 |
* given {@code CompositeData}. The given |
|
183 |
* {@code CompositeData} must contain |
|
2 | 184 |
* all the following attributes: |
185 |
* |
|
186 |
* <blockquote> |
|
187 |
* <table border> |
|
188 |
* <tr> |
|
189 |
* <th align=left>Attribute Name</th> |
|
190 |
* <th align=left>Type</th> |
|
191 |
* </tr> |
|
192 |
* <tr> |
|
193 |
* <td>index</td> |
|
30042 | 194 |
* <td>{@code java.lang.Long}</td> |
2 | 195 |
* </tr> |
196 |
* <tr> |
|
197 |
* <td>startTime</td> |
|
30042 | 198 |
* <td>{@code java.lang.Long}</td> |
2 | 199 |
* </tr> |
200 |
* <tr> |
|
201 |
* <td>endTime</td> |
|
30042 | 202 |
* <td>{@code java.lang.Long}</td> |
2 | 203 |
* </tr> |
204 |
* <tr> |
|
205 |
* <td>memoryUsageBeforeGc</td> |
|
30042 | 206 |
* <td>{@code javax.management.openmbean.TabularData}</td> |
2 | 207 |
* </tr> |
208 |
* <tr> |
|
209 |
* <td>memoryUsageAfterGc</td> |
|
30042 | 210 |
* <td>{@code javax.management.openmbean.TabularData}</td> |
2 | 211 |
* </tr> |
212 |
* </table> |
|
213 |
* </blockquote> |
|
214 |
* |
|
30042 | 215 |
* @throws IllegalArgumentException if {@code cd} does not |
216 |
* represent a {@code GcInfo} object with the attributes |
|
2 | 217 |
* described above. |
218 |
* |
|
30042 | 219 |
* @return a {@code GcInfo} object represented by {@code cd} |
220 |
* if {@code cd} is not {@code null}; {@code null} otherwise. |
|
2 | 221 |
*/ |
222 |
public static GcInfo from(CompositeData cd) { |
|
223 |
if (cd == null) { |
|
224 |
return null; |
|
225 |
} |
|
226 |
||
227 |
if (cd instanceof GcInfoCompositeData) { |
|
228 |
return ((GcInfoCompositeData) cd).getGcInfo(); |
|
229 |
} else { |
|
230 |
return new GcInfo(cd); |
|
231 |
} |
|
232 |
||
233 |
} |
|
234 |
||
235 |
// Implementation of the CompositeData interface |
|
236 |
public boolean containsKey(String key) { |
|
237 |
return cdata.containsKey(key); |
|
238 |
} |
|
239 |
||
240 |
public boolean containsValue(Object value) { |
|
241 |
return cdata.containsValue(value); |
|
242 |
} |
|
243 |
||
244 |
public boolean equals(Object obj) { |
|
245 |
return cdata.equals(obj); |
|
246 |
} |
|
247 |
||
248 |
public Object get(String key) { |
|
249 |
return cdata.get(key); |
|
250 |
} |
|
251 |
||
252 |
public Object[] getAll(String[] keys) { |
|
253 |
return cdata.getAll(keys); |
|
254 |
} |
|
255 |
||
256 |
public CompositeType getCompositeType() { |
|
257 |
return cdata.getCompositeType(); |
|
258 |
} |
|
259 |
||
260 |
public int hashCode() { |
|
261 |
return cdata.hashCode(); |
|
262 |
} |
|
263 |
||
264 |
public String toString() { |
|
265 |
return cdata.toString(); |
|
266 |
} |
|
267 |
||
25798
0b2f54e47bc4
8054050: Fix stay raw and unchecked lint warnings in core libs
darcy
parents:
23010
diff
changeset
|
268 |
public Collection<?> values() { |
2 | 269 |
return cdata.values(); |
270 |
} |
|
271 |
||
272 |
/** |
|
30042 | 273 |
* Return the {@code CompositeData} representation of this |
2 | 274 |
* {@code GcInfo}, including any GC-specific attributes. The |
275 |
* returned value will have at least all the attributes described |
|
276 |
* in the {@link #from(CompositeData) from} method, plus optionally |
|
277 |
* other attributes. |
|
278 |
* |
|
279 |
* @param ct the {@code CompositeType} that the caller expects. |
|
280 |
* This parameter is ignored and can be null. |
|
281 |
* |
|
282 |
* @return the {@code CompositeData} representation. |
|
283 |
*/ |
|
284 |
public CompositeData toCompositeData(CompositeType ct) { |
|
285 |
return cdata; |
|
286 |
} |
|
287 |
} |