RelinkableCallSite objects. A dynamic linker is a main
objects when using Dynalink, it coordinates linking of call sites with
linkers of available language runtimes that are represented by
GuardingDynamicLinker objects (you only need to deal with these if
you are yourself implementing a language runtime with its own object model
and/or type conversions). To use Dynalink, you have to create one or more
dynamic linkers using a DynamicLinkerFactory. Subsequently, you need
to invoke its link(RelinkableCallSite) method from
invokedynamic bootstrap methods to let it manage all the call sites
they create. Usual usage would be to create at least one class per language
runtime to contain one linker instance as:
class MyLanguageRuntime {
private static final GuardingDynamicLinker myLanguageLinker = new MyLanguageLinker();
private static final DynamicLinker dynamicLinker = createDynamicLinker();
private static DynamicLinker createDynamicLinker() {
final DynamicLinkerFactory factory = new DynamicLinkerFactory();
factory.setPrioritizedLinker(myLanguageLinker);
return factory.createLinker();
}
public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type) {
return dynamicLinker.link(
new SimpleRelinkableCallSite(
new CallSiteDescriptor(lookup, parseOperation(name), type)));
}
private static Operation parseOperation(String name) {
...
}
}
The above setup of one static linker instance is often too simple. You will
often have your language runtime have a concept of some kind of
"context class loader" and you will want to create one dynamic linker per
such class loader, to ensure it incorporates linkers for all other language
runtimes visible to that class loader (see
DynamicLinkerFactory#setClassLoader(ClassLoader)).
There are three components you need to provide in the above example:
GuardingDynamicLinker for your own
language. If your runtime doesn't have its own object model or type
conversions, you don't need to implement a GuardingDynamicLinker; you
would simply not invoke the setPrioritizedLinker method on the factory.SimpleRelinkableCallSite, but you might want to use
ChainedCallSite instead. You'll need to experiment and decide what
fits your runtime the best. You can further subclass either of these or
implement your own.CallSiteDescriptors to your call sites.
They are immutable objects that contain all the information about the call
site: the class performing the lookups, the operation being invoked, and the
method signature. You will have to supply your own scheme to encode and
decode operations in the call site name or static parameters, that is why
in the above example the parseOperation method is left unimplemented.| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final String | |
| private static final String | |
| private static final String | |
| private final LinkerServices | |
| private final GuardedInvocationTransformer | |
| private static final MethodHandle | |
| private static final String | |
| private static final StackWalker | |
| private final boolean | |
| private final int |
| Access | Constructor and Description |
|---|---|
| pack-priv | DynamicLinker(final LinkerServices
the linkerServices used by the linker, created by the factory. linkerServices, final GuardedInvocationTransformer prelinkTransformer, final boolean syncOnRelink, final int unstableRelinkThreshold)Creates a new dynamic linker. |
| Modifier and Type | Method and Description |
|---|---|
| private MethodHandle | |
| public static StackTraceElement | Returns: a stack trace element describing the location of the call site currently being linked, or null if it is not invoked while a call site is being linked.Returns a stack trace element describing the location of the
|
| public LinkerServices | Returns: the object representing the linker services of this class.Returns the object representing the linker services of this class that
are normally exposed to individual |
| private static boolean | Returns: true if this frame represents MethodHandleNatives.linkCallSite().the frame frameReturns |
| private static boolean | Returns: true if this frame represents DynamicLinker.relink().the frame frameReturns |
| public < the particular subclass of T extends RelinkableCallSite> TRelinkableCallSite for
which to create a link. | Returns: the callSite, for easy call chaining.the call site to link. callSite)Links an invokedynamic call site. |
| private MethodHandle | Returns: return the method handle for the invocationthe call site itself callSite, final int relinkCount, final Object... arguments to the invocation arguments)Relinks a call site conforming to the invocation arguments. |
| private static boolean |
| CLASS_NAME | back to summary |
|---|---|
| private static final String CLASS_NAME | |
| INITIAL_LINK_CLASS_NAME | back to summary |
|---|---|
| private static final String INITIAL_LINK_CLASS_NAME | |
| INITIAL_LINK_METHOD_NAME | back to summary |
|---|---|
| private static final String INITIAL_LINK_METHOD_NAME | |
| INVOKE_PACKAGE_PREFIX | back to summary |
|---|---|
| private static final String INVOKE_PACKAGE_PREFIX | |
| linkerServices | back to summary |
|---|---|
| private final LinkerServices linkerServices | |
| prelinkTransformer | back to summary |
|---|---|
| private final GuardedInvocationTransformer prelinkTransformer | |
| RELINK | back to summary |
|---|---|
| private static final MethodHandle RELINK | |
| RELINK_METHOD_NAME | back to summary |
|---|---|
| private static final String RELINK_METHOD_NAME | |
| stackWalker | back to summary |
|---|---|
| private static final StackWalker stackWalker | |
| syncOnRelink | back to summary |
|---|---|
| private final boolean syncOnRelink | |
| unstableRelinkThreshold | back to summary |
|---|---|
| private final int unstableRelinkThreshold | |
| DynamicLinker | back to summary |
|---|---|
| pack-priv DynamicLinker(final LinkerServices linkerServices, final GuardedInvocationTransformer prelinkTransformer, final boolean syncOnRelink, final int unstableRelinkThreshold) Creates a new dynamic linker.
| |
| createRelinkAndInvokeMethod | back to summary |
|---|---|
| private MethodHandle createRelinkAndInvokeMethod(final RelinkableCallSite callSite, final int relinkCount) | |
| getLinkedCallSiteLocation | back to summary |
|---|---|
| public static StackTraceElement getLinkedCallSiteLocation() Returns a stack trace element describing the location of the
| |
| getLinkerServices | back to summary |
|---|---|
| public LinkerServices getLinkerServices() Returns the object representing the linker services of this class that
are normally exposed to individual
| |
| isInitialLinkFrame | back to summary |
|---|---|
| private static boolean isInitialLinkFrame(final StackWalker. Returns
| |
| isRelinkFrame | back to summary |
|---|---|
| private static boolean isRelinkFrame(final StackWalker. Returns
| |
| link | back to summary |
|---|---|
| public <T extends RelinkableCallSite> T link(final T callSite) Links an invokedynamic call site. It will install a method handle into the call site that invokes the relinking mechanism of this linker. Next time the call site is invoked, it will be linked for the actual arguments it was invoked with.
| |
| relink | back to summary |
|---|---|
| private MethodHandle relink(final RelinkableCallSite callSite, final int relinkCount, final Object... arguments) throws Exception Relinks a call site conforming to the invocation arguments.
| |
| testFrame | back to summary |
|---|---|
| private static boolean testFrame(final StackWalker. | |