Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/shenandoah/mxbeans/TestMemoryMXBeans.java
32285 views
/*1* Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223/**24* @test TestMemoryMXBeans25* @key gc26* @summary Test JMX memory beans27*28* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xmx1g TestMemoryMXBeans -1 102429* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms1g -Xmx1g TestMemoryMXBeans 1024 102430* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms128m -Xmx1g TestMemoryMXBeans 128 102431* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms1g -Xmx1g -XX:ShenandoahUncommitDelay=0 TestMemoryMXBeans 1024 102432* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -Xms128m -Xmx1g -XX:ShenandoahUncommitDelay=0 TestMemoryMXBeans 128 102433*/3435import java.lang.management.*;36import java.util.*;3738public class TestMemoryMXBeans {3940public static void main(String[] args) throws Exception {41if (args.length < 2) {42throw new IllegalStateException("Should provide expected heap sizes");43}4445long initSize = 1L * Integer.parseInt(args[0]) * 1024 * 1024;46long maxSize = 1L * Integer.parseInt(args[1]) * 1024 * 1024;4748// wait for GC to uncommit49Thread.sleep(1000);5051testMemoryBean(initSize, maxSize);52}5354public static void testMemoryBean(long initSize, long maxSize) {55MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();56long heapInit = memoryMXBean.getHeapMemoryUsage().getInit();57long heapCommitted = memoryMXBean.getHeapMemoryUsage().getCommitted();58long heapMax = memoryMXBean.getHeapMemoryUsage().getMax();59long nonHeapInit = memoryMXBean.getNonHeapMemoryUsage().getInit();60long nonHeapCommitted = memoryMXBean.getNonHeapMemoryUsage().getCommitted();61long nonHeapMax = memoryMXBean.getNonHeapMemoryUsage().getMax();6263if (initSize > 0 && heapInit != initSize) {64throw new IllegalStateException("Init heap size is wrong: " + heapInit + " vs " + initSize);65}66if (maxSize > 0 && heapMax != maxSize) {67throw new IllegalStateException("Max heap size is wrong: " + heapMax + " vs " + maxSize);68}69if (initSize > 0 && maxSize > 0 && initSize != maxSize && heapCommitted == heapMax) {70throw new IllegalStateException("Committed heap size is max: " + heapCommitted +71" (init: " + initSize + ", max: " + maxSize + ")");72}73if (initSize > 0 && maxSize > 0 && initSize == maxSize && heapCommitted != heapMax) {74throw new IllegalStateException("Committed heap size is not max: " + heapCommitted +75" (init: " + initSize + ", max: " + maxSize + ")");76}77if (initSize > 0 && heapCommitted < initSize) {78throw new IllegalStateException("Committed heap size is below min: " + heapCommitted +79" (init: " + initSize + ", max: " + maxSize + ")");80}81}82}838485