aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoriignatyev <none@none>2014-03-27 17:29:41 +0400
committeriignatyev <none@none>2014-03-27 17:29:41 +0400
commit4a5721bbf8bdd86c3b8faf84cd17a7deef8675d3 (patch)
treea558e9532b34330e91024a2666f8432389b45f98 /test
parent383b0522bf3e9b2c4935d761c39e88353ce4b6eb (diff)
8038193: Add command line option tests for BMI options
Reviewed-by: iveresov, kvn, iignatyev Contributed-by: filipp.zhinkin@oracle.com
Diffstat (limited to 'test')
-rw-r--r--test/compiler/arguments/BMICommandLineOptionTestBase.java68
-rw-r--r--test/compiler/arguments/BMISupportedCPUTest.java72
-rw-r--r--test/compiler/arguments/BMIUnsupportedCPUTest.java114
-rw-r--r--test/compiler/arguments/TestUseBMI1InstructionsOnSupportedCPU.java51
-rw-r--r--test/compiler/arguments/TestUseBMI1InstructionsOnUnsupportedCPU.java52
-rw-r--r--test/compiler/arguments/TestUseCountLeadingZerosInstructionOnSupportedCPU.java52
-rw-r--r--test/compiler/arguments/TestUseCountLeadingZerosInstructionOnUnsupportedCPU.java52
-rw-r--r--test/compiler/arguments/TestUseCountTrailingZerosInstructionOnSupportedCPU.java72
-rw-r--r--test/compiler/arguments/TestUseCountTrailingZerosInstructionOnUnsupportedCPU.java70
-rw-r--r--test/testlibrary/com/oracle/java/testlibrary/ExitCode.java40
-rw-r--r--test/testlibrary/com/oracle/java/testlibrary/Utils.java36
-rw-r--r--test/testlibrary/com/oracle/java/testlibrary/cli/CPUSpecificCommandLineOptionTest.java110
-rw-r--r--test/testlibrary/com/oracle/java/testlibrary/cli/CommandLineOptionTest.java173
13 files changed, 961 insertions, 1 deletions
diff --git a/test/compiler/arguments/BMICommandLineOptionTestBase.java b/test/compiler/arguments/BMICommandLineOptionTestBase.java
new file mode 100644
index 000000000..6d4fa400d
--- /dev/null
+++ b/test/compiler/arguments/BMICommandLineOptionTestBase.java
@@ -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);
+ }
+
+}
+
diff --git a/test/compiler/arguments/BMISupportedCPUTest.java b/test/compiler/arguments/BMISupportedCPUTest.java
new file mode 100644
index 000000000..c0af31fd7
--- /dev/null
+++ b/test/compiler/arguments/BMISupportedCPUTest.java
@@ -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);
+ }
+}
+
diff --git a/test/compiler/arguments/BMIUnsupportedCPUTest.java b/test/compiler/arguments/BMIUnsupportedCPUTest.java
new file mode 100644
index 000000000..7a78c74e5
--- /dev/null
+++ b/test/compiler/arguments/BMIUnsupportedCPUTest.java
@@ -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);
+ }
+}
+
diff --git a/test/compiler/arguments/TestUseBMI1InstructionsOnSupportedCPU.java b/test/compiler/arguments/TestUseBMI1InstructionsOnSupportedCPU.java
new file mode 100644
index 000000000..559c3a6a6
--- /dev/null
+++ b/test/compiler/arguments/TestUseBMI1InstructionsOnSupportedCPU.java
@@ -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();
+ }
+}
+
diff --git a/test/compiler/arguments/TestUseBMI1InstructionsOnUnsupportedCPU.java b/test/compiler/arguments/TestUseBMI1InstructionsOnUnsupportedCPU.java
new file mode 100644
index 000000000..3df8d659c
--- /dev/null
+++ b/test/compiler/arguments/TestUseBMI1InstructionsOnUnsupportedCPU.java
@@ -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();
+ }
+}
+
diff --git a/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnSupportedCPU.java b/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnSupportedCPU.java
new file mode 100644
index 000000000..c84377483
--- /dev/null
+++ b/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnSupportedCPU.java
@@ -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();
+ }
+}
+
diff --git a/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnUnsupportedCPU.java b/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnUnsupportedCPU.java
new file mode 100644
index 000000000..e2ffba28a
--- /dev/null
+++ b/test/compiler/arguments/TestUseCountLeadingZerosInstructionOnUnsupportedCPU.java
@@ -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();
+ }
+}
+
diff --git a/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnSupportedCPU.java b/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnSupportedCPU.java
new file mode 100644
index 000000000..995d450e3
--- /dev/null
+++ b/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnSupportedCPU.java
@@ -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();
+ }
+}
+
diff --git a/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnUnsupportedCPU.java b/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnUnsupportedCPU.java
new file mode 100644
index 000000000..86853aab0
--- /dev/null
+++ b/test/compiler/arguments/TestUseCountTrailingZerosInstructionOnUnsupportedCPU.java
@@ -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();
+ }
+}
+
diff --git a/test/testlibrary/com/oracle/java/testlibrary/ExitCode.java b/test/testlibrary/com/oracle/java/testlibrary/ExitCode.java
new file mode 100644
index 000000000..2db3be2d2
--- /dev/null
+++ b/test/testlibrary/com/oracle/java/testlibrary/ExitCode.java
@@ -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;
+ }
+}
+
diff --git a/test/testlibrary/com/oracle/java/testlibrary/Utils.java b/test/testlibrary/com/oracle/java/testlibrary/Utils.java
index a0031e706..03fd773e0 100644
--- a/test/testlibrary/com/oracle/java/testlibrary/Utils.java
+++ b/test/testlibrary/com/oracle/java/testlibrary/Utils.java
@@ -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 @@ public final class Utils {
}
/**
+ * 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.
diff --git a/test/testlibrary/com/oracle/java/testlibrary/cli/CPUSpecificCommandLineOptionTest.java b/test/testlibrary/com/oracle/java/testlibrary/cli/CPUSpecificCommandLineOptionTest.java
new file mode 100644
index 000000000..a300e038d
--- /dev/null
+++ b/test/testlibrary/com/oracle/java/testlibrary/cli/CPUSpecificCommandLineOptionTest.java
@@ -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;
+ }
+}
+
diff --git a/test/testlibrary/com/oracle/java/testlibrary/cli/CommandLineOptionTest.java b/test/testlibrary/com/oracle/java/testlibrary/cli/CommandLineOptionTest.java
new file mode 100644
index 000000000..d4d4e7c74
--- /dev/null
+++ b/test/testlibrary/com/oracle/java/testlibrary/cli/CommandLineOptionTest.java
@@ -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;
+}
+