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 */
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 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 }
89 case "Diagnostic": {
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 }