< prev index next >
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/ReplacementsImpl.java
Print this page
*** 22,31 ****
--- 22,32 ----
*/
package org.graalvm.compiler.replacements;
+ import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE;
import static org.graalvm.compiler.core.common.GraalOptions.UseSnippetGraphCache;
import static org.graalvm.compiler.debug.DebugContext.DEFAULT_LOG_STREAM;
import static org.graalvm.compiler.java.BytecodeParserOptions.InlineDuringParsing;
import static org.graalvm.compiler.java.BytecodeParserOptions.InlineIntrinsicsDuringParsing;
import static org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createIntrinsicInlineInfo;
*** 70,79 ****
--- 71,81 ----
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins;
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext;
+ import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderPlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
*** 96,106 ****
import jdk.vm.ci.meta.ResolvedJavaType;
public class ReplacementsImpl implements Replacements, InlineInvokePlugin {
protected final OptionValues options;
! public final Providers providers;
public final SnippetReflectionProvider snippetReflection;
public final TargetDescription target;
private GraphBuilderConfiguration.Plugins graphBuilderPlugins;
private final DebugHandlersFactory debugHandlersFactory;
--- 98,117 ----
import jdk.vm.ci.meta.ResolvedJavaType;
public class ReplacementsImpl implements Replacements, InlineInvokePlugin {
protected final OptionValues options;
!
! public Providers getProviders() {
! return providers;
! }
!
! public void setProviders(Providers providers) {
! this.providers = providers.copyWith(this);
! }
!
! protected Providers providers;
public final SnippetReflectionProvider snippetReflection;
public final TargetDescription target;
private GraphBuilderConfiguration.Plugins graphBuilderPlugins;
private final DebugHandlersFactory debugHandlersFactory;
*** 128,143 ****
@Override
public GraphBuilderConfiguration.Plugins getGraphBuilderPlugins() {
return graphBuilderPlugins;
}
! protected boolean hasGeneratedInvocationPluginAnnotation(ResolvedJavaMethod method) {
! return method.getAnnotation(Node.NodeIntrinsic.class) != null || method.getAnnotation(Fold.class) != null;
}
!
! protected boolean hasGenericInvocationPluginAnnotation(ResolvedJavaMethod method) {
! return method.getAnnotation(Word.Operation.class) != null;
}
private static final int MAX_GRAPH_INLINING_DEPTH = 100; // more than enough
/**
--- 139,157 ----
@Override
public GraphBuilderConfiguration.Plugins getGraphBuilderPlugins() {
return graphBuilderPlugins;
}
! @Override
! public Class<? extends GraphBuilderPlugin> getIntrinsifyingPlugin(ResolvedJavaMethod method) {
! if (method.getAnnotation(Node.NodeIntrinsic.class) != null || method.getAnnotation(Fold.class) != null) {
! return GeneratedInvocationPlugin.class;
}
! if (method.getAnnotation(Word.Operation.class) != null) {
! return WordOperationPlugin.class;
! }
! return null;
}
private static final int MAX_GRAPH_INLINING_DEPTH = 100; // more than enough
/**
*** 161,188 ****
assert b.getDepth() < MAX_GRAPH_INLINING_DEPTH : "inlining limit exceeded";
// Force inlining when parsing replacements
return createIntrinsicInlineInfo(method, null, defaultBytecodeProvider);
} else {
! assert method.getAnnotation(NodeIntrinsic.class) == null : String.format("@%s method %s must only be called from within a replacement%n%s", NodeIntrinsic.class.getSimpleName(),
method.format("%h.%n"), b);
}
return null;
}
@Override
public void notifyNotInlined(GraphBuilderContext b, ResolvedJavaMethod method, Invoke invoke) {
if (b.parsingIntrinsic()) {
IntrinsicContext intrinsic = b.getIntrinsic();
if (!intrinsic.isCallToOriginal(method)) {
! if (hasGeneratedInvocationPluginAnnotation(method)) {
! throw new GraalError("%s should have been handled by a %s", method.format("%H.%n(%p)"), GeneratedInvocationPlugin.class.getSimpleName());
! }
! if (hasGenericInvocationPluginAnnotation(method)) {
! throw new GraalError("%s should have been handled by %s", method.format("%H.%n(%p)"), WordOperationPlugin.class.getSimpleName());
}
-
throw new GraalError("All non-recursive calls in the intrinsic %s must be inlined or intrinsified: found call to %s",
intrinsic.getIntrinsicMethod().format("%H.%n(%p)"), method.format("%h.%n(%p)"));
}
}
}
--- 175,205 ----
assert b.getDepth() < MAX_GRAPH_INLINING_DEPTH : "inlining limit exceeded";
// Force inlining when parsing replacements
return createIntrinsicInlineInfo(method, null, defaultBytecodeProvider);
} else {
! assert IS_BUILDING_NATIVE_IMAGE || method.getAnnotation(NodeIntrinsic.class) == null : String.format("@%s method %s must only be called from within a replacement%n%s",
! NodeIntrinsic.class.getSimpleName(),
method.format("%h.%n"), b);
}
return null;
}
@Override
public void notifyNotInlined(GraphBuilderContext b, ResolvedJavaMethod method, Invoke invoke) {
if (b.parsingIntrinsic()) {
IntrinsicContext intrinsic = b.getIntrinsic();
if (!intrinsic.isCallToOriginal(method)) {
! Class<? extends GraphBuilderPlugin> pluginClass = getIntrinsifyingPlugin(method);
! if (pluginClass != null) {
! String methodDesc = method.format("%H.%n(%p)");
! throw new GraalError("Call to %s should have been intrinsified by a %s. " +
! "This is typically caused by Eclipse failing to run an annotation " +
! "processor. This can usually be fixed by forcing Eclipse to rebuild " +
! "the source file in which %s is declared",
! methodDesc, pluginClass.getSimpleName(), methodDesc);
}
throw new GraalError("All non-recursive calls in the intrinsic %s must be inlined or intrinsified: found call to %s",
intrinsic.getIntrinsicMethod().format("%H.%n(%p)"), method.format("%h.%n(%p)"));
}
}
}
*** 211,221 ****
return getSnippet(method, null, args, trackNodeSourcePosition, replaceePosition);
}
private static final AtomicInteger nextDebugContextId = new AtomicInteger();
! protected DebugContext openDebugContext(String idPrefix, ResolvedJavaMethod method) {
DebugContext outer = DebugContext.forCurrentThread();
Description description = new Description(method, idPrefix + nextDebugContextId.incrementAndGet());
List<DebugHandlersFactory> factories = debugHandlersFactory == null ? Collections.emptyList() : Collections.singletonList(debugHandlersFactory);
return DebugContext.create(options, description, outer.getGlobalMetrics(), DEFAULT_LOG_STREAM, factories);
}
--- 228,238 ----
return getSnippet(method, null, args, trackNodeSourcePosition, replaceePosition);
}
private static final AtomicInteger nextDebugContextId = new AtomicInteger();
! public DebugContext openDebugContext(String idPrefix, ResolvedJavaMethod method) {
DebugContext outer = DebugContext.forCurrentThread();
Description description = new Description(method, idPrefix + nextDebugContextId.incrementAndGet());
List<DebugHandlersFactory> factories = debugHandlersFactory == null ? Collections.emptyList() : Collections.singletonList(debugHandlersFactory);
return DebugContext.create(options, description, outer.getGlobalMetrics(), DEFAULT_LOG_STREAM, factories);
}
*** 247,257 ****
assert !trackNodeSourcePosition || graph.trackNodeSourcePosition();
return graph;
}
@Override
! public void registerSnippet(ResolvedJavaMethod method, boolean trackNodeSourcePosition) {
// No initialization needed as snippet graphs are created on demand in getSnippet
}
@Override
public boolean hasSubstitution(ResolvedJavaMethod method, int invokeBci) {
--- 264,274 ----
assert !trackNodeSourcePosition || graph.trackNodeSourcePosition();
return graph;
}
@Override
! public void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition) {
// No initialization needed as snippet graphs are created on demand in getSnippet
}
@Override
public boolean hasSubstitution(ResolvedJavaMethod method, int invokeBci) {
*** 384,394 ****
* {@link #substitutedMethod} will be replaced with a forced inline of
* {@link #substitutedMethod}.
*/
protected final ResolvedJavaMethod substitutedMethod;
! protected GraphMaker(ReplacementsImpl replacements, ResolvedJavaMethod substitute, ResolvedJavaMethod substitutedMethod) {
this.replacements = replacements;
this.method = substitute;
this.substitutedMethod = substitutedMethod;
}
--- 401,411 ----
* {@link #substitutedMethod} will be replaced with a forced inline of
* {@link #substitutedMethod}.
*/
protected final ResolvedJavaMethod substitutedMethod;
! public GraphMaker(ReplacementsImpl replacements, ResolvedJavaMethod substitute, ResolvedJavaMethod substitutedMethod) {
this.replacements = replacements;
this.method = substitute;
this.substitutedMethod = substitutedMethod;
}
*** 486,502 ****
plugins.prependParameterPlugin(new ConstantBindingParameterPlugin(args, metaAccess, replacements.snippetReflection));
}
IntrinsicContext initialIntrinsicContext = null;
Snippet snippetAnnotation = method.getAnnotation(Snippet.class);
! if (snippetAnnotation == null) {
// Post-parse inlined intrinsic
initialIntrinsicContext = new IntrinsicContext(substitutedMethod, method, bytecodeProvider, INLINE_AFTER_PARSING);
} else {
// Snippet
ResolvedJavaMethod original = substitutedMethod != null ? substitutedMethod : method;
! initialIntrinsicContext = new IntrinsicContext(original, method, bytecodeProvider, INLINE_AFTER_PARSING, snippetAnnotation.allowPartialIntrinsicArgumentMismatch());
}
createGraphBuilder(metaAccess, replacements.providers.getStampProvider(), replacements.providers.getConstantReflection(), replacements.providers.getConstantFieldProvider(), config,
OptimisticOptimizations.NONE, initialIntrinsicContext).apply(graph);
--- 503,521 ----
plugins.prependParameterPlugin(new ConstantBindingParameterPlugin(args, metaAccess, replacements.snippetReflection));
}
IntrinsicContext initialIntrinsicContext = null;
Snippet snippetAnnotation = method.getAnnotation(Snippet.class);
! MethodSubstitution methodAnnotation = method.getAnnotation(MethodSubstitution.class);
! if (methodAnnotation == null && snippetAnnotation == null) {
// Post-parse inlined intrinsic
initialIntrinsicContext = new IntrinsicContext(substitutedMethod, method, bytecodeProvider, INLINE_AFTER_PARSING);
} else {
// Snippet
ResolvedJavaMethod original = substitutedMethod != null ? substitutedMethod : method;
! initialIntrinsicContext = new IntrinsicContext(original, method, bytecodeProvider, INLINE_AFTER_PARSING,
! snippetAnnotation != null ? snippetAnnotation.allowPartialIntrinsicArgumentMismatch() : true);
}
createGraphBuilder(metaAccess, replacements.providers.getStampProvider(), replacements.providers.getConstantReflection(), replacements.providers.getConstantFieldProvider(), config,
OptimisticOptimizations.NONE, initialIntrinsicContext).apply(graph);
< prev index next >