Top Description Inners Fields Constructors Methods
org.graalvm.nativebridge

public final Class ForeignException

extends RuntimeException
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
org.graalvm.jniutils.JNICalls, .JNI.JByteArray, .JNI.JClass, .JNI.JMethodID, .JNI.JNIEnv, .JNI.JObject, .JNI.JThrowable, .JNI.JValue, .JNIExceptionWrapper, .JNIUtil, org.graalvm.nativebridge.BinaryOutput.ByteArrayBinaryOutput, org.graalvm.nativeimage.StackValue, org.graalvm.nativeimage.c.type.CTypeConversion

This exception is used to transfer a local exception over the boundary. The local exception is marshaled, passed over the boundary as a ForeignException, unmarshalled, and re-thrown.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final ForeignException.JNIMethodResolver
pack-priv static final byte
pack-priv static final byte
private static volatile JNICalls
private final byte
private static final ForeignException
MARSHALLING_FAILED

Pre-allocated ForeignException for double failure.

private static final ThreadLocal<ForeignException>
private final byte[]
private static final ForeignException.JNIMethodResolver
pack-priv static final byte

Constructor Summary

AccessConstructor and Description
private
ForeignException(byte[] rawData, byte kind, boolean writableStackTrace)

Method Summary

Modifier and TypeMethod and Description
private static JNI.JThrowable
private static JNI.JByteArray
private static void
pack-priv static ForeignException
create(byte[] rawData, byte kind)

private static JNICalls
public static ForeignException
forThrowable(Throwable
the exception that should be passed over the boundary
exception
,
BinaryMarshaller<? super Throwable>
the marshaller to marshall the exception
marshaller
)

Creates a ForeignException by marshaling the exception using marshaller.

public static JNICalls
getJNICalls()

Returns the JNICalls transferring the ForeignException thrown in the HotSpot to an isolate.

public static StackTraceElement[]

Returns:

the stack trace combining both local and foreign stack trace elements
mergeStackTrace
(StackTraceElement[]
the stack trace marshalled into the ForeignException
foreignExceptionStack
)

Merges foreign stack trace marshalled in the ForeignException with local ForeignException's stack trace.

private static <T extends Throwable> T
public RuntimeException
throwOriginalException(BinaryMarshaller<? extends Throwable>
the marshaller to unmarshal the exception
marshaller
)

Unmarshalls the foreign exception transferred by this ForeignException and re-throws it.

public void
throwUsingJNI(JNI.JNIEnv env)

Re-throws this exception in host using a JNI API.

pack-priv byte[]

Field Detail

CreateForeignExceptionback to summary
private static final ForeignException.JNIMethodResolver CreateForeignException
GUEST_TO_HOSTback to summary
pack-priv static final byte GUEST_TO_HOST
HOST_TO_GUESTback to summary
pack-priv static final byte HOST_TO_GUEST
jniCallsback to summary
private static volatile JNICalls jniCalls
kindback to summary
private final byte kind
MARSHALLING_FAILEDback to summary
private static final ForeignException MARSHALLING_FAILED

Pre-allocated ForeignException for double failure.

pendingExceptionback to summary
private static final ThreadLocal<ForeignException> pendingException
rawDataback to summary
private final byte[] rawData
ToByteArrayback to summary
private static final ForeignException.JNIMethodResolver ToByteArray
UNDEFINEDback to summary
pack-priv static final byte UNDEFINED

Constructor Detail

ForeignExceptionback to summary
private ForeignException(byte[] rawData, byte kind, boolean writableStackTrace)

Method Detail

callCreateForeignExceptionback to summary
private static JNI.JThrowable callCreateForeignException(JNI.JNIEnv env, JNI.JByteArray rawValue)
callToByteArrayback to summary
private static JNI.JByteArray callToByteArray(JNI.JNIEnv env, JNI.JObject p0)
clearPendingExceptionback to summary
private static void clearPendingException()
createback to summary
pack-priv static ForeignException create(byte[] rawData, byte kind)
createJNICallsback to summary
private static JNICalls createJNICalls()
forThrowableback to summary
public static ForeignException forThrowable(Throwable exception, BinaryMarshaller<? super Throwable> marshaller)

Creates a ForeignException by marshaling the exception using marshaller. This method is intended to be called by the code generated by the bridge processor. It's still possible to use it by the hand-written code, but it's recommended to use the bridge processor.

Parameters
exception:Throwable

the exception that should be passed over the boundary

marshaller:BinaryMarshaller<? super Throwable>

the marshaller to marshall the exception

getJNICallsback to summary
public static JNICalls getJNICalls()

Returns the JNICalls transferring the ForeignException thrown in the HotSpot to an isolate. This method is intended to be called by the code generated by the bridge processor. It's still possible to use it by the hand-written code, but it's recommended to use the bridge processor.

mergeStackTraceback to summary
public static StackTraceElement[] mergeStackTrace(StackTraceElement[] foreignExceptionStack)

Merges foreign stack trace marshalled in the ForeignException with local ForeignException's stack trace. This is a helper method for throwable marshallers to merge local and foreign stack traces. Typical usage looks like this:

final class DefaultThrowableMarshaller implements BinaryMarshaller<Throwable> {
    private final BinaryMarshaller<StackTraceElement[]> stackTraceMarshaller = MyJNIConfig.getDefault().lookupMarshaller(StackTraceElement[].class);

    @Override
    public Throwable read(BinaryInput in) {
        String foreignExceptionClassName = in.readUTF();
        String foreignExceptionMessage = in.readUTF();
        StackTraceElement[] foreignExceptionStack = stackTraceMarshaller.read(in);
        RuntimeException exception = new RuntimeException(foreignExceptionClassName + ": " + foreignExceptionMessage);
        exception.setStackTrace(ForeignException.mergeStackTrace(foreignExceptionStack));
        return exception;
    }

    @Override
    public void write(BinaryOutput out, Throwable object) {
        out.writeUTF(object.getClass().getName());
        out.writeUTF(object.getMessage());
        stackTraceMarshaller.write(out, object.getStackTrace());
    }
}
Parameters
foreignExceptionStack:StackTraceElement[]

the stack trace marshalled into the ForeignException

Returns:StackTraceElement[]

the stack trace combining both local and foreign stack trace elements

silenceExceptionback to summary
private static <T extends Throwable> T silenceException(Class<T> type, Throwable t) throws Throwable-:T
Annotations
@SuppressWarnings:unchecked, unused
throwOriginalExceptionback to summary
public RuntimeException throwOriginalException(BinaryMarshaller<? extends Throwable> marshaller)

Unmarshalls the foreign exception transferred by this ForeignException and re-throws it. This method is intended to be called by the code generated by the bridge processor. It's still possible to use it by the hand-written code, but it's recommended to use the bridge processor.

Parameters
marshaller:BinaryMarshaller<? extends Throwable>

the marshaller to unmarshal the exception

throwUsingJNIback to summary
public void throwUsingJNI(JNI.JNIEnv env)

Re-throws this exception in host using a JNI API. This method is intended to be called by the code generated by the bridge processor. It's still possible to use it by the hand-written code, but it's recommended to use the bridge processor.

toByteArrayback to summary
pack-priv byte[] toByteArray()
org.graalvm.nativebridge back to summary

private final Class ForeignException.JNIMethodResolver

extends Object
implements JNIMethod
Class Inheritance
All Implemented Interfaces
org.graalvm.jniutils.JNICalls.JNIMethod

Field Summary

Modifier and TypeField and Description
private volatile JNI.JClass
private volatile JNI.JMethodID
private final String
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
JNIMethodResolver(String methodName, String methodSignature)

Method Summary

Modifier and TypeMethod and Description
public String
getDisplayName()

Implements org.graalvm.jniutils.JNICalls.JNIMethod.getDisplayName.

Returns a method display name used for logging.

pack-priv JNI.JClass
public JNI.JMethodID
pack-priv ForeignException.JNIMethodResolver
resolve(JNI.JNIEnv jniEnv)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entryPointsClassback to summary
private volatile JNI.JClass entryPointsClass
methodIdback to summary
private volatile JNI.JMethodID methodId
methodNameback to summary
private final String methodName
methodSignatureback to summary
private final String methodSignature

Constructor Detail

JNIMethodResolverback to summary
pack-priv JNIMethodResolver(String methodName, String methodSignature)

Method Detail

getDisplayNameback to summary
public String getDisplayName()

Implements org.graalvm.jniutils.JNICalls.JNIMethod.getDisplayName.

Doc from org.graalvm.jniutils.JNICalls.JNIMethod.getDisplayName.

Returns a method display name used for logging.

Annotations
@Override
getEntryPointsback to summary
pack-priv JNI.JClass getEntryPoints(JNI.JNIEnv env)
getJMethodIDback to summary
public JNI.JMethodID getJMethodID()

Implements org.graalvm.jniutils.JNICalls.JNIMethod.getJMethodID.

Doc from org.graalvm.jniutils.JNICalls.JNIMethod.getJMethodID.

Returns a method JNI JMethodID.

Annotations
@Override
resolveback to summary
pack-priv ForeignException.JNIMethodResolver resolve(JNI.JNIEnv jniEnv)