Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/metaspace/TestMetaspacePerfCounters.java
32284 views
/*1* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.List;24import java.util.ArrayList;2526import com.oracle.java.testlibrary.*;27import static com.oracle.java.testlibrary.Asserts.*;2829/* @test TestMetaspacePerfCounters30* @bug 801465931* @requires vm.gc=="null"32* @library /testlibrary33* @summary Tests that performance counters for metaspace and compressed class34* space exists and works.35*36* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters37* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters38* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters39* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:-UseCompressedClassPointers -XX:+UsePerfData -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC TestMetaspacePerfCounters40*41* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseSerialGC TestMetaspacePerfCounters42* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseParallelGC -XX:+UseParallelOldGC TestMetaspacePerfCounters43* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UseG1GC TestMetaspacePerfCounters44* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:+UsePerfData -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC TestMetaspacePerfCounters45*/46public class TestMetaspacePerfCounters {47public static Class fooClass = null;48private static final String[] counterNames = {"minCapacity", "maxCapacity", "capacity", "used"};4950public static void main(String[] args) throws Exception {51String metaspace = "sun.gc.metaspace";52String ccs = "sun.gc.compressedclassspace";5354checkPerfCounters(metaspace);5556if (isUsingCompressedClassPointers()) {57checkPerfCounters(ccs);58checkUsedIncreasesWhenLoadingClass(ccs);59} else {60checkEmptyPerfCounters(ccs);61checkUsedIncreasesWhenLoadingClass(metaspace);62}63}6465private static void checkPerfCounters(String ns) throws Exception {66long minCapacity = getMinCapacity(ns);67long maxCapacity = getMaxCapacity(ns);68long capacity = getCapacity(ns);69long used = getUsed(ns);7071assertGTE(minCapacity, 0L);72assertGTE(used, minCapacity);73assertGTE(capacity, used);74assertGTE(maxCapacity, capacity);75}7677private static void checkEmptyPerfCounters(String ns) throws Exception {78for (PerfCounter counter : countersInNamespace(ns)) {79String msg = "Expected " + counter.getName() + " to equal 0";80assertEQ(counter.longValue(), 0L, msg);81}82}8384private static void checkUsedIncreasesWhenLoadingClass(String ns) throws Exception {85long before = getUsed(ns);86fooClass = compileAndLoad("Foo", "public class Foo { }");87System.gc();88long after = getUsed(ns);8990assertGT(after, before);91}9293private static List<PerfCounter> countersInNamespace(String ns) throws Exception {94List<PerfCounter> counters = new ArrayList<>();95for (String name : counterNames) {96counters.add(PerfCounters.findByName(ns + "." + name));97}98return counters;99}100101private static Class<?> compileAndLoad(String name, String source) throws Exception {102byte[] byteCode = InMemoryJavaCompiler.compile(name, source);103return ByteCodeLoader.load(name, byteCode);104}105106private static boolean isUsingCompressedClassPointers() {107return Platform.is64bit() && InputArguments.contains("-XX:+UseCompressedClassPointers");108}109110private static long getMinCapacity(String ns) throws Exception {111return PerfCounters.findByName(ns + ".minCapacity").longValue();112}113114private static long getCapacity(String ns) throws Exception {115return PerfCounters.findByName(ns + ".capacity").longValue();116}117118private static long getMaxCapacity(String ns) throws Exception {119return PerfCounters.findByName(ns + ".maxCapacity").longValue();120}121122private static long getUsed(String ns) throws Exception {123return PerfCounters.findByName(ns + ".used").longValue();124}125}126127128