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

Serial: Exception in getCollectionUsage(): committed should be < max

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 21, 22
    • hotspot
    • gc
    • generic
    • generic

      # How to reproduce
      we got this exception when getting `MemoryUsage` via mxbean
      ```
      Exception in thread "main" java.lang.IllegalArgumentException: committed = 503382016 should be < max = 503316480
              at java.lang.management.MemoryUsage.<init>(MemoryUsage.java:160)
              at sun.management.MemoryPoolImpl.getCollectionUsage0(Native Method)
              at sun.management.MemoryPoolImpl.getCollectionUsage(MemoryPoolImpl.java:266)
              at Test.main(Test.java:11)
      ```
      The test case is quite simple,
      ```
      public class Test {
          public static void main(String[] args) throws Exception {
              System.gc();
              List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
              for (MemoryPoolMXBean pool : pools) {
                  System.out.println(pool.getName());
                  System.out.println(pool.getCollectionUsage());
              }
          }
      }
      ```
      and java command is `-XX:+UseSerialGC -Xms600m -Xmn600m`

      # Why this happen
      We know the computation of eden/survivor size is
      ```
      survivor_size = align_down(young_gen_size / (SurvivorRatio + 2))
      eden_size = young_gen_size - (2*survivor_size)
      ```
      Under certain circumstances, the aligning down here will make `survivor_committed_size` to decrease more than expected, causing `eden_committed_size` to soar above `eden_max_size`. And all this leads to the exception wo got here: committed = 503382016 should be < max = 503316480

      # How to Fix
      A simple work-around for this issue is checking whether eden committed size is more than its max size. If so, set a minimum committed size for survivor, and recompute eden size accordingly.

            xwlu Xiaowei Lu
            xwlu Xiaowei Lu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: