1 /* 2 * Copyright (c) 2013, 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.ProcessTools; 25 import jdk.test.lib.process.OutputAnalyzer; 26 27 /* 28 * @test 29 * @bug 8006997 30 * @summary ContendedPaddingWidth should be range-checked 31 * 32 * @library /test/lib 33 * @modules java.base/jdk.internal.misc 34 * java.management 35 * @run driver Options 36 */ 37 public class Options { 38 39 public static void main(String[] args) throws Exception { 40 ProcessBuilder pb; 41 OutputAnalyzer output; 42 43 pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=-128", "-version"); 44 output = new OutputAnalyzer(pb.start()); 45 output.shouldContain("ContendedPaddingWidth"); 46 output.shouldContain("outside the allowed range"); 47 output.shouldHaveExitValue(1); 48 49 pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=-8", "-version"); 50 output = new OutputAnalyzer(pb.start()); 51 output.shouldContain("ContendedPaddingWidth"); 52 output.shouldContain("outside the allowed range"); 53 output.shouldHaveExitValue(1); 54 55 pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=-1", "-version"); 56 output = new OutputAnalyzer(pb.start()); 57 output.shouldContain("ContendedPaddingWidth"); 58 output.shouldContain("outside the allowed range"); 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("outside the allowed range"); 93 output.shouldHaveExitValue(1); 94 95 pb = ProcessTools.createJavaProcessBuilder("-XX:ContendedPaddingWidth=8200", "-version"); // 8192+8 = 8200 96 output = new OutputAnalyzer(pb.start()); 97 output.shouldContain("ContendedPaddingWidth"); 98 output.shouldContain("outside the allowed range"); 99 output.shouldHaveExitValue(1); 100 101 } 102 103 }