01: /*
02: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
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: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package sun.management;
27:
28: import com.sun.management.GarbageCollectorMXBean;
29: import java.lang.management.ManagementFactory;
30: import java.lang.management.MemoryPoolMXBean;
31: import java.lang.management.MemoryUsage;
32:
33: import com.sun.management.GcInfo;
34: import javax.management.openmbean.CompositeData;
35: import javax.management.MBeanInfo;
36: import javax.management.MBeanAttributeInfo;
37:
38: import java.util.List;
39: import java.util.ListIterator;
40:
41: /**
42: * Implementation class for the garbage collector.
43: * Standard and committed hotspot-specific metrics if any.
44: *
45: * ManagementFactory.getGarbageCollectorMXBeans() returns a list
46: * of instances of this class.
47: */
48: class GarbageCollectorImpl extends MemoryManagerImpl implements
49: GarbageCollectorMXBean {
50:
51: GarbageCollectorImpl(String name) {
52: super (name);
53: }
54:
55: public native long getCollectionCount();
56:
57: public native long getCollectionTime();
58:
59: // The memory pools are static and won't be changed.
60: // TODO: If the hotspot implementation begins to have pools
61: // dynamically created and removed, this needs to be modified.
62: private String[] poolNames = null;
63:
64: synchronized String[] getAllPoolNames() {
65: if (poolNames == null) {
66: List pools = ManagementFactory.getMemoryPoolMXBeans();
67: poolNames = new String[pools.size()];
68: int i = 0;
69: for (ListIterator iter = pools.listIterator(); iter
70: .hasNext(); i++) {
71: MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
72: poolNames[i] = p.getName();
73: }
74: }
75: return poolNames;
76: }
77:
78: // Sun JDK extension
79: private GcInfoBuilder gcInfoBuilder;
80:
81: public GcInfo getLastGcInfo() {
82: synchronized (this ) {
83: if (gcInfoBuilder == null) {
84: gcInfoBuilder = new GcInfoBuilder(this ,
85: getAllPoolNames());
86: }
87: }
88:
89: GcInfo info = gcInfoBuilder.getLastGcInfo();
90: return info;
91: }
92:
93: }
|