8035857: Add tests to verify correctness of operations with BMI1 and LZCNT instructions

Reviewed-by: iveresov, kvn, iignatyev
This commit is contained in:
Filipp Zhinkin 2014-03-22 00:26:48 +04:00 committed by Igor Ignatyev
parent fc7f4197f1
commit 8167043964
18 changed files with 1686 additions and 0 deletions

View File

@ -500,6 +500,16 @@ WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
c = *p;
WB_END
WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o))
const char* cpu_features = VM_Version::cpu_features();
ThreadToNativeFromVM ttn(thread);
jstring features_string = env->NewStringUTF(cpu_features);
CHECK_JNI_EXCEPTION_(env, NULL);
return features_string;
WB_END
//Some convenience methods to deal with objects from java
int WhiteBox::offset_for_field(const char* field_name, oop object,
Symbol* signature_symbol) {
@ -611,6 +621,7 @@ static JNINativeMethod methods[] = {
{CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
{CC"fullGC", CC"()V", (void*)&WB_FullGC },
{CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
{CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
};
#undef CC

View File

@ -0,0 +1,442 @@
/*
* 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 java.util.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.charset.StandardCharsets;
import com.oracle.java.testlibrary.*;
/**
* Test runner that invokes all methods implemented by particular Expr
* with random arguments in two different JVM processes and compares output.
* JVMs being started in different modes - one in int and other in comp
* with C2 and disabled tiered compilation.
*/
public class BMITestRunner {
enum VMMode {
COMP, INT;
};
public static int DEFAULT_ITERATIONS_COUNT = 4000;
/**
* Execute all methods implemented by <b>expr</b> in int and comp modes
* and compare output.
* Test pass only of output obtained with different VM modes is equal.
* To control behaviour of test following options could be passed:
* <ul>
* <li>-iterations=&lt;N&gt; each operation implemented by
* <b>expr</b> will be executed <i>N</i> times. Default value
* is 4000.</li>
* <li>-seed=&lt;SEED&gt; arguments for <b>expr</b>'s methods
* obtained via RNG initiated with seed <i>SEED</i>. By default
* some random seed will be used.</li>
* </ul>
*
* @param expr operation that should be tested
* @param testOpts options to control test behaviour
* @param additionalVMOpts additional options for VM
*
* @throws Throwable if test failed.
*/
public static void runTests(Class<? extends Expr> expr,
String testOpts[],
String... additionalVMOpts)
throws Throwable {
int seed = new Random().nextInt();
int iterations = DEFAULT_ITERATIONS_COUNT;
for (String testOption : testOpts) {
if (testOption.startsWith("-iterations=")) {
iterations = Integer.valueOf(testOption.
replace("-iterations=", ""));
} else if (testOption.startsWith("-seed=")) {
seed = Integer.valueOf(testOption.replace("-seed=", ""));
}
}
System.out.println("Running test with seed: " + seed);
OutputAnalyzer intOutput = runTest(expr, VMMode.INT,
additionalVMOpts,
seed, iterations);
OutputAnalyzer compOutput = runTest(expr, VMMode.COMP,
additionalVMOpts,
seed, iterations);
dumpOutput(intOutput, "int");
dumpOutput(compOutput, "comp");
Asserts.assertStringsEqual(intOutput.getStdout(),
compOutput.getStdout(),
"Results obtained in -Xint and " +
"-Xcomp should be the same.");
}
/**
* Execute tests on methods implemented by <b>expr</b> in new VM
* started in <b>testVMMode</b> mode.
*
* @param expr operation that should be tested
* @param testVMMode VM mode for test
* @param additionalVMOpts additional options for VM
* @param seed for RNG used it tests
* @param iterations that will be used to invoke <b>expr</b>'s methods.
*
* @return OutputAnalyzer for executed test.
* @throws Throwable when something goes wrong.
*/
public static OutputAnalyzer runTest(Class<? extends Expr> expr,
VMMode testVMMode,
String additionalVMOpts[],
int seed, int iterations)
throws Throwable {
List<String> vmOpts = new LinkedList<String>();
Collections.addAll(vmOpts, additionalVMOpts);
//setup mode-specific options
switch (testVMMode) {
case INT:
Collections.addAll(vmOpts, new String[] { "-Xint" });
break;
case COMP:
Collections.addAll(vmOpts, new String[] {
"-Xcomp",
"-XX:-TieredCompilation",
String.format("-XX:CompileCommand=compileonly,%s::*",
expr.getName())
});
break;
}
Collections.addAll(vmOpts, new String[] {
"-XX:+DisplayVMOutputToStderr",
Executor.class.getName(),
expr.getName(),
new Integer(seed).toString(),
new Integer(iterations).toString()
});
OutputAnalyzer outputAnalyzer = ProcessTools.
executeTestJvm(vmOpts.toArray(new String[vmOpts.size()]));
outputAnalyzer.shouldHaveExitValue(0);
return outputAnalyzer;
}
/**
* Dump stdout and stderr of test process to <i>prefix</i>.test.out
* and <i>prefix</i>.test.err respectively.
*
* @param outputAnalyzer OutputAnalyzer whom output should be dumped
* @param prefix Prefix that will be used in file names.
* @throws IOException if unable to dump output to file.
*/
protected static void dumpOutput(OutputAnalyzer outputAnalyzer,
String prefix)
throws IOException {
Files.write(Paths.get(prefix + ".test.out"),
outputAnalyzer.getStdout().getBytes());
Files.write(Paths.get(prefix + ".test.err"),
outputAnalyzer.getStderr().getBytes());
}
/**
* Executor that invoke all methods implemented by particular
* Expr instance.
*/
public static class Executor {
/**
* Usage: BMITestRunner$Executor <ExprClassName> <seed> <iterations>
*/
public static void main(String args[]) throws Exception {
@SuppressWarnings("unchecked")
Class<? extends Expr> exprClass =
(Class<? extends Expr>)Class.forName(args[0]);
Expr expr = exprClass.getConstructor().newInstance();
Random rng = new Random(Integer.valueOf(args[1]));
int iterations = Integer.valueOf(args[2]);
runTests(expr, iterations, rng);
}
public static int[] getIntBitShifts() {
//SIZE+1 shift is for zero.
int data[] = new int[Integer.SIZE+1];
for (int s = 0; s < data.length; s++) {
data[s] = 1<<s;
}
return data;
}
public static long[] getLongBitShifts() {
//SIZE+1 shift is for zero.
long data[] = new long[Long.SIZE+1];
for (int s = 0; s < data.length; s++) {
data[s] = 1L<<s;
}
return data;
}
public static void log(String format, Object... args) {
System.out.println(String.format(format, args));
}
public static void runTests(Expr expr, int iterations, Random rng) {
runUnaryIntRegTest(expr, iterations, rng);
runUnaryIntMemTest(expr, iterations, rng);
runUnaryLongRegTest(expr, iterations, rng);
runUnaryLongMemTest(expr, iterations, rng);
runBinaryRegRegIntTest(expr, iterations, rng);
runBinaryRegMemIntTest(expr, iterations, rng);
runBinaryMemRegIntTest(expr, iterations, rng);
runBinaryMemMemIntTest(expr, iterations, rng);
runBinaryRegRegLongTest(expr, iterations, rng);
runBinaryRegMemLongTest(expr, iterations, rng);
runBinaryMemRegLongTest(expr, iterations, rng);
runBinaryMemMemLongTest(expr, iterations, rng);
}
public static void runUnaryIntRegTest(Expr expr, int iterations,
Random rng) {
if (!(expr.isUnaryArgumentSupported()
&& expr.isIntExprSupported())) {
return;
}
for (int value : getIntBitShifts()) {
log("UnaryIntReg(0X%x) -> 0X%x",
value, expr.intExpr(value));
}
for (int i = 0; i < iterations; i++) {
int value = rng.nextInt();
log("UnaryIntReg(0X%x) -> 0X%x",
value, expr.intExpr(value));
}
}
public static void runUnaryIntMemTest(Expr expr, int iterations,
Random rng) {
if (!(expr.isUnaryArgumentSupported()
&& expr.isIntExprSupported()
&& expr.isMemExprSupported())) {
return;
}
for (int value : getIntBitShifts()) {
log("UnaryIntMem(0X%x) -> 0X%x",
value, expr.intExpr(new Expr.MemI(value)));
}
for (int i = 0; i < iterations; i++) {
int value = rng.nextInt();
log("UnaryIntMem(0X%x) -> 0X%x",
value, expr.intExpr(new Expr.MemI(value)));
}
}
public static void runUnaryLongRegTest(Expr expr, int iterations,
Random rng) {
if (!(expr.isUnaryArgumentSupported()
&& expr.isLongExprSupported())) {
return;
}
for (long value : getLongBitShifts()) {
log("UnaryLongReg(0X%x) -> 0X%x",
value, expr.longExpr(value));
}
for (int i = 0; i < iterations; i++) {
long value = rng.nextLong();
log("UnaryLongReg(0X%x) -> 0X%x",
value, expr.longExpr(value));
}
}
public static void runUnaryLongMemTest(Expr expr, int iterations,
Random rng) {
if (!(expr.isUnaryArgumentSupported()
&& expr.isLongExprSupported()
&& expr.isMemExprSupported())) {
return;
}
for (long value : getLongBitShifts()) {
log("UnaryLongMem(0X%x) -> 0X%x",
value, expr.longExpr(new Expr.MemL(value)));
}
for (int i = 0; i < iterations; i++) {
long value = rng.nextLong();
log("UnaryLongMem(0X%x) -> 0X%x",
value, expr.longExpr(new Expr.MemL(value)));
}
}
public static void runBinaryRegRegIntTest(Expr expr, int iterations,
Random rng) {
if (!(expr.isIntExprSupported()
&& expr.isBinaryArgumentSupported())) {
return;
}
for (int i = 0; i < iterations; i++) {
int aValue = rng.nextInt();
int bValue = rng.nextInt();
log("BinaryIntRegReg(0X%x, 0X%x) -> 0X%x",
aValue, bValue, expr.intExpr(aValue, bValue));
}
}
public static void runBinaryRegMemIntTest(Expr expr, int iterations,
Random rng) {
if (!(expr.isIntExprSupported()
&& expr.isBinaryArgumentSupported()
&& expr.isMemExprSupported())) {
return;
}
for (int i = 0; i < iterations; i++) {
int aValue = rng.nextInt();
int bValue = rng.nextInt();
log("BinaryIntRegMem(0X%x, 0X%x) -> 0X%x", aValue, bValue,
expr.intExpr(aValue, new Expr.MemI(bValue)));
}
}
public static void runBinaryMemRegIntTest(Expr expr, int iterations,
Random rng) {
if (!(expr.isIntExprSupported()
&& expr.isBinaryArgumentSupported()
&& expr.isMemExprSupported())) {
return;
}
for (int i = 0; i < iterations; i++) {
int aValue = rng.nextInt();
int bValue = rng.nextInt();
log("BinaryIntMemReg(0X%x, 0X%x) -> 0X%x", aValue, bValue,
expr.intExpr(new Expr.MemI(aValue), bValue));
}
}
public static void runBinaryMemMemIntTest(Expr expr, int iterations,
Random rng) {
if (!(expr.isIntExprSupported()
&& expr.isBinaryArgumentSupported()
&& expr.isMemExprSupported())) {
return;
}
for (int i = 0; i < iterations; i++) {
int aValue = rng.nextInt();
int bValue = rng.nextInt();
log("BinaryIntMemMem(0X%x, 0X%x) -> 0X%x", aValue, bValue,
expr.intExpr(new Expr.MemI(aValue),
new Expr.MemI(bValue)));
}
}
public static void runBinaryRegRegLongTest(Expr expr,
int iterations,
Random rng) {
if (!(expr.isLongExprSupported()
&& expr.isBinaryArgumentSupported())) {
return;
}
for (int i = 0; i < iterations; i++) {
long aValue = rng.nextLong();
long bValue = rng.nextLong();
log("BinaryLongRegReg(0X%x, 0X%x) -> 0X%x", aValue, bValue,
expr.longExpr(aValue, bValue));
}
}
public static void runBinaryRegMemLongTest(Expr expr,
int iterations,
Random rng) {
if (!(expr.isLongExprSupported()
&& expr.isBinaryArgumentSupported()
&& expr.isMemExprSupported())) {
return;
}
for (int i = 0; i < iterations; i++) {
long aValue = rng.nextLong();
long bValue = rng.nextLong();
log("BinaryLongRegMem(0X%x, 0X%x) -> 0X%x", aValue, bValue,
expr.longExpr(aValue, new Expr.MemL(bValue)));
}
}
public static void runBinaryMemRegLongTest(Expr expr,
int iterations,
Random rng) {
if (!(expr.isLongExprSupported()
&& expr.isBinaryArgumentSupported()
&& expr.isMemExprSupported())) {
return;
}
for (int i = 0; i < iterations; i++) {
long aValue = rng.nextLong();
long bValue = rng.nextLong();
log("BinaryLongMemReg(0X%x, 0X%x) -> 0X%x", aValue, bValue,
expr.longExpr(new Expr.MemL(aValue), bValue));
}
}
public static void runBinaryMemMemLongTest(Expr expr,
int iterations,
Random rng) {
if (!(expr.isLongExprSupported()
&& expr.isBinaryArgumentSupported()
&& expr.isMemExprSupported())) {
return;
}
for (int i = 0; i < iterations; i++) {
long aValue = rng.nextLong();
long bValue = rng.nextLong();
log("BinaryLongMemMem(0X%x, 0X%x) -> 0X%x", aValue, bValue,
expr.longExpr(new Expr.MemL(aValue),
new Expr.MemL(bValue)));
}
}
}
}

View File

@ -0,0 +1,178 @@
/*
* 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.
*
*/
/**
* Expression that should be replaced by particular instrinsic
* or intruction during compilation.
*/
public abstract class Expr {
public static class MemI {
public MemI(int i) {
this.value = i;
}
public int value;
}
public static class MemL {
public MemL(long l) {
this.value = l;
}
public long value;
}
public boolean isUnaryArgumentSupported() {
return false;
}
public boolean isIntExprSupported() {
return false;
}
public boolean isBinaryArgumentSupported() {
return false;
}
public boolean isLongExprSupported() {
return false;
}
public boolean isMemExprSupported() {
return false;
}
public int intExpr(int reg) {
throw new UnsupportedOperationException();
}
public int intExpr(MemI mem) {
throw new UnsupportedOperationException();
}
public int intExpr(int a, int b) {
throw new UnsupportedOperationException();
}
public int intExpr(int a, MemI b) {
throw new UnsupportedOperationException();
}
public int intExpr(MemI a, int b) {
throw new UnsupportedOperationException();
}
public int intExpr(MemI a, MemI b) {
throw new UnsupportedOperationException();
}
public long longExpr(long reg) {
throw new UnsupportedOperationException();
}
public long longExpr(MemL mem) {
throw new UnsupportedOperationException();
}
public long longExpr(long a, long b) {
throw new UnsupportedOperationException();
}
public long longExpr(long a, MemL b) {
throw new UnsupportedOperationException();
}
public long longExpr(MemL a, long b) {
throw new UnsupportedOperationException();
}
public long longExpr(MemL a, MemL b) {
throw new UnsupportedOperationException();
}
public static class BMIExpr extends Expr {
public boolean isMemExprSupported() {
return true;
}
}
public static class BMIBinaryExpr extends BMIExpr {
public boolean isBinaryArgumentSupported() {
return true;
}
}
public static class BMIUnaryExpr extends BMIExpr {
public boolean isUnaryArgumentSupported() {
return true;
}
}
public static class BMIBinaryIntExpr extends BMIBinaryExpr {
public boolean isIntExprSupported() {
return true;
}
}
public static class BMIBinaryLongExpr extends BMIBinaryExpr {
public boolean isLongExprSupported() {
return true;
}
}
public static class BMIUnaryIntExpr extends BMIUnaryExpr {
public boolean isIntExprSupported() {
return true;
}
}
public static class BMIUnaryLongExpr extends BMIUnaryExpr {
public boolean isLongExprSupported() {
return true;
}
}
public static class BitCountingExpr extends Expr {
public boolean isUnaryArgumentSupported() {
return true;
}
}
public static class BitCountingIntExpr extends BitCountingExpr {
public boolean isIntExprSupported() {
return true;
}
}
public static class BitCountingLongExpr extends BitCountingExpr {
public boolean isLongExprSupported() {
return true;
}
}
}

View File

@ -0,0 +1,91 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of ANDN instruction
* @library /testlibrary /testlibrary/whitebox
* @build TestAndnI BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestAndnI
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestAndnI {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. "+
"Test skipped.");
return;
}
BMITestRunner.runTests(AndnIExpr.class, args,
"-XX:+UseBMI1Instructions");
BMITestRunner.runTests(AndnICommutativeExpr.class, args,
"-XX:+UseBMI1Instructions");
}
public static class AndnIExpr extends Expr.BMIBinaryIntExpr {
public int intExpr(int src1, int src2) {
return ~src1 & src2;
}
public int intExpr(int src1, Expr.MemI src2) {
return ~src1 & src2.value;
}
public int intExpr(Expr.MemI src1, int src2) {
return ~src1.value & src2;
}
public int intExpr(Expr.MemI src1, Expr.MemI src2) {
return ~src1.value & src2.value;
}
}
public static class AndnICommutativeExpr extends Expr.BMIBinaryIntExpr {
public int intExpr(int src1, int src2) {
return src1 & ~src2;
}
public int intExpr(int src1, Expr.MemI src2) {
return src1 & ~src2.value;
}
public int intExpr(Expr.MemI src1, int src2) {
return src1.value & ~src2;
}
public int intExpr(Expr.MemI src1, Expr.MemI src2) {
return src1.value & ~src2.value;
}
}
}

View File

@ -0,0 +1,95 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of ANDN instruction
* @library /testlibrary /testlibrary/whitebox
* @build TestAndnL BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestAndnL
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestAndnL {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(AndnLExpr.class, args,
"-XX:+UseBMI1Instructions");
BMITestRunner.runTests(AndnLCommutativeExpr.class, args,
"-XX:+UseBMI1Instructions");
}
public static class AndnLExpr extends Expr.BMIBinaryLongExpr {
public long longExpr(long src1, long src2) {
return ~src1 & src2;
}
public long longExpr(long src1, Expr.MemL src2) {
return ~src1 & src2.value;
}
public long longExpr(Expr.MemL src1, long src2) {
return ~src1.value & src2;
}
public long longExpr(Expr.MemL src1, Expr.MemL src2) {
return ~src1.value & src2.value;
}
}
public static class AndnLCommutativeExpr extends Expr.BMIBinaryLongExpr {
public long longExpr(long src1, long src2) {
return src1 & ~src2;
}
public long longExpr(long src1, Expr.MemL src2) {
return src1 & ~src2.value;
}
public long longExpr(Expr.MemL src1, long src2) {
return src1.value & ~src2;
}
public long longExpr(Expr.MemL src1, Expr.MemL src2) {
return src1.value & ~src2.value;
}
}
}

View File

@ -0,0 +1,78 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of BLSI instruction
* @library /testlibrary /testlibrary/whitebox
* @build TestBlsiI BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestBlsiI
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestBlsiI {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(BlsiIExpr.class, args,
"-XX:+UseBMI1Instructions");
BMITestRunner.runTests(BlsiICommutativeExpr.class, args,
"-XX:+UseBMI1Instructions");
}
public static class BlsiIExpr extends Expr.BMIUnaryIntExpr {
public int intExpr(int src) {
return -src & src;
}
public int intExpr(Expr.MemI src) {
return -src.value & src.value;
}
}
public static class BlsiICommutativeExpr extends Expr.BMIUnaryIntExpr {
public int intExpr(int src) {
return src & -src;
}
public int intExpr(Expr.MemI src) {
return src.value & -src.value;
}
}
}

View File

@ -0,0 +1,78 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of BLSI instruction
* @library /testlibrary /testlibrary/whitebox
* @build TestBlsiL BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestBlsiL
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestBlsiL {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(BlsiLExpr.class, args,
"-XX:+UseBMI1Instructions");
BMITestRunner.runTests(BlsiLCommutativeExpr.class, args,
"-XX:+UseBMI1Instructions");
}
public static class BlsiLExpr extends Expr.BMIUnaryLongExpr {
public long longExpr(long src) {
return -src & src;
}
public long longExpr(Expr.MemL src) {
return -src.value & src.value;
}
}
public static class BlsiLCommutativeExpr extends Expr.BMIUnaryLongExpr {
public long longExpr(long src) {
return src & -src;
}
public long longExpr(Expr.MemL src) {
return src.value & -src.value;
}
}
}

View File

@ -0,0 +1,78 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of BLSMSK instruction
* @library /testlibrary /testlibrary/whitebox
* @build TestBlsmskI BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestBlsmskI
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestBlsmskI {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(BlsmskIExpr.class, args,
"-XX:+UseBMI1Instructions");
BMITestRunner.runTests(BlsmskICommutativeExpr.class, args,
"-XX:+UseBMI1Instructions");
}
public static class BlsmskIExpr extends Expr.BMIUnaryIntExpr {
public int intExpr(int src) {
return (src - 1) ^ src;
}
public int intExpr(Expr.MemI src) {
return (src.value - 1) ^ src.value;
}
}
public static class BlsmskICommutativeExpr extends Expr.BMIUnaryIntExpr {
public int intExpr(int src) {
return src ^ (src - 1);
}
public int intExpr(Expr.MemI src) {
return src.value ^ (src.value - 1);
}
}
}

View File

@ -0,0 +1,80 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of BLSMSK instruction
* @library /testlibrary /testlibrary/whitebox
* @build TestBlsmskL BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestBlsmskL
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestBlsmskL {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(BlsmskLExpr.class, args,
"-XX:+UseBMI1Instructions");
BMITestRunner.runTests(BlsmskLCommutativeExpr.class, args,
"-XX:+UseBMI1Instructions");
}
public static class BlsmskLExpr
extends Expr.BMIUnaryLongExpr {
public long longExpr(long src) {
return (src - 1) ^ src;
}
public long longExpr(Expr.MemL src) {
return (src.value - 1) ^ src.value;
}
}
public static class BlsmskLCommutativeExpr
extends Expr.BMIUnaryLongExpr {
public long longExpr(long src) {
return src ^ (src - 1);
}
public long longExpr(Expr.MemL src) {
return src.value ^ (src.value - 1);
}
}
}

View File

@ -0,0 +1,78 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of BLSR instruction
* @library /testlibrary /testlibrary/whitebox
* @build TestBlsrI BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestBlsrI
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestBlsrI {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(BlsrIExpr.class, args,
"-XX:+UseBMI1Instructions");
BMITestRunner.runTests(BlsrICommutativeExpr.class, args,
"-XX:+UseBMI1Instructions");
}
public static class BlsrIExpr extends Expr.BMIUnaryIntExpr {
public int intExpr(int src) {
return (src - 1) & src;
}
public int intExpr(Expr.MemI src) {
return (src.value - 1) & src.value;
}
}
public static class BlsrICommutativeExpr extends Expr.BMIUnaryIntExpr {
public int intExpr(int src) {
return src & (src - 1);
}
public int intExpr(Expr.MemI src) {
return src.value & (src.value - 1);
}
}
}

View File

@ -0,0 +1,78 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of BLSR instruction
* @library /testlibrary /testlibrary/whitebox
* @build TestBlsrL BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestBlsrL
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestBlsrL {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(BlsrLExpr.class, args,
"-XX:+UseBMI1Instructions");
BMITestRunner.runTests(BlsrLCommutativeExpr.class, args,
"-XX:+UseBMI1Instructions");
}
public static class BlsrLExpr extends Expr.BMIUnaryLongExpr {
public long longExpr(long src) {
return (src - 1) & src;
}
public long longExpr(Expr.MemL src) {
return (src.value - 1) & src.value;
}
}
public static class BlsrLCommutativeExpr extends Expr.BMIUnaryLongExpr {
public long longExpr(long src) {
return src & (src - 1);
}
public long longExpr(Expr.MemL src) {
return src.value & (src.value - 1);
}
}
}

View File

@ -0,0 +1,60 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of intrinsic
* @library /testlibrary /testlibrary/whitebox
* @build TestLzcntI BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestLzcntI
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestLzcntI {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("lzcnt")) {
System.out.println("CPU does not support lzcnt feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(LzcntIExpr.class, args,
"-XX:+UseCountLeadingZerosInstruction");
}
public static class LzcntIExpr extends Expr.BitCountingIntExpr {
public int intExpr(int src) {
return Integer.numberOfLeadingZeros(src);
}
}
}

View File

@ -0,0 +1,60 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of intrinsic
* @library /testlibrary /testlibrary/whitebox
* @build TestLzcntL BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestLzcntL
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestLzcntL {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("lzcnt")) {
System.out.println("CPU does not support lzcnt feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(LzcntLExpr.class, args,
"-XX:+UseCountLeadingZerosInstruction");
}
public static class LzcntLExpr extends Expr.BitCountingLongExpr {
public long longExpr(long src) {
return Long.numberOfLeadingZeros(src);
}
}
}

View File

@ -0,0 +1,60 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of intrinsic
* @library /testlibrary /testlibrary/whitebox
* @build TestTzcntI BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestTzcntI
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestTzcntI {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(TzcntIExpr.class, args,
"-XX:+UseCountTrailingZerosInstruction");
}
public static class TzcntIExpr extends Expr.BitCountingIntExpr {
public int intExpr(int src) {
return Integer.numberOfTrailingZeros(src);
}
}
}

View File

@ -0,0 +1,60 @@
/*
* 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 that results of computations are the same w/
* and w/o usage of intrinsic
* @library /testlibrary /testlibrary/whitebox
* @build TestTzcntL BMITestRunner Expr
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI TestTzcntL
*/
import sun.hotspot.cpuinfo.CPUInfo;
public class TestTzcntL {
public static void main(String args[]) throws Throwable {
if (!CPUInfo.hasFeature("bmi1")) {
System.out.println("CPU does not support bmi1 feature. " +
"Test skipped.");
return;
}
BMITestRunner.runTests(TzcntLExpr.class, args,
"-XX:+UseCountTrailingZerosInstruction");
}
public static class TzcntLExpr extends Expr.BitCountingLongExpr {
public long longExpr(long src) {
return Long.numberOfTrailingZeros(src);
}
}
}

View File

@ -378,6 +378,64 @@ public class Asserts {
}
}
/**
* Asserts that two strings are equal.
*
* If strings are not equals, then exception message
* will contain {@code msg} followed by list of mismatched lines.
*
* @param str1 First string to compare.
* @param str2 Second string to compare.
* @param msg A description of the assumption.
* @throws RuntimeException if strings are not equal.
*/
public static void assertStringsEqual(String str1, String str2,
String msg) {
String lineSeparator = System.getProperty("line.separator");
String str1Lines[] = str1.split(lineSeparator);
String str2Lines[] = str2.split(lineSeparator);
int minLength = Math.min(str1Lines.length, str2Lines.length);
String longestStringLines[] = ((str1Lines.length == minLength) ?
str2Lines : str1Lines);
boolean stringsAreDifferent = false;
StringBuilder messageBuilder = new StringBuilder(msg);
messageBuilder.append("\n");
for (int line = 0; line < minLength; line++) {
if (!str1Lines[line].equals(str2Lines[line])) {
messageBuilder.append(String.
format("[line %d] '%s' differs " +
"from '%s'\n",
line,
str1Lines[line],
str2Lines[line]));
stringsAreDifferent = true;
}
}
if (minLength < longestStringLines.length) {
String stringName = ((longestStringLines == str1Lines) ?
"first" : "second");
messageBuilder.append(String.format("Only %s string contains " +
"following lines:\n",
stringName));
stringsAreDifferent = true;
for(int line = minLength; line < longestStringLines.length; line++) {
messageBuilder.append(String.
format("[line %d] '%s'", line,
longestStringLines[line]));
}
}
if (stringsAreDifferent) {
error(messageBuilder.toString());
}
}
private static <T extends Comparable<T>> int compare(T lhs, T rhs, String msg) {
assertNotNull(lhs, msg);
assertNotNull(rhs, msg);

View File

@ -150,4 +150,7 @@ public class WhiteBox {
public native void runMemoryUnitTests();
public native void readFromNoaccessArea();
// CPU features
public native String getCPUFeatures();
}

View File

@ -0,0 +1,98 @@
/*
* 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 sun.hotspot.cpuinfo;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import sun.hotspot.WhiteBox;
/**
* Information about CPU on test box.
*
* CPUInfo uses WhiteBox to gather information,
* so WhiteBox class should be added to bootclasspath
* and option -XX:+WhiteBoxAPI should expclicetly
* specified on command line.
*/
public class CPUInfo {
private static final List<String> features;
private static final String additionalCPUInfo;
static {
WhiteBox wb = WhiteBox.getWhiteBox();
Pattern additionalCPUInfoRE =
Pattern.compile("([^(]*\\([^)]*\\)[^,]*),\\s*");
String cpuFeaturesString = wb.getCPUFeatures();
Matcher matcher = additionalCPUInfoRE.matcher(cpuFeaturesString);
if (matcher.find()) {
additionalCPUInfo = matcher.group(1);
} else {
additionalCPUInfo = "";
}
String splittedFeatures[] = matcher.replaceAll("").split("(, )| ");
features = Collections.unmodifiableList(Arrays.
asList(splittedFeatures));
}
/**
* Get additional information about CPU.
* For example, on X86 in will be family/model/stepping
* and number of cores.
*
* @return additional CPU info
*/
public static String getAdditionalCPUInfo() {
return additionalCPUInfo;
}
/**
* Get all known features supported by CPU.
*
* @return unmodifiable list with names of all known features
* supported by CPU.
*/
public static List<String> getFeatures() {
return features;
}
/**
* Check if some feature is supported by CPU.
*
* @param feature Name of feature to be tested.
* @return <b>true</b> if tested feature is supported by CPU.
*/
public static boolean hasFeature(String feature) {
return features.contains(feature.toLowerCase());
}
}