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

setCollectionUsageThreshold() doesn't throw IllegalArgumentException

    XMLWordPrintable

Details

    • svc
    • b42
    • generic
    • generic
    • Verified

    Description



      Name: agR10195 Date: 02/18/2004


      The test Bug.java reveals that setCollectionUsageThreshold() sometimes does not
      throw IllegalArgumentException, if threshold is greater than maximum amount of
      memory that the pool can use.

      The test tries to set threshold max+1 and expects IllegalArgumentException
      to be thrown. The exception is thrown just for one pool: "Survivor Space 2".

      Please, note that getCollectionUsage() returns MemoryUsage that has zeroes
      instead of init, used, committed, max for each pool.

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

      public class Bug {
          public static void main(String[] argv) {
              List pools = ManagementFactory.getMemoryPoolMBeans();

              for (int i = 0; i < pools.size(); i++) {
                  MemoryPoolMBean pool = (MemoryPoolMBean) pools.get(i);
                  System.out.println("\n" + i + " pool " + pool.getName());

                  boolean isSupported = pool.isCollectionUsageThresholdSupported();
                  if (!isSupported) {
                      System.out.println(" does not support collection usage "
                                       + "thresholds");
                      continue;
                  }
                  System.out.println(" supports collection usage thresholds");
                                       
                  MemoryUsage usage = pool.getCollectionUsage();
                  if (usage == null) {
                      System.out.println(" usage is null");
                      continue;
                  }
                  
                  long max = Math.abs(usage.getMax());
                  try {
                      pool.setCollectionUsageThreshold(max + 1);
                      System.out.println(" ERROR: IllegalArgumentException is not "
                                       + "thrown for threshold " + (max + 1) + " ("
                                       + pool.getCollectionUsage() + ")");
                  } catch (IllegalArgumentException e) {
                      System.out.println(" OK: IllegalArgumentException is thrown "
                                       + "for threshold " + (max + 1) + " ("
                                       + pool.getCollectionUsage() + ")");
                  }
              }
          }
      }

      % ../jdk1.5.0-b38/solaris-sparc/bin/java Bug

      0 pool Code Cache
        does not support collection usage thresholds

      1 pool Eden Space
        supports collection usage thresholds
        ERROR: IllegalArgumentException is not thrown for threshold 1 (init = 0(0K)
      used = 0(0K) committed = 0 (0K)max = 0(0K) )

      2 pool Survivor Space 1
        supports collection usage thresholds
        ERROR: IllegalArgumentException is not thrown for threshold 1 (init = 0(0K)
      used = 0(0K) committed = 0 (0K)max = 0(0K) )

      3 pool Survivor Space 2
        supports collection usage thresholds
        OK: IllegalArgumentException is thrown for threshold 1 (init = 0(0K) used =
      0(0K) committed = 0 (0K)max = 0(0K) )

      4 pool Tenured Gen
        supports collection usage thresholds
        ERROR: IllegalArgumentException is not thrown for threshold 1 (init = 0(0K)
      used = 0(0K) committed = 0 (0K)max = 0(0K) )

      5 pool Perm Gen
        supports collection usage thresholds
        ERROR: IllegalArgumentException is not thrown for threshold 1 (init = 0(0K)
      used = 0(0K) committed = 0 (0K)max = 0(0K) )

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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: