United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7173044 Memory monitor demo hangs the system if MemoryUsage obj returns -1 .
JDK-7173044 : Memory monitor demo hangs the system if MemoryUsage obj returns -1 .

Details
Type:
Enhancement
Submit Date:
2012-05-31
Status:
Resolved
Updated Date:
2013-07-23
Project Name:
JDK
Resolved Date:
2012-06-12
Component:
core-svc
OS:
windows_7
Sub-Component:
java.lang.management
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Backport:

Sub Tasks

Description
A DESCRIPTION OF THE REQUEST :
In MemoryMonitor.java: plotMemoryUsage method.

This piece of code  "
 MemoryPoolMXBean mp = mpools.get(npool);
 float usedMemory =  mp.getUsage().getUsed();
 float totalMemory =  mp.getUsage().getMax();  "

 is followed by

 "
 // .. Memory Free ..
 big.setColor(mfColor);
 int MemUsage = (int) (((totalMemory - usedMemory) / totalMemory) * 10);
 int i = 0;
 for ( ; i < MemUsage ; i++) {
        mfRect.setRect(x1+5,(float) y1+ssH+i*blockHeight,
                 blockWidth, blockHeight-1);
        big.fill(mfRect);
 }
"

If totalMemory is -1, MemUsage will become a very large value, and the demo hangs in the loop.

In order to reproduce the problem, another jdk other than ri is required because these beans are jdk dependent. It can be reproduced using ibm jdk to run the MemoryMonitor demo.


JUSTIFICATION :
Spec says it is allowed for MemoryUsage.getMax to return -1 if the maximum memory size is undefined.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The demo is still working when MemoryUsage.getMax returns -1 .
ACTUAL -
The demo hangs.

                                    

Comments
SUGGESTED FIX

src/share/demo/management/MemoryMonitor/MemoryMonitor.java

*** 120,129 ****
--- 120,130 ----
          private BufferedImage bimg;
          private Graphics2D big;
          private Font font = new Font("Times New Roman", Font.PLAIN, 11);
          private int columnInc;
          private float usedMem[][];
+         private float usedMemMax[];
          private int ptNum[];
          private int ascent, descent;
          private Rectangle graphOutlineRect = new Rectangle();
          private Rectangle2D mfRect = new Rectangle2D.Float();
          private Rectangle2D muRect = new Rectangle2D.Float();
*** 140,149 ****
--- 141,154 ----
                  public void mouseClicked(MouseEvent e) {
                      if (thread == null) start(); else stop();
                  }
              });
              usedMem = new float[numPools][];
+             usedMemMax = new float[numPools];
+             for (int i = 0; i < numPools; i++) {
+                 usedMemMax[i] = 1024f * 1024f ;
+             }
              ptNum = new int[numPools];
          }
  
          @Override
          public Dimension getMinimumSize() {
*** 192,201 ****
--- 197,212 ----
          public void plotMemoryUsage(int x1, int y1, int x2, int y2, int npool) {
  
              MemoryPoolMXBean mp = mpools.get(npool);
              float usedMemory =  mp.getUsage().getUsed();
              float totalMemory =  mp.getUsage().getMax();
+             if (totalMemory < 0) {
+                 if (usedMemory > usedMemMax[npool]) {
+                     usedMemMax[npool] = usedMemory;
+                 }
+                 totalMemory = usedMemMax[npool];
+             }
  
              // .. Draw allocated and used strings ..
              big.setColor(Color.green);
  
              // Print Max memory allocated for this memory pool.
                                     
2012-06-04
EVALUATION

The demo should anticipate that getMax() can return -1.
                                     
2012-06-04
EVALUATION

http://hg.openjdk.java.net/jdk8/tl/jdk/rev/4573662cb28c
                                     
2012-06-05



Hardware and Software, Engineered to Work Together