Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/metaspace/TestMetaspaceMemoryPool.java
32284 views
/*1* Copyright (c) 2013, 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.lang.management.*;25import com.oracle.java.testlibrary.*;26import static com.oracle.java.testlibrary.Asserts.*;2728/* @test TestMetaspaceMemoryPool29* @bug 800075430* @summary Tests that a MemoryPoolMXBeans is created for metaspace and that a31* MemoryManagerMXBean is created.32* @library /testlibrary33* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops TestMetaspaceMemoryPool34* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseCompressedOops -XX:MaxMetaspaceSize=60m TestMetaspaceMemoryPool35* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers TestMetaspaceMemoryPool36* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompressedOops -XX:+UseCompressedClassPointers -XX:CompressedClassSpaceSize=60m TestMetaspaceMemoryPool37*/38public class TestMetaspaceMemoryPool {39public static void main(String[] args) {40verifyThatMetaspaceMemoryManagerExists();4142boolean isMetaspaceMaxDefined = InputArguments.containsPrefix("-XX:MaxMetaspaceSize");43verifyMemoryPool(getMemoryPool("Metaspace"), isMetaspaceMaxDefined);4445if (Platform.is64bit()) {46if (InputArguments.contains("-XX:+UseCompressedOops")) {47MemoryPoolMXBean cksPool = getMemoryPool("Compressed Class Space");48verifyMemoryPool(cksPool, true);49}50}51}5253private static void verifyThatMetaspaceMemoryManagerExists() {54List<MemoryManagerMXBean> managers = ManagementFactory.getMemoryManagerMXBeans();55for (MemoryManagerMXBean manager : managers) {56if (manager.getName().equals("Metaspace Manager")) {57return;58}59}6061throw new RuntimeException("Expected to find a metaspace memory manager");62}6364private static MemoryPoolMXBean getMemoryPool(String name) {65List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();66for (MemoryPoolMXBean pool : pools) {67if (pool.getName().equals(name)) {68return pool;69}70}7172throw new RuntimeException("Expected to find a memory pool with name " + name);73}7475private static void verifyMemoryPool(MemoryPoolMXBean pool, boolean isMaxDefined) {76MemoryUsage mu = pool.getUsage();77long init = mu.getInit();78long used = mu.getUsed();79long committed = mu.getCommitted();80long max = mu.getMax();8182assertGTE(init, 0L);83assertGTE(used, init);84assertGTE(committed, used);8586if (isMaxDefined) {87assertGTE(max, committed);88} else {89assertEQ(max, -1L);90}91}92}939495