blob: b5ac9a987ccde6c3186599cf3c64b30adaaba822 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
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
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * 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
26package sun.management;
27
28import com.sun.management.GarbageCollectorMXBean;
29import java.lang.management.ManagementFactory;
30import java.lang.management.MemoryPoolMXBean;
31import java.lang.management.MemoryUsage;
32
33import com.sun.management.GcInfo;
34import javax.management.openmbean.CompositeData;
35import javax.management.MBeanInfo;
36import javax.management.MBeanAttributeInfo;
37
38import java.util.List;
39import 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 */
48class GarbageCollectorImpl extends MemoryManagerImpl
49 implements GarbageCollectorMXBean {
50
51 GarbageCollectorImpl(String name) {
52 super(name);
53 }
54
55 public native long getCollectionCount();
56 public native long getCollectionTime();
57
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 synchronized String[] getAllPoolNames() {
64 if (poolNames == null) {
65 List pools = ManagementFactory.getMemoryPoolMXBeans();
66 poolNames = new String[pools.size()];
67 int i = 0;
68 for (ListIterator iter = pools.listIterator();
69 iter.hasNext();
70 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 public GcInfo getLastGcInfo() {
81 synchronized (this) {
82 if (gcInfoBuilder == null) {
83 gcInfoBuilder = new GcInfoBuilder(this, getAllPoolNames());
84 }
85 }
86
87 GcInfo info = gcInfoBuilder.getLastGcInfo();
88 return info;
89 }
90
91}