< prev index next >

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

Print this page

  1 /*
  2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.

  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 /*
 26  * @test id=passive
 27  * @summary Check that MX notifications are reported for all cycles
 28  * @library /test/lib /
 29  * @requires vm.gc.Shenandoah
 30  *
 31  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 32  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 33  *      -XX:+ShenandoahDegeneratedGC -Dprecise=true
 34  *      TestChurnNotifications
 35  *
 36  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 37  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 38  *      -XX:-ShenandoahDegeneratedGC -Dprecise=true
 39  *      TestChurnNotifications
 40  */
 41 
 42 /*
 43  * @test id=aggressive
 44  * @summary Check that MX notifications are reported for all cycles
 45  * @library /test/lib /
 46  * @requires vm.gc.Shenandoah
 47  *
 48  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 49  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 50  *      -Dprecise=false
 51  *      TestChurnNotifications
 52  */
 53 
 54 /*
 55  * @test id=adaptive
 56  * @summary Check that MX notifications are reported for all cycles
 57  * @library /test/lib /
 58  * @requires vm.gc.Shenandoah
 59  *
 60  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 61  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 62  *      -Dprecise=false
 63  *      TestChurnNotifications
 64  */
 65 
 66 /*
 67  * @test id=static
 68  * @summary Check that MX notifications are reported for all cycles
 69  * @library /test/lib /
 70  * @requires vm.gc.Shenandoah
 71  *
 72  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 73  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
 74  *      -Dprecise=false
 75  *      TestChurnNotifications
 76  */
 77 
 78 /*
 79  * @test id=compact
 80  * @summary Check that MX notifications are reported for all cycles
 81  * @library /test/lib /
 82  * @requires vm.gc.Shenandoah
 83  *
 84  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 85  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
 86  *      -Dprecise=false
 87  *      TestChurnNotifications
 88  */
 89 












 90 import java.util.*;
 91 import java.util.concurrent.atomic.*;
 92 import javax.management.*;
 93 import java.lang.management.*;
 94 import javax.management.openmbean.*;
 95 
 96 import jdk.test.lib.Utils;
 97 
 98 import com.sun.management.GarbageCollectionNotificationInfo;
 99 
100 public class TestChurnNotifications {
101 
102     static final long HEAP_MB = 128;                           // adjust for test configuration above
103     static final long TARGET_MB = Long.getLong("target", 2_000); // 2 Gb allocation
104 
105     // Should we track the churn precisely?
106     // Precise tracking is only reliable when GC is fully stop-the-world. Otherwise,
107     // we cannot tell, looking at heap used before/after, what was the GC churn.
108     static final boolean PRECISE = Boolean.getBoolean("precise");
109 
110     static final long M = 1024 * 1024;
111 
112     static volatile Object sink;
113 


114     public static void main(String[] args) throws Exception {
115         final long startTimeNanos = System.nanoTime();
116 
117         final AtomicLong churnBytes = new AtomicLong();
118 
119         NotificationListener listener = new NotificationListener() {
120             @Override
121             public void handleNotification(Notification n, Object o) {
122                 if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
123                     GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData());
124                     Map<String, MemoryUsage> mapBefore = info.getGcInfo().getMemoryUsageBeforeGc();
125                     Map<String, MemoryUsage> mapAfter = info.getGcInfo().getMemoryUsageAfterGc();
126 
127                     MemoryUsage before = mapBefore.get("Shenandoah");
128                     MemoryUsage after = mapAfter.get("Shenandoah");
129 
130                     if ((before != null) && (after != null)) {
131                         long diff = before.getUsed() - after.getUsed();
132                         if (diff > 0) {
133                             churnBytes.addAndGet(diff);
134                         }
135                     }
136                 }
137             }
138         };
139 
140         for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
141             ((NotificationEmitter) bean).addNotificationListener(listener, null, null);
142         }
143 
144         final int size = 100_000;
145         long count = TARGET_MB * 1024 * 1024 / (16 + 4 * size);
146 
147         long mem = count * (16 + 4 * size);
148 

  1 /*
  2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 /*
 27  * @test id=passive
 28  * @summary Check that MX notifications are reported for all cycles
 29  * @library /test/lib /
 30  * @requires vm.gc.Shenandoah & vm.opt.ShenandoahGCMode != "generational"
 31  *
 32  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 33  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 34  *      -XX:+ShenandoahDegeneratedGC -Dprecise=true
 35  *      TestChurnNotifications
 36  *
 37  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 38  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 39  *      -XX:-ShenandoahDegeneratedGC -Dprecise=true
 40  *      TestChurnNotifications
 41  */
 42 
 43 /*
 44  * @test id=aggressive
 45  * @summary Check that MX notifications are reported for all cycles
 46  * @library /test/lib /
 47  * @requires vm.gc.Shenandoah & vm.opt.ShenandoahGCMode != "generational"
 48  *
 49  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 50  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 51  *      -Dprecise=false
 52  *      TestChurnNotifications
 53  */
 54 
 55 /*
 56  * @test id=adaptive
 57  * @summary Check that MX notifications are reported for all cycles
 58  * @library /test/lib /
 59  * @requires vm.gc.Shenandoah & vm.opt.ShenandoahGCMode != "generational"
 60  *
 61  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 62  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 63  *      -Dprecise=false
 64  *      TestChurnNotifications
 65  */
 66 
 67 /*
 68  * @test id=static
 69  * @summary Check that MX notifications are reported for all cycles
 70  * @library /test/lib /
 71  * @requires vm.gc.Shenandoah & vm.opt.ShenandoahGCMode != "generational"
 72  *
 73  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 74  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
 75  *      -Dprecise=false
 76  *      TestChurnNotifications
 77  */
 78 
 79 /*
 80  * @test id=compact
 81  * @summary Check that MX notifications are reported for all cycles
 82  * @library /test/lib /
 83  * @requires vm.gc.Shenandoah & vm.opt.ShenandoahGCMode != "generational"
 84  *
 85  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 86  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
 87  *      -Dprecise=false
 88  *      TestChurnNotifications
 89  */
 90 
 91 /*
 92  * @test id=generational
 93  * @summary Check that MX notifications are reported for all cycles
 94  * @library /test/lib /
 95  * @requires vm.gc.Shenandoah
 96  *
 97  * @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 98  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
 99  *      -Dprecise=false -Dmem.pool=Young
100  *      TestChurnNotifications
101  */
102 
103 import java.util.*;
104 import java.util.concurrent.atomic.*;
105 import javax.management.*;
106 import java.lang.management.*;
107 import javax.management.openmbean.*;
108 
109 import jdk.test.lib.Utils;
110 
111 import com.sun.management.GarbageCollectionNotificationInfo;
112 
113 public class TestChurnNotifications {
114 
115     static final long HEAP_MB = 128;                           // adjust for test configuration above
116     static final long TARGET_MB = Long.getLong("target", 2_000); // 2 Gb allocation
117 
118     // Should we track the churn precisely?
119     // Precise tracking is only reliable when GC is fully stop-the-world. Otherwise,
120     // we cannot tell, looking at heap used before/after, what was the GC churn.
121     static final boolean PRECISE = Boolean.getBoolean("precise");
122 
123     static final long M = 1024 * 1024;
124 
125     static volatile Object sink;
126 
127     private static final String POOL_NAME = "Young".equals(System.getProperty("mem.pool")) ? "Shenandoah Young Gen" : "Shenandoah";
128 
129     public static void main(String[] args) throws Exception {
130         final long startTimeNanos = System.nanoTime();
131 
132         final AtomicLong churnBytes = new AtomicLong();
133 
134         NotificationListener listener = new NotificationListener() {
135             @Override
136             public void handleNotification(Notification n, Object o) {
137                 if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
138                     GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData());
139                     Map<String, MemoryUsage> mapBefore = info.getGcInfo().getMemoryUsageBeforeGc();
140                     Map<String, MemoryUsage> mapAfter = info.getGcInfo().getMemoryUsageAfterGc();
141 
142                     MemoryUsage before = mapBefore.get(POOL_NAME);
143                     MemoryUsage after = mapAfter.get(POOL_NAME);
144 
145                     if ((before != null) && (after != null)) {
146                         long diff = before.getUsed() - after.getUsed();
147                         if (diff > 0) {
148                             churnBytes.addAndGet(diff);
149                         }
150                     }
151                 }
152             }
153         };
154 
155         for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
156             ((NotificationEmitter) bean).addNotificationListener(listener, null, null);
157         }
158 
159         final int size = 100_000;
160         long count = TARGET_MB * 1024 * 1024 / (16 + 4 * size);
161 
162         long mem = count * (16 + 4 * size);
163 
< prev index next >