< prev index next >

test/gc/cms/TestMBeanCMS.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. 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  * @test Test6581734.java
  26  * @bug 6581734
  27  * @requires vm.gc=="ConcMarkSweep" | vm.gc=="null"
  28  * @summary CMS Old Gen's collection usage is zero after GC which is incorrect
  29  * @modules java.management
  30  * @run main/othervm -Xmx512m -verbose:gc -XX:+UseConcMarkSweepGC Test6581734
  31  *
  32  */
  33 import java.util.*;
  34 import java.lang.management.*;
  35 






  36 // 6581734 states that memory pool usage via the mbean is wrong
  37 // for CMS (zero, even after a collection).
  38 //
  39 // 6580448 states that the collection count similarly is wrong
  40 // (stays at zero for CMS collections)
  41 // -- closed as dup of 6581734 as the same fix resolves both.
  42 
  43 
  44 public class Test6581734 {
  45 
  46     private String poolName = "CMS";
  47     private String collectorName = "ConcurrentMarkSweep";
  48 
  49     public static void main(String [] args) {
  50 
  51         Test6581734 t = null;
  52         if (args.length==2) {
  53             t = new Test6581734(args[0], args[1]);
  54         } else {
  55             System.out.println("Defaulting to monitor CMS pool and collector.");
  56             t = new Test6581734();
  57         }
  58         t.run();
  59     }
  60 
  61     public Test6581734(String pool, String collector) {
  62         poolName = pool;
  63         collectorName = collector;
  64     }
  65 
  66     public Test6581734() {
  67     }
  68 
  69     public void run() {
  70         // Use some memory, enough that we expect collections should
  71         // have happened.
  72         // Must run with options to ensure no stop the world full GC,
  73         // but e.g. at least one CMS cycle.
  74         allocationWork(300*1024*1024);
  75         System.out.println("Done allocationWork");
  76 
  77         // Verify some non-zero results are stored.
  78         List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
  79         int poolsFound = 0;
  80         int poolsWithStats = 0;
  81         for (int i=0; i<pools.size(); i++) {
  82             MemoryPoolMXBean pool = pools.get(i);
  83             String name = pool.getName();
  84             System.out.println("found pool: " + name);
  85 
  86             if (name.contains(poolName)) {


   1 /*
   2  * Copyright (c) 2010, 2016, Oracle and/or its affiliates. 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  * @test TestMBeanCMS.java
  26  * @bug 6581734
  27  * @requires vm.gc=="ConcMarkSweep" | vm.gc=="null"
  28  * @summary CMS Old Gen's collection usage is zero after GC which is incorrect
  29  * @modules java.management
  30  * @run main/othervm -Xmx512m -verbose:gc -XX:+UseConcMarkSweepGC TestMBeanCMS
  31  *
  32  */


  33 
  34 import java.lang.management.GarbageCollectorMXBean;
  35 import java.lang.management.ManagementFactory;
  36 import java.lang.management.MemoryPoolMXBean;
  37 import java.util.LinkedList;
  38 import java.util.List;
  39 
  40 // 6581734 states that memory pool usage via the mbean is wrong
  41 // for CMS (zero, even after a collection).
  42 //
  43 // 6580448 states that the collection count similarly is wrong
  44 // (stays at zero for CMS collections)
  45 // -- closed as dup of 6581734 as the same fix resolves both.
  46 
  47 
  48 public class TestMBeanCMS {
  49 
  50     private String poolName = "CMS";
  51     private String collectorName = "ConcurrentMarkSweep";
  52 
  53     public static void main(String [] args) {
  54 
  55         TestMBeanCMS t = null;
  56         if (args.length==2) {
  57             t = new TestMBeanCMS(args[0], args[1]);
  58         } else {
  59             System.out.println("Defaulting to monitor CMS pool and collector.");
  60             t = new TestMBeanCMS();
  61         }
  62         t.run();
  63     }
  64 
  65     public TestMBeanCMS(String pool, String collector) {
  66         poolName = pool;
  67         collectorName = collector;
  68     }
  69 
  70     public TestMBeanCMS() {
  71     }
  72 
  73     public void run() {
  74         // Use some memory, enough that we expect collections should
  75         // have happened.
  76         // Must run with options to ensure no stop the world full GC,
  77         // but e.g. at least one CMS cycle.
  78         allocationWork(300*1024*1024);
  79         System.out.println("Done allocationWork");
  80 
  81         // Verify some non-zero results are stored.
  82         List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
  83         int poolsFound = 0;
  84         int poolsWithStats = 0;
  85         for (int i=0; i<pools.size(); i++) {
  86             MemoryPoolMXBean pool = pools.get(i);
  87             String name = pool.getName();
  88             System.out.println("found pool: " + name);
  89 
  90             if (name.contains(poolName)) {


< prev index next >