Path: blob/master/test/hotspot/jtreg/gc/metaspace/TestMetaspaceMemoryPool.java
40942 views
/*1* Copyright (c) 2013, 2019, 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*/2223package gc.metaspace;2425import java.util.List;26import java.lang.management.*;27import jdk.test.lib.Platform;28import static jdk.test.lib.Asserts.*;2930/* @test TestMetaspaceMemoryPool31* @bug 800075432* @summary Tests that a MemoryPoolMXBeans is created for metaspace and that a33* MemoryManagerMXBean is created.34* @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true35* @library /test/lib36* @library /37* @modules java.base/jdk.internal.misc38* java.management39* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops gc.metaspace.TestMetaspaceMemoryPool40* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:MaxMetaspaceSize=60m gc.metaspace.TestMetaspaceMemoryPool41* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers gc.metaspace.TestMetaspaceMemoryPool42* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:CompressedClassSpaceSize=60m gc.metaspace.TestMetaspaceMemoryPool43*/44public class TestMetaspaceMemoryPool {45public static void main(String[] args) {46verifyThatMetaspaceMemoryManagerExists();4748boolean isMetaspaceMaxDefined = InputArguments.containsPrefix("-XX:MaxMetaspaceSize");49verifyMemoryPool(getMemoryPool("Metaspace"), isMetaspaceMaxDefined);5051if (Platform.is64bit()) {52if (InputArguments.contains("-XX:+UseCompressedOops")) {53MemoryPoolMXBean cksPool = getMemoryPool("Compressed Class Space");54verifyMemoryPool(cksPool, true);55}56}57}5859private static void verifyThatMetaspaceMemoryManagerExists() {60List<MemoryManagerMXBean> managers = ManagementFactory.getMemoryManagerMXBeans();61for (MemoryManagerMXBean manager : managers) {62if (manager.getName().equals("Metaspace Manager")) {63return;64}65}6667throw new RuntimeException("Expected to find a metaspace memory manager");68}6970private static MemoryPoolMXBean getMemoryPool(String name) {71List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();72for (MemoryPoolMXBean pool : pools) {73if (pool.getName().equals(name)) {74return pool;75}76}7778throw new RuntimeException("Expected to find a memory pool with name " + name);79}8081private static void verifyMemoryPool(MemoryPoolMXBean pool, boolean isMaxDefined) {82MemoryUsage mu = pool.getUsage();83long init = mu.getInit();84long used = mu.getUsed();85long committed = mu.getCommitted();86long max = mu.getMax();8788assertGTE(init, 0L);89assertGTE(used, init);90assertGTE(committed, used);9192if (isMaxDefined) {93assertGTE(max, committed);94} else {95assertEQ(max, -1L);96}97}98}99100101