7173044: MemoryMonitor hangs if getMax method in MemoryUsage object returns -1
authorzhouyx
Tue, 05 Jun 2012 10:16:22 +0800
changeset 12866 48fd3e04f1f6
parent 12865 d197a6781b1f
child 12867 5492127ab0a8
7173044: MemoryMonitor hangs if getMax method in MemoryUsage object returns -1 Reviewed-by: dholmes, sspitsyn
jdk/src/share/demo/management/MemoryMonitor/MemoryMonitor.java
--- a/jdk/src/share/demo/management/MemoryMonitor/MemoryMonitor.java	Mon Jun 04 18:06:45 2012 +0800
+++ b/jdk/src/share/demo/management/MemoryMonitor/MemoryMonitor.java	Tue Jun 05 10:16:22 2012 +0800
@@ -122,6 +122,7 @@
         private Font font = new Font("Times New Roman", Font.PLAIN, 11);
         private int columnInc;
         private float usedMem[][];
+        private float usedMemMax[]; // Used when max pool size is undefined
         private int ptNum[];
         private int ascent, descent;
         private Rectangle graphOutlineRect = new Rectangle();
@@ -142,6 +143,10 @@
                 }
             });
             usedMem = new float[numPools][];
+            usedMemMax = new float[numPools];
+            for (int i = 0; i < numPools; i++) {
+                usedMemMax[i] = 1024f * 1024f ;
+            }
             ptNum = new int[numPools];
         }
 
@@ -194,6 +199,12 @@
             MemoryPoolMXBean mp = mpools.get(npool);
             float usedMemory =  mp.getUsage().getUsed();
             float totalMemory =  mp.getUsage().getMax();
+            if (totalMemory < 0) { // Max is undefined for this pool
+                if (usedMemory > usedMemMax[npool]) {
+                    usedMemMax[npool] = usedMemory;
+                }
+                totalMemory = usedMemMax[npool];
+            }
 
             // .. Draw allocated and used strings ..
             big.setColor(Color.green);