1/* 2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test TestArrayAllocatorMallocLimit 26 * @summary Sanity check that the ArrayAllocatorMallocLimit flag can be set. 27 * The test helps verifying that size_t flags can be set/read. 28 * @bug 8054823 29 * @key gc 30 * @library /test/lib 31 * @modules java.base/jdk.internal.misc 32 * java.management 33 * @run driver TestArrayAllocatorMallocLimit 34 */ 35 36import jdk.test.lib.Asserts; 37import jdk.test.lib.process.OutputAnalyzer; 38import jdk.test.lib.process.ProcessTools; 39import java.math.BigInteger; 40 41public class TestArrayAllocatorMallocLimit { 42 public static void main(String [] args) throws Exception { 43 testDefaultValue(); 44 testSetValue(); 45 } 46 47 private static final String flagName = "ArrayAllocatorMallocLimit"; 48 49 // size_t ArrayAllocatorMallocLimit = 18446744073709551615{experimental} 50 private static final String printFlagsFinalPattern = " *size_t *" + flagName + " *:?= *(\\d+) *\\{experimental\\} *"; 51 52 public static void testDefaultValue() throws Exception { 53 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 54 "-XX:+UnlockExperimentalVMOptions", "-XX:+PrintFlagsFinal", "-version"); 55 56 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 57 String value = output.firstMatch(printFlagsFinalPattern, 1); 58 59 try { 60 Asserts.assertNotNull(value, "Couldn't find size_t flag " + flagName); 61 62 // A size_t is not always parseable with Long.parseValue, 63 // use BigInteger instead. 64 BigInteger biValue = new BigInteger(value); 65 66 // Sanity check that we got a non-zero value. 67 Asserts.assertNotEquals(biValue, "0"); 68 69 output.shouldHaveExitValue(0); 70 } catch (Exception e) { 71 System.err.println(output.getOutput()); 72 throw e; 73 } 74 } 75 76 public static void testSetValue() throws Exception { 77 long flagValue = 2048; 78 79 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 80 "-XX:+UnlockExperimentalVMOptions", "-XX:" + flagName + "=" + flagValue, "-XX:+PrintFlagsFinal", "-version"); 81 82 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 83 String value = output.firstMatch(printFlagsFinalPattern, 1); 84 85 try { 86 Asserts.assertNotNull("Couldn't find size_t flag " + flagName); 87 88 long longValue = Long.parseLong(value); 89 90 Asserts.assertEquals(longValue, flagValue); 91 92 output.shouldHaveExitValue(0); 93 } catch (Exception e) { 94 System.err.println(output.getOutput()); 95 throw e; 96 } 97 } 98 99} 100