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