changeset 5345:fac65bd270cf

7173044: MemoryMonitor hangs if getMax method in MemoryUsage object returns -1 Reviewed-by: dholmes, sspitsyn
author zhouyx
date Tue, 05 Jun 2012 10:16:22 +0800
parents 9901543ae28d
children 99f0af9af023
files src/share/demo/management/MemoryMonitor/MemoryMonitor.java
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/demo/management/MemoryMonitor/MemoryMonitor.java	Sat Mar 31 16:55:56 2012 +0800
+++ b/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);