Search in sources :

Example 1 with Callback

use of com.oracle.truffle.espresso.jni.Callback in project graal by oracle.

the class StructsAccess method initializeStructs.

@SuppressWarnings("try")
private static Structs initializeStructs(EspressoContext context, TruffleObject initializeStructs, TruffleObject lookupMemberOffset) {
    try (DebugCloseable timer = STRUCTS_TIMER.scope(context.getTimers())) {
        Structs[] box = new Structs[1];
        Callback doInitStructs = new Callback(1, new Callback.Function() {

            @Override
            @CompilerDirectives.TruffleBoundary
            public Object call(Object... args) {
                TruffleObject memberInfoPtr = (TruffleObject) args[0];
                box[0] = new Structs(context.getJNI(), memberInfoPtr, lookupMemberOffset);
                return RawPointer.nullInstance();
            }
        });
        /*
             * Go down to native to initialize the data structure storing the offsets of used
             * structs (The memberInfoPtr seen in the callback). This will get back to java code
             * once the data structure is created. Once we get out of the native call, the structure
             * is freed and cannot be used anymore.
             */
        @Pointer TruffleObject closure = context.getNativeAccess().createNativeClosure(doInitStructs, NativeSignature.create(NativeType.VOID, NativeType.POINTER));
        try {
            InteropLibrary.getUncached().execute(initializeStructs, closure);
        } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
            throw EspressoError.shouldNotReachHere();
        }
        return box[0];
    }
}
Also used : RawPointer(com.oracle.truffle.espresso.ffi.RawPointer) Pointer(com.oracle.truffle.espresso.ffi.Pointer) ArityException(com.oracle.truffle.api.interop.ArityException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Callback(com.oracle.truffle.espresso.jni.Callback) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

Aggregations

ArityException (com.oracle.truffle.api.interop.ArityException)1 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)1 Pointer (com.oracle.truffle.espresso.ffi.Pointer)1 RawPointer (com.oracle.truffle.espresso.ffi.RawPointer)1 Callback (com.oracle.truffle.espresso.jni.Callback)1 DebugCloseable (com.oracle.truffle.espresso.perf.DebugCloseable)1