Path: blob/master/test/jdk/java/lang/management/MemoryPoolMXBean/LargeHeapThresholdTest.java
41152 views
/*1* Copyright (c) 2017, 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*/2223/*24* @test25* @bug 665321426* @requires os.simpleArch=="x64"27* @run main/othervm -Xmx3000M LargeHeapThresholdTest28* @summary MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes29*30* Large is >= 2 gigabytes31* This test tries to find memory pools with maximum allowable size of at32* least 2 gigabytes and set their usage thresholds to this value. If tested33* Java implementation is defective34* "java.lang.IllegalArgumentException: Invalid threshold value > max value of size_t"35* will be thrown.36* If no pool with maximum allowable size of at least 2 gigabytes exists37* the test passes. There is a good chance that such pool will exist if JVM38* is started with '-Xmx3000M' command line switch.39*/404142import java.lang.management.ManagementFactory;43import java.lang.management.MemoryPoolMXBean;44import java.util.List;454647public class LargeHeapThresholdTest {4849final static long TWO_G = ((long) Integer.MAX_VALUE + 1); // 2 gigabytes5051public static void main(String[] args) {52List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();53boolean verified = false;54for (MemoryPoolMXBean i : pools) {55if ((i.getUsage().getMax() >= TWO_G)56&& i.isUsageThresholdSupported()) {57i.setUsageThreshold(TWO_G);58if(i.getUsageThreshold() != TWO_G)59throw new RuntimeException("Usage threshold for"60+ " pool '" + i.getName() + "' is " + i.getUsageThreshold()61+ " and not equal to 2GB");62verified = true;63}64}65System.out.println("Ability to use big heap thresholds has "66+ (verified ? "" : "NOT ") + "been verified");67}68}697071