1 /*
2  * Copyright (c) 2018, 2019, 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.graphbuilderconf.GraphBuilderConfiguration;
35 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderPlugin;
36 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
37 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin;
38 import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
39 import org.graalvm.compiler.options.OptionValues;
40 
41 import jdk.vm.ci.meta.ResolvedJavaMethod;
42 
43 /**
44  * A convenience class when want to subclass and override just a portion of the Replacements API.
45  */
46 public class DelegatingReplacements implements Replacements {
47     protected final Replacements delegate;
48 
DelegatingReplacements(Replacements delegate)49     public DelegatingReplacements(Replacements delegate) {
50         this.delegate = delegate;
51     }
52 
53     @Override
getProviders()54     public CoreProviders getProviders() {
55         return delegate.getProviders();
56     }
57 
58     @Override
getGraphBuilderPlugins()59     public GraphBuilderConfiguration.Plugins getGraphBuilderPlugins() {
60         return delegate.getGraphBuilderPlugins();
61     }
62 
63     @Override
getIntrinsifyingPlugin(ResolvedJavaMethod method)64     public Class<? extends GraphBuilderPlugin> getIntrinsifyingPlugin(ResolvedJavaMethod method) {
65         return delegate.getIntrinsifyingPlugin(method);
66     }
67 
68     @Override
getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, OptionValues options)69     public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition,
70                     OptionValues options) {
71         return delegate.getSnippet(method, recursiveEntry, args, trackNodeSourcePosition, replaceePosition, options);
72     }
73 
74     @Override
registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition, OptionValues options)75     public void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition, OptionValues options) {
76         delegate.registerSnippet(method, original, receiver, trackNodeSourcePosition, options);
77     }
78 
79     @Override
getMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context, StructuredGraph.AllowAssumptions allowAssumptions, Cancellable cancellable, OptionValues options)80     public StructuredGraph getMethodSubstitution(MethodSubstitutionPlugin plugin, ResolvedJavaMethod original, IntrinsicContext.CompilationContext context,
81                     StructuredGraph.AllowAssumptions allowAssumptions, Cancellable cancellable, OptionValues options) {
82         return delegate.getMethodSubstitution(plugin, original, context, allowAssumptions, cancellable, options);
83     }
84 
85     @Override
registerMethodSubstitution(MethodSubstitutionPlugin plugin)86     public void registerMethodSubstitution(MethodSubstitutionPlugin plugin) {
87         delegate.registerMethodSubstitution(plugin);
88     }
89 
90     @Override
registerConditionalPlugin(InvocationPlugin plugin)91     public void registerConditionalPlugin(InvocationPlugin plugin) {
92         delegate.registerConditionalPlugin(plugin);
93     }
94 
95     @Override
getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, OptionValues options)96     public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition, OptionValues options) {
97         return delegate.getSubstitution(method, invokeBci, trackNodeSourcePosition, replaceePosition, options);
98     }
99 
100     @Override
getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug, Cancellable cancellable)101     public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, CompilationIdentifier compilationId, DebugContext debug, Cancellable cancellable) {
102         return delegate.getIntrinsicGraph(method, compilationId, debug, cancellable);
103     }
104 
105     @Override
hasSubstitution(ResolvedJavaMethod method, int invokeBci)106     public boolean hasSubstitution(ResolvedJavaMethod method, int invokeBci) {
107         return delegate.hasSubstitution(method, invokeBci);
108     }
109 
110     @Override
getDefaultReplacementBytecodeProvider()111     public BytecodeProvider getDefaultReplacementBytecodeProvider() {
112         return delegate.getDefaultReplacementBytecodeProvider();
113     }
114 
115     @Override
registerSnippetTemplateCache(SnippetTemplateCache snippetTemplates)116     public void registerSnippetTemplateCache(SnippetTemplateCache snippetTemplates) {
117         delegate.registerSnippetTemplateCache(snippetTemplates);
118     }
119 
120     @Override
getSnippetTemplateCache(Class<T> templatesClass)121     public <T extends SnippetTemplateCache> T getSnippetTemplateCache(Class<T> templatesClass) {
122         return delegate.getSnippetTemplateCache(templatesClass);
123     }
124 }
125