1 /* 2 * Copyright (c) 2014, 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 /testlibrary 31 * @run driver TestArrayAllocatorMallocLimit 32 */ 33 34 import com.oracle.java.testlibrary.Asserts; 35 import com.oracle.java.testlibrary.OutputAnalyzer; 36 import com.oracle.java.testlibrary.ProcessTools; 37 import java.math.BigInteger; 38 39 public class TestArrayAllocatorMallocLimit { 40 public static void main(String [] args) throws Exception { 41 testDefaultValue(); 42 testSetValue(); 43 } 44 45 private static final String flagName = "ArrayAllocatorMallocLimit"; 46 47 // size_t ArrayAllocatorMallocLimit = 18446744073709551615{experimental} 48 private static final String printFlagsFinalPattern = " *size_t *" + flagName + " *:?= *(\\d+) *\\{experimental\\} *"; 49 50 public static void testDefaultValue() throws Exception { 51 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 52 "-XX:+UnlockExperimentalVMOptions", "-XX:+PrintFlagsFinal", "-version"); 53 54 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 55 String value = output.firstMatch(printFlagsFinalPattern, 1); 56 57 try { 58 Asserts.assertNotNull(value, "Couldn't find size_t flag " + flagName); 59 60 // A size_t is not always parseable with Long.parseValue, 61 // use BigInteger instead. 62 BigInteger biValue = new BigInteger(value); 63 64 // Sanity check that we got a non-zero value. 65 Asserts.assertNotEquals(biValue, "0"); 66 67 output.shouldHaveExitValue(0); 68 } catch (Exception e) { 69 System.err.println(output.getOutput()); 70 throw e; 71 } 72 } 73 74 public static void testSetValue() throws Exception { 75 long flagValue = 2048; 76 77 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 78 "-XX:+UnlockExperimentalVMOptions", "-XX:" + flagName + "=" + flagValue, "-XX:+PrintFlagsFinal", "-version"); 79 80 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 81 String value = output.firstMatch(printFlagsFinalPattern, 1); 82 83 try { 84 Asserts.assertNotNull("Couldn't find size_t flag " + flagName); 85 86 long longValue = Long.parseLong(value); 87 88 Asserts.assertEquals(longValue, flagValue); 89 90 output.shouldHaveExitValue(0); 91 } catch (Exception e) { 92 System.err.println(output.getOutput()); 93 throw e; 94 } 95 } 96 97 }