Class LibraryFactory<T extends Library>
resolve(Class).
Library instances are either automatically dispatched or manually dispatched.
Automatically dispatched libraries always return true for
Library.accepts(Object) therefore they can be used with changing receiver values.
Manually dispatched libraries are created once for a receiver and are only valid as long as
accepts returns true. Once accepts was checked for
an individual value, it is guaranteed that the accepts continues to return true. It is therefore
not necessary to call accepts again for multiple message invocations. To create automatically
dispatched versions of libraries use either createDispatched(int) or
getUncached(). For calling manually dispatched libraries it is recommended to use
CachedLibrary instead using the factory manually.
Library instances are either cached or uncached. Cached instances are library
instances designed to be used in ASTs. Cached instances are typically adoptable and store additional profiling information for the cached export. This allows to
generate call-site specific profiling information for libray calls. Before a cached instance can
be used it must be adopted by a parent node.
Uncached versions are designed to be used from slow-path runtime methods or whenever call-site
specific profiling is not desired. All uncached versions of a library are annotated with
@TruffleBoundary. Uncached instances always return
false for Node.isAdoptable().
This class is intended to be sub-classed by generated code only. Do not sub-class
LibraryFactory manually.
- Since:
- 19.0
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLibraryFactory(Class<T> libraryClass, List<Message> messages) Deprecated.new versions of the library generator won't use this constructor anymoreprotectedLibraryFactory(Class<T> libraryClass, List<Message> messages, boolean dynamicDispatchEnabled) Constructor for generated subclasses. -
Method Summary
Modifier and TypeMethodDescriptionprotected static booleanassertAdopted(Node node) Internal method for generated code only.final TCreates a new manually dispatched cached library for a given receiver.protected final TcreateAOT(LibraryExport<T> lib) Creates an AOT version for a library export.protected TcreateAssertions(T delegate) Creates an assertion version of this library.protected TcreateDelegate(T original) Creates a delegate version of a library.final TcreateDispatched(int limit) Creates a new cached and automatically dispatched library given a limit.protected abstract TcreateDispatchImpl(int limit) Creates a cached automatically dispatched version of this library.protected FinalBitSetcreateMessageBitSet(Message... enabledMessages) Creates a final bitset of the given messages.protected abstract TCreates a proxy version of this library.protected abstract TCreates a uncached automatically dispatched version of this library.protected abstract ObjectgenericDispatch(Library library, Object receiver, Message message, Object[] arguments, int parameterOffset) Performs a generic dispatch for this library.protected final List<LibraryExport<T>> Returns a list of ordered exports to be used for AOT preparation if supported.protected abstract Class<?> getDefaultClass(Object receiver) Returns default exported used for a given receiver.protected static <T extends Library>
TgetDelegateLibrary(T lib, Object delegate) Returns the delegated library to use when messages are delegated.protected MethodHandles.LookupReturns a method handle lookup used to initialize the library class.Returns an unmodifiable list of messages that this library provides.final TReturns an uncached automatically dispatched version of the library.final TgetUncached(Object receiver) Returns an uncached manually dispatched library for a given receiver.protected static booleanisDelegated(Library lib, int index) Returnstrueif a message is delegated, otherwisefalse.protected static ObjectreadDelegate(Library lib, Object receiver) Reads the delegate for a receiver.protected static <T extends Library>
voidregister(Class<T> libraryClass, LibraryFactory<T> library) static <T extends Library>
LibraryFactory<T> Looks up the resolved library instance for a library class.toString()
-
Constructor Details
-
LibraryFactory
Deprecated.new versions of the library generator won't use this constructor anymoreConstructor for generated subclasses. Do not sub-classLibraryFactorymanually.- Since:
- 19.0
-
LibraryFactory
protected LibraryFactory(Class<T> libraryClass, List<Message> messages, boolean dynamicDispatchEnabled) Constructor for generated subclasses. Do not sub-classLibraryFactorymanually.- Since:
- 25.1
-
-
Method Details
-
createDispatched
Creates a new cached and automatically dispatched library given a limit. The limit specifies the number of cached instances that will be automatically dispatched until the dispatched library rewrites itself to an uncached version of the library. If the limit is zero then the library will use an uncached version from the start. Negative values will throw anIllegalArgumentException. It is discouraged to useInteger.MAX_VALUEas parameter to this method. Reasonable values for the limit range from zero to ten.If possible it is recommended to not use this method manually but to use
CachedLibraryinstead.Whenever the limit is reached for a node and the uncached version is in use, the current enclosing node will be available to the uncached library export of the library using
EncapsulatingNodeReference.- Since:
- 19.0
- See Also:
-
create
Creates a new manually dispatched cached library for a given receiver. The receiver must not benull. The returned library must be adopted before used. For calling manually dispatched libraries it is recommended to useCachedLibraryinstead using the factory manually.- Since:
- 19.0
- See Also:
-
createAOT
Creates an AOT version for a library export. Intended to be used by generated code, do not use manually.- Since:
- 21.2
-
getUncached
Returns an uncached automatically dispatched version of the library. This is version of a library is used for slow-path calls.- Since:
- 19.0
-
getUncached
-
getMessages
Returns an unmodifiable list of messages that this library provides. The returned list is ordered bymessage ids.- Since:
- 22.0
-
assertAdopted
Internal method for generated code only.- Since:
- 23.1
-
createDispatchImpl
Creates a cached automatically dispatched version of this library. An implementation for this method is generated, do not implement or call manually.- Since:
- 19.0
-
getAOTExports
Returns a list of ordered exports to be used for AOT preparation if supported. Intended to be used by generated code only, do not use manually.- Since:
- 21.2
-
createUncachedDispatch
Creates a uncached automatically dispatched version of this library. An implementation for this method is generated, do not implement or call manually.- Since:
- 19.0
-
createProxy
Creates a proxy version of this library. A proxy version is responsible for dispatching to reflective implementations of messages. An implementation for this method is generated, do not implement manually.- Since:
- 19.0
-
createDelegate
-
createAssertions
-
getDefaultClass
-
getLookup
Returns a method handle lookup used to initialize the library class.- Since:
- 24.0
-
genericDispatch
protected abstract Object genericDispatch(Library library, Object receiver, Message message, Object[] arguments, int parameterOffset) throws Exception Performs a generic dispatch for this library. An implementation for this method is generated, do not implement manually.- Throws:
Exception- Since:
- 19.0
-
createMessageBitSet
Creates a final bitset of the given messages. Uses an internal index for the messages. An implementation for this method is generated, do not implement manually.- Since:
- 20.0
-
isDelegated
Returnstrueif a message is delegated, otherwisefalse. Intended to be used by generated code only, do not use manually.- Since:
- 20.0
-
readDelegate
-
getDelegateLibrary
-
resolve
Looks up the resolved library instance for a library class. If a library class was not yet loaded it will be initialized automatically. If the passed library class is not a valid library then aIllegalArgumentExceptionis thrown.- Since:
- 19.0
- See Also:
-
register
protected static <T extends Library> void register(Class<T> libraryClass, LibraryFactory<T> library) - Since:
- 19.0
-
toString
-