Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4991795

resetPeakUsage() accessed via MBeanServer always returns null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 5.0
    • core-svc



      Name: agR10195 Date: 02/09/2004


      The test below reveals that MemoryPoolMBean.resetPeakUsage() returns null
      if the metric is accessed via MBeanServer:

      import java.io.*;
      import java.util.*;
      import java.lang.management.*;
      import javax.management.*;

      public class Test {
          private static MBeanServer mbeanServer = null;

          public static void main(String[] argv) throws Exception {

              // Register an MBean
              System.setProperty("javax.management.builder.initial", "");
              mbeanServer = ManagementFactory.getPlatformMBeanServer();
              System.out.println("mbeanServer = " + mbeanServer);
                  
              // Get all pools that register on the server
              Vector pools = getMemoryPoolMBeansOnServer();
              for (int i = 0; i < pools.size(); i++) {
                  ObjectName pool = (ObjectName) pools.get(i);
                  System.out.println(i + ": name = " + pool);
                  Object object = mbeanServer.invoke(pool, "resetPeakUsage",
                                                     null, null);
                  MemoryUsage usage = (MemoryUsage) object;
                  System.out.println(" usage = " + usage);
                  
                  object = mbeanServer.getAttribute(pool, "Valid");
                  Boolean b = (Boolean) object;
                  boolean isValid = b.booleanValue();
                  if (usage == null && isValid) {
                      System.out.println(" resetPeakUsage() returned null, but the "
                                       + "pool is valid");
                  }
              }
          }
          
          public static Vector getMemoryPoolMBeansOnServer() {
              Set set = mbeanServer.queryNames(null, null);
              Vector filteredSet = new Vector();
              Iterator iterator = set.iterator();

              // Filter out non-pool MBeans
              while (iterator.hasNext()) {
                  ObjectName object = (ObjectName) iterator.next();
                  String name = object.toString();
                  String sample = ManagementFactory.MEMORY_POOL_MBEAN_DOMAIN_TYPE
                                + ",name=";

                  if (name.startsWith(sample))
                      filteredSet.add(object);
              }

              return filteredSet;
          }
      }

      % ../jdk1.5.0-b37/solaris-sparc/bin/java Test
      mbeanServer = com.sun.jmx.mbeanserver.JmxMBeanServer@1e0bc08
      0: name = java.lang:type=MemoryPool,name=Eden Space
         usage = null
         resetPeakUsage() returned null, but the pool is valid
      1: name = java.lang:type=MemoryPool,name=Code Cache
         usage = null
         resetPeakUsage() returned null, but the pool is valid
      2: name = java.lang:type=MemoryPool,name=Tenured Gen
         usage = null
         resetPeakUsage() returned null, but the pool is valid
      3: name = java.lang:type=MemoryPool,name=Perm Gen
         usage = null
         resetPeakUsage() returned null, but the pool is valid
      4: name = java.lang:type=MemoryPool,name=Survivor Space 1
         usage = null
         resetPeakUsage() returned null, but the pool is valid
      5: name = java.lang:type=MemoryPool,name=Survivor Space 2
         usage = null
         resetPeakUsage() returned null, but the pool is valid

      null is a valid result for resetPeakUsage(), if the pool is invalid. However,
      in this case, null is incorrect result, since all pools are valid. The method
      works corrrectly, if the metric is accessed directly.

      ======================================================================

            Unassigned Unassigned
            gazsunw Gaz Gaz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: