Search in sources :

Example 66 with Pointer

use of org.graalvm.word.Pointer in project graal by oracle.

the class AESCryptSubstitutions method crypt.

private static void crypt(Object rcvr, byte[] in, int inOffset, byte[] out, int outOffset, boolean encrypt, boolean withOriginalKey) {
    checkArgs(in, inOffset, out, outOffset);
    Object realReceiver = PiNode.piCastNonNull(rcvr, AESCryptClass);
    Object kObject = RawLoadNode.load(realReceiver, kOffset, JavaKind.Object, LocationIdentity.any());
    Pointer kAddr = Word.objectToTrackedPointer(kObject).add(getArrayBaseOffset(JavaKind.Int));
    Word inAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(in, getArrayBaseOffset(JavaKind.Byte) + inOffset));
    Word outAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(out, getArrayBaseOffset(JavaKind.Byte) + outOffset));
    if (encrypt) {
        encryptBlockStub(ENCRYPT_BLOCK, inAddr, outAddr, kAddr);
    } else {
        if (withOriginalKey) {
            Object lastKeyObject = RawLoadNode.load(realReceiver, lastKeyOffset, JavaKind.Object, LocationIdentity.any());
            Pointer lastKeyAddr = Word.objectToTrackedPointer(lastKeyObject).add(getArrayBaseOffset(JavaKind.Byte));
            decryptBlockWithOriginalKeyStub(DECRYPT_BLOCK_WITH_ORIGINAL_KEY, inAddr, outAddr, kAddr, lastKeyAddr);
        } else {
            decryptBlockStub(DECRYPT_BLOCK, inAddr, outAddr, kAddr);
        }
    }
}
Also used : Word(org.graalvm.compiler.word.Word) Pointer(org.graalvm.word.Pointer)

Example 67 with Pointer

use of org.graalvm.word.Pointer in project graal by oracle.

the class CRC32Substitutions method update.

/**
 * Removed in 9.
 */
@MethodSubstitution(optional = true)
static int update(int crc, int b) {
    final Pointer crcTableRawAddress = WordFactory.pointer(GraalHotSpotVMConfigNode.crcTableAddress());
    int c = ~crc;
    int index = (b ^ c) & 0xFF;
    int offset = index << 2;
    int result = crcTableRawAddress.readInt(offset);
    result = result ^ (c >>> 8);
    return ~result;
}
Also used : Pointer(org.graalvm.word.Pointer) MethodSubstitution(org.graalvm.compiler.api.replacements.MethodSubstitution)

Example 68 with Pointer

use of org.graalvm.word.Pointer in project graal by oracle.

the class CipherBlockChainingSubstitutions method crypt.

private static void crypt(Object rcvr, byte[] in, int inOffset, int inLength, byte[] out, int outOffset, Object embeddedCipher, boolean encrypt, boolean withOriginalKey) {
    AESCryptSubstitutions.checkArgs(in, inOffset, out, outOffset);
    Object realReceiver = PiNode.piCastNonNull(rcvr, cipherBlockChainingClass);
    Object aesCipher = getAESCryptClass().cast(embeddedCipher);
    Object kObject = RawLoadNode.load(aesCipher, AESCryptSubstitutions.kOffset, JavaKind.Object, LocationIdentity.any());
    Object rObject = RawLoadNode.load(realReceiver, rOffset, JavaKind.Object, LocationIdentity.any());
    Pointer kAddr = Word.objectToTrackedPointer(kObject).add(getArrayBaseOffset(JavaKind.Int));
    Pointer rAddr = Word.objectToTrackedPointer(rObject).add(getArrayBaseOffset(JavaKind.Byte));
    Word inAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(in, getArrayBaseOffset(JavaKind.Byte) + inOffset));
    Word outAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(out, getArrayBaseOffset(JavaKind.Byte) + outOffset));
    if (encrypt) {
        encryptAESCryptStub(ENCRYPT, inAddr, outAddr, kAddr, rAddr, inLength);
    } else {
        if (withOriginalKey) {
            Object lastKeyObject = RawLoadNode.load(aesCipher, AESCryptSubstitutions.lastKeyOffset, JavaKind.Object, LocationIdentity.any());
            Pointer lastKeyAddr = Word.objectToTrackedPointer(lastKeyObject).add(getArrayBaseOffset(JavaKind.Byte));
            decryptAESCryptWithOriginalKeyStub(DECRYPT_WITH_ORIGINAL_KEY, inAddr, outAddr, kAddr, rAddr, inLength, lastKeyAddr);
        } else {
            decryptAESCryptStub(DECRYPT, inAddr, outAddr, kAddr, rAddr, inLength);
        }
    }
}
Also used : Word(org.graalvm.compiler.word.Word) Pointer(org.graalvm.word.Pointer)

Example 69 with Pointer

use of org.graalvm.word.Pointer in project graal by oracle.

the class AlignedHeapChunkMemoryWalkerAccessFeature method getObjectOffset.

/**
 * Return the offset of an object within the objects part of a chunk.
 */
private static UnsignedWord getObjectOffset(AlignedHeader that, Object obj) {
    final Pointer objectsStart = getObjectsStart(that);
    final Pointer objectPointer = Word.objectToUntrackedPointer(obj);
    assert objectsStart.belowOrEqual(objectPointer);
    assert objectPointer.belowOrEqual(that.getEnd());
    return objectPointer.subtract(objectsStart);
}
Also used : Pointer(org.graalvm.word.Pointer)

Example 70 with Pointer

use of org.graalvm.word.Pointer in project graal by oracle.

the class AlignedHeapChunkMemoryWalkerAccessFeature method allocateMemory.

/**
 * Allocate memory within this AlignedHeapChunk. No initialization of the memory happens here.
 */
static Pointer allocateMemory(AlignedHeader that, UnsignedWord size) {
    Pointer result = WordFactory.nullPointer();
    final UnsignedWord available = availableObjectMemory(that);
    /* Is memory available for the requested size? */
    if (size.belowOrEqual(available)) {
        /* Returned memory is at the start, */
        result = that.getTop();
        final Pointer newTop = result.add(size);
        setTopCarefully(that, newTop);
    }
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer)

Aggregations

Pointer (org.graalvm.word.Pointer)103 UnsignedWord (org.graalvm.word.UnsignedWord)45 Log (com.oracle.svm.core.log.Log)30 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)17 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)15 Snippet (org.graalvm.compiler.api.replacements.Snippet)14 Word (org.graalvm.compiler.word.Word)12 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)9 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)7 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)5 NeverInline (com.oracle.svm.core.annotate.NeverInline)5 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)5 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)4 DynamicHub (com.oracle.svm.core.hub.DynamicHub)3 CCharPointerPointer (org.graalvm.nativeimage.c.type.CCharPointerPointer)3 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)3 SignedWord (org.graalvm.word.SignedWord)3 DeoptimizedFrame (com.oracle.svm.core.deopt.DeoptimizedFrame)2 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)2 Dirent.direntPointer (com.oracle.svm.core.posix.headers.Dirent.direntPointer)2