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];
}
}
Aggregations