Skip to content

Commit

Permalink
[GR-18988] JVMCI 19.3-b04 for jdk8.
Browse files Browse the repository at this point in the history
PullRequest: graal/4666
  • Loading branch information
ezzarghili committed Oct 29, 2019
2 parents 62d9800 + 6c89152 commit f3d4fe5
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jdk:

env:
global:
- JVMCI_VERSION="jvmci-19.3-b03"
- JDK8_UPDATE_VERSION="222"
- JVMCI_VERSION="jvmci-19.3-b04"
- JDK8_UPDATE_VERSION="232"
- JDK8_UPDATE_VERSION_SUFFIX=""

matrix:
Expand Down
6 changes: 3 additions & 3 deletions common.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ overlay = 66a6d5b786a13ffa8d683174192c466d4c94ea5f
# openjdk8 JDKs on Linux are built by Oracle Labs
# openjdk8 JDKs on macOS are based on AdoptOpenJDK binaries
jdks: {
oraclejdk8: {name : oraclejdk, version : "8u221-jvmci-19.3-b03", platformspecific: true}
openjdk8: {name : openjdk, version : "8u222-jvmci-19.3-b03", platformspecific: true}
oraclejdk8Debug: {name : oraclejdk, version : "8u221-jvmci-19.3-b03-fastdebug", platformspecific: true}
oraclejdk8: {name : oraclejdk, version : "8u231-jvmci-19.3-b04", platformspecific: true}
openjdk8: {name : openjdk, version : "8u232-jvmci-19.3-b04", platformspecific: true}
oraclejdk8Debug: {name : oraclejdk, version : "8u231-jvmci-19.3-b04-fastdebug", platformspecific: true}
oraclejdk11: {name : oraclejdk, version : "11.0.3+12", platformspecific: true}
openjdk11: {name : openjdk, version : "11.0.3+7", platformspecific: true}
labsjdk-ce-11: {name : labsjdk, version : "ce-11.0.5+9-jvmci-19.3-b03", platformspecific: true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
*/
package org.graalvm.compiler.hotspot.test;

import static org.graalvm.compiler.hotspot.meta.HotSpotGraphBuilderPlugins.aesDecryptName;
import static org.graalvm.compiler.hotspot.meta.HotSpotGraphBuilderPlugins.aesEncryptName;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -368,10 +365,6 @@ public CheckGraalIntrinsics() {
add(ignore,
"com/sun/crypto/provider/GHASH.processBlocks([BII[J[J)V");
}
if (!(config.useSHA1Intrinsics() || config.useSHA256Intrinsics() || config.useSHA512Intrinsics())) {
add(ignore,
"sun/security/provider/DigestBase.implCompressMultiBlock0([BII)I");
}
if (!config.useFMAIntrinsics) {
add(ignore,
"java/lang/Math.fma(DDD)D",
Expand Down Expand Up @@ -516,15 +509,16 @@ public CheckGraalIntrinsics() {
"java/util/zip/CRC32C.updateDirectByteBuffer(IJII)I");
}

boolean implNames = HotSpotGraphBuilderPlugins.cbcUsesImplNames(config);
String cbcEncryptName = implNames ? "implEncrypt" : "encrypt";
String cbcDecryptName = implNames ? "implDecrypt" : "decrypt";
String cbcEncryptName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(config, "com/sun/crypto/provider/CipherBlockChaining", "implEncrypt", "encrypt");
String cbcDecryptName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(config, "com/sun/crypto/provider/CipherBlockChaining", "implDecrypt", "decrypt");
String aesEncryptName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(config, "com/sun/crypto/provider/AESCrypt", "implEncryptBlock", "encryptBlock");
String aesDecryptName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(config, "com/sun/crypto/provider/AESCrypt", "implDecryptBlock", "decryptBlock");

// AES intrinsics
if (!config.useAESIntrinsics) {
add(ignore,
"com/sun/crypto/provider/AESCrypt." + aesDecryptName + "([BI[BI)V",
"com/sun/crypto/provider/AESCrypt." + aesEncryptName + "([BI[BI)V",
"com/sun/crypto/provider/AESCrypt." + aesDecryptName + "([BI[BI)V",
"com/sun/crypto/provider/CipherBlockChaining." + cbcDecryptName + "([BII[BI)I",
"com/sun/crypto/provider/CipherBlockChaining." + cbcEncryptName + "([BII[BI)I");
}
Expand All @@ -549,28 +543,21 @@ public CheckGraalIntrinsics() {
if (!config.useSquareToLenIntrinsic()) {
add(ignore, "java/math/BigInteger.implSquareToLen([II[II)[I");
}

// DigestBase intrinsics
if (HotSpotGraphBuilderPlugins.isIntrinsicName(config, "sun/security/provider/DigestBase", "implCompressMultiBlock0") &&
!(config.useSHA1Intrinsics() || config.useSHA256Intrinsics() || config.useSHA512Intrinsics())) {
add(ignore, "sun/security/provider/DigestBase.implCompressMultiBlock0([BII)I");
}
// SHA intrinsics
String shaCompressName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(config, "sun/security/provider/SHA", "implCompress0", "implCompress");
if (!config.useSHA1Intrinsics()) {
if (isJDK9OrHigher()) {
add(ignore, "sun/security/provider/SHA.implCompress0([BI)V");
} else {
add(ignore, "sun/security/provider/SHA.implCompress([BI)V");
}
add(ignore, "sun/security/provider/SHA." + shaCompressName + "([BI)V");
}
if (!config.useSHA256Intrinsics()) {
if (isJDK9OrHigher()) {
add(ignore, "sun/security/provider/SHA2.implCompress0([BI)V");
} else {
add(ignore, "sun/security/provider/SHA2.implCompress([BI)V");
}
add(ignore, "sun/security/provider/SHA2." + shaCompressName + "([BI)V");
}
if (!config.useSHA512Intrinsics()) {
if (isJDK9OrHigher()) {
add(ignore, "sun/security/provider/SHA5.implCompress0([BI)V");
} else {
add(ignore, "sun/security/provider/SHA5.implCompress([BI)V");
}
add(ignore, "sun/security/provider/SHA5." + shaCompressName + "([BI)V");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public HotSpotCryptoSubstitutionTest() throws Exception {

@Test
public void testAESCryptIntrinsics() throws Exception {
if (compileAndInstall("com.sun.crypto.provider.AESCrypt", HotSpotGraphBuilderPlugins.aesEncryptName, HotSpotGraphBuilderPlugins.aesDecryptName)) {
String aesEncryptName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(runtime().getVMConfig(), "com/sun/crypto/provider/AESCrypt", "implEncryptBlock", "encryptBlock");
String aesDecryptName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(runtime().getVMConfig(), "com/sun/crypto/provider/AESCrypt", "implDecryptBlock", "decryptBlock");
if (compileAndInstall("com.sun.crypto.provider.AESCrypt", aesEncryptName, aesDecryptName)) {
ByteArrayOutputStream actual = new ByteArrayOutputStream();
actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding"));
actual.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding"));
Expand All @@ -90,9 +92,8 @@ public void testAESCryptIntrinsics() throws Exception {

@Test
public void testCipherBlockChainingIntrinsics() throws Exception {
boolean implNames = HotSpotGraphBuilderPlugins.cbcUsesImplNames(runtime().getVMConfig());
String cbcEncryptName = implNames ? "implEncrypt" : "encrypt";
String cbcDecryptName = implNames ? "implDecrypt" : "decrypt";
String cbcEncryptName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(runtime().getVMConfig(), "com/sun/crypto/provider/CipherBlockChaining", "implEncrypt", "encrypt");
String cbcDecryptName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(runtime().getVMConfig(), "com/sun/crypto/provider/CipherBlockChaining", "implDecrypt", "decrypt");
if (compileAndInstall("com.sun.crypto.provider.CipherBlockChaining", cbcEncryptName, cbcDecryptName)) {
ByteArrayOutputStream actual = new ByteArrayOutputStream();
actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
import org.graalvm.compiler.api.test.Graal;
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
import org.graalvm.compiler.hotspot.replacements.SHA2Substitutions;
import org.graalvm.compiler.hotspot.replacements.SHA5Substitutions;
import org.graalvm.compiler.hotspot.replacements.SHASubstitutions;
import org.graalvm.compiler.hotspot.meta.HotSpotGraphBuilderPlugins;
import org.graalvm.compiler.runtime.RuntimeProvider;

import jdk.vm.ci.code.InstalledCode;
Expand Down Expand Up @@ -74,7 +72,8 @@ GraalHotSpotVMConfig getConfig() {
@Test
public void testSha1() {
if (getConfig().useSHA1Intrinsics()) {
testWithInstalledIntrinsic("sun.security.provider.SHA", SHASubstitutions.implCompressName, "testDigest", "SHA-1", getData());
String implCompressName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(getConfig(), "sun/security/provider/SHA", "implCompress0", "implCompress");
testWithInstalledIntrinsic("sun.security.provider.SHA", implCompressName, "testDigest", "SHA-1", getData());
}
}

Expand Down Expand Up @@ -107,14 +106,16 @@ void testWithInstalledIntrinsic(String className, String methodName, String test
@Test
public void testSha256() {
if (getConfig().useSHA256Intrinsics()) {
testWithInstalledIntrinsic("sun.security.provider.SHA2", SHA2Substitutions.implCompressName, "testDigest", "SHA-256", getData());
String implCompressName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(getConfig(), "sun/security/provider/SHA", "implCompress0", "implCompress");
testWithInstalledIntrinsic("sun.security.provider.SHA2", implCompressName, "testDigest", "SHA-256", getData());
}
}

@Test
public void testSha512() {
if (getConfig().useSHA512Intrinsics()) {
testWithInstalledIntrinsic("sun.security.provider.SHA5", SHA5Substitutions.implCompressName, "testDigest", "SHA-512", getData());
String implCompressName = HotSpotGraphBuilderPlugins.lookupIntrinsicName(getConfig(), "sun/security/provider/SHA", "implCompress0", "implCompress");
testWithInstalledIntrinsic("sun.security.provider.SHA5", implCompressName, "testDigest", "SHA-512", getData());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,62 +444,73 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
r.registerMethodSubstitution(ThreadSubstitutions.class, "isInterrupted", Receiver.class, boolean.class);
}

public static final String aesEncryptName;
public static final String aesDecryptName;

public static final String reflectionClass;
public static final String constantPoolClass;

static {
if (JavaVersionUtil.JAVA_SPEC <= 8) {
aesEncryptName = "encryptBlock";
aesDecryptName = "decryptBlock";
reflectionClass = "sun.reflect.Reflection";
constantPoolClass = "sun.reflect.ConstantPool";
} else {
aesEncryptName = "implEncryptBlock";
aesDecryptName = "implDecryptBlock";
reflectionClass = "jdk.internal.reflect.Reflection";
constantPoolClass = "jdk.internal.reflect.ConstantPool";
}
}

public static boolean cbcUsesImplNames(GraalHotSpotVMConfig config) {
public static String lookupIntrinsicName(GraalHotSpotVMConfig config, String className, String name1, String name2) {
boolean foundName1 = false;
boolean foundName2 = false;
String name = name1;
for (VMIntrinsicMethod intrinsic : config.getStore().getIntrinsics()) {
if ("com/sun/crypto/provider/CipherBlockChaining".equals(intrinsic.declaringClass)) {
if ("encrypt".equals(intrinsic.name)) {
return false;
} else if ("implEncrypt".equals(intrinsic.name)) {
return true;
if (className.equals(intrinsic.declaringClass)) {
if (name1.equals(intrinsic.name)) {
foundName1 = true;
} else if (name2.equals(intrinsic.name)) {
foundName2 = true;
name = name2;
}
}
}
if (foundName1 != foundName2) {
return name;
}
throw GraalError.shouldNotReachHere();
}

public static boolean isIntrinsicName(GraalHotSpotVMConfig config, String className, String name) {
for (VMIntrinsicMethod intrinsic : config.getStore().getIntrinsics()) {
if (className.equals(intrinsic.declaringClass)) {
if (name.equals(intrinsic.name)) {
return true;
}
}
}
return false;
}

private static void registerAESPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) {
if (config.useAESIntrinsics) {
assert config.aescryptEncryptBlockStub != 0L;
assert config.aescryptDecryptBlockStub != 0L;
assert config.cipherBlockChainingEncryptAESCryptStub != 0L;
assert config.cipherBlockChainingDecryptAESCryptStub != 0L;
String arch = config.osArch;
String decryptSuffix = arch.equals("sparc") ? "WithOriginalKey" : "";

String cbcEncryptName = lookupIntrinsicName(config, "com/sun/crypto/provider/CipherBlockChaining", "implEncrypt", "encrypt");
String cbcDecryptName = lookupIntrinsicName(config, "com/sun/crypto/provider/CipherBlockChaining", "implDecrypt", "decrypt");
Registration r = new Registration(plugins, "com.sun.crypto.provider.CipherBlockChaining", replacements);
r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, cbcEncryptName, Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class);
r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, cbcDecryptName, cbcDecryptName + decryptSuffix, Receiver.class, byte[].class, int.class, int.class, byte[].class,
int.class);

String aesEncryptName = lookupIntrinsicName(config, "com/sun/crypto/provider/AESCrypt", "implEncryptBlock", "encryptBlock");
String aesDecryptName = lookupIntrinsicName(config, "com/sun/crypto/provider/AESCrypt", "implDecryptBlock", "decryptBlock");

r = new Registration(plugins, "com.sun.crypto.provider.AESCrypt", replacements);
r.registerMethodSubstitution(AESCryptSubstitutions.class, aesEncryptName, Receiver.class, byte[].class, int.class, byte[].class, int.class);
r.registerMethodSubstitution(AESCryptSubstitutions.class, aesDecryptName, aesDecryptName + decryptSuffix, Receiver.class, byte[].class, int.class, byte[].class, int.class);
}
String arch = config.osArch;
String decryptSuffix = arch.equals("sparc") ? "WithOriginalKey" : "";
Registration r = new Registration(plugins, "com.sun.crypto.provider.CipherBlockChaining", replacements);

boolean implNames = cbcUsesImplNames(config);
String cbcEncryptName = implNames ? "implEncrypt" : "encrypt";
String cbcDecryptName = implNames ? "implDecrypt" : "decrypt";

r.registerConditionalMethodSubstitution(config.useAESIntrinsics, CipherBlockChainingSubstitutions.class, cbcEncryptName, Receiver.class, byte[].class, int.class, int.class, byte[].class,
int.class);
r.registerConditionalMethodSubstitution(config.useAESIntrinsics, CipherBlockChainingSubstitutions.class, cbcDecryptName, cbcDecryptName + decryptSuffix, Receiver.class, byte[].class,
int.class, int.class, byte[].class, int.class);
r = new Registration(plugins, "com.sun.crypto.provider.AESCrypt", replacements);
r.registerConditionalMethodSubstitution(config.useAESIntrinsics, AESCryptSubstitutions.class, aesEncryptName, Receiver.class, byte[].class, int.class, byte[].class, int.class);
r.registerConditionalMethodSubstitution(config.useAESIntrinsics, AESCryptSubstitutions.class, aesDecryptName, aesDecryptName + decryptSuffix, Receiver.class, byte[].class, int.class,
byte[].class, int.class);
}

private static void registerBigIntegerPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) {
Expand All @@ -525,20 +536,27 @@ private static void registerSHAPlugins(InvocationPlugins plugins, GraalHotSpotVM
boolean useSha256 = config.useSHA256Intrinsics();
boolean useSha512 = config.useSHA512Intrinsics();

if (JavaVersionUtil.JAVA_SPEC > 8 && (useSha1 || useSha256 || useSha512)) {
if (isIntrinsicName(config, "sun/security/provider/DigestBase", "implCompressMultiBlock0") && (useSha1 || useSha256 || useSha512)) {
Registration r = new Registration(plugins, "sun.security.provider.DigestBase", replacements);
r.registerConditionalMethodSubstitution((useSha1 || useSha256 || useSha512), DigestBaseSubstitutions.class, "implCompressMultiBlock0", Receiver.class, byte[].class, int.class, int.class);
r.registerMethodSubstitution(DigestBaseSubstitutions.class, "implCompressMultiBlock0", Receiver.class, byte[].class, int.class, int.class);
}

assert !useSha1 || config.sha1ImplCompress != 0L;
Registration r = new Registration(plugins, "sun.security.provider.SHA", replacements);
r.registerConditionalMethodSubstitution(useSha1, SHASubstitutions.class, SHASubstitutions.implCompressName, "implCompress0", Receiver.class, byte[].class, int.class);
assert !useSha256 || config.sha256ImplCompress != 0L;
Registration r2 = new Registration(plugins, "sun.security.provider.SHA2", replacements);
r2.registerConditionalMethodSubstitution(useSha256, SHA2Substitutions.class, SHA2Substitutions.implCompressName, "implCompress0", Receiver.class, byte[].class, int.class);
assert !useSha512 || config.sha512ImplCompress != 0L;
Registration r5 = new Registration(plugins, "sun.security.provider.SHA5", replacements);
r5.registerConditionalMethodSubstitution(useSha512, SHA5Substitutions.class, SHA5Substitutions.implCompressName, "implCompress0", Receiver.class, byte[].class, int.class);
String implCompressName = lookupIntrinsicName(config, "sun/security/provider/SHA", "implCompress", "implCompress0");
if (useSha1) {
assert config.sha1ImplCompress != 0L;
Registration r = new Registration(plugins, "sun.security.provider.SHA", replacements);
r.registerMethodSubstitution(SHASubstitutions.class, implCompressName, "implCompress0", Receiver.class, byte[].class, int.class);
}
if (useSha256) {
assert config.sha256ImplCompress != 0L;
Registration r = new Registration(plugins, "sun.security.provider.SHA2", replacements);
r.registerMethodSubstitution(SHA2Substitutions.class, implCompressName, "implCompress0", Receiver.class, byte[].class, int.class);
}
if (useSha512) {
assert config.sha512ImplCompress != 0L;
Registration r = new Registration(plugins, "sun.security.provider.SHA5", replacements);
r.registerMethodSubstitution(SHA5Substitutions.class, implCompressName, "implCompress0", Receiver.class, byte[].class, int.class);
}
}

private static void registerGHASHPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.graalvm.compiler.nodes.extended.RawLoadNode;
import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
import org.graalvm.compiler.replacements.ReplacementsUtil;
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.compiler.word.Word;
import org.graalvm.word.LocationIdentity;
import org.graalvm.word.WordFactory;
Expand All @@ -46,8 +45,6 @@
@ClassSubstitution(className = "sun.security.provider.SHA2", optional = true)
public class SHA2Substitutions {

public static final String implCompressName = JavaVersionUtil.JAVA_SPEC <= 8 ? "implCompress" : "implCompress0";

@MethodSubstitution(isStatic = false)
static void implCompress0(Object receiver, byte[] buf, int ofs) {
Object realReceiver = PiNode.piCastNonNull(receiver, HotSpotReplacementsUtil.methodHolderClass(INJECTED_INTRINSIC_CONTEXT));
Expand Down
Loading

0 comments on commit f3d4fe5

Please sign in to comment.