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