Options.java revision 8359:ed6389f70257
1/*
2 * Copyright (c) 2013, 2015, 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
24import jdk.test.lib.*;
25
26/*
27 * @test
28 * @bug     8006997
29 * @summary ContendedPaddingWidth should be range-checked
30 *
31 * @library /testlibrary
32 * @modules java.base/sun.misc
33 *          java.management
34 * @run main Options
35 */
36public class Options {
37
38    public static void main(String[] args) throws Exception {
39        ProcessBuilder pb;
40        OutputAnalyzer output;
41
42        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=-128", "-version");
43        output = new OutputAnalyzer(pb.start());
44        output.shouldContain("ContendedPaddingWidth");
45        output.shouldContain("must be in between");
46        output.shouldHaveExitValue(1);
47
48        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=-8", "-version");
49        output = new OutputAnalyzer(pb.start());
50        output.shouldContain("ContendedPaddingWidth");
51        output.shouldContain("must be in between");
52        output.shouldHaveExitValue(1);
53
54        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=-1", "-version");
55        output = new OutputAnalyzer(pb.start());
56        output.shouldContain("ContendedPaddingWidth");
57        output.shouldContain("must be in between");
58        output.shouldContain("must be a multiple of 8");
59        output.shouldHaveExitValue(1);
60
61        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=0", "-version");
62        output = new OutputAnalyzer(pb.start());
63        output.shouldHaveExitValue(0);
64
65        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=1", "-version");
66        output = new OutputAnalyzer(pb.start());
67        output.shouldContain("ContendedPaddingWidth");
68        output.shouldContain("must be a multiple of 8");
69        output.shouldHaveExitValue(1);
70
71        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8", "-version");
72        output = new OutputAnalyzer(pb.start());
73        output.shouldHaveExitValue(0);
74
75        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8184", "-version"); // 8192-8 = 8184
76        output = new OutputAnalyzer(pb.start());
77        output.shouldHaveExitValue(0);
78
79        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8191", "-version");
80        output = new OutputAnalyzer(pb.start());
81        output.shouldContain("ContendedPaddingWidth");
82        output.shouldContain("must be a multiple of 8");
83        output.shouldHaveExitValue(1);
84
85        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8192", "-version");
86        output = new OutputAnalyzer(pb.start());
87        output.shouldHaveExitValue(0);
88
89        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8193", "-version");
90        output = new OutputAnalyzer(pb.start());
91        output.shouldContain("ContendedPaddingWidth");
92        output.shouldContain("must be in between");
93        output.shouldContain("must be a multiple of 8");
94        output.shouldHaveExitValue(1);
95
96        pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8200", "-version"); // 8192+8 = 8200
97        output = new OutputAnalyzer(pb.start());
98        output.shouldContain("ContendedPaddingWidth");
99        output.shouldContain("must be in between");
100        output.shouldHaveExitValue(1);
101
102   }
103
104}
105
106