# HG changeset patch # User Tom Rodriguez # Date 1445461854 25200 # Node ID bc1d4ecfae54c2d751dbe145fa25b63dce8a9972 # Parent 6c50e0c1e630520063a89183e6e7b6fbe68210f7 Avoid use of sun.misc.Version to control JDK specific intrinsics diff -r 6c50e0c1e630 -r bc1d4ecfae54 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java Wed Oct 21 09:22:42 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java Wed Oct 21 14:10:54 2015 -0700 @@ -24,8 +24,6 @@ import static com.oracle.graal.graphbuilderconf.IntrinsicContext.CompilationContext.ROOT_COMPILATION; import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; -import static sun.misc.Version.jdkMajorVersion; -import static sun.misc.Version.jdkMinorVersion; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -49,6 +47,7 @@ import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; import com.oracle.graal.graphbuilderconf.IntrinsicContext; +import com.oracle.graal.hotspot.meta.HotSpotGraphBuilderPlugins; import com.oracle.graal.hotspot.meta.HotSpotProviders; import com.oracle.graal.java.GraphBuilderPhase; import com.oracle.graal.nodes.StructuredGraph; @@ -91,8 +90,7 @@ @Test public void testAESCryptIntrinsics() throws Exception { - String[] methods = jdkMajorVersion() >= 1 && jdkMinorVersion() <= 8 ? new String[]{"encryptBlock", "decryptBlock"} : new String[]{"implEncryptBlock", "implDecryptBlock"}; - if (compileAndInstall("com.sun.crypto.provider.AESCrypt", methods)) { + if (compileAndInstall("com.sun.crypto.provider.AESCrypt", HotSpotGraphBuilderPlugins.aesEncryptName, HotSpotGraphBuilderPlugins.aesDecryptName)) { ByteArrayOutputStream actual = new ByteArrayOutputStream(); actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding")); actual.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding")); @@ -102,8 +100,7 @@ @Test public void testCipherBlockChainingIntrinsics() throws Exception { - String[] methods = jdkMajorVersion() >= 1 && jdkMinorVersion() <= 8 ? new String[]{"encrypt", "decrypt"} : new String[]{"implEncrypt", "implDecrypt"}; - if (compileAndInstall("com.sun.crypto.provider.CipherBlockChaining", methods)) { + if (compileAndInstall("com.sun.crypto.provider.CipherBlockChaining", HotSpotGraphBuilderPlugins.cbcEncryptName, HotSpotGraphBuilderPlugins.cbcDecryptName)) { ByteArrayOutputStream actual = new ByteArrayOutputStream(); actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding")); actual.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding")); diff -r 6c50e0c1e630 -r bc1d4ecfae54 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Wed Oct 21 09:22:42 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Wed Oct 21 14:10:54 2015 -0700 @@ -26,8 +26,6 @@ import static com.oracle.graal.hotspot.replacements.SystemSubstitutions.JAVA_TIME_MILLIS; import static com.oracle.graal.hotspot.replacements.SystemSubstitutions.JAVA_TIME_NANOS; import static com.oracle.graal.java.BytecodeParserOptions.InlineDuringParsing; -import static sun.misc.Version.jdkMajorVersion; -import static sun.misc.Version.jdkMinorVersion; import java.lang.invoke.ConstantCallSite; import java.lang.invoke.MutableCallSite; @@ -60,6 +58,7 @@ import com.oracle.graal.hotspot.replacements.CallSiteTargetNode; import com.oracle.graal.hotspot.replacements.CipherBlockChainingSubstitutions; import com.oracle.graal.hotspot.replacements.HotSpotClassSubstitutions; +import com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil; import com.oracle.graal.hotspot.replacements.IdentityHashCodeNode; import com.oracle.graal.hotspot.replacements.ObjectCloneNode; import com.oracle.graal.hotspot.replacements.ObjectSubstitutions; @@ -154,7 +153,7 @@ r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isPrimitive", Receiver.class); r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getSuperclass", Receiver.class); - if (jdkMajorVersion() >= 1 && jdkMinorVersion() <= 8) { + if (HotSpotReplacementsUtil.arrayKlassComponentMirrorOffsetExists()) { r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getComponentType", Receiver.class); } @@ -269,6 +268,25 @@ }); } + public static final String cbcEncryptName; + public static final String cbcDecryptName; + public static final String aesEncryptName; + public static final String aesDecryptName; + + static { + if (System.getProperty("java.specification.version").compareTo("1.9") < 0) { + cbcEncryptName = "encrypt"; + cbcDecryptName = "decrypt"; + aesEncryptName = "encryptBlock"; + aesDecryptName = "decryptBlock"; + } else { + cbcEncryptName = "implEncrypt"; + cbcDecryptName = "implDecrypt"; + aesEncryptName = "implEncryptBlock"; + aesDecryptName = "implDecryptBlock"; + } + } + private static void registerAESPlugins(InvocationPlugins plugins, HotSpotVMConfig config) { if (config.useAESIntrinsics) { assert config.aescryptEncryptBlockStub != 0L; @@ -278,24 +296,14 @@ Class c = MethodSubstitutionPlugin.resolveClass("com.sun.crypto.provider.CipherBlockChaining", true); if (c != null) { Registration r = new Registration(plugins, c); - if (jdkMajorVersion() >= 1 && jdkMinorVersion() <= 8) { - r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, "encrypt", Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class); - r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, "decrypt", Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class); - } else { - r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, "implEncrypt", Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class); - r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, "implDecrypt", Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class); - } + r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, cbcEncryptName, Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class); + r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, cbcDecryptName, Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class); } c = MethodSubstitutionPlugin.resolveClass("com.sun.crypto.provider.AESCrypt", true); if (c != null) { Registration r = new Registration(plugins, c); - if (jdkMajorVersion() >= 1 && jdkMinorVersion() <= 8) { - r.registerMethodSubstitution(AESCryptSubstitutions.class, "encryptBlock", Receiver.class, byte[].class, int.class, byte[].class, int.class); - r.registerMethodSubstitution(AESCryptSubstitutions.class, "decryptBlock", Receiver.class, byte[].class, int.class, byte[].class, int.class); - } else { - r.registerMethodSubstitution(AESCryptSubstitutions.class, "implEncryptBlock", Receiver.class, byte[].class, int.class, byte[].class, int.class); - r.registerMethodSubstitution(AESCryptSubstitutions.class, "implDecryptBlock", Receiver.class, byte[].class, int.class, byte[].class, int.class); - } + r.registerMethodSubstitution(AESCryptSubstitutions.class, aesEncryptName, Receiver.class, byte[].class, int.class, byte[].class, int.class); + r.registerMethodSubstitution(AESCryptSubstitutions.class, aesDecryptName, Receiver.class, byte[].class, int.class, byte[].class, int.class); } } } @@ -308,7 +316,7 @@ assert config.cipherBlockChainingDecryptAESCryptStub != 0L; Registration r = new Registration(plugins, CRC32.class); r.registerMethodSubstitution(CRC32Substitutions.class, "update", int.class, int.class); - if (jdkMajorVersion() >= 1 && jdkMinorVersion() <= 8) { + if (System.getProperty("java.specification.version").compareTo("1.9") < 0) { r.registerMethodSubstitution(CRC32Substitutions.class, "updateBytes", int.class, byte[].class, int.class, int.class); r.registerMethodSubstitution(CRC32Substitutions.class, "updateByteBuffer", int.class, long.class, int.class, int.class); } else { diff -r 6c50e0c1e630 -r bc1d4ecfae54 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Wed Oct 21 09:22:42 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Wed Oct 21 14:10:54 2015 -0700 @@ -459,6 +459,10 @@ } } + public static boolean arrayKlassComponentMirrorOffsetExists() { + return Lazy.arrayKlassComponentMirrorOffset != Integer.MAX_VALUE; + } + @Fold public static int arrayKlassComponentMirrorOffset() { if (Lazy.arrayKlassComponentMirrorOffset == Integer.MAX_VALUE) {