Top Description Inners Fields Constructors Methods
org.graalvm.nativebridge

public final Class JNIConfig

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, java.lang.reflect.Array, .GenericArrayType, .ParameterizedType, .Type, java.util.HashMap, .LinkedList, .List, .ListIterator, .Map, .Objects, java.util.function.Function, .LongBinaryOperator, .LongUnaryOperator, .Supplier, org.graalvm.collections.Pair

A configuration used by the NativeIsolate and classes generated by the native bridge processor.
See Also
GenerateHotSpotToNativeBridge

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
JNIConfig.Builder

A builder class to construct JNIConfig instances.

Field Summary

Modifier and TypeField and Description
private final Map<Class<? extends Annotation>, List<Pair<Class<?>, BinaryMarshaller<?>>>>
private final LongUnaryOperator
private final Map<Type, BinaryMarshaller<?>>
private final LongUnaryOperator
private final LongBinaryOperator
private final LongBinaryOperator
private final Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>>

Constructor Summary

AccessConstructor and Description
pack-priv
JNIConfig(Map<Type, BinaryMarshaller<?>> binaryMarshallers, Map<Class<? extends Annotation>, List<Pair<Class<?>, BinaryMarshaller<?>>>> annotationBinaryMarshallers, LongUnaryOperator attachThreadAction, LongUnaryOperator detachThreadAction, LongBinaryOperator shutDownIsolateAction, LongBinaryOperator releaseNativeObjectAction, Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>> threadLocalFactory)

Method Summary

Modifier and TypeMethod and Description
private static Class<?>
pack-priv long
attachThread(long isolate)

pack-priv boolean
detachThread(long isolateThread)

private static Class<?>
erasure(Type type)

pack-priv Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>>
private static <T> T
lookup(Map<Class<? extends Annotation>, List<Pair<Class<?>, T>>> marshallers, Type type, Class<? extends Annotation> annotationType)

private final BinaryMarshaller<?>
lookupBinaryMarshallerImpl(Type type, Class<? extends Annotation>... annotationTypes)

public final <T> BinaryMarshaller<T>
lookupMarshaller(Class<T>
the parameter or return type.
type
,
Class<? extends Annotation>...
parameter or method annotation types.
annotationTypes
)

Looks up BinaryMarshaller for the type and annotationTypes.

public final <T> BinaryMarshaller<T>
lookupMarshaller(TypeLiteral<T>
the parameter or return type.
parameterizedType
,
Class<? extends Annotation>...
parameter or method annotation types.
annotationTypes
)

Looks up BinaryMarshaller for the parameterizedType and annotationTypes.

public static JNIConfig.Builder
pack-priv boolean
releaseNativeObject(long isolateThread, long handle)

pack-priv boolean
shutDownIsolate(long isolate, long isolateThread)

private static RuntimeException
private static void
verifyAnnotation(Class<? extends Annotation> annotationType)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationBinaryMarshallersback to summary
private final Map<Class<? extends Annotation>, List<Pair<Class<?>, BinaryMarshaller<?>>>> annotationBinaryMarshallers
attachThreadActionback to summary
private final LongUnaryOperator attachThreadAction
binaryMarshallersback to summary
private final Map<Type, BinaryMarshaller<?>> binaryMarshallers
detachThreadActionback to summary
private final LongUnaryOperator detachThreadAction
releaseNativeObjectActionback to summary
private final LongBinaryOperator releaseNativeObjectAction
shutDownIsolateActionback to summary
private final LongBinaryOperator shutDownIsolateAction
threadLocalFactoryback to summary
private final Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>> threadLocalFactory

Constructor Detail

JNIConfigback to summary
pack-priv JNIConfig(Map<Type, BinaryMarshaller<?>> binaryMarshallers, Map<Class<? extends Annotation>, List<Pair<Class<?>, BinaryMarshaller<?>>>> annotationBinaryMarshallers, LongUnaryOperator attachThreadAction, LongUnaryOperator detachThreadAction, LongBinaryOperator shutDownIsolateAction, LongBinaryOperator releaseNativeObjectAction, Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>> threadLocalFactory)

Method Detail

arrayTypeFromComponentTypeback to summary
private static Class<?> arrayTypeFromComponentType(Class<?> componentType)
attachThreadback to summary
pack-priv long attachThread(long isolate)
detachThreadback to summary
pack-priv boolean detachThread(long isolateThread)
erasureback to summary
private static Class<?> erasure(Type type)
getThreadLocalFactoryback to summary
pack-priv Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>> getThreadLocalFactory()
lookupback to summary
private static <T> T lookup(Map<Class<? extends Annotation>, List<Pair<Class<?>, T>>> marshallers, Type type, Class<? extends Annotation> annotationType)
lookupBinaryMarshallerImplback to summary
private final BinaryMarshaller<?> lookupBinaryMarshallerImpl(Type type, Class<? extends Annotation>... annotationTypes)
Annotations
@SafeVarargs
lookupMarshallerback to summary
public final <T> BinaryMarshaller<T> lookupMarshaller(Class<T> type, Class<? extends Annotation>... annotationTypes)

Looks up BinaryMarshaller for the type and annotationTypes. The method first tries to find a marshaller registered for the type and some annotation from annotationTypes. If no such marshaller exists, it tries to find a marshaller registered just for the type. If there is no such a marshaller it throws the UnsupportedOperationException.

Parameters
type:Class<T>

the parameter or return type.

annotationTypes:Class<? extends Annotation>[]

parameter or method annotation types.

Annotations
@SuppressWarnings:unchecked
@SafeVarargs
Exceptions
UnsupportedOperationException:
if there is no registered marshaller for the type.
lookupMarshallerback to summary
public final <T> BinaryMarshaller<T> lookupMarshaller(TypeLiteral<T> parameterizedType, Class<? extends Annotation>... annotationTypes)

Looks up BinaryMarshaller for the parameterizedType and annotationTypes. The method first tries to find a marshaller registered for the parameterizedType and some annotation from annotationTypes. If no such marshaller exists, it tries to find a marshaller registered just for the parameterizedType. If there is no such a marshaller it throws the UnsupportedOperationException.

Parameters
parameterizedType:TypeLiteral<T>

the parameter or return type.

annotationTypes:Class<? extends Annotation>[]

parameter or method annotation types.

Annotations
@SuppressWarnings:unchecked
@SafeVarargs
Exceptions
UnsupportedOperationException:
if there is no registered marshaller for the parameterizedType.
newBuilderback to summary
public static JNIConfig.Builder newBuilder()
releaseNativeObjectback to summary
pack-priv boolean releaseNativeObject(long isolateThread, long handle)
shutDownIsolateback to summary
pack-priv boolean shutDownIsolate(long isolate, long isolateThread)
unsupportedback to summary
private static RuntimeException unsupported(Type type)
verifyAnnotationback to summary
private static void verifyAnnotation(Class<? extends Annotation> annotationType)
org.graalvm.nativebridge back to summary

public final Class JNIConfig.Builder

extends Object
Class Inheritance

A builder class to construct JNIConfig instances.

Field Summary

Modifier and TypeField and Description
private final Map<Class<? extends Annotation>, List<Pair<Class<?>, BinaryMarshaller<?>>>>
private static final LongUnaryOperator
private LongUnaryOperator
private final Map<Type, BinaryMarshaller<?>>
private static final LongUnaryOperator
private LongUnaryOperator
private static final LongBinaryOperator
private LongBinaryOperator
private static final LongBinaryOperator
private LongBinaryOperator
private Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public JNIConfig
build()

Builds the JNIConfig.

public static BinaryMarshaller<StackTraceElement[]>
defaultStackTraceMarshaller()

Returns a BinaryMarshaller for stack trace marshalling.

private static <T> void
insert(Map<Class<? extends Annotation>, List<Pair<Class<?>, T>>> into, Class<?> type, Class<? extends Annotation> annotationType, T marshaller)

public <T> JNIConfig.Builder
registerMarshaller(Class<T>
the type to register BinaryMarshaller for.
type
,
BinaryMarshaller<T>
the marshaller to register.
marshaller
)

Registers a BinaryMarshaller for the type.

public <T> JNIConfig.Builder
registerMarshaller(TypeLiteral<T>
the type to register BinaryMarshaller for.
parameterizedType
,
BinaryMarshaller<T>
the marshaller to register.
marshaller
)

Registers a BinaryMarshaller for the parameterizedType.

public <T> JNIConfig.Builder
registerMarshaller(Class<T>
the type to register BinaryMarshaller for.
type
,
Class<? extends Annotation>
a required annotation to look up the marshaller.
annotationType
,
BinaryMarshaller<T>
the marshaller to register.
marshaller
)

Registers a BinaryMarshaller for the type and annotationType.

public <T> JNIConfig.Builder
registerMarshaller(TypeLiteral<T>
the type to register BinaryMarshaller for.
parameterizedType
,
Class<? extends Annotation>
a required annotation to look up the marshaller.
annotationType
,
BinaryMarshaller<T>
the marshaller to register.
marshaller
)

Registers a BinaryMarshaller for the parameterizedType and annotationType.

public JNIConfig.Builder
setAttachThreadAction(LongUnaryOperator
a LongUnaryOperator that takes an isolate address as a parameter and returns the isolate thread address.
action
)

Registers a callback used by the NativeIsolate to attach the current thread to an isolate.

public JNIConfig.Builder
setDetachThreadAction(LongUnaryOperator
a LongUnaryOperator that takes an isolate thread address as a parameter and returns 0 on success or non-zero in case of an error.
action
)

Registers a callback used by the NativeIsolate to detach the current thread from an isolate.

public JNIConfig.Builder
setNativeThreadLocalFactory(Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>> factory)

Registers a thread local factory whenever the default thread local handling should be overriden.

public JNIConfig.Builder
setReleaseNativeObjectAction(LongBinaryOperator
a LongBinaryOperator that takes an isolate thread address and object handle as parameters and returns 0 on success or non-zero in case of an error.
action
)

Registers a callback used by the NativeObject to free an object in a native image heap referenced by the garbage-collected handle.

public JNIConfig.Builder
setShutDownIsolateAction(LongBinaryOperator
a LongBinaryOperator that takes an isolate address and an isolate thread address as parameters and returns 0 on success or non-zero in case of an error.
action
)

Registers a callback used by the NativeIsolate to tear down the isolate.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationBinaryMarshallersback to summary
private final Map<Class<? extends Annotation>, List<Pair<Class<?>, BinaryMarshaller<?>>>> annotationBinaryMarshallers
ATTACH_UNSUPPORTEDback to summary
private static final LongUnaryOperator ATTACH_UNSUPPORTED
attachThreadActionback to summary
private LongUnaryOperator attachThreadAction
binaryMarshallersback to summary
private final Map<Type, BinaryMarshaller<?>> binaryMarshallers
DETACH_UNSUPPORTEDback to summary
private static final LongUnaryOperator DETACH_UNSUPPORTED
detachThreadActionback to summary
private LongUnaryOperator detachThreadAction
RELEASE_UNSUPPORTEDback to summary
private static final LongBinaryOperator RELEASE_UNSUPPORTED
releaseNativeObjectActionback to summary
private LongBinaryOperator releaseNativeObjectAction
SHUTDOWN_UNSUPPORTEDback to summary
private static final LongBinaryOperator SHUTDOWN_UNSUPPORTED
shutDownIsolateActionback to summary
private LongBinaryOperator shutDownIsolateAction
threadLocalFactoryback to summary
private Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>> threadLocalFactory

Constructor Detail

Builderback to summary
pack-priv Builder()

Method Detail

buildback to summary
public JNIConfig build()

Builds the JNIConfig.

defaultStackTraceMarshallerback to summary
public static BinaryMarshaller<StackTraceElement[]> defaultStackTraceMarshaller()

Returns a BinaryMarshaller for stack trace marshalling.

insertback to summary
private static <T> void insert(Map<Class<? extends Annotation>, List<Pair<Class<?>, T>>> into, Class<?> type, Class<? extends Annotation> annotationType, T marshaller)
registerMarshallerback to summary
public <T> JNIConfig.Builder registerMarshaller(Class<T> type, BinaryMarshaller<T> marshaller)

Registers a BinaryMarshaller for the type.

Parameters
type:Class<T>

the type to register BinaryMarshaller for.

marshaller:BinaryMarshaller<T>

the marshaller to register.

registerMarshallerback to summary
public <T> JNIConfig.Builder registerMarshaller(TypeLiteral<T> parameterizedType, BinaryMarshaller<T> marshaller)

Registers a BinaryMarshaller for the parameterizedType.

Parameters
parameterizedType:TypeLiteral<T>

the type to register BinaryMarshaller for.

marshaller:BinaryMarshaller<T>

the marshaller to register.

registerMarshallerback to summary
public <T> JNIConfig.Builder registerMarshaller(Class<T> type, Class<? extends Annotation> annotationType, BinaryMarshaller<T> marshaller)

Registers a BinaryMarshaller for the type and annotationType.

Parameters
type:Class<T>

the type to register BinaryMarshaller for.

annotationType:Class<? extends Annotation>

a required annotation to look up the marshaller.

marshaller:BinaryMarshaller<T>

the marshaller to register.

registerMarshallerback to summary
public <T> JNIConfig.Builder registerMarshaller(TypeLiteral<T> parameterizedType, Class<? extends Annotation> annotationType, BinaryMarshaller<T> marshaller)

Registers a BinaryMarshaller for the parameterizedType and annotationType.

Parameters
parameterizedType:TypeLiteral<T>

the type to register BinaryMarshaller for.

annotationType:Class<? extends Annotation>

a required annotation to look up the marshaller.

marshaller:BinaryMarshaller<T>

the marshaller to register.

setAttachThreadActionback to summary
public JNIConfig.Builder setAttachThreadAction(LongUnaryOperator action)

Registers a callback used by the NativeIsolate to attach the current thread to an isolate.

Parameters
action:LongUnaryOperator

a LongUnaryOperator that takes an isolate address as a parameter and returns the isolate thread address.

setDetachThreadActionback to summary
public JNIConfig.Builder setDetachThreadAction(LongUnaryOperator action)

Registers a callback used by the NativeIsolate to detach the current thread from an isolate.

Parameters
action:LongUnaryOperator

a LongUnaryOperator that takes an isolate thread address as a parameter and returns 0 on success or non-zero in case of an error.

setNativeThreadLocalFactoryback to summary
public JNIConfig.Builder setNativeThreadLocalFactory(Function<Supplier<NativeIsolateThread>, ThreadLocal<NativeIsolateThread>> factory)

Registers a thread local factory whenever the default thread local handling should be overriden. This can be useful to install a terminating thread local using JVMCI services when needed.

See Also
NativeObject
setReleaseNativeObjectActionback to summary
public JNIConfig.Builder setReleaseNativeObjectAction(LongBinaryOperator action)

Registers a callback used by the NativeObject to free an object in a native image heap referenced by the garbage-collected handle. At some point after a NativeObject is garbage collected, a call to the action is made to release the corresponding object in the native image heap.

Parameters
action:LongBinaryOperator

a LongBinaryOperator that takes an isolate thread address and object handle as parameters and returns 0 on success or non-zero in case of an error.

See Also
NativeObject
setShutDownIsolateActionback to summary
public JNIConfig.Builder setShutDownIsolateAction(LongBinaryOperator action)

Registers a callback used by the NativeIsolate to tear down the isolate.

Parameters
action:LongBinaryOperator

a LongBinaryOperator that takes an isolate address and an isolate thread address as parameters and returns 0 on success or non-zero in case of an error.