< prev index next >

test/hotspot/jtreg/runtime/CommandLine/VMOptionWarning.java

Print this page

  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  */

 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             }

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 }

  1 /*
  2  * Copyright (c) 2014, 2025, 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  */

 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 import jdk.test.lib.process.ProcessTools;
 70 import jdk.test.lib.process.OutputAnalyzer;
 71 import jdk.test.lib.Platform;
 72 
 73 public class VMOptionWarning {
 74     public static void main(String[] args) throws Exception {
 75         if (args.length != 1) {
 76             throw new RuntimeException("wrong number of args: " + args.length);
 77         }
 78 
 79         ProcessBuilder pb;
 80         OutputAnalyzer output;
 81         switch (args[0]) {
 82             case "Experimental": {
 83                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+AlwaysSafeConstructors", "-version");
 84                 output = new OutputAnalyzer(pb.start());
 85                 output.shouldNotHaveExitValue(0);
 86                 output.shouldContain("Error: VM option 'AlwaysSafeConstructors' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.");
 87                 break;
 88             }

 90                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+PrintInlining", "-version");
 91                 output = new OutputAnalyzer(pb.start());
 92                 output.shouldNotHaveExitValue(0);
 93                 output.shouldContain("Error: VM option 'PrintInlining' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");
 94                 break;
 95             }
 96             case "DiagnosticCompileCommand": {
 97                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompileCommand=PrintAssembly,MyClass::myMethod", "-version");
 98                 output = new OutputAnalyzer(pb.start());
 99                 output.shouldNotHaveExitValue(0);
100                 output.shouldContain("Error: VM option 'PrintAssembly' is diagnostic and must be enabled via -XX:+UnlockDiagnosticVMOptions.");
101                 break;
102             }
103             case "Develop": {
104                 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+VerifyStack", "-version");
105                 output = new OutputAnalyzer(pb.start());
106                 output.shouldNotHaveExitValue(0);
107                 output.shouldContain("Error: VM option 'VerifyStack' is develop and is available only in debug version of VM.");
108                 break;
109             }














110             default: {
111                 throw new RuntimeException("Invalid argument: " + args[0]);
112             }
113         }
114     }
115 }
< prev index next >