public class InvocationPlugins extends Object
InvocationPlugin
s.
Most plugins are registered during initialization (i.e., before
InvocationPlugins.lookupInvocation(ResolvedJavaMethod)
or InvocationPlugins.getBindings(boolean)
is called). These
registrations can be made with InvocationPlugins.Registration
,
InvocationPlugins.register(InvocationPlugin, String, String, Type...)
,
InvocationPlugins.register(InvocationPlugin, Type, String, Type...)
or
InvocationPlugins.registerOptional(InvocationPlugin, Type, String, Type...)
. Initialization is not
thread-safe and so must only be performed by a single thread.
Plugins that are not guaranteed to be made during initialization must use
InvocationPlugins.LateRegistration
.Modifier and Type | Class and Description |
---|---|
static class |
InvocationPlugins.Binding
Associates an
InvocationPlugin with the details of a method it substitutes. |
static class |
InvocationPlugins.InvocationPluginReceiver |
static class |
InvocationPlugins.LateRegistration
Utility for registering plugins after Graal may have been initialized.
|
static class |
InvocationPlugins.Registration
Utility for registration of invocation plugins.
|
static class |
InvocationPlugins.ResolvedJavaSymbol
A symbol for an already resolved method.
|
Modifier and Type | Field and Description |
---|---|
protected InvocationPlugins |
parent
The plugins searched before searching in
this object.
|
Constructor and Description |
---|
InvocationPlugins()
Creates a set of invocation plugins with no parent.
|
InvocationPlugins(InvocationPlugins parent)
Creates a set of invocation plugins.
|
InvocationPlugins(Map<jdk.vm.ci.meta.ResolvedJavaMethod,InvocationPlugin> plugins,
InvocationPlugins parent)
Creates a closed set of invocation plugins for a set of resolved methods.
|
Modifier and Type | Method and Description |
---|---|
void |
addTestPlugins(InvocationPlugins other,
List<org.graalvm.collections.Pair<String,InvocationPlugins.Binding>> ignored)
Extends the plugins in this object with those from
other . |
boolean |
canBeIntrinsified(jdk.vm.ci.meta.ResolvedJavaType declaringClass)
Determines if methods in a given class can have invocation plugins.
|
void |
checkNewNodes(GraphBuilderContext b,
InvocationPlugin plugin,
NodeIterable<Node> newNodes)
Checks a set of nodes added to the graph by an
InvocationPlugin . |
void |
closeRegistration()
Processes deferred registrations and then closes this object for future registration.
|
void |
defer(Runnable deferrable)
Adds a
Runnable for doing registration deferred until the first time
InvocationPlugins.get(ResolvedJavaMethod) or InvocationPlugins.closeRegistration() is called on this object. |
org.graalvm.collections.EconomicMap<String,List<InvocationPlugins.Binding>> |
getBindings(boolean includeParents)
Gets the set of registered invocation plugins.
|
InvocationPlugins |
getParent()
Gets the invocation plugins searched
before searching in this object.
|
boolean |
isEmpty()
Determines if this object currently contains any plugins (in any state of registration).
|
InvocationPlugin |
lookupInvocation(jdk.vm.ci.meta.ResolvedJavaMethod method)
Gets the plugin for a given method.
|
protected void |
register(InvocationPlugin plugin,
boolean isOptional,
boolean allowOverwrite,
Type declaringClass,
String name,
Type... argumentTypes) |
void |
register(InvocationPlugin plugin,
String declaringClass,
String name,
Type... argumentTypes) |
void |
register(InvocationPlugin plugin,
Type declaringClass,
String name,
Type... argumentTypes)
Registers an invocation plugin for a given method.
|
void |
registerOptional(InvocationPlugin plugin,
Type declaringClass,
String name,
Type... argumentTypes)
Registers an invocation plugin for a given, optional method.
|
void |
removeTestPlugins(InvocationPlugins other)
Removes the plugins from
other in this object that were added by
InvocationPlugins.addTestPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins, java.util.List<org.graalvm.collections.Pair<java.lang.String, org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Binding>>) . |
static Class<?> |
resolveClass(String className,
boolean optional)
Resolves a name to a class.
|
static Constructor<?> |
resolveConstructor(Class<?> declaringClass,
InvocationPlugins.Binding binding)
Resolves a given binding to a constructor in a given class.
|
static jdk.vm.ci.meta.ResolvedJavaMethod |
resolveJavaMethod(jdk.vm.ci.meta.ResolvedJavaType declaringClass,
InvocationPlugins.Binding binding)
Same as
InvocationPlugins.resolveMethod(Class, Binding) and
InvocationPlugins.resolveConstructor(Class, Binding) except in terms of ResolvedJavaType and
ResolvedJavaMethod . |
static Method |
resolveMethod(Class<?> declaringClass,
InvocationPlugins.Binding binding)
Resolves a given binding to a method in a given class.
|
static Class<?> |
resolveType(Type type,
boolean optional)
|
String |
toString() |
protected final InvocationPlugins parent
public InvocationPlugins()
public InvocationPlugins(InvocationPlugins parent)
parent
- if non-null, this object will be searched first when looking up pluginspublic InvocationPlugins(Map<jdk.vm.ci.meta.ResolvedJavaMethod,InvocationPlugin> plugins, InvocationPlugins parent)
public void defer(Runnable deferrable)
Runnable
for doing registration deferred until the first time
InvocationPlugins.get(ResolvedJavaMethod)
or InvocationPlugins.closeRegistration()
is called on this object.public boolean canBeIntrinsified(jdk.vm.ci.meta.ResolvedJavaType declaringClass)
declaringClass
- the class to testpublic void addTestPlugins(InvocationPlugins other, List<org.graalvm.collections.Pair<String,InvocationPlugins.Binding>> ignored)
other
. The added plugins should be
removed after the test.
This extension mechanism exists only for tests that want to add extra invocation plugins
after the compiler has been initialized.ignored
- if non-null, the bindings from other
already in this object prior to
calling this method are added to this list. These bindings are not added to this
object.public void removeTestPlugins(InvocationPlugins other)
other
in this object that were added by
InvocationPlugins.addTestPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins, java.util.List<org.graalvm.collections.Pair<java.lang.String, org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Binding>>)
.public void closeRegistration()
public boolean isEmpty()
deferred registrations
, it is assumed that
executing them will result in at least one plugin being registered.protected void register(InvocationPlugin plugin, boolean isOptional, boolean allowOverwrite, Type declaringClass, String name, Type... argumentTypes)
public final void register(InvocationPlugin plugin, Type declaringClass, String name, Type... argumentTypes)
method
.argumentTypes
- the argument types of the method. Element 0 of this array must be the
Class
value for InvocationPlugin.Receiver
iff the method is
non-static. Upon returning, element 0 will have been rewritten to
declaringClass
public final void register(InvocationPlugin plugin, String declaringClass, String name, Type... argumentTypes)
public final void registerOptional(InvocationPlugin plugin, Type declaringClass, String name, Type... argumentTypes)
method
.argumentTypes
- the argument types of the method. Element 0 of this array must be the
Class
value for InvocationPlugin.Receiver
iff the method is
non-static. Upon returning, element 0 will have been rewritten to
declaringClass
public InvocationPlugin lookupInvocation(jdk.vm.ci.meta.ResolvedJavaMethod method)
method
- the method to lookupmethod
or null
if none existspublic org.graalvm.collections.EconomicMap<String,List<InvocationPlugins.Binding>> getBindings(boolean includeParents)
public InvocationPlugins getParent()
public void checkNewNodes(GraphBuilderContext b, InvocationPlugin plugin, NodeIterable<Node> newNodes)
InvocationPlugin
.b
- the graph builder that applied the pluginplugin
- a plugin that was just appliednewNodes
- the nodes added to the graph by plugin
AssertionError
- if any check failpublic static Class<?> resolveClass(String className, boolean optional)
className
- the name of the class to resolveoptional
- if true, resolution failure returns nulloptional
is truepublic static Class<?> resolveType(Type type, boolean optional)
type
- the type to resolveoptional
- if true, resolution failure returns nulloptional
is truepublic static Method resolveMethod(Class<?> declaringClass, InvocationPlugins.Binding binding)
binding
is found and the return types of all the matching
methods form an inheritance chain, the one with the most specific type is returned; otherwise
NoSuchMethodError
is thrown.declaringClass
- the class to search for a method matching binding
declaringClass
matching binding
public static jdk.vm.ci.meta.ResolvedJavaMethod resolveJavaMethod(jdk.vm.ci.meta.ResolvedJavaType declaringClass, InvocationPlugins.Binding binding)
InvocationPlugins.resolveMethod(Class, Binding)
and
InvocationPlugins.resolveConstructor(Class, Binding)
except in terms of ResolvedJavaType
and
ResolvedJavaMethod
.public static Constructor<?> resolveConstructor(Class<?> declaringClass, InvocationPlugins.Binding binding)
declaringClass
- the class to search for a constructor matching binding
declaringClass
matching binding