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 import com.oracle.java.testlibrary.ExitCode; 25 import com.oracle.java.testlibrary.cli.CommandLineOptionTest; 26 27 /** 28 * @test 29 * @bug 8031323 30 * @summary Verify SurvivorAlignmentInBytes option processing. 31 * @library /testlibrary 32 * @requires vm.opt.SurvivorAlignmentInBytes == null 33 * & vm.opt.ObjectAlignmentInBytes == null 34 * & vm.opt.UnlockExperimentalVMOptions == null 35 * & (vm.opt.IgnoreUnrecognizedVMOptions == null 36 * | vm.opt.IgnoreUnrecognizedVMOptions == "false") 37 * @run main TestSurvivorAlignmentInBytesOption 38 */ 39 public class TestSurvivorAlignmentInBytesOption { 40 public static void main(String args[]) throws Throwable { 41 String optionName = "SurvivorAlignmentInBytes"; 42 String unlockExperimentalVMOpts = "UnlockExperimentalVMOptions"; 43 String optionIsExperimental 44 = CommandLineOptionTest.getExperimentalOptionErrorMessage( 45 optionName); 46 String valueIsTooSmall= ".*SurvivorAlignmentInBytes=.*must be greater" 47 + " than ObjectAlignmentInBytes.*"; 48 String mustBePowerOf2 = ".*SurvivorAlignmentInBytes=.*must be " 49 + "power of 2.*"; 50 51 // Verify that without -XX:+UnlockExperimentalVMOptions usage of 52 // SurvivorAlignmentInBytes option will cause JVM startup failure 53 // with the warning message saying that that option is experimental. 54 String shouldFailMessage = String.format("JVM option '%s' is " 55 + "experimental.%nJVM startup should fail without " 56 + "-XX:+UnlockExperimentalVMOptions option", optionName); 57 CommandLineOptionTest.verifyJVMStartup( 58 new String[]{optionIsExperimental}, null, 59 shouldFailMessage, shouldFailMessage, 60 ExitCode.FAIL, false, 61 "-XX:-UnlockExperimentalVMOptions", 62 CommandLineOptionTest.prepareBooleanFlag( 63 unlockExperimentalVMOpts, false), 64 CommandLineOptionTest.prepareNumericFlag(optionName, 64)); 65 66 // Verify that with -XX:+UnlockExperimentalVMOptions passed to JVM 67 // usage of SurvivorAlignmentInBytes option won't cause JVM startup 68 // failure. 69 String shouldPassMessage = String.format("JVM option '%s' is " 70 + "experimental.%nJVM startup should pass with " 71 + "-XX:+UnlockExperimentalVMOptions option", optionName); 72 String noWarningMessage = "There should be no warnings when use " 73 + "with -XX:+UnlockExperimentalVMOptions option"; 74 CommandLineOptionTest.verifyJVMStartup( 75 null, new String[]{optionIsExperimental}, 76 shouldPassMessage, noWarningMessage, 77 ExitCode.OK, false, 78 CommandLineOptionTest.prepareBooleanFlag( 79 unlockExperimentalVMOpts, true), 80 CommandLineOptionTest.prepareNumericFlag(optionName, 64)); 81 82 // Verify that if specified SurvivorAlignmentInBytes is lower than 83 // ObjectAlignmentInBytes, then the JVM startup will fail with 84 // appropriate error message. 85 shouldFailMessage = String.format("JVM startup should fail with " 86 + "'%s' option value lower than ObjectAlignmentInBytes", optionName); 87 CommandLineOptionTest.verifyJVMStartup( 88 new String[]{valueIsTooSmall}, null, 89 shouldFailMessage, shouldFailMessage, 90 ExitCode.FAIL, false, 91 CommandLineOptionTest.prepareBooleanFlag( 92 unlockExperimentalVMOpts, true), 93 CommandLineOptionTest.prepareNumericFlag(optionName, 2)); 94 95 // Verify that if specified SurvivorAlignmentInBytes value is not 96 // a power of 2 then the JVM startup will fail with appropriate error 97 // message. 98 shouldFailMessage = String.format("JVM startup should fail with " 99 + "'%s' option value is not a power of 2", optionName); 100 CommandLineOptionTest.verifyJVMStartup( 101 new String[]{mustBePowerOf2}, null, 102 shouldFailMessage, shouldFailMessage, 103 ExitCode.FAIL, false, 104 CommandLineOptionTest.prepareBooleanFlag( 105 unlockExperimentalVMOpts, true), 106 CommandLineOptionTest.prepareNumericFlag(optionName, 127)); 107 108 // Verify that if SurvivorAlignmentInBytes has correct value, then 109 // the JVM will be started without errors. 110 shouldPassMessage = String.format("JVM startup should pass with " 111 + "correct '%s' option value", optionName); 112 noWarningMessage = String.format("There should be no warnings when use " 113 + "correct '%s' option value", optionName); 114 CommandLineOptionTest.verifyJVMStartup( 115 null, new String[]{".*SurvivorAlignmentInBytes.*"}, 116 shouldPassMessage, noWarningMessage, 117 ExitCode.OK, false, 118 CommandLineOptionTest.prepareBooleanFlag( 119 unlockExperimentalVMOpts, true), 120 CommandLineOptionTest.prepareNumericFlag(optionName, 128)); 121 122 // Verify that we can setup different SurvivorAlignmentInBytes values. 123 for (int alignment = 32; alignment <= 128; alignment *= 2) { 124 shouldPassMessage = String.format("JVM startup should pass with " 125 + "'%s' = %d", optionName, alignment); 126 CommandLineOptionTest.verifyOptionValue(optionName, 127 Integer.toString(alignment), shouldPassMessage, 128 CommandLineOptionTest.prepareBooleanFlag( 129 unlockExperimentalVMOpts, true), 130 CommandLineOptionTest.prepareNumericFlag( 131 optionName, alignment)); 132 } 133 } 134 }