< prev index next >
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/AESCryptSubstitutions.java
Print this page
*** 27,38 ****
import static org.graalvm.compiler.hotspot.HotSpotBackend.ENCRYPT_BLOCK;
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.VERY_SLOW_PATH_PROBABILITY;
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.probability;
import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayBaseOffset;
- import java.lang.reflect.Field;
-
import org.graalvm.compiler.api.replacements.ClassSubstitution;
import org.graalvm.compiler.api.replacements.MethodSubstitution;
import org.graalvm.compiler.core.common.LocationIdentity;
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
import org.graalvm.compiler.debug.GraalError;
--- 27,36 ----
*** 59,82 ****
public class AESCryptSubstitutions {
static final long kOffset;
static final long lastKeyOffset;
static final Class<?> AESCryptClass;
! static final int AES_BLOCK_SIZE;
static {
try {
// Need to use the system class loader as com.sun.crypto.provider.AESCrypt
// is normally loaded by the extension class loader which is not delegated
// to by the JVMCI class loader.
ClassLoader cl = ClassLoader.getSystemClassLoader();
AESCryptClass = Class.forName("com.sun.crypto.provider.AESCrypt", true, cl);
kOffset = UnsafeAccess.UNSAFE.objectFieldOffset(AESCryptClass.getDeclaredField("K"));
lastKeyOffset = UnsafeAccess.UNSAFE.objectFieldOffset(AESCryptClass.getDeclaredField("lastKey"));
! Field aesBlockSizeField = Class.forName("com.sun.crypto.provider.AESConstants", true, cl).getDeclaredField("AES_BLOCK_SIZE");
! aesBlockSizeField.setAccessible(true);
! AES_BLOCK_SIZE = aesBlockSizeField.getInt(null);
} catch (Exception ex) {
throw new GraalError(ex);
}
}
--- 57,80 ----
public class AESCryptSubstitutions {
static final long kOffset;
static final long lastKeyOffset;
static final Class<?> AESCryptClass;
! static final int AES_BLOCK_SIZE_IN_BYTES;
static {
try {
// Need to use the system class loader as com.sun.crypto.provider.AESCrypt
// is normally loaded by the extension class loader which is not delegated
// to by the JVMCI class loader.
ClassLoader cl = ClassLoader.getSystemClassLoader();
AESCryptClass = Class.forName("com.sun.crypto.provider.AESCrypt", true, cl);
kOffset = UnsafeAccess.UNSAFE.objectFieldOffset(AESCryptClass.getDeclaredField("K"));
lastKeyOffset = UnsafeAccess.UNSAFE.objectFieldOffset(AESCryptClass.getDeclaredField("lastKey"));
! // Thankfully the AES block size is a constant (128 bits) and so we don't need to
! // reflect on com.sun.crypto.provider.AESConstants.AES_BLOCK_SIZE.
! AES_BLOCK_SIZE_IN_BYTES = 16;
} catch (Exception ex) {
throw new GraalError(ex);
}
}
*** 139,149 ****
/**
* Perform null and array bounds checks for arguments to a cipher operation.
*/
static void checkArgs(byte[] in, int inOffset, byte[] out, int outOffset) {
! if (probability(VERY_SLOW_PATH_PROBABILITY, inOffset < 0 || in.length - AES_BLOCK_SIZE < inOffset || outOffset < 0 || out.length - AES_BLOCK_SIZE < outOffset)) {
DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint);
}
}
@NodeIntrinsic(ForeignCallNode.class)
--- 137,147 ----
/**
* Perform null and array bounds checks for arguments to a cipher operation.
*/
static void checkArgs(byte[] in, int inOffset, byte[] out, int outOffset) {
! if (probability(VERY_SLOW_PATH_PROBABILITY, inOffset < 0 || in.length - AES_BLOCK_SIZE_IN_BYTES < inOffset || outOffset < 0 || out.length - AES_BLOCK_SIZE_IN_BYTES < outOffset)) {
DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint);
}
}
@NodeIntrinsic(ForeignCallNode.class)
< prev index next >