1 /*
  2  * Copyright (c) 2014, 2026, 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 VMOptionWarningExperimental
 26  * @bug 8027314
 27  * @summary Warn if experimental vm option is used and -XX:+UnlockExperimentalVMOptions isn't specified.
 28  * @requires vm.flagless
 29  * @requires !vm.opt.final.UnlockExperimentalVMOptions
 30  * @library /test/lib
 31  * @modules java.base/jdk.internal.misc
 32  *          java.management
 33  * @run driver VMOptionWarning Experimental
 34  */
 35 
 36 /* @test VMOptionWarningDiagnostic
 37  * @bug 8027314
 38  * @summary Warn if diagnostic vm option is used and -XX:+UnlockDiagnosticVMOptions isn't specified.
 39  * @requires vm.flagless
 40  * @requires !vm.debug
 41  * @library /test/lib
 42  * @modules java.base/jdk.internal.misc
 43  *          java.management
 44  * @run driver VMOptionWarning Diagnostic
 45  */
 46 
 47 /* @test VMCompileCommandWarningDiagnostic
 48  * @bug 8351958
 49  * @summary Warn if compile command that is an alias for a diagnostic vm option is used and -XX:+UnlockDiagnosticVMOptions isn't specified.
 50  * @requires vm.flagless
 51  * @requires !vm.debug
 52  * @library /test/lib
 53  * @modules java.base/jdk.internal.misc
 54  *          java.management
 55  * @run driver VMOptionWarning DiagnosticCompileCommand
 56  */
 57 
 58 /* @test VMOptionWarningDevelop
 59  * @bug 8027314
 60  * @summary Warn if develop vm option is used with product version of VM.
 61  * @requires vm.flagless
 62  * @requires !vm.debug
 63  * @library /test/lib
 64  * @modules java.base/jdk.internal.misc
 65  *          java.management
 66  * @run driver VMOptionWarning Develop
 67  */
 68 
 69 /* @test VMOptionWarningCompactObjectHeaders
 70  * @bug 8360700
 71  * @summary Warn if -XX:+UseCompactObjectHeaders is used with -XX:-UseObjectMonitorTable
 72  * @requires vm.flagless
 73  * @library /test/lib
 74  * @modules java.base/jdk.internal.misc
 75  *          java.management
 76  * @run driver VMOptionWarning CompactObjectHeaders
 77  */
 78 
 79 /* @test VMOptionWarningUseObjectMonitorTable
 80  * @bug 8360700
 81  * @summary Warn if -XX:-UseObjectMonitorTable is used without -XX:-UseCompactObjectHeaders
 82  * @requires vm.flagless
 83  * @library /test/lib
 84  * @modules java.base/jdk.internal.misc
 85  *          java.management
 86  * @run driver VMOptionWarning UseObjectMonitorTable
 87  */
 88 
 89 import jdk.test.lib.process.ProcessTools;
 90 import jdk.test.lib.process.OutputAnalyzer;
 91 import jdk.test.lib.Platform;
 92 
 93 public class VMOptionWarning {
 94     public static void main(String[] args) throws Exception {
 95         if (args.length != 1) {
 96             throw new RuntimeException("wrong number of args: " + args.length);
 97         }
 98 
 99         ProcessBuilder pb;
100         OutputAnalyzer output;
101         switch (args[0]) {
102             case "Experimental": {
103                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+AlwaysSafeConstructors", "-version");
104                 output = new OutputAnalyzer(pb.start());
105                 output.shouldNotHaveExitValue(0);
106                 output.shouldContain("Error: VM option 'AlwaysSafeConstructors' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.");
107                 break;
108             }
109             case "Diagnostic": {
110                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+PrintInlining", "-version");
111                 output = new OutputAnalyzer(pb.start());
112                 output.shouldNotHaveExitValue(0);
113                 output.shouldContain("Error: VM option 'PrintInlining' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");
114                 break;
115             }
116             case "DiagnosticCompileCommand": {
117                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompileCommand=PrintAssembly,MyClass::myMethod", "-version");
118                 output = new OutputAnalyzer(pb.start());
119                 output.shouldNotHaveExitValue(0);
120                 output.shouldContain("Error: VM option 'PrintAssembly' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");
121                 break;
122             }
123             case "Develop": {
124                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+VerifyStack", "-version");
125                 output = new OutputAnalyzer(pb.start());
126                 output.shouldNotHaveExitValue(0);
127                 output.shouldContain("Error: VM option 'VerifyStack' is develop and is available only in debug version of VM.");
128                 break;
129             }
130             case "CompactObjectHeaders": {
131                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+UseCompactObjectHeaders", "-XX:+UnlockDiagnosticVMOptions", "-XX:-UseObjectMonitorTable", "-version");
132                 output = new OutputAnalyzer(pb.start());
133                 output.shouldHaveExitValue(0);
134                 output.shouldContain("warning: -UseObjectMonitorTable is incompatible with +UseCompactObjectHeaders; ignoring -UseObjectMonitorTable");
135                 break;
136             }
137             case "UseObjectMonitorTable": {
138                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", "-XX:-UseObjectMonitorTable", "-version");
139                 output = new OutputAnalyzer(pb.start());
140                 output.shouldHaveExitValue(0);
141                 output.shouldContain("warning: -UseObjectMonitorTable is incompatible with +UseCompactObjectHeaders; ignoring -UseObjectMonitorTable");
142                 break;
143             }
144             default: {
145                 throw new RuntimeException("Invalid argument: " + args[0]);
146             }
147         }
148     }
149 }