1 /*
2  * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 
25 package org.graalvm.compiler.nodes.spi;
26 
27 import org.graalvm.compiler.api.replacements.SnippetTemplateCache;
28 import org.graalvm.compiler.bytecode.BytecodeProvider;
29 import org.graalvm.compiler.core.common.CompilationIdentifier;
30 import org.graalvm.compiler.debug.DebugContext;
31 import org.graalvm.compiler.graph.NodeSourcePosition;
32 import org.graalvm.compiler.nodes.Cancellable;
33 import org.graalvm.compiler.nodes.StructuredGraph;
34 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
35 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
36 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderPlugin;
37 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
38 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
39 import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
40 import org.graalvm.compiler.options.OptionValues;
41 
42 import jdk.vm.ci.meta.ResolvedJavaMethod;
43 
44 /**
45  * A convenience class when want to subclass and override just a portion of the Replacements API.
46  */
47 public class DelegatingReplacements implements Replacements {
48     protected final Replacements delegate;
49 
DelegatingReplacements(Replacements delegate)50     public DelegatingReplacements(Replacements delegate) {
51         this.delegate = delegate;
52     }
53 
54     @Override
getProviders()55     public CoreProviders getProviders() {
56         return delegate.getProviders();
57     }
58 
59     @Override
getGraphBuilderPlugins()60     public GraphBuilderConfiguration.Plugins getGraphBuilderPlugins() {
61         return delegate.getGraphBuilderPlugins();
62     }
63 
64     @Override
getIntrinsifyingPlugin(ResolvedJavaMethod method)65     public Class<? extends GraphBuilderPlugin> getIntrinsifyingPlugin(ResolvedJavaMethod method) {
66         return delegate.getIntrinsifyingPlugin(method);
67     }
68 
69     @Override
getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, OptionValues options)70     public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition,
71                     OptionValues options) {
72         return delegate.getSnippet(method, recursiveEntry, args, trackNodeSourcePosition, replaceePosition, options);
73     }
74 
75     @Override
getSnippetParameterInfo(ResolvedJavaMethod method)76     public SnippetParameterInfo getSnippetParameterInfo(ResolvedJavaMethod method) {
77         return delegate.getSnippetParameterInfo(method);
78     }
79 
80     @Override
isSnippet(ResolvedJavaMethod method)81     public boolean isSnippet(ResolvedJavaMethod method) {
82         return delegate.isSnippet(method);
83     }
84 
85     @Override
registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition, OptionValues options)86     public void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition, OptionValues options) {
87         delegate.registerSnippet(method, original, receiver, trackNodeSourcePosition, options);
88     }
89 
90     @Override
getMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context, AllowAssumptions allowAssumptions, Cancellable cancellable, OptionValues options)91     public StructuredGraph getMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context,
92                     AllowAssumptions allowAssumptions, Cancellable cancellable, OptionValues options) {
93         return delegate.getMethodSubstitution(plugin, original, context, allowAssumptions, cancellable, options);
94     }
95 
96     @Override
registerMethodSubstitution(MethodSubstitutionPlugin plugin)97     public void registerMethodSubstitution(MethodSubstitutionPlugin plugin) {
98         delegate.registerMethodSubstitution(plugin);
99     }
100 
101     @Override
registerConditionalPlugin(InvocationPlugin plugin)102     public void registerConditionalPlugin(InvocationPlugin plugin) {
103         delegate.registerConditionalPlugin(plugin);
104     }
105 
106     @Override
getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, AllowAssumptions allowAssumptions, OptionValues options)107     public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, AllowAssumptions allowAssumptions,
108                     OptionValues options) {
109         return delegate.getSubstitution(method, invokeBci, trackNodeSourcePosition, replaceePosition, allowAssumptions, options);
110     }
111 
112     @Override
getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug, AllowAssumptions allowAssumptions, Cancellable cancellable)113     public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug, AllowAssumptions allowAssumptions, Cancellable cancellable) {
114         return delegate.getIntrinsicGraph(method, compilationId, debug, allowAssumptions, cancellable);
115     }
116 
117     @Override
hasSubstitution(ResolvedJavaMethod method, int invokeBci)118     public boolean hasSubstitution(ResolvedJavaMethod method, int invokeBci) {
119         return delegate.hasSubstitution(method, invokeBci);
120     }
121 
122     @Override
getDefaultReplacementBytecodeProvider()123     public BytecodeProvider getDefaultReplacementBytecodeProvider() {
124         return delegate.getDefaultReplacementBytecodeProvider();
125     }
126 
127     @Override
registerSnippetTemplateCache(SnippetTemplateCache snippetTemplates)128     public void registerSnippetTemplateCache(SnippetTemplateCache snippetTemplates) {
129         delegate.registerSnippetTemplateCache(snippetTemplates);
130     }
131 
132     @Override
getSnippetTemplateCache(Class<T> templatesClass)133     public <T extends SnippetTemplateCache> T getSnippetTemplateCache(Class<T> templatesClass) {
134         return delegate.getSnippetTemplateCache(templatesClass);
135     }
136 }
137