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

setCollectionUsageThreshold throws IAException, if max and threshold are 0

    XMLWordPrintable

    Details

      Description



      Name: agR10195 Date: 01/28/2004



      Alexey Gibadullin, ###@###.###

      The following test reveals that MemoryPoolMBean.setCollectionUsageThreshold(0)
      method throws IllegalArgumentException, if max value of the pool is 0.

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

      public class Test {
          public static void main(String[] argv) {
              List poolsMBean = ManagementFactory.getMemoryPoolMBeans();
              
              for (int i = 0; i < poolsMBean.size(); i++) {
                  MemoryPoolMBean pool = (MemoryPoolMBean) poolsMBean.get(i);
                  long threshold;
                  
                  System.out.println("\n" + i + ": " + pool.getName() + " "
                                   + pool.getUsage());
                  
                  if (!pool.isCollectionUsageThresholdSupported()) {
                      System.out.println("CollectionUsageThreshold is not supported");
                      continue;
                  }
                  
                  long max = pool.getUsage().getMax();
                  
                  if (max != 0) {
                      System.out.println("Max value is not 0");
                      continue;
                  }
                  System.out.println("Max value is 0");
                  
                  try {
                      pool.setCollectionUsageThreshold(0);
                  } catch (Exception e) {
                      e.printStackTrace(System.out);
                  }
              }
          }
      }

      % ../jdk1.5.0-b35/solaris-sparc/bin/java Test

      0: Code Cache init = 163840(160K) used = 594816(580K) committed = 622592
      (608K)max = 33554432(32768K)
      CollectionUsageThreshold is not supported

      1: Eden Space init = 2097152(2048K) used = 217152(212K) committed = 2097152
      (2048K)max = -1(-1K)
      Max value is not 0

      2: Survivor Space 1 init = 65536(64K) used = 0(0K) committed = 65536 (64K)max =
      -1(-1K)
      Max value is not 0

      3: Survivor Space 2 init = 65536(64K) used = 0(0K) committed = 65536 (64K)max =
      0(0K)
      Max value is 0
      java.lang.IllegalArgumentException: Invalid threshold: 0 > max (0).
              at
      sun.management.MemoryPoolImpl.setCollectionUsageThreshold(MemoryPoolImpl.java:18
      4)
              at Test.main(Test.java:29)

      4: Tenured Gen init = 1441792(1408K) used = 0(0K) committed = 1441792 (1408K)max
      = 59703296(58304K)
      Max value is not 0

      5: Perm Gen init = 8388608(8192K) used = 1433152(1399K) committed = 8388608
      (8192K)max = 67108864(65536K)
      Max value is not 0

      The spec for setCollectionUsageThreshold(long) says:

          void setCollectionUsageThreshold(long threhsold)
          
          Sets the collection usage threshold of this memory pool to the given
          threshold value. When this threshold is set to positive, the Java
          virtual machine will check the memory usage at its best appropriate
          time after it has expended effort in recycling unused objects in this
          memory pool.
          
          Parameters: threhsold - the new collection usage threshold value in bytes.
                      Must be non-negative.

          Throws: IllegalArgumentException - if limit is negative or greater than the
                                                ^^^^^
                  maximum amount of memory that this memory pool can use.


      1. There is no variable "limit" mentioned in the spec. The similar specification
         for setUsageThreshold says:
         
         Throws: IllegalArgumentException - if threshold is negative or greater than
                 the maximum amount of memory that this memory pool can use.
                 
         So, it looks like a misprint in setCollectionUsageThreshold(long):
         "threshold" sould be read instead of "limit".
         
      2. Concerning that, IllegalArgumentException should not be thrown for
         threshold=0, since it is not "greater than the maximum amount of memory
         that this memory pool can use" (max).
         
         Similiar bug was found in MemoryUsage() constructor:

             4979453 sun.management.MemoryPoolImpl.getCollectionUsage() throws IAE
                     (max=0)
         
      One more minor misprint is in MemoryPoolMBean.getUsage().toString():

          init = 2097152(2048K) used = 217152(212K) committed = 2097152
          (2048K)max = -1(-1K)
          
      It looks like a space " " is missed before "max" substring.

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mchung Mandy Chung
              Reporter:
              gazsunw Gaz Gaz (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: