< prev index next >

test/hotspot/jtreg/gc/TestMemoryMXBeansAndPoolsPresence.java

Print this page




  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 import java.util.List;
  25 import java.util.ArrayList;
  26 import java.lang.management.*;
  27 import static jdk.test.lib.Asserts.*;
  28 import java.util.stream.*;
  29 
  30 /* @test TestMemoryMXBeansAndPoolsPresence
  31  * @bug 8191564
  32  * @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.
  33  * @library /test/lib
  34  * @modules java.base/jdk.internal.misc
  35  *          java.management
  36  * @requires vm.gc == null
  37  * @run main/othervm -XX:+UseG1GC TestMemoryMXBeansAndPoolsPresence G1

  38  * @run main/othervm -XX:+UseParallelGC TestMemoryMXBeansAndPoolsPresence Parallel
  39  * @run main/othervm -XX:+UseSerialGC TestMemoryMXBeansAndPoolsPresence Serial
  40  */
  41 
  42 /* @test TestMemoryMXBeansAndPoolsPresenceCMS
  43  * @bug 8191564
  44  * @library /test/lib
  45  * @modules java.base/jdk.internal.misc
  46  *          java.management
  47  * @comment Graal does not support CMS
  48  * @requires vm.gc == null & !vm.graal.enabled
  49  * @run main/othervm -XX:+UseConcMarkSweepGC TestMemoryMXBeansAndPoolsPresence CMS
  50  */
  51 
  52 class GCBeanDescription {
  53     public String name;
  54     public String[] poolNames;
  55 
  56     public GCBeanDescription(String name, String[] poolNames) {
  57         this.name = name;


  69         for (GCBeanDescription desc : expectedBeans) {
  70             List<GarbageCollectorMXBean> beans = gcBeans.stream()
  71                                                         .filter(b -> b.getName().equals(desc.name))
  72                                                         .collect(Collectors.toList());
  73             assertEQ(beans.size(), 1);
  74 
  75             GarbageCollectorMXBean bean = beans.get(0);
  76             assertEQ(desc.name, bean.getName());
  77 
  78             String[] pools = bean.getMemoryPoolNames();
  79             assertEQ(desc.poolNames.length, pools.length);
  80             for (int i = 0; i < desc.poolNames.length; i++) {
  81                 assertEQ(desc.poolNames[i], pools[i]);
  82             }
  83         }
  84     }
  85 
  86     public static void main(String[] args) {
  87         switch (args[0]) {
  88             case "G1":

  89                 test(new GCBeanDescription("G1 Young Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}),
  90                      new GCBeanDescription("G1 Old Generation",   new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}));
  91                 break;











  92             case "CMS":
  93                 test(new GCBeanDescription("ParNew",              new String[] {"Par Eden Space", "Par Survivor Space"}),
  94                      new GCBeanDescription("ConcurrentMarkSweep", new String[] {"Par Eden Space", "Par Survivor Space", "CMS Old Gen"}));
  95                 break;
  96             case "Parallel":
  97                 test(new GCBeanDescription("PS Scavenge",         new String[] {"PS Eden Space", "PS Survivor Space"}),
  98                      new GCBeanDescription("PS MarkSweep",        new String[] {"PS Eden Space", "PS Survivor Space", "PS Old Gen"}));
  99                 break;
 100             case "Serial":
 101                 test(new GCBeanDescription("Copy",              new String[] {"Eden Space", "Survivor Space"}),
 102                      new GCBeanDescription("MarkSweepCompact",  new String[] {"Eden Space", "Survivor Space", "Tenured Gen"}));
 103                 break;
 104             default:
 105                 assertTrue(false);
 106                 break;
 107 
 108         }
 109     }
 110 }


  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 import java.util.List;
  25 import java.util.ArrayList;
  26 import java.lang.management.*;
  27 import static jdk.test.lib.Asserts.*;
  28 import java.util.stream.*;
  29 
  30 /* @test TestMemoryMXBeansAndPoolsPresence
  31  * @bug 8191564
  32  * @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.
  33  * @library /test/lib
  34  * @modules java.base/jdk.internal.misc
  35  *          java.management
  36  * @requires vm.gc == null
  37  * @run main/othervm -XX:+UseG1GC -XX:-G1UseLegacyMonitoring TestMemoryMXBeansAndPoolsPresence G1 NoLegacy
  38  * @run main/othervm -XX:+UseG1GC -XX:+G1UseLegacyMonitoring TestMemoryMXBeansAndPoolsPresence G1 Legacy
  39  * @run main/othervm -XX:+UseParallelGC TestMemoryMXBeansAndPoolsPresence Parallel
  40  * @run main/othervm -XX:+UseSerialGC TestMemoryMXBeansAndPoolsPresence Serial
  41  */
  42 
  43 /* @test TestMemoryMXBeansAndPoolsPresenceCMS
  44  * @bug 8191564
  45  * @library /test/lib
  46  * @modules java.base/jdk.internal.misc
  47  *          java.management
  48  * @comment Graal does not support CMS
  49  * @requires vm.gc == null & !vm.graal.enabled
  50  * @run main/othervm -XX:+UseConcMarkSweepGC TestMemoryMXBeansAndPoolsPresence CMS
  51  */
  52 
  53 class GCBeanDescription {
  54     public String name;
  55     public String[] poolNames;
  56 
  57     public GCBeanDescription(String name, String[] poolNames) {
  58         this.name = name;


  70         for (GCBeanDescription desc : expectedBeans) {
  71             List<GarbageCollectorMXBean> beans = gcBeans.stream()
  72                                                         .filter(b -> b.getName().equals(desc.name))
  73                                                         .collect(Collectors.toList());
  74             assertEQ(beans.size(), 1);
  75 
  76             GarbageCollectorMXBean bean = beans.get(0);
  77             assertEQ(desc.name, bean.getName());
  78 
  79             String[] pools = bean.getMemoryPoolNames();
  80             assertEQ(desc.poolNames.length, pools.length);
  81             for (int i = 0; i < desc.poolNames.length; i++) {
  82                 assertEQ(desc.poolNames[i], pools[i]);
  83             }
  84         }
  85     }
  86 
  87     public static void main(String[] args) {
  88         switch (args[0]) {
  89             case "G1":
  90                 if (args[1].equals("Legacy")) {
  91                     test(new GCBeanDescription("G1 Young Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}),
  92                          new GCBeanDescription("G1 Old Generation",   new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}));
  93                 } else {
  94                     test(new GCBeanDescription("G1 Young",
  95                                                new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Humongous Space"}),
  96                          new GCBeanDescription("G1 Mixed",
  97                                                new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Humongous Space",
  98                                                              "G1 Old Space"}),
  99                          new GCBeanDescription("G1 Full",
 100                                                new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Humongous Space",
 101                                                              "G1 Archive Space", "G1 Old Space"}),
 102                          new GCBeanDescription("G1 Concurrent Cycle",
 103                                                new String[] {"G1 Humongous Space", "G1 Old Space"}));
 104                 }                break;
 105             case "CMS":
 106                 test(new GCBeanDescription("ParNew",              new String[] {"Par Eden Space", "Par Survivor Space"}),
 107                      new GCBeanDescription("ConcurrentMarkSweep", new String[] {"Par Eden Space", "Par Survivor Space", "CMS Old Gen"}));
 108                 break;
 109             case "Parallel":
 110                 test(new GCBeanDescription("PS Scavenge",         new String[] {"PS Eden Space", "PS Survivor Space"}),
 111                      new GCBeanDescription("PS MarkSweep",        new String[] {"PS Eden Space", "PS Survivor Space", "PS Old Gen"}));
 112                 break;
 113             case "Serial":
 114                 test(new GCBeanDescription("Copy",              new String[] {"Eden Space", "Survivor Space"}),
 115                      new GCBeanDescription("MarkSweepCompact",  new String[] {"Eden Space", "Survivor Space", "Tenured Gen"}));
 116                 break;
 117             default:
 118                 assertTrue(false);
 119                 break;
 120 
 121         }
 122     }
 123 }
< prev index next >