8038193: Add command line option tests for BMI options
authoriignatyev
Thu, 27 Mar 2014 17:29:41 +0400
changeset 23501 ba4a33b2a569
parent 23499 9d5b7480c9f4
child 23502 f41b7404d441
8038193: Add command line option tests for BMI options Reviewed-by: kvn, iignatyev Contributed-by: filipp.zhinkin@oracle.com
hotspot/test/compiler/arguments/BMICommandLineOptionTestBase.java
hotspot/test/compiler/arguments/BMISupportedCPUTest.java
hotspot/test/compiler/arguments/BMIUnsupportedCPUTest.java
hotspot/test/compiler/arguments/TestUseBMI1InstructionsOnSupportedCPU.java
hotspot/test/compiler/arguments/TestUseBMI1InstructionsOnUnsupportedCPU.java
hotspot/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnSupportedCPU.java
hotspot/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnUnsupportedCPU.java
hotspot/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnSupportedCPU.java
hotspot/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnUnsupportedCPU.java
hotspot/test/testlibrary/com/oracle/java/testlibrary/ExitCode.java
hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java
hotspot/test/testlibrary/com/oracle/java/testlibrary/cli/CPUSpecificCommandLineOptionTest.java
hotspot/test/testlibrary/com/oracle/java/testlibrary/cli/CommandLineOptionTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arguments/BMICommandLineOptionTestBase.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import com.oracle.java.testlibrary.cli.*;
+
+/**
+ * Base class for all X86 bit manipulation related command line options.
+ */
+public abstract class BMICommandLineOptionTestBase
+              extends CPUSpecificCommandLineOptionTest {
+
+    public static final String LZCNT_WARNING =
+        "lzcnt instruction is not available on this CPU";
+    public static final String TZCNT_WARNING =
+        "tzcnt instruction is not available on this CPU";
+    public static final String BMI1_WARNING =
+        "BMI1 instructions are not available on this CPU";
+
+    protected final String optionName;
+    protected final String warningMessage;
+    protected final String errorMessage;
+
+    /**
+     * Construct new test on {@code optionName} option.
+     *
+     * @param optionName Name of the option to be tested
+     *                   without -XX:[+-] prefix.
+     * @param warningMessage Message that can occur in VM output
+     *                       if CPU on test box does not support
+     *                       features required by the option.
+     * @param supportedCPUFeatures CPU features requires by the option,
+     *                             that should be supported on test box.
+     * @param unsupportedCPUFeatures CPU features requires by the option,
+     *                               that should not be supported on test box.
+     */
+    public BMICommandLineOptionTestBase(String optionName,
+                                        String warningMessage,
+                                        String supportedCPUFeatures[],
+                                        String unsupportedCPUFeatures[]) {
+        super(".*", supportedCPUFeatures, unsupportedCPUFeatures);
+            this.optionName = optionName;
+            this.warningMessage = warningMessage;
+            this.errorMessage = CommandLineOptionTest.
+                UNRECOGNIZED_OPTION_ERROR_FORMAT.format(optionName);
+    }
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arguments/BMISupportedCPUTest.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import com.oracle.java.testlibrary.*;
+import com.oracle.java.testlibrary.cli.*;
+
+/**
+ * Test on bit manipulation related command line options,
+ * that should be executed on CPU that supports all required
+ * features.
+ */
+public class BMISupportedCPUTest extends BMICommandLineOptionTestBase {
+
+    /**
+     * Construct new test on {@code optionName} option.
+     *
+     * @param optionName Name of the option to be tested
+     *                   without -XX:[+-] prefix.
+     * @param warningMessage Message that can occur in VM output
+     *                       if CPU on test box does not support
+     *                       features required by the option.
+     * @param cpuFeatures CPU features requires by the option.
+     */
+    public BMISupportedCPUTest(String optionName,
+                               String warningMessage,
+                               String... cpuFeatures) {
+        super(optionName, warningMessage, cpuFeatures, null);
+    }
+
+    @Override
+    public void runTestCases() throws Throwable {
+        // verify that VM will succesfully start up whithout warnings
+        CommandLineOptionTest.
+            verifyJVMStartup("-XX:+" + optionName,
+                             null, new String[] { warningMessage },
+                             ExitCode.OK);
+
+        // verify that VM will succesfully start up whithout warnings
+        CommandLineOptionTest.
+            verifyJVMStartup("-XX:-" + optionName,
+                             null, new String[] { warningMessage },
+                             ExitCode.OK);
+
+        // verify that on appropriate CPU option in on by default
+        CommandLineOptionTest.verifyOptionValue(optionName, "true");
+
+        // verify that option could be explicitly turned off
+        CommandLineOptionTest.verifyOptionValue(optionName, "false",
+                                                "-XX:-" + optionName);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arguments/BMIUnsupportedCPUTest.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import com.oracle.java.testlibrary.*;
+import com.oracle.java.testlibrary.cli.*;
+
+/**
+ * Test on bit manipulation related command line options,
+ * that should be executed on CPU that does not support
+ * required features.
+ */
+public class BMIUnsupportedCPUTest extends BMICommandLineOptionTestBase {
+
+    /**
+     * Construct new test on {@code optionName} option.
+     *
+     * @param optionName Name of the option to be tested
+     *                   without -XX:[+-] prefix.
+     * @param warningMessage Message that can occur in VM output
+     *                       if CPU on test box does not support
+     *                       features required by the option.
+     * @param cpuFeatures CPU features requires by the option.
+     */
+    public BMIUnsupportedCPUTest(String optionName,
+                                 String warningMessage,
+                                 String... cpuFeatures) {
+        super(optionName, warningMessage, null, cpuFeatures);
+    }
+
+    @Override
+    public void runTestCases() throws Throwable {
+        if (Platform.isX86() || Platform.isX64()) {
+            unsupportedX86CPUTestCases();
+        } else {
+            unsupportedNonX86CPUTestCases();
+        }
+    }
+
+    /**
+     * Run test cases common for all bit manipulation related VM options
+     * targeted to X86 CPU that does not support required features.
+     *
+     * @throws Throwable if test failed.
+     */
+    public void unsupportedX86CPUTestCases() throws Throwable {
+
+        // verify that VM will succesfully start up, but output will
+        // contain a warning
+        CommandLineOptionTest.
+            verifyJVMStartup("-XX:+" + optionName,
+                             new String[] { warningMessage },
+                             new String[] { errorMessage },
+                             ExitCode.OK);
+
+        // verify that VM will succesfully startup without any warnings
+        CommandLineOptionTest.
+            verifyJVMStartup("-XX:-" + optionName,
+                             null,
+                             new String[] { warningMessage, errorMessage },
+                             ExitCode.OK);
+
+        // verify that on unsupported CPUs option is off by default
+        CommandLineOptionTest.verifyOptionValue(optionName, "false");
+
+        // verify that on unsupported CPUs option will be off even if
+        // it was explicitly turned on by uset
+        CommandLineOptionTest.verifyOptionValue(optionName, "false",
+                                                     "-XX:+" + optionName);
+
+    }
+
+    /**
+     * Run test cases common for all bit manipulation related VM options
+     * targeted to non-X86 CPU that does not support required features.
+     *
+     * @throws Throwable if test failed.
+     */
+    public void unsupportedNonX86CPUTestCases() throws Throwable {
+
+        // verify that VM known nothing about tested option
+        CommandLineOptionTest.
+            verifyJVMStartup("-XX:+" + optionName,
+                             new String[] { errorMessage },
+                             null,
+                             ExitCode.FAIL);
+
+        CommandLineOptionTest.
+            verifyJVMStartup("-XX:-" + optionName,
+                             new String[] { errorMessage },
+                             null,
+                             ExitCode.FAIL);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arguments/TestUseBMI1InstructionsOnSupportedCPU.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8031321
+ * @summary Verify processing of UseBMI1Instructions option on CPU with
+ *          BMI1 feature support.
+ * @library /testlibrary /testlibrary/whitebox
+ * @build TestUseBMI1InstructionsOnSupportedCPU
+ *        BMISupportedCPUTest
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
+ *                   -XX:+WhiteBoxAPI TestUseBMI1InstructionsOnSupportedCPU
+ */
+
+import sun.hotspot.cpuinfo.CPUInfo;
+import com.oracle.java.testlibrary.*;
+
+public class TestUseBMI1InstructionsOnSupportedCPU
+     extends BMISupportedCPUTest {
+
+    public TestUseBMI1InstructionsOnSupportedCPU() {
+        super("UseBMI1Instructions", BMI1_WARNING, "bmi1");
+    }
+
+    public static void main(String args[]) throws Throwable {
+        new TestUseBMI1InstructionsOnSupportedCPU().test();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arguments/TestUseBMI1InstructionsOnUnsupportedCPU.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8031321
+ * @summary Verify processing of UseBMI1Instructions option on CPU without
+ *          BMI1 feature support.
+ * @library /testlibrary /testlibrary/whitebox
+ * @build TestUseBMI1InstructionsOnUnsupportedCPU
+ *        BMIUnsupportedCPUTest
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
+ *                   -XX:+WhiteBoxAPI TestUseBMI1InstructionsOnUnsupportedCPU
+ */
+
+import sun.hotspot.cpuinfo.CPUInfo;
+import com.oracle.java.testlibrary.*;
+import com.oracle.java.testlibrary.cli.*;
+
+public class TestUseBMI1InstructionsOnUnsupportedCPU
+      extends BMIUnsupportedCPUTest {
+
+    public TestUseBMI1InstructionsOnUnsupportedCPU() {
+        super("UseBMI1Instructions", BMI1_WARNING, "bmi1");
+    }
+
+    public static void main(String args[]) throws Throwable {
+        new TestUseBMI1InstructionsOnUnsupportedCPU().test();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnSupportedCPU.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8031321
+ * @summary Verify processing of UseCountLeadingZerosInstruction option
+ *          on CPU with LZCNT support.
+ * @library /testlibrary /testlibrary/whitebox
+ * @build TestUseCountLeadingZerosInstructionOnSupportedCPU
+ *        BMISupportedCPUTest
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
+ *                   -XX:+WhiteBoxAPI
+ *                   TestUseCountLeadingZerosInstructionOnSupportedCPU
+ */
+
+import sun.hotspot.cpuinfo.CPUInfo;
+import com.oracle.java.testlibrary.*;
+
+public class TestUseCountLeadingZerosInstructionOnSupportedCPU
+     extends BMISupportedCPUTest {
+
+    public TestUseCountLeadingZerosInstructionOnSupportedCPU() {
+        super("UseCountLeadingZerosInstruction", LZCNT_WARNING, "lzcnt");
+    }
+
+    public static void main(String args[]) throws Throwable {
+        new TestUseCountLeadingZerosInstructionOnSupportedCPU().test();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnUnsupportedCPU.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8031321
+ * @summary Verify processing of UseCountLeadingZerosInstruction option
+ *          on CPU without LZCNT support.
+ * @library /testlibrary /testlibrary/whitebox
+ * @build TestUseCountLeadingZerosInstructionOnUnsupportedCPU
+ *        BMIUnsupportedCPUTest
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
+ *                   -XX:+WhiteBoxAPI
+ *                   TestUseCountLeadingZerosInstructionOnUnsupportedCPU
+ */
+
+import sun.hotspot.cpuinfo.CPUInfo;
+import com.oracle.java.testlibrary.*;
+
+public class TestUseCountLeadingZerosInstructionOnUnsupportedCPU
+     extends BMIUnsupportedCPUTest {
+
+    public TestUseCountLeadingZerosInstructionOnUnsupportedCPU() {
+        super("UseCountLeadingZerosInstruction", LZCNT_WARNING, "lzcnt");
+    }
+
+    public static void main(String args[]) throws Throwable {
+        new TestUseCountLeadingZerosInstructionOnUnsupportedCPU().test();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnSupportedCPU.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8031321
+ * @summary Verify processing of UseCountTrailingZerosInstruction option
+ *          on CPU with TZCNT (BMI1 feature) support.
+ * @library /testlibrary /testlibrary/whitebox
+ * @build TestUseCountTrailingZerosInstructionOnSupportedCPU
+ *        BMISupportedCPUTest
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
+ *                   -XX:+WhiteBoxAPI
+ *                   TestUseCountTrailingZerosInstructionOnSupportedCPU
+ */
+
+import sun.hotspot.cpuinfo.CPUInfo;
+import com.oracle.java.testlibrary.*;
+import com.oracle.java.testlibrary.cli.*;
+
+public class TestUseCountTrailingZerosInstructionOnSupportedCPU
+     extends BMISupportedCPUTest {
+
+    public TestUseCountTrailingZerosInstructionOnSupportedCPU() {
+        super("UseCountTrailingZerosInstruction", TZCNT_WARNING, "bmi1");
+    }
+
+    @Override
+    public void runTestCases() throws Throwable {
+
+        super.runTestCases();
+
+        // verify that option will be disabled if all BMI1 instuctions
+        // are explicitly disabled
+        CommandLineOptionTest.
+            verifyOptionValue("UseCountTrailingZerosInstruction", "false",
+                              "-XX:-UseBMI1Instructions");
+
+        // verify that option could be turned on even if other BMI1
+        // instructions were turned off
+        CommandLineOptionTest.
+            verifyOptionValue("UseCountTrailingZerosInstruction", "true",
+                              "-XX:-UseBMI1Instructions",
+                              "-XX:+UseCountTrailingZerosInstruction");
+    }
+
+    public static void main(String args[]) throws Throwable {
+        new TestUseCountTrailingZerosInstructionOnSupportedCPU().test();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnUnsupportedCPU.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8031321
+ * @summary Verify processing of UseCountTrailingZerosInstruction option
+ *          on CPU without TZCNT instuction (BMI1 feature) support.
+ * @library /testlibrary /testlibrary/whitebox
+ * @build TestUseCountTrailingZerosInstructionOnUnsupportedCPU
+ *        BMIUnsupportedCPUTest
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
+ *                   -XX:+WhiteBoxAPI
+ *                   TestUseCountTrailingZerosInstructionOnUnsupportedCPU
+ */
+
+import sun.hotspot.cpuinfo.CPUInfo;
+import com.oracle.java.testlibrary.*;
+import com.oracle.java.testlibrary.cli.*;
+
+public class TestUseCountTrailingZerosInstructionOnUnsupportedCPU
+     extends BMIUnsupportedCPUTest {
+
+    public TestUseCountTrailingZerosInstructionOnUnsupportedCPU() {
+        super("UseCountTrailingZerosInstruction", TZCNT_WARNING, "bmi1");
+    }
+
+    @Override
+    public void unsupportedX86CPUTestCases() throws Throwable {
+
+        super.unsupportedX86CPUTestCases();
+
+        // verify that option will not be turned on during
+        // UseBMI1Instuctions processing
+        CommandLineOptionTest.
+            verifyOptionValue("UseCountTrailingZerosInstruction", "false",
+                              "-XX:+UseBMI1Instructions");
+
+        CommandLineOptionTest.
+            verifyOptionValue("UseCountTrailingZerosInstruction", "false",
+                              "-XX:+UseCountTrailingZerosInstruction",
+                              "-XX:+UseBMI1Instructions");
+    }
+
+    public static void main(String args[]) throws Throwable {
+        new TestUseCountTrailingZerosInstructionOnUnsupportedCPU().test();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/ExitCode.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.java.testlibrary;
+
+/**
+ * Exit code values that could be returned by the JVM.
+ */
+public enum ExitCode {
+    OK(0),
+    FAIL(1),
+    CRASH(134);
+
+    public final int value;
+
+    ExitCode(int value) {
+        this.value = value;
+    }
+}
+
--- a/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java	Thu Mar 27 11:17:26 2014 +0400
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/Utils.java	Thu Mar 27 17:29:41 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -108,6 +108,40 @@
     }
 
     /**
+     * Returns the default JTReg arguments for a jvm running a test without
+     * options that matches regular expresions in {@code filters}.
+     * This is the combination of JTReg arguments test.vm.opts and test.java.opts.
+     * @param filters Regular expressions used to filter out options.
+     * @return An array of options, or an empty array if no opptions.
+     */
+    public static String[] getFilteredTestJavaOpts(String... filters) {
+        String options[] = getTestJavaOpts();
+
+        if (filters.length == 0) {
+            return options;
+        }
+
+        List<String> filteredOptions = new ArrayList<String>(options.length);
+        Pattern patterns[] = new Pattern[filters.length];
+        for (int i = 0; i < filters.length; i++) {
+            patterns[i] = Pattern.compile(filters[i]);
+        }
+
+        for (String option : options) {
+            boolean matched = false;
+            for (int i = 0; i < patterns.length && !matched; i++) {
+                Matcher matcher = patterns[i].matcher(option);
+                matched = matcher.find();
+            }
+            if (!matched) {
+                filteredOptions.add(option);
+            }
+        }
+
+        return filteredOptions.toArray(new String[filteredOptions.size()]);
+    }
+
+    /**
      * Combines given arguments with default JTReg arguments for a jvm running a test.
      * This is the combination of JTReg arguments test.vm.opts and test.java.opts
      * @return The combination of JTReg test java options and user args.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/cli/CPUSpecificCommandLineOptionTest.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.java.testlibrary.cli;
+
+import sun.hotspot.cpuinfo.CPUInfo;
+import com.oracle.java.testlibrary.*;
+
+/**
+ * Base class for command line options tests that
+ * requires specific CPU arch or specific CPU features.
+ */
+public abstract class CPUSpecificCommandLineOptionTest
+              extends CommandLineOptionTest {
+
+    private String cpuArchPattern;
+    private String supportedCPUFeatures[];
+    private String unsupportedCPUFeatures[];
+
+    /**
+     * Create new CPU specific test instance that does not
+     * require any CPU features.
+     *
+     * @param cpuArchPattern Regular expression that should
+     *                       match os.arch.
+     */
+    public CPUSpecificCommandLineOptionTest(String cpuArchPattern) {
+        this(cpuArchPattern, null, null);
+    }
+
+    /**
+     * Create new CPU specific test instance that does not
+     * require from CPU support of {@code supportedCPUFeatures} features
+     * and no support of {@code unsupportedCPUFeatures}.
+     *
+     * @param cpuArchPattern Regular expression that should
+     *                       match os.arch.
+     * @param supportedCPUFeatures Array with names of features that
+     *                             should be supported by CPU. If <b>null</b>,
+     *                             then no features have to be supported.
+     * @param unsupportedCPUFeatures Array with names of features that
+     *                               should not be supported by CPU.
+     *                               If <b>null</b>, then CPU may support any
+     *                               features.
+     */
+    public CPUSpecificCommandLineOptionTest(String cpuArchPattern,
+                                            String supportedCPUFeatures[],
+                                            String unsupportedCPUFeatures[]) {
+        this.cpuArchPattern = cpuArchPattern;
+        this.supportedCPUFeatures = supportedCPUFeatures;
+        this.unsupportedCPUFeatures = unsupportedCPUFeatures;
+    }
+
+    /**
+     * Check that CPU on test box has appropriate architecture, support all
+     * required features and does not support all features that should not be
+     * supported.
+     *
+     * @return <b>true</b> if CPU on test box fulfill all requirements.
+     */
+    @Override
+    public boolean checkPreconditions() {
+        if (!Platform.getOsArch().matches(cpuArchPattern)) {
+            System.out.println("CPU arch does not match " + cpuArchPattern);
+            return false;
+        }
+
+        if (supportedCPUFeatures != null) {
+            for (String feature : supportedCPUFeatures) {
+                if (!CPUInfo.hasFeature(feature)) {
+                    System.out.println("CPU does not support " + feature +
+                                       " feature");
+                    return false;
+                }
+            }
+        }
+
+        if (unsupportedCPUFeatures != null) {
+            for (String feature : unsupportedCPUFeatures) {
+                if (CPUInfo.hasFeature(feature)) {
+                    System.out.println("CPU support " + feature + " feature");
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/testlibrary/com/oracle/java/testlibrary/cli/CommandLineOptionTest.java	Thu Mar 27 17:29:41 2014 +0400
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.oracle.java.testlibrary.cli;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import com.oracle.java.testlibrary.*;
+
+/**
+ * Base class for command line option tests.
+ */
+public abstract class CommandLineOptionTest {
+
+    public static final String UNRECOGNIZED_OPTION_ERROR_FORMAT =
+        "Unrecognized VM option '[+-]?%s'";
+
+    public static final String printFlagsFinalFormat = "%s\\s*:?=\\s*%s";
+
+    /**
+     * Verify that JVM startup behaviour matches our expectations.
+     *
+     * @param option The option that should be passed to JVM
+     * @param excpectedMessages Array of patterns that should occur
+     *                          in JVM output. If <b>null</b> then
+     *                          JVM output could be empty.
+     * @param unexpectedMessages Array of patterns that should not
+     *                           occur in JVM output. If <b>null</b> then
+     *                          JVM output could be empty.
+     * @param exitCode expected exit code.
+     * @throws Throwable if verification fails or some other issues occur.
+     */
+    public static void verifyJVMStartup(String option,
+                                        String expectedMessages[],
+                                        String unexpectedMessages[],
+                                        ExitCode exitCode)
+                                 throws Throwable {
+
+        OutputAnalyzer outputAnalyzer =
+            ProcessTools.executeTestJvm(option, "-version");
+
+        outputAnalyzer.shouldHaveExitValue(exitCode.value);
+
+        if (expectedMessages != null) {
+            for (String expectedMessage : expectedMessages) {
+                outputAnalyzer.shouldMatch(expectedMessage);
+            }
+        }
+
+        if (unexpectedMessages != null) {
+            for (String unexpectedMessage : unexpectedMessages) {
+                outputAnalyzer.shouldNotMatch(unexpectedMessage);
+            }
+        }
+    }
+
+    /**
+     * Verify that value of specified JVM option is the same as
+     * expected value.
+     * This method filter out option with {@code optionName}
+     * name from test java options.
+     *
+     * @param optionName Name of tested option.
+     * @param expectedValue Expected value of tested option.
+     * @param additionalVMOpts Additonal options that should be
+     *                         passed to JVM.
+     * @throws Throwable if verification fails or some other issues occur.
+     */
+    public static void verifyOptionValue(String optionName,
+                                         String expectedValue,
+                                         String... additionalVMOpts)
+                                  throws Throwable {
+        verifyOptionValue(optionName, expectedValue, true, additionalVMOpts);
+    }
+
+    /**
+     * Verify that value of specified JVM option is the same as
+     * expected value.
+     * This method filter out option with {@code optionName}
+     * name from test java options.
+     *
+     * @param optionName Name of tested option.
+     * @param expectedValue Expected value of tested option.
+     * @param addTestVmOptions If <b>true</b>, then test VM options
+     *                         will be used.
+     * @param additionalVMOpts Additonal options that should be
+     *                         passed to JVM.
+     * @throws Throwable if verification fails or some other issues occur.
+     */
+    public static void verifyOptionValue(String optionName,
+                                         String expectedValue,
+                                         boolean addTestVmOptions,
+                                         String... additionalVMOpts)
+                                  throws Throwable {
+
+        List<String> vmOpts = new ArrayList<String>();
+
+        if (addTestVmOptions) {
+            Collections.addAll(vmOpts,
+                               Utils.getFilteredTestJavaOpts(optionName));
+        }
+        Collections.addAll(vmOpts, additionalVMOpts);
+        Collections.addAll(vmOpts, new String[] {
+                "-XX:+PrintFlagsFinal",
+                "-version"
+            });
+
+        ProcessBuilder processBuilder =
+            ProcessTools.
+            createJavaProcessBuilder(vmOpts.
+                                     toArray(new String[vmOpts.size()]));
+
+        OutputAnalyzer outputAnalyzer =
+            new OutputAnalyzer(processBuilder.start());
+
+        outputAnalyzer.shouldHaveExitValue(0);
+        outputAnalyzer.shouldMatch(String.
+                                   format(printFlagsFinalFormat,
+                                          optionName,
+                                          expectedValue));
+    }
+
+
+    /**
+     * Run command line option test.
+     *
+     * @throws Throwable if test failed.
+     */
+    public final void test() throws Throwable {
+        if (checkPreconditions()) {
+            runTestCases();
+        }
+    }
+
+    /**
+     * Check that all preconditions for test execution are met.
+     *
+     * @return <b>true</b> if test could be executed.
+     */
+    public boolean checkPreconditions() {
+        return true;
+    }
+
+    /**
+     * Run test cases.
+     *
+     * @throws Throwable if test failed.
+     */
+    public abstract void runTestCases() throws Throwable;
+}
+