Search in sources :

Example 1 with CallableFromNative

use of com.oracle.truffle.espresso.substitutions.CallableFromNative in project graal by oracle.

the class NativeEnv method intrinsicWrapper.

private Callback intrinsicWrapper(CallableFromNative.Factory factory) {
    int extraArg = (factory.prependEnv()) ? 1 : 0;
    return new Callback(factory.parameterCount() + extraArg, new Callback.Function() {

        @CompilerDirectives.CompilationFinal
        private CallableFromNative subst = null;

        @Override
        public Object call(Object... args) {
            boolean isJni = factory.prependEnv();
            try {
                if (subst == null) {
                    CompilerDirectives.transferToInterpreterAndInvalidate();
                    subst = factory.create(getMeta());
                }
                return subst.invoke(NativeEnv.this, args);
            } catch (EspressoException | StackOverflowError | OutOfMemoryError e) {
                if (isJni) {
                    // This will most likely SOE again. Nothing we can do about that
                    // unfortunately.
                    EspressoException wrappedError = (e instanceof EspressoException) ? (EspressoException) e : (e instanceof StackOverflowError) ? getContext().getStackOverflow() : getContext().getOutOfMemory();
                    jni().setPendingException(wrappedError);
                    return defaultValue(factory.returnType());
                }
                throw e;
            }
        }
    });
}
Also used : EspressoException(com.oracle.truffle.espresso.runtime.EspressoException) CallableFromNative(com.oracle.truffle.espresso.substitutions.CallableFromNative) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Aggregations

TruffleObject (com.oracle.truffle.api.interop.TruffleObject)1 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)1 CallableFromNative (com.oracle.truffle.espresso.substitutions.CallableFromNative)1