< 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 -Dmem.pool=Young
+  *      TestChurnNotifications
+  */
+ 
  import java.util.*;
  import java.util.concurrent.atomic.*;
  import javax.management.*;
  import java.lang.management.*;
  import javax.management.openmbean.*;

*** 126,12 ***
  
      static final long M = 1024 * 1024;
  
      static volatile Object sink;
  
      public static void main(String[] args) throws Exception {
!         final long startTime = System.currentTimeMillis();
  
          final AtomicLong churnBytes = new AtomicLong();
  
          NotificationListener listener = new NotificationListener() {
              @Override
--- 139,14 ---
  
      static final long M = 1024 * 1024;
  
      static volatile Object sink;
  
+     private static final String POOL_NAME = "Young".equals(System.getProperty("mem.pool")) ? "Shenandoah Young Gen" : "Shenandoah";
+ 
      public static void main(String[] args) throws Exception {
!         final long startTimeNanos = System.nanoTime();
  
          final AtomicLong churnBytes = new AtomicLong();
  
          NotificationListener listener = new NotificationListener() {
              @Override

*** 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);
--- 154,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(POOL_NAME);
!                     MemoryUsage after = mapAfter.get(POOL_NAME);
  
                      if ((before != null) && (after != null)) {
                          long diff = before.getUsed() - after.getUsed();
                          if (diff > 0) {
                              churnBytes.addAndGet(diff);

*** 174,12 ***
          long actual = 0;
  
          // Look at test timeout to figure out how long we can wait without breaking into timeout.
          // Default to 1/4 of the remaining time in 1s steps.
          final long STEP_MS = 1000;
!         long spentTime = System.currentTimeMillis() - startTime;
!         long maxTries = (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) - spentTime) / STEP_MS / 4;
  
          // Wait until enough notifications are accrued to match minimum boundary.
          long tries = 0;
          while (tries++ < maxTries) {
              actual = churnBytes.get();
--- 189,12 ---
          long actual = 0;
  
          // Look at test timeout to figure out how long we can wait without breaking into timeout.
          // Default to 1/4 of the remaining time in 1s steps.
          final long STEP_MS = 1000;
!         long spentTimeNanos = System.nanoTime() - startTimeNanos;
!         long maxTries = (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) - (spentTimeNanos / 1_000_000L)) / STEP_MS / 4;
  
          // Wait until enough notifications are accrued to match minimum boundary.
          long tries = 0;
          while (tries++ < maxTries) {
              actual = churnBytes.get();
< prev index next >