Path: blob/master/test/hotspot/jtreg/gc/arguments/TestArrayAllocatorMallocLimit.java
40942 views
/*1* Copyright (c) 2014, 2020, 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.arguments;2425/*26* @test TestArrayAllocatorMallocLimit27* @summary Sanity check that the ArrayAllocatorMallocLimit flag can be set.28* The test helps verifying that size_t flags can be set/read.29* @bug 805482330* @library /test/lib31* @library /32* @modules java.base/jdk.internal.misc33* java.management34* @run driver gc.arguments.TestArrayAllocatorMallocLimit35*/3637import jdk.test.lib.Asserts;38import jdk.test.lib.process.OutputAnalyzer;39import jdk.test.lib.process.ProcessTools;40import java.math.BigInteger;4142public class TestArrayAllocatorMallocLimit {43public static void main(String [] args) throws Exception {44testDefaultValue();45testSetValue();46}4748private static final String flagName = "ArrayAllocatorMallocLimit";4950// size_t ArrayAllocatorMallocLimit = 18446744073709551615{experimental}51private static final String printFlagsFinalPattern = " *size_t *" + flagName + " *:?= *(\\d+) *\\{experimental\\} *";5253public static void testDefaultValue() throws Exception {54ProcessBuilder pb = GCArguments.createJavaProcessBuilder(55"-XX:+UnlockExperimentalVMOptions", "-XX:+PrintFlagsFinal", "-version");5657OutputAnalyzer output = new OutputAnalyzer(pb.start());58String value = output.firstMatch(printFlagsFinalPattern, 1);5960try {61Asserts.assertNotNull(value, "Couldn't find size_t flag " + flagName);6263// A size_t is not always parseable with Long.parseValue,64// use BigInteger instead.65BigInteger biValue = new BigInteger(value);6667// Sanity check that we got a non-zero value.68Asserts.assertNotEquals(biValue, "0");6970output.shouldHaveExitValue(0);71} catch (Exception e) {72System.err.println(output.getOutput());73throw e;74}75}7677public static void testSetValue() throws Exception {78long flagValue = 2048;7980ProcessBuilder pb = GCArguments.createJavaProcessBuilder(81"-XX:+UnlockExperimentalVMOptions", "-XX:" + flagName + "=" + flagValue, "-XX:+PrintFlagsFinal", "-version");8283OutputAnalyzer output = new OutputAnalyzer(pb.start());84String value = output.firstMatch(printFlagsFinalPattern, 1);8586try {87Asserts.assertNotNull("Couldn't find size_t flag " + flagName);8889long longValue = Long.parseLong(value);9091Asserts.assertEquals(longValue, flagValue);9293output.shouldHaveExitValue(0);94} catch (Exception e) {95System.err.println(output.getOutput());96throw e;97}98}99100}101102103