public class DynamicLinker extends Object
RelinkableCallSite
objects. Users of it (scripting frameworks and language runtimes) have to
create a linker using the DynamicLinkerFactory
and invoke its link method from the invokedynamic bootstrap
methods to set the target of all the call sites in the code they generate. Usual usage would be to create 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 caller, String name, MethodType type) { return dynamicLinker.link(new MonomorphicCallSite(CallSiteDescriptorFactory.create(lookup, name, type))); } }Note how there are three components you will need to provide here:
GuardingDynamicLinker
for your own language. If your runtime doesn't
have its own language and/or object model (i.e. it's a generic scripting shell), you don't need to implement a
dynamic linker; you would simply not invoke the setPrioritizedLinker
method on the factory, or even better,
simply use DefaultBootstrapper
.MonomorphicCallSite
, but you might want to use ChainedCallSite
instead. You'll need to
experiment and decide what fits your language runtime the best. You can subclass either of these or roll your own if
you need to.CallSiteDescriptor
s to your call sites. They are immutable objects that contain
all the information about the call site: the class performing the lookups, the name of the method being invoked, and
the method signature. The library has a default CallSiteDescriptorFactory
for descriptors that you can use,
or you can create your own descriptor classes, especially if you need to add further information (values passed in
additional parameters to the bootstrap method) to them.Modifier and Type | Method and Description |
---|---|
static StackTraceElement |
getLinkedCallSiteLocation()
Returns a stack trace element describing the location of the call site currently being linked on the current
thread.
|
LinkerServices |
getLinkerServices()
Returns the object representing the lower level linker services of this class that are normally exposed to
individual language-specific linkers.
|
static StackTraceElement |
getRelinkedCallSiteLocation()
Deprecated.
Use
getLinkedCallSiteLocation() instead. |
<T extends RelinkableCallSite> |
link(T callSite)
Links an invokedynamic call site.
|
public <T extends RelinkableCallSite> T link(T callSite)
callSite
- the call site to link.public LinkerServices getLinkerServices()
link(RelinkableCallSite)
method, in certain circumstances you might want to use the lower level services
directly; either to lookup specific method handles, to access the type converters, and so on.public static StackTraceElement getLinkedCallSiteLocation()
@Deprecated public static StackTraceElement getRelinkedCallSiteLocation()
getLinkedCallSiteLocation()
instead.Copyright © 2019 Attila Szegedi. All rights reserved.