public class ReplacementsImpl extends Object implements Replacements, InlineInvokePlugin
Modifier and Type | Class and Description |
---|---|
protected class |
ReplacementsImpl.ClassReplacements
Encapsulates method and macro substitutions for a single class.
|
static class |
ReplacementsImpl.GraphMaker
Creates and preprocesses a graph for a replacement.
|
(package private) static class |
ReplacementsImpl.JavaSignature |
InlineInvokePlugin.InlineInfo
Modifier and Type | Field and Description |
---|---|
private Map<String,AtomicReference<ReplacementsImpl.ClassReplacements>> |
classReplacements
Per-class replacements.
|
private GraphBuilderConfiguration.Plugins |
graphBuilderPlugins |
protected ConcurrentMap<ResolvedJavaMethod,StructuredGraph> |
graphs
The preprocessed replacement graphs.
|
private Map<String,Class<?>[]> |
internalNameToSubstitutionClasses |
private static int |
MAX_GRAPH_INLINING_DEPTH |
Providers |
providers |
private static DebugTimer |
SnippetPreparationTime |
SnippetReflectionProvider |
snippetReflection |
private Map<String,SnippetTemplateCache> |
snippetTemplateCache |
TargetDescription |
target |
private static boolean |
UseSnippetGraphCache |
Constructor and Description |
---|
ReplacementsImpl(Providers providers,
SnippetReflectionProvider snippetReflection,
TargetDescription target) |
Modifier and Type | Method and Description |
---|---|
private static boolean |
checkSubstitutionInternalName(Class<?> substitutions,
String internalName) |
protected ReplacementsImpl.GraphMaker |
createGraphMaker(ResolvedJavaMethod substitute,
ResolvedJavaMethod original)
Can be overridden to return an object that specializes various parts of graph preprocessing.
|
Collection<ResolvedJavaMethod> |
getAllReplacements()
Returns all methods that are currently registered as method/macro substitution or as a
snippet.
|
protected ReplacementsImpl.ClassReplacements |
getClassReplacements(String internalName)
Gets the method and macro replacements for a given class.
|
GraphBuilderConfiguration.Plugins |
getGraphBuilderPlugins() |
private SubstitutionGuard |
getGuard(Class<? extends SubstitutionGuard> guardClass) |
StructuredGraph |
getSnippet(ResolvedJavaMethod method,
Object[] args)
Gets the snippet graph derived from a given method.
|
StructuredGraph |
getSnippet(ResolvedJavaMethod method,
ResolvedJavaMethod recursiveEntry,
Object[] args)
Gets the snippet graph derived from a given method.
|
<T extends SnippetTemplateCache> |
getSnippetTemplateCache(Class<T> templatesClass)
Get snippet templates that were registered with
Replacements.registerSnippetTemplateCache(SnippetTemplateCache) . |
StructuredGraph |
getSubstitution(ResolvedJavaMethod original,
boolean fromBytecodeOnly,
int invokeBci)
Gets a graph that is a substitution for a given method.
|
ResolvedJavaMethod |
getSubstitutionMethod(ResolvedJavaMethod original)
Gets a method that is a substitution for a given method.
|
protected boolean |
hasGenericInvocationPluginAnnotation(ResolvedJavaMethod method) |
boolean |
hasSubstitution(ResolvedJavaMethod method,
boolean fromBytecodeOnly,
int callerBci)
Determines if there is a substitution
graph for a given method.
|
StructuredGraph |
makeGraph(ResolvedJavaMethod method,
Object[] args,
ResolvedJavaMethod original)
Creates a preprocessed graph for a snippet or method substitution.
|
void |
notifyNotInlined(GraphBuilderContext b,
ResolvedJavaMethod method,
Invoke invoke)
Notifies this plugin of the
Invoke node created for a method that was not inlined per
InlineInvokePlugin.shouldInlineInvoke(com.oracle.graal.graphbuilderconf.GraphBuilderContext, jdk.internal.jvmci.meta.ResolvedJavaMethod, com.oracle.graal.nodes.ValueNode[], jdk.internal.jvmci.meta.JavaType) . |
private static String |
originalName(Method substituteMethod,
String methodSubstitution) |
protected ResolvedJavaMethod |
registerMethodSubstitution(ReplacementsImpl.ClassReplacements cr,
Executable originalMember,
Method substituteMethod)
Registers a method substitution.
|
void |
registerSnippet(ResolvedJavaMethod method)
Registers a method as snippet.
|
void |
registerSnippetTemplateCache(SnippetTemplateCache templates)
Register snippet templates.
|
void |
registerSubstitutions(Type original,
Class<?> substitutionClass)
Registers all the method substitutions defined by a given
class.
|
private static Class<?> |
resolveClass(JavaType type) |
static Class<?> |
resolveClass(String className,
boolean optional)
Resolves a name to a class.
|
void |
setGraphBuilderPlugins(GraphBuilderConfiguration.Plugins plugins) |
InlineInvokePlugin.InlineInfo |
shouldInlineInvoke(GraphBuilderContext b,
ResolvedJavaMethod method,
ValueNode[] args,
JavaType returnType)
Determines whether a given method should be inlined based on whether it has a substitution or
whether the inlining context is already within a substitution.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getSubstitution, hasSubstitution
notifyAfterInline, notifyBeforeInline
public final SnippetReflectionProvider snippetReflection
public final TargetDescription target
private GraphBuilderConfiguration.Plugins graphBuilderPlugins
protected final ConcurrentMap<ResolvedJavaMethod,StructuredGraph> graphs
private static final int MAX_GRAPH_INLINING_DEPTH
private final Map<String,AtomicReference<ReplacementsImpl.ClassReplacements>> classReplacements
private final Map<String,Class<?>[]> internalNameToSubstitutionClasses
private final Map<String,SnippetTemplateCache> snippetTemplateCache
private static final boolean UseSnippetGraphCache
private static final DebugTimer SnippetPreparationTime
public ReplacementsImpl(Providers providers, SnippetReflectionProvider snippetReflection, TargetDescription target)
public void setGraphBuilderPlugins(GraphBuilderConfiguration.Plugins plugins)
public GraphBuilderConfiguration.Plugins getGraphBuilderPlugins()
protected boolean hasGenericInvocationPluginAnnotation(ResolvedJavaMethod method)
public InlineInvokePlugin.InlineInfo shouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, JavaType returnType)
shouldInlineInvoke
in interface InlineInvokePlugin
b
- the contextmethod
- the target method of an invokeargs
- the arguments to the invokereturnType
- the return type derived from method
's signaturemethod
is to be inlined or null if it should not be
inlined based on substitution related criteriapublic void notifyNotInlined(GraphBuilderContext b, ResolvedJavaMethod method, Invoke invoke)
InlineInvokePlugin
Invoke
node created for a method that was not inlined per
InlineInvokePlugin.shouldInlineInvoke(com.oracle.graal.graphbuilderconf.GraphBuilderContext, jdk.internal.jvmci.meta.ResolvedJavaMethod, com.oracle.graal.nodes.ValueNode[], jdk.internal.jvmci.meta.JavaType)
.notifyNotInlined
in interface InlineInvokePlugin
b
- the contextmethod
- the method that was not inlinedinvoke
- the invoke node created for the call to method
protected ReplacementsImpl.ClassReplacements getClassReplacements(String internalName)
internalName
the first time
this method is called for internalName
.public StructuredGraph getSnippet(ResolvedJavaMethod method, Object[] args)
Replacements
getSnippet
in interface Replacements
args
- arguments to the snippet if available, otherwise null
method
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args)
Replacements
getSnippet
in interface Replacements
recursiveEntry
- if the snippet contains a call to this method, it's considered as
recursive call and won't be processed for substitutions.args
- arguments to the snippet if available, otherwise null
method
public void registerSnippet(ResolvedJavaMethod method)
Replacements
registerSnippet
in interface Replacements
public StructuredGraph getSubstitution(ResolvedJavaMethod original, boolean fromBytecodeOnly, int invokeBci)
Replacements
getSubstitution
in interface Replacements
fromBytecodeOnly
- only return a graph created by parsing the bytecode of another methodinvokeBci
- the call site BCI if this request is made for inlining a substitute
otherwise -1
method
private SubstitutionGuard getGuard(Class<? extends SubstitutionGuard> guardClass)
private static boolean checkSubstitutionInternalName(Class<?> substitutions, String internalName)
public void registerSubstitutions(Type original, Class<?> substitutionClass)
Replacements
registerSubstitutions
in interface Replacements
original
- the original class for which substitutions are being registered. This must be
the same type denoted by the ClassSubstitution
annotation on
substitutions
. It is required here so that an implementation is not forced
to read annotations during registration.substitutionClass
- the class defining substitutions for original
. This class must
be annotated with ClassSubstitution
.protected ResolvedJavaMethod registerMethodSubstitution(ReplacementsImpl.ClassReplacements cr, Executable originalMember, Method substituteMethod)
originalMember
- a method or constructor being substitutedsubstituteMethod
- the substitute methodpublic StructuredGraph makeGraph(ResolvedJavaMethod method, Object[] args, ResolvedJavaMethod original)
method
- the snippet or method substitution for which a graph will be createdargs
- original
- the original method if method
is a substitution otherwise nullprotected ReplacementsImpl.GraphMaker createGraphMaker(ResolvedJavaMethod substitute, ResolvedJavaMethod original)
private static String originalName(Method substituteMethod, String methodSubstitution)
public static Class<?> resolveClass(String className, boolean optional)
className
- the name of the class to resolveoptional
- if true, resolution failure returns nulloptional
is trueprivate static Class<?> resolveClass(JavaType type)
public Collection<ResolvedJavaMethod> getAllReplacements()
Replacements
getAllReplacements
in interface Replacements
public boolean hasSubstitution(ResolvedJavaMethod method, boolean fromBytecodeOnly, int callerBci)
Replacements
hasSubstitution
in interface Replacements
fromBytecodeOnly
- only consider graphs created by parsing the bytecode of another
methodcallerBci
- the call site BCI if this request is made for inlining a substitute
otherwise -1
method
public ResolvedJavaMethod getSubstitutionMethod(ResolvedJavaMethod original)
Replacements
getSubstitutionMethod
in interface Replacements
method
public void registerSnippetTemplateCache(SnippetTemplateCache templates)
Replacements
registerSnippetTemplateCache
in interface Replacements
public <T extends SnippetTemplateCache> T getSnippetTemplateCache(Class<T> templatesClass)
Replacements
Replacements.registerSnippetTemplateCache(SnippetTemplateCache)
.getSnippetTemplateCache
in interface Replacements