8130120: Handling of SHA intrinsics inconsistent across platforms
Introduce common warning message and common processing of SHA intrinsic-related arguments. Reviewed-by: kvn, mcberg
This commit is contained in:
parent
9245cdc214
commit
547a40e75a
@ -214,34 +214,31 @@ void VM_Version::get_processor_features() {
|
||||
FLAG_SET_DEFAULT(UseSHA, false);
|
||||
}
|
||||
|
||||
if (!UseSHA) {
|
||||
if (UseSHA && (auxv & HWCAP_SHA1)) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA1Intrinsics) {
|
||||
warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
|
||||
}
|
||||
|
||||
if (UseSHA && (auxv & HWCAP_SHA2)) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA256Intrinsics) {
|
||||
warning("Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
|
||||
}
|
||||
|
||||
if (UseSHA512Intrinsics) {
|
||||
warning("Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
|
||||
} else {
|
||||
if (auxv & HWCAP_SHA1) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA1Intrinsics) {
|
||||
warning("SHA1 instruction is not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
|
||||
}
|
||||
if (auxv & HWCAP_SHA2) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA256Intrinsics) {
|
||||
warning("SHA256 instruction (for SHA-224 and SHA-256) is not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
|
||||
}
|
||||
if (UseSHA512Intrinsics) {
|
||||
warning("SHA512 instruction (for SHA-384 and SHA-512) is not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
|
||||
}
|
||||
if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA, false);
|
||||
}
|
||||
|
||||
// This machine allows unaligned memory accesses
|
||||
|
@ -329,39 +329,35 @@ void VM_Version::initialize() {
|
||||
FLAG_SET_DEFAULT(UseSHA, false);
|
||||
}
|
||||
|
||||
if (!UseSHA) {
|
||||
if (UseSHA && has_sha1()) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA1Intrinsics) {
|
||||
warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
|
||||
FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
|
||||
} else {
|
||||
if (has_sha1()) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA1Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA1Intrinsics) {
|
||||
warning("SHA1 instruction is not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
|
||||
}
|
||||
if (has_sha256()) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA256Intrinsics) {
|
||||
warning("SHA256 instruction (for SHA-224 and SHA-256) is not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_sha512()) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA512Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA512Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA512Intrinsics) {
|
||||
warning("SHA512 instruction (for SHA-384 and SHA-512) is not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
|
||||
if (UseSHA && has_sha256()) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA256Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, true);
|
||||
}
|
||||
if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA, false);
|
||||
} else if (UseSHA256Intrinsics) {
|
||||
warning("Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
|
||||
}
|
||||
|
||||
if (UseSHA && has_sha512()) {
|
||||
if (FLAG_IS_DEFAULT(UseSHA512Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA512Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA512Intrinsics) {
|
||||
warning("Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
|
||||
}
|
||||
|
||||
if (!(UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA, false);
|
||||
}
|
||||
|
||||
// SPARC T4 and above should have support for CRC32C instruction
|
||||
|
@ -692,10 +692,19 @@ void VM_Version::get_processor_features() {
|
||||
warning("SHA instructions are not available on this CPU");
|
||||
FLAG_SET_DEFAULT(UseSHA, false);
|
||||
}
|
||||
if (UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics) {
|
||||
warning("SHA intrinsics are not available on this CPU");
|
||||
|
||||
if (UseSHA1Intrinsics) {
|
||||
warning("Intrinsics for SHA-1 crypto hash functions not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
|
||||
}
|
||||
|
||||
if (UseSHA256Intrinsics) {
|
||||
warning("Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
|
||||
}
|
||||
|
||||
if (UseSHA512Intrinsics) {
|
||||
warning("Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU.");
|
||||
FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
|
||||
}
|
||||
|
||||
|
@ -728,7 +728,8 @@ public:
|
||||
"Control whether AES instructions can be used on x86/x64") \
|
||||
\
|
||||
product(bool, UseSHA, false, \
|
||||
"Control whether SHA instructions can be used on SPARC") \
|
||||
"Control whether SHA instructions can be used " \
|
||||
"on SPARC and on ARM") \
|
||||
\
|
||||
product(bool, UseGHASHIntrinsics, false, \
|
||||
"Use intrinsics for GHASH versions of crypto") \
|
||||
@ -837,13 +838,16 @@ public:
|
||||
"Use intrinsics for AES versions of crypto") \
|
||||
\
|
||||
product(bool, UseSHA1Intrinsics, false, \
|
||||
"Use intrinsics for SHA-1 crypto hash function") \
|
||||
"Use intrinsics for SHA-1 crypto hash function. " \
|
||||
"Requires that UseSHA is enabled.") \
|
||||
\
|
||||
product(bool, UseSHA256Intrinsics, false, \
|
||||
"Use intrinsics for SHA-224 and SHA-256 crypto hash functions") \
|
||||
"Use intrinsics for SHA-224 and SHA-256 crypto hash functions. " \
|
||||
"Requires that UseSHA is enabled.") \
|
||||
\
|
||||
product(bool, UseSHA512Intrinsics, false, \
|
||||
"Use intrinsics for SHA-384 and SHA-512 crypto hash functions") \
|
||||
"Use intrinsics for SHA-384 and SHA-512 crypto hash functions. " \
|
||||
"Requires that UseSHA is enabled.") \
|
||||
\
|
||||
product(bool, UseCRC32Intrinsics, false, \
|
||||
"use intrinsics for java.util.zip.CRC32") \
|
||||
|
@ -47,16 +47,12 @@ public class SHAOptionsBase extends CommandLineOptionTest {
|
||||
// expressions, not just a plain strings.
|
||||
protected static final String SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE
|
||||
= "SHA instructions are not available on this CPU";
|
||||
protected static final String SHA1_INSTRUCTION_IS_NOT_AVAILABLE
|
||||
= "SHA1 instruction is not available on this CPU\\.";
|
||||
protected static final String SHA256_INSTRUCTION_IS_NOT_AVAILABLE
|
||||
= "SHA256 instruction \\(for SHA-224 and SHA-256\\) "
|
||||
+ "is not available on this CPU\\.";
|
||||
protected static final String SHA512_INSTRUCTION_IS_NOT_AVAILABLE
|
||||
= "SHA512 instruction \\(for SHA-384 and SHA-512\\) "
|
||||
+ "is not available on this CPU\\.";
|
||||
protected static final String SHA_INTRINSICS_ARE_NOT_AVAILABLE
|
||||
= "SHA intrinsics are not available on this CPU";
|
||||
protected static final String SHA1_INTRINSICS_ARE_NOT_AVAILABLE
|
||||
= "Intrinsics for SHA-1 crypto hash functions not available on this CPU.";
|
||||
protected static final String SHA256_INTRINSICS_ARE_NOT_AVAILABLE
|
||||
= "Intrinsics for SHA-224 and SHA-256 crypto hash functions not available on this CPU.";
|
||||
protected static final String SHA512_INTRINSICS_ARE_NOT_AVAILABLE
|
||||
= "Intrinsics for SHA-384 and SHA-512 crypto hash functions not available on this CPU.";
|
||||
|
||||
private final TestCase[] testCases;
|
||||
|
||||
@ -71,33 +67,23 @@ public class SHAOptionsBase extends CommandLineOptionTest {
|
||||
* instructions required by the option are not supported.
|
||||
*/
|
||||
protected static String getWarningForUnsupportedCPU(String optionName) {
|
||||
if (Platform.isSparc() || Platform.isAArch64()) {
|
||||
if (Platform.isSparc() || Platform.isAArch64() ||
|
||||
Platform.isX64() || Platform.isX86()) {
|
||||
switch (optionName) {
|
||||
case SHAOptionsBase.USE_SHA_OPTION:
|
||||
return SHAOptionsBase.SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE;
|
||||
case SHAOptionsBase.USE_SHA1_INTRINSICS_OPTION:
|
||||
return SHAOptionsBase.SHA1_INSTRUCTION_IS_NOT_AVAILABLE;
|
||||
case SHAOptionsBase.USE_SHA256_INTRINSICS_OPTION:
|
||||
return SHAOptionsBase.SHA256_INSTRUCTION_IS_NOT_AVAILABLE;
|
||||
case SHAOptionsBase.USE_SHA512_INTRINSICS_OPTION:
|
||||
return SHAOptionsBase.SHA512_INSTRUCTION_IS_NOT_AVAILABLE;
|
||||
default:
|
||||
throw new Error("Unexpected option " + optionName);
|
||||
}
|
||||
} else if (Platform.isX64() || Platform.isX86()) {
|
||||
switch (optionName) {
|
||||
case SHAOptionsBase.USE_SHA_OPTION:
|
||||
return SHAOptionsBase.SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE;
|
||||
case SHAOptionsBase.USE_SHA1_INTRINSICS_OPTION:
|
||||
case SHAOptionsBase.USE_SHA256_INTRINSICS_OPTION:
|
||||
case SHAOptionsBase.USE_SHA512_INTRINSICS_OPTION:
|
||||
return SHAOptionsBase.SHA_INTRINSICS_ARE_NOT_AVAILABLE;
|
||||
default:
|
||||
throw new Error("Unexpected option " + optionName);
|
||||
case SHAOptionsBase.USE_SHA_OPTION:
|
||||
return SHAOptionsBase.SHA_INSTRUCTIONS_ARE_NOT_AVAILABLE;
|
||||
case SHAOptionsBase.USE_SHA1_INTRINSICS_OPTION:
|
||||
return SHAOptionsBase.SHA1_INTRINSICS_ARE_NOT_AVAILABLE;
|
||||
case SHAOptionsBase.USE_SHA256_INTRINSICS_OPTION:
|
||||
return SHAOptionsBase.SHA256_INTRINSICS_ARE_NOT_AVAILABLE;
|
||||
case SHAOptionsBase.USE_SHA512_INTRINSICS_OPTION:
|
||||
return SHAOptionsBase.SHA512_INTRINSICS_ARE_NOT_AVAILABLE;
|
||||
default:
|
||||
throw new Error("Unexpected option " + optionName);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Support for CPUs other then X86 or SPARC is not "
|
||||
+ "implemented.");
|
||||
throw new Error("Support for CPUs different fromn X86, SPARC, and AARCH64 "
|
||||
+ "is not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,18 +64,20 @@ public class GenericTestCaseForSupportedCPU extends
|
||||
SHAOptionsBase.USE_SHA_OPTION, true),
|
||||
CommandLineOptionTest.prepareBooleanFlag(optionName, false));
|
||||
|
||||
// Verify that it is possible to enable the tested option and disable
|
||||
// all SHA intrinsics via -UseSHA without any warnings.
|
||||
CommandLineOptionTest.verifySameJVMStartup(null, new String[] {
|
||||
SHAOptionsBase.getWarningForUnsupportedCPU(optionName)
|
||||
}, shouldPassMessage, String.format("It should be able to "
|
||||
+ "enable option '%s' even if %s was passed to JVM",
|
||||
optionName, CommandLineOptionTest.prepareBooleanFlag(
|
||||
SHAOptionsBase.USE_SHA_OPTION, false)),
|
||||
ExitCode.OK,
|
||||
CommandLineOptionTest.prepareBooleanFlag(
|
||||
SHAOptionsBase.USE_SHA_OPTION, false),
|
||||
CommandLineOptionTest.prepareBooleanFlag(optionName, true));
|
||||
if (!optionName.equals(SHAOptionsBase.USE_SHA_OPTION)) {
|
||||
// Verify that if -XX:-UseSHA is passed to the JVM, it is not possible
|
||||
// to enable the tested option and a warning is printed.
|
||||
CommandLineOptionTest.verifySameJVMStartup(
|
||||
new String[] { SHAOptionsBase.getWarningForUnsupportedCPU(optionName) },
|
||||
null,
|
||||
shouldPassMessage,
|
||||
String.format("Enabling option '%s' should not be possible and should result in a warning if %s was passed to JVM",
|
||||
optionName,
|
||||
CommandLineOptionTest.prepareBooleanFlag(SHAOptionsBase.USE_SHA_OPTION, false)),
|
||||
ExitCode.OK,
|
||||
CommandLineOptionTest.prepareBooleanFlag(SHAOptionsBase.USE_SHA_OPTION, false),
|
||||
CommandLineOptionTest.prepareBooleanFlag(optionName, true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,14 +49,22 @@ public class GenericTestCaseForUnsupportedAArch64CPU extends
|
||||
}, shouldPassMessage, shouldPassMessage, ExitCode.OK,
|
||||
CommandLineOptionTest.prepareBooleanFlag(optionName, false));
|
||||
|
||||
shouldPassMessage = String.format("JVM should start with '-XX:+"
|
||||
+ "%s' flag, but output should contain warning.", optionName);
|
||||
// Verify that when the tested option is explicitly enabled, then
|
||||
// a warning will occur in VM output.
|
||||
CommandLineOptionTest.verifySameJVMStartup(new String[] {
|
||||
SHAOptionsBase.getWarningForUnsupportedCPU(optionName)
|
||||
}, null, shouldPassMessage, shouldPassMessage, ExitCode.OK,
|
||||
CommandLineOptionTest.prepareBooleanFlag(optionName, true));
|
||||
shouldPassMessage = String.format("If JVM is started with '-XX:-"
|
||||
+ "%s' '-XX:+%s', output should contain warning.",
|
||||
SHAOptionsBase.USE_SHA_OPTION, optionName);
|
||||
|
||||
// Verify that when the tested option is enabled, then
|
||||
// a warning will occur in VM output if UseSHA is disabled.
|
||||
if (!optionName.equals(SHAOptionsBase.USE_SHA_OPTION)) {
|
||||
CommandLineOptionTest.verifySameJVMStartup(
|
||||
new String[] { SHAOptionsBase.getWarningForUnsupportedCPU(optionName) },
|
||||
null,
|
||||
shouldPassMessage,
|
||||
shouldPassMessage,
|
||||
ExitCode.OK,
|
||||
CommandLineOptionTest.prepareBooleanFlag(SHAOptionsBase.USE_SHA_OPTION, false),
|
||||
CommandLineOptionTest.prepareBooleanFlag(optionName, true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,6 +48,19 @@ public class GenericTestCaseForUnsupportedSparcCPU extends
|
||||
SHAOptionsBase.getWarningForUnsupportedCPU(optionName)
|
||||
}, shouldPassMessage, shouldPassMessage, ExitCode.OK,
|
||||
CommandLineOptionTest.prepareBooleanFlag(optionName, false));
|
||||
|
||||
// Verify that when the tested option is enabled, then
|
||||
// a warning will occur in VM output if UseSHA is disabled.
|
||||
if (!optionName.equals(SHAOptionsBase.USE_SHA_OPTION)) {
|
||||
CommandLineOptionTest.verifySameJVMStartup(
|
||||
new String[] { SHAOptionsBase.getWarningForUnsupportedCPU(optionName) },
|
||||
null,
|
||||
shouldPassMessage,
|
||||
shouldPassMessage,
|
||||
ExitCode.OK,
|
||||
CommandLineOptionTest.prepareBooleanFlag(SHAOptionsBase.USE_SHA_OPTION, false),
|
||||
CommandLineOptionTest.prepareBooleanFlag(optionName, true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user