Search in sources :

Example 1 with Struct

use of com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.Struct in project graal by oracle.

the class NativeMemSetNode method getAccessLength.

static long getAccessLength(LLVMManagedPointer pointer, long length, NativeTypeLibrary nativeTypes) {
    Object object = pointer.getObject();
    Object type = nativeTypes.getNativeType(object);
    if (type instanceof LLVMInteropType.Array) {
        long elementSize = ((LLVMInteropType.Array) type).elementSize;
        if (length % elementSize == 0) {
            return elementSize;
        }
    }
    if (type instanceof LLVMInteropType.Struct) {
        StructMember member = findMember((Struct) type, pointer.getOffset());
        /*
             * That's a bit of a guess: We assume that this tries to set 'n' members of the same
             * size. So, we just take the size of the first member as the access length. If that
             * isn't true, we will fail afterwards when doing actual access.
             */
        if (member != null && member.type instanceof LLVMInteropType.Value && length % member.type.getSize() == 0) {
            return member.type.getSize();
        }
    }
    /*
         * Fallback to byte-wise copy if either the type is unknown, not an array, or the length is
         * not a multiple of the array element size.
         */
    return 1;
}
Also used : StructMember(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.StructMember) Struct(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.Struct)

Example 2 with Struct

use of com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.Struct in project graal by oracle.

the class LLVMResolveForeignClassChainNode method doClazzResolving.

@Specialization(replaces = "doClassResolvingCached")
public LLVMPointer doClazzResolving(LLVMPointer receiver, String ident, LLVMInteropType.Clazz clazz, @Cached LLVMForeignVirtualSuperElemPtrNode virtualSuperElemPtrNode, @Cached LLVMForeignDirectSuperElemPtrNode directSuperElemPtrNode) throws UnknownIdentifierException {
    LLVMPointer curReceiver = receiver;
    Pair<long[], Struct> p = clazz.getSuperOffsetInformation(ident);
    for (long val : p.getLeft()) {
        LLVMForeignGetSuperElemPtrNode access = (val & 1) == 1 ? virtualSuperElemPtrNode : directSuperElemPtrNode;
        curReceiver = access.execute(curReceiver, val >> 1);
    }
    return curReceiver.export(p.getRight() == null ? clazz : p.getRight());
}
Also used : LLVMPointer(com.oracle.truffle.llvm.runtime.pointer.LLVMPointer) LLVMForeignGetSuperElemPtrNode(com.oracle.truffle.llvm.runtime.interop.export.LLVMForeignGetSuperElemPtrNode) Struct(com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.Struct) Specialization(com.oracle.truffle.api.dsl.Specialization)

Aggregations

Struct (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.Struct)2 Specialization (com.oracle.truffle.api.dsl.Specialization)1 StructMember (com.oracle.truffle.llvm.runtime.interop.access.LLVMInteropType.StructMember)1 LLVMForeignGetSuperElemPtrNode (com.oracle.truffle.llvm.runtime.interop.export.LLVMForeignGetSuperElemPtrNode)1 LLVMPointer (com.oracle.truffle.llvm.runtime.pointer.LLVMPointer)1