42 import org.graalvm.compiler.bytecode.BytecodeProvider; |
42 import org.graalvm.compiler.bytecode.BytecodeProvider; |
43 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; |
43 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; |
44 import org.graalvm.compiler.core.common.type.ObjectStamp; |
44 import org.graalvm.compiler.core.common.type.ObjectStamp; |
45 import org.graalvm.compiler.core.common.type.StampFactory; |
45 import org.graalvm.compiler.core.common.type.StampFactory; |
46 import org.graalvm.compiler.core.common.type.TypeReference; |
46 import org.graalvm.compiler.core.common.type.TypeReference; |
|
47 import org.graalvm.compiler.debug.GraalError; |
47 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
48 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
48 import org.graalvm.compiler.hotspot.nodes.CurrentJavaThreadNode; |
49 import org.graalvm.compiler.hotspot.nodes.CurrentJavaThreadNode; |
49 import org.graalvm.compiler.hotspot.replacements.AESCryptSubstitutions; |
50 import org.graalvm.compiler.hotspot.replacements.AESCryptSubstitutions; |
50 import org.graalvm.compiler.hotspot.replacements.ArraysSupportSubstitutions; |
51 import org.graalvm.compiler.hotspot.replacements.ArraysSupportSubstitutions; |
51 import org.graalvm.compiler.hotspot.replacements.BigIntegerSubstitutions; |
52 import org.graalvm.compiler.hotspot.replacements.BigIntegerSubstitutions; |
104 import org.graalvm.compiler.word.WordOperationPlugin; |
105 import org.graalvm.compiler.word.WordOperationPlugin; |
105 import org.graalvm.compiler.word.WordTypes; |
106 import org.graalvm.compiler.word.WordTypes; |
106 import jdk.internal.vm.compiler.word.LocationIdentity; |
107 import jdk.internal.vm.compiler.word.LocationIdentity; |
107 |
108 |
108 import jdk.vm.ci.code.CodeUtil; |
109 import jdk.vm.ci.code.CodeUtil; |
|
110 import jdk.vm.ci.hotspot.VMIntrinsicMethod; |
109 import jdk.vm.ci.meta.ConstantReflectionProvider; |
111 import jdk.vm.ci.meta.ConstantReflectionProvider; |
110 import jdk.vm.ci.meta.DeoptimizationAction; |
112 import jdk.vm.ci.meta.DeoptimizationAction; |
111 import jdk.vm.ci.meta.JavaKind; |
113 import jdk.vm.ci.meta.JavaKind; |
112 import jdk.vm.ci.meta.MetaAccessProvider; |
114 import jdk.vm.ci.meta.MetaAccessProvider; |
113 import jdk.vm.ci.meta.ResolvedJavaMethod; |
115 import jdk.vm.ci.meta.ResolvedJavaMethod; |
427 }); |
429 }); |
428 |
430 |
429 r.registerMethodSubstitution(ThreadSubstitutions.class, "isInterrupted", Receiver.class, boolean.class); |
431 r.registerMethodSubstitution(ThreadSubstitutions.class, "isInterrupted", Receiver.class, boolean.class); |
430 } |
432 } |
431 |
433 |
432 public static final String cbcEncryptName; |
|
433 public static final String cbcDecryptName; |
|
434 public static final String aesEncryptName; |
434 public static final String aesEncryptName; |
435 public static final String aesDecryptName; |
435 public static final String aesDecryptName; |
436 |
436 |
437 public static final String reflectionClass; |
437 public static final String reflectionClass; |
438 public static final String constantPoolClass; |
438 public static final String constantPoolClass; |
439 |
439 |
440 static { |
440 static { |
441 if (JavaVersionUtil.JAVA_SPEC <= 8) { |
441 if (JavaVersionUtil.JAVA_SPEC <= 8) { |
442 cbcEncryptName = "encrypt"; |
|
443 cbcDecryptName = "decrypt"; |
|
444 aesEncryptName = "encryptBlock"; |
442 aesEncryptName = "encryptBlock"; |
445 aesDecryptName = "decryptBlock"; |
443 aesDecryptName = "decryptBlock"; |
446 reflectionClass = "sun.reflect.Reflection"; |
444 reflectionClass = "sun.reflect.Reflection"; |
447 constantPoolClass = "sun.reflect.ConstantPool"; |
445 constantPoolClass = "sun.reflect.ConstantPool"; |
448 } else { |
446 } else { |
449 cbcEncryptName = "implEncrypt"; |
|
450 cbcDecryptName = "implDecrypt"; |
|
451 aesEncryptName = "implEncryptBlock"; |
447 aesEncryptName = "implEncryptBlock"; |
452 aesDecryptName = "implDecryptBlock"; |
448 aesDecryptName = "implDecryptBlock"; |
453 reflectionClass = "jdk.internal.reflect.Reflection"; |
449 reflectionClass = "jdk.internal.reflect.Reflection"; |
454 constantPoolClass = "jdk.internal.reflect.ConstantPool"; |
450 constantPoolClass = "jdk.internal.reflect.ConstantPool"; |
455 } |
451 } |
|
452 } |
|
453 |
|
454 public static boolean cbcUsesImplNames(GraalHotSpotVMConfig config) { |
|
455 for (VMIntrinsicMethod intrinsic : config.getStore().getIntrinsics()) { |
|
456 if ("com/sun/crypto/provider/CipherBlockChaining".equals(intrinsic.declaringClass)) { |
|
457 if ("encrypt".equals(intrinsic.name)) { |
|
458 return false; |
|
459 } else if ("implEncrypt".equals(intrinsic.name)) { |
|
460 return true; |
|
461 } |
|
462 } |
|
463 } |
|
464 throw GraalError.shouldNotReachHere(); |
456 } |
465 } |
457 |
466 |
458 private static void registerAESPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, BytecodeProvider bytecodeProvider) { |
467 private static void registerAESPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, BytecodeProvider bytecodeProvider) { |
459 if (config.useAESIntrinsics) { |
468 if (config.useAESIntrinsics) { |
460 assert config.aescryptEncryptBlockStub != 0L; |
469 assert config.aescryptEncryptBlockStub != 0L; |
462 assert config.cipherBlockChainingEncryptAESCryptStub != 0L; |
471 assert config.cipherBlockChainingEncryptAESCryptStub != 0L; |
463 assert config.cipherBlockChainingDecryptAESCryptStub != 0L; |
472 assert config.cipherBlockChainingDecryptAESCryptStub != 0L; |
464 String arch = config.osArch; |
473 String arch = config.osArch; |
465 String decryptSuffix = arch.equals("sparc") ? "WithOriginalKey" : ""; |
474 String decryptSuffix = arch.equals("sparc") ? "WithOriginalKey" : ""; |
466 Registration r = new Registration(plugins, "com.sun.crypto.provider.CipherBlockChaining", bytecodeProvider); |
475 Registration r = new Registration(plugins, "com.sun.crypto.provider.CipherBlockChaining", bytecodeProvider); |
|
476 |
|
477 boolean implNames = cbcUsesImplNames(config); |
|
478 String cbcEncryptName = implNames ? "implEncrypt" : "encrypt"; |
|
479 String cbcDecryptName = implNames ? "implDecrypt" : "decrypt"; |
|
480 |
467 r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, cbcEncryptName, Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class); |
481 r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, cbcEncryptName, Receiver.class, byte[].class, int.class, int.class, byte[].class, int.class); |
468 r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, cbcDecryptName, cbcDecryptName + decryptSuffix, Receiver.class, byte[].class, int.class, int.class, byte[].class, |
482 r.registerMethodSubstitution(CipherBlockChainingSubstitutions.class, cbcDecryptName, cbcDecryptName + decryptSuffix, Receiver.class, byte[].class, int.class, int.class, byte[].class, |
469 int.class); |
483 int.class); |
|
484 |
470 r = new Registration(plugins, "com.sun.crypto.provider.AESCrypt", bytecodeProvider); |
485 r = new Registration(plugins, "com.sun.crypto.provider.AESCrypt", bytecodeProvider); |
471 r.registerMethodSubstitution(AESCryptSubstitutions.class, aesEncryptName, Receiver.class, byte[].class, int.class, byte[].class, int.class); |
486 r.registerMethodSubstitution(AESCryptSubstitutions.class, aesEncryptName, Receiver.class, byte[].class, int.class, byte[].class, int.class); |
472 r.registerMethodSubstitution(AESCryptSubstitutions.class, aesDecryptName, aesDecryptName + decryptSuffix, Receiver.class, byte[].class, int.class, byte[].class, int.class); |
487 r.registerMethodSubstitution(AESCryptSubstitutions.class, aesDecryptName, aesDecryptName + decryptSuffix, Receiver.class, byte[].class, int.class, byte[].class, int.class); |
473 } |
488 } |
474 } |
489 } |