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

G1 GarbageCollectionNotificationInfo has same information for before and after

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 7u40
    • 7u9
    • hotspot
    • gc
    • windows_7

      FULL PRODUCT VERSION :
      java version " 1.7.0_09 "
      Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
      Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      If you add youself as a NotificationListener on the GarbageCollectors in the ManagementFactory, the GarbageCollectionNotificationInfo you receive contains the same information for getMemoryUsageBeforeGc and getMemoryUsageAfterGc

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      This is the default garbage collector
      {Tenured Gen=init = 11206656(10944K) used = 0(0K) committed = 11206656(10944K) max = 178978816(174784K), Eden Space=init = 4521984(4416K) used = 2014904(1967K) committed = 4521984(4416K) max = 71630848(69952K), Code Cache=init = 163840(160K) used = 662976(647K) committed = 688128(672K) max = 33554432(32768K), Survivor Space=init = 524288(512K) used = 0(0K) committed = 524288(512K) max = 8912896(8704K), Perm Gen=init = 12582912(12288K) used = 1649968(1611K) committed = 12582912(12288K) max = 67108864(65536K)}
      {Tenured Gen=init = 11206656(10944K) used = 278024(271K) committed = 11206656(10944K) max = 178978816(174784K), Eden Space=init = 4521984(4416K) used = 0(0K) committed = 4521984(4416K) max = 71630848(69952K), Code Cache=init = 163840(160K) used = 662976(647K) committed = 688128(672K) max = 33554432(32768K), Survivor Space=init = 524288(512K) used = 0(0K) committed = 524288(512K) max = 8912896(8704K), Perm Gen=init = 12582912(12288K) used = 1649968(1611K) committed = 12582912(12288K) max = 67108864(65536K)}

      ACTUAL -
      This is with the G1 garbage collector
      {G1 Eden Space=init = 8388608(8192K) used = 1048576(1024K) committed = 8388608(8192K) max = -1(-1K), G1 Old Gen=init = 8388608(8192K) used = 0(0K) committed = 8388608(8192K) max = 268435456(262144K), Code Cache=init = 163840(160K) used = 661696(646K) committed = 688128(672K) max = 33554432(32768K), G1 Perm Gen=init = 12582912(12288K) used = 1649968(1611K) committed = 12582912(12288K) max = 67108864(65536K), G1 Survivor Space=init = 0(0K) used = 0(0K) committed = 0(0K) max = -1(-1K)}
      {G1 Eden Space=init = 8388608(8192K) used = 2097152(2048K) committed = 8388608(8192K) max = -1(-1K), G1 Old Gen=init = 8388608(8192K) used = 0(0K) committed = 8388608(8192K) max = 268435456(262144K), Code Cache=init = 163840(160K) used = 661696(646K) committed = 688128(672K) max = 33554432(32768K), G1 Perm Gen=init = 12582912(12288K) used = 1649968(1611K) committed = 12582912(12288K) max = 67108864(65536K), G1 Survivor Space=init = 0(0K) used = 0(0K) committed = 0(0K) max = -1(-1K)}


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.lang.management.GarbageCollectorMXBean;
      import java.lang.management.ManagementFactory;
      import java.lang.management.PlatformManagedObject;
      import java.util.ArrayList;
      import java.util.List;

      import javax.management.Notification;
      import javax.management.NotificationEmitter;
      import javax.management.NotificationListener;
      import javax.management.openmbean.CompositeData;

      import com.sun.management.GarbageCollectionNotificationInfo;

      /**
       *
       */
      public class NotificationTest {

        public static void main(String[] args) {
          for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
            addNotificationListener(bean);
          }

          List<String> strings = new ArrayList<String>();
          
          for(int i=0;i<10000;i++) {
            System.out.println(i);
          }
          
          System.gc();
          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
          }
        }
        
        public static void addNotificationListener(PlatformManagedObject mbs) {
          if (mbs instanceof NotificationEmitter) {
            NotificationEmitter emitter = (NotificationEmitter)mbs;
            emitter.addNotificationListener(new NotificationListener() {
              @Override
              public void handleNotification(Notification notification, Object handback) {
                String notifType = notification.getType();
                if (notifType.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                  // retrieve the garbage collection notification information
                  GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData)notification
                          .getUserData());
                  System.out.println(info.getGcInfo().getMemoryUsageBeforeGc());
                  System.out.println(info.getGcInfo().getMemoryUsageAfterGc());
                }
              }
            }, null, null);
          }
        }

      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            mcastegr Mattis Castegren (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: