< prev index next >

test/hotspot/jtreg/gc/shenandoah/mxbeans/TestChurnNotifications.java

Print this page
*** 1,7 ***
--- 1,8 ---
  /*
   * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
+  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

*** 102,10 ***
--- 103,22 ---
   *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
   *      -Dprecise=false
   *      TestChurnNotifications
   */
  
+ /*
+  * @test id=generational
+  * @summary Check that MX notifications are reported for all cycles
+  * @library /test/lib /
+  * @requires vm.gc.Shenandoah
+  *
+  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
+  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
+  *      -Dprecise=false
+  *      TestChurnNotifications
+  */
+ 
  import java.util.*;
  import java.util.concurrent.atomic.*;
  import javax.management.*;
  import java.lang.management.*;
  import javax.management.openmbean.*;

*** 126,10 ***
--- 139,21 ---
  
      static final long M = 1024 * 1024;
  
      static volatile Object sink;
  
+     private static final String DEFAULT_POOL_NAME = "Shenandoah";
+     private static final String YOUNG_GEN_POOL_NAME = "Shenandoah Young Gen";
+ 
+     private static MemoryUsage getUsage(Map<String, MemoryUsage> pools) {
+         MemoryUsage usage = pools.get(DEFAULT_POOL_NAME);
+         if (usage == null) {
+             usage = pools.get(YOUNG_GEN_POOL_NAME);
+         }
+         return usage;
+     }
+ 
      public static void main(String[] args) throws Exception {
          final long startTime = System.currentTimeMillis();
  
          final AtomicLong churnBytes = new AtomicLong();
  

*** 139,12 ***
                  if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                      GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData());
                      Map<String, MemoryUsage> mapBefore = info.getGcInfo().getMemoryUsageBeforeGc();
                      Map<String, MemoryUsage> mapAfter = info.getGcInfo().getMemoryUsageAfterGc();
  
!                     MemoryUsage before = mapBefore.get("Shenandoah");
!                     MemoryUsage after = mapAfter.get("Shenandoah");
  
                      if ((before != null) && (after != null)) {
                          long diff = before.getUsed() - after.getUsed();
                          if (diff > 0) {
                              churnBytes.addAndGet(diff);
--- 163,12 ---
                  if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                      GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData());
                      Map<String, MemoryUsage> mapBefore = info.getGcInfo().getMemoryUsageBeforeGc();
                      Map<String, MemoryUsage> mapAfter = info.getGcInfo().getMemoryUsageAfterGc();
  
!                     MemoryUsage before = getUsage(mapBefore);
!                     MemoryUsage after = getUsage(mapAfter);
  
                      if ((before != null) && (after != null)) {
                          long diff = before.getUsed() - after.getUsed();
                          if (diff > 0) {
                              churnBytes.addAndGet(diff);
< prev index next >