< prev index next >

test/gc/metaspace/TestMetaspacePerfCounters.java

Print this page
rev 11781 : 8163413: gc/metaspace/TestMetaspacePerfCounters failure
Reviewed-by:


   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 import java.util.List;
  25 import java.util.ArrayList;
  26 
  27 import jdk.test.lib.*;


  28 import static jdk.test.lib.Asserts.*;
  29 
  30 /* @test TestMetaspacePerfCounters
  31  * @bug 8014659
  32  * @requires vm.gc=="null"
  33  * @library /testlibrary
  34  * @summary Tests that performance counters for metaspace and compressed class
  35  *          space exists and works.
  36  * @modules java.base/jdk.internal.misc
  37  *          java.compiler
  38  *          java.management
  39  *          jdk.jvmstat/sun.jvmstat.monitor
  40  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
  41  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
  42  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters
  43  *
  44  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
  45  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
  46  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters
  47  */
  48 public class TestMetaspacePerfCounters {
  49     public static Class fooClass = null;
  50     private static final String[] counterNames = {"minCapacity", "maxCapacity", "capacity", "used"};

  51 
  52     public static void main(String[] args) throws Exception {
  53         String metaspace = "sun.gc.metaspace";
  54         String ccs = "sun.gc.compressedclassspace";
  55 
  56         checkPerfCounters(metaspace);
  57 
  58         if (isUsingCompressedClassPointers()) {
  59             checkPerfCounters(ccs);
  60             checkUsedIncreasesWhenLoadingClass(ccs);
  61         } else {
  62             checkEmptyPerfCounters(ccs);
  63             checkUsedIncreasesWhenLoadingClass(metaspace);
  64         }
  65     }
  66 
  67     private static void checkPerfCounters(String ns) throws Exception {
  68         long minCapacity = getMinCapacity(ns);
  69         long maxCapacity = getMaxCapacity(ns);
  70         long capacity = getCapacity(ns);
  71         long used = getUsed(ns);

















  72 
  73         assertGTE(minCapacity, 0L);
  74         assertGTE(used, minCapacity);
  75         assertGTE(capacity, used);
  76         assertGTE(maxCapacity, capacity);
  77     }
  78 
  79     private static void checkEmptyPerfCounters(String ns) throws Exception {
  80         for (PerfCounter counter : countersInNamespace(ns)) {
  81             String msg = "Expected " + counter.getName() + " to equal 0";
  82             assertEQ(counter.longValue(), 0L, msg);
  83         }
  84     }
  85 
  86     private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {
  87         // Need to ensure that used is up to date and that all unreachable
  88         // classes are unloaded before doing this check.
  89         System.gc();
  90         long before = getUsed(ns);
  91         fooClass = compileAndLoad("Foo", "public class Foo { }");


 109     }
 110 
 111     private static boolean isUsingCompressedClassPointers() {
 112         return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers");
 113     }
 114 
 115     private static long getMinCapacity(String ns) throws Exception {
 116         return PerfCounters.findByName(ns + ".minCapacity").longValue();
 117     }
 118 
 119     private static long getCapacity(String ns) throws Exception {
 120         return PerfCounters.findByName(ns + ".capacity").longValue();
 121     }
 122 
 123     private static long getMaxCapacity(String ns) throws Exception {
 124         return PerfCounters.findByName(ns + ".maxCapacity").longValue();
 125     }
 126 
 127     private static long getUsed(String ns) throws Exception {
 128         return PerfCounters.findByName(ns + ".used").longValue();








 129     }
 130 }


   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 import java.lang.management.GarbageCollectorMXBean;
  25 import java.util.List;
  26 import java.util.ArrayList;

  27 import jdk.test.lib.*;
  28 import sun.management.ManagementFactoryHelper;
  29 
  30 import static jdk.test.lib.Asserts.*;
  31 
  32 /* @test TestMetaspacePerfCounters
  33  * @bug 8014659
  34  * @requires vm.gc=="null"
  35  * @library /testlibrary
  36  * @summary Tests that performance counters for metaspace and compressed class
  37  *          space exists and works.
  38  * @modules java.base/jdk.internal.misc
  39  *          java.compiler
  40  *          java.management/sun.management
  41  *          jdk.jvmstat/sun.jvmstat.monitor
  42  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
  43  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
  44  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters
  45  *
  46  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters
  47  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters
  48  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters
  49  */
  50 public class TestMetaspacePerfCounters {
  51     public static Class fooClass = null;
  52     private static final String[] counterNames = {"minCapacity", "maxCapacity", "capacity", "used"};
  53     private static final List<GarbageCollectorMXBean> gcBeans = ManagementFactoryHelper.getGarbageCollectorMXBeans();
  54 
  55     public static void main(String[] args) throws Exception {
  56         String metaspace = "sun.gc.metaspace";
  57         String ccs = "sun.gc.compressedclassspace";
  58 
  59         checkPerfCounters(metaspace);
  60 
  61         if (isUsingCompressedClassPointers()) {
  62             checkPerfCounters(ccs);
  63             checkUsedIncreasesWhenLoadingClass(ccs);
  64         } else {
  65             checkEmptyPerfCounters(ccs);
  66             checkUsedIncreasesWhenLoadingClass(metaspace);
  67         }
  68     }
  69 
  70     private static void checkPerfCounters(String ns) throws Exception {
  71         long gcCountBefore;
  72         long gcCountAfter;
  73         long minCapacity;
  74         long maxCapacity;
  75         long capacity;
  76         long used;
  77 
  78         // The perf counter values are updated during GC and to be able to
  79         // do the assertions below we need to ensure that the values are from
  80         // the same GC cycle.
  81         do {
  82             gcCountBefore = currentGCCount();
  83 
  84             minCapacity = getMinCapacity(ns);
  85             maxCapacity = getMaxCapacity(ns);
  86             capacity = getCapacity(ns);
  87             used = getUsed(ns);
  88 
  89             gcCountAfter = currentGCCount();
  90             assertGTE(gcCountAfter, gcCountBefore);
  91         } while(gcCountAfter > gcCountBefore);
  92 
  93         assertGTE(minCapacity, 0L);
  94         assertGTE(used, minCapacity);
  95         assertGTE(capacity, used);
  96         assertGTE(maxCapacity, capacity);
  97     }
  98 
  99     private static void checkEmptyPerfCounters(String ns) throws Exception {
 100         for (PerfCounter counter : countersInNamespace(ns)) {
 101             String msg = "Expected " + counter.getName() + " to equal 0";
 102             assertEQ(counter.longValue(), 0L, msg);
 103         }
 104     }
 105 
 106     private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {
 107         // Need to ensure that used is up to date and that all unreachable
 108         // classes are unloaded before doing this check.
 109         System.gc();
 110         long before = getUsed(ns);
 111         fooClass = compileAndLoad("Foo", "public class Foo { }");


 129     }
 130 
 131     private static boolean isUsingCompressedClassPointers() {
 132         return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers");
 133     }
 134 
 135     private static long getMinCapacity(String ns) throws Exception {
 136         return PerfCounters.findByName(ns + ".minCapacity").longValue();
 137     }
 138 
 139     private static long getCapacity(String ns) throws Exception {
 140         return PerfCounters.findByName(ns + ".capacity").longValue();
 141     }
 142 
 143     private static long getMaxCapacity(String ns) throws Exception {
 144         return PerfCounters.findByName(ns + ".maxCapacity").longValue();
 145     }
 146 
 147     private static long getUsed(String ns) throws Exception {
 148         return PerfCounters.findByName(ns + ".used").longValue();
 149     }
 150 
 151     private static long currentGCCount() {
 152         long gcCount = 0;
 153         for (GarbageCollectorMXBean bean : gcBeans) {
 154             gcCount += bean.getCollectionCount();
 155         }
 156         return gcCount;
 157     }
 158 }
< prev index next >