History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/tools/jconsole/MemoryPoolProxy.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/tools/jconsole/MemoryPoolProxy.java+133−0
@@ -0,0 +1,133 @@
1+/*
2+ * Copyright (c) 2004, Oracle and/or its affiliates. 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. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle 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 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.
24+ */
25+
26+package sun.tools.jconsole;
27+
28+import javax.management.ObjectName;
29+import java.lang.management.ManagementFactory;
30+import java.lang.management.MemoryPoolMXBean;
31+import java.lang.management.MemoryUsage;
32+import com.sun.management.GarbageCollectorMXBean;
33+import com.sun.management.GcInfo;
34+import java.util.HashMap;
35+import java.util.Set;
36+import java.util.Map;
37+import java.util.Map.Entry;
38+
39+import static java.lang.management.ManagementFactory.*;
40+
41+public class MemoryPoolProxy {
42+ private String poolName;
43+ private ProxyClient client;
44+ private ObjectName objName;
45+ private MemoryPoolMXBean pool;
46+ private Map<ObjectName,Long> gcMBeans;
47+ private GcInfo lastGcInfo;
48+
49+ public MemoryPoolProxy(ProxyClient client, ObjectName poolName) throws java.io.IOException {
50+ this.client = client;
51+ this.objName = objName;
52+ this.pool = client.getMXBean(poolName, MemoryPoolMXBean.class);
53+ this.poolName = this.pool.getName();
54+ this.gcMBeans = new HashMap<ObjectName,Long>();
55+ this.lastGcInfo = null;
56+
57+ String[] mgrNames = pool.getMemoryManagerNames();
58+ for (String name : mgrNames) {
59+ try {
60+ ObjectName mbeanName = new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE +
61+ ",name=" + name);
62+ if (client.isRegistered(mbeanName)) {
63+ gcMBeans.put(mbeanName, new Long(0));
64+ }
65+ } catch (Exception e) {
66+ assert false;
67+ }
68+
69+ }
70+ }
71+
72+ public boolean isCollectedMemoryPool() {
73+ return (gcMBeans.size() != 0);
74+ }
75+
76+ public ObjectName getObjectName() {
77+ return objName;
78+ }
79+
80+ public MemoryPoolStat getStat() throws java.io.IOException {
81+ long usageThreshold = (pool.isUsageThresholdSupported()
82+ ? pool.getUsageThreshold()
83+ : -1);
84+ long collectThreshold = (pool.isCollectionUsageThresholdSupported()
85+ ? pool.getCollectionUsageThreshold()
86+ : -1);
87+ long lastGcStartTime = 0;
88+ long lastGcEndTime = 0;
89+ MemoryUsage beforeGcUsage = null;
90+ MemoryUsage afterGcUsage = null;
91+ long gcId = 0;
92+ if (lastGcInfo != null) {
93+ gcId = lastGcInfo.getId();
94+ lastGcStartTime = lastGcInfo.getStartTime();
95+ lastGcEndTime = lastGcInfo.getEndTime();
96+ beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
97+ afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
98+ }
99+
100+ Set<Map.Entry<ObjectName,Long>> set = gcMBeans.entrySet();
101+ for (Map.Entry<ObjectName,Long> e : set) {
102+ GarbageCollectorMXBean gc =
103+ client.getMXBean(e.getKey(),
104+ com.sun.management.GarbageCollectorMXBean.class);
105+ Long gcCount = e.getValue();
106+ Long newCount = gc.getCollectionCount();
107+ if (newCount > gcCount) {
108+ gcMBeans.put(e.getKey(), new Long(newCount));
109+ lastGcInfo = gc.getLastGcInfo();
110+ if (lastGcInfo.getEndTime() > lastGcEndTime) {
111+ gcId = lastGcInfo.getId();
112+ lastGcStartTime = lastGcInfo.getStartTime();
113+ lastGcEndTime = lastGcInfo.getEndTime();
114+ beforeGcUsage = lastGcInfo.getMemoryUsageBeforeGc().get(poolName);
115+ afterGcUsage = lastGcInfo.getMemoryUsageAfterGc().get(poolName);
116+ assert(beforeGcUsage != null);
117+ assert(afterGcUsage != null);
118+ }
119+ }
120+ }
121+
122+ MemoryUsage usage = pool.getUsage();
123+ return new MemoryPoolStat(poolName,
124+ usageThreshold,
125+ usage,
126+ gcId,
127+ lastGcStartTime,
128+ lastGcEndTime,
129+ collectThreshold,
130+ beforeGcUsage,
131+ afterGcUsage);
132+ }
133+}