use of org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin in project graal by oracle.
the class ReplacementsImpl method getSubstitutionBytecode.
@Override
public Bytecode getSubstitutionBytecode(ResolvedJavaMethod method) {
InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
if (plugin instanceof MethodSubstitutionPlugin) {
MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
ResolvedJavaMethod substitute = msPlugin.getSubstitute(providers.getMetaAccess());
return msPlugin.getBytecodeProvider().getBytecode(substitute);
}
return null;
}
use of org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin in project graal by oracle.
the class ReplacementsImpl method getSubstitution.
@Override
public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
StructuredGraph result;
InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
if (plugin != null && (!plugin.inlineOnly() || invokeBci >= 0)) {
MetaAccessProvider metaAccess = providers.getMetaAccess();
if (plugin instanceof MethodSubstitutionPlugin) {
MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess);
StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(substitute) : null;
if (graph == null || graph.trackNodeSourcePosition() != trackNodeSourcePosition) {
try (DebugContext debug = openDebugContext("Substitution_", method)) {
graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method, trackNodeSourcePosition, replaceePosition);
if (!UseSnippetGraphCache.getValue(options)) {
return graph;
}
graph.freeze();
graphs.putIfAbsent(substitute, graph);
graph = graphs.get(substitute);
}
}
assert graph.isFrozen();
result = graph;
} else {
Bytecode code = new ResolvedJavaMethodBytecode(method);
ConstantReflectionProvider constantReflection = providers.getConstantReflection();
ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider();
StampProvider stampProvider = providers.getStampProvider();
try (DebugContext debug = openDebugContext("Substitution_", method)) {
result = new IntrinsicGraphBuilder(options, debug, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin);
}
}
} else {
result = null;
}
return result;
}
use of org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin in project graal by oracle.
the class TestIntrinsicCompiles method test.
@Test
@SuppressWarnings("try")
public void test() throws ClassNotFoundException {
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) JVMCI.getRuntime().getCompiler();
HotSpotGraalRuntimeProvider rt = (HotSpotGraalRuntimeProvider) Graal.getRequiredCapability(RuntimeProvider.class);
HotSpotProviders providers = rt.getHostBackend().getProviders();
Plugins graphBuilderPlugins = providers.getGraphBuilderPlugins();
InvocationPlugins invocationPlugins = graphBuilderPlugins.getInvocationPlugins();
EconomicMap<String, List<Binding>> bindings = invocationPlugins.getBindings(true);
HotSpotVMConfigStore store = rt.getVMConfig().getStore();
List<VMIntrinsicMethod> intrinsics = store.getIntrinsics();
OptionValues options = getInitialOptions();
DebugContext debug = getDebugContext(options);
for (VMIntrinsicMethod intrinsic : intrinsics) {
InvocationPlugin plugin = CheckGraalIntrinsics.findPlugin(bindings, intrinsic);
if (plugin != null) {
if (plugin instanceof MethodSubstitutionPlugin) {
ResolvedJavaMethod method = CheckGraalIntrinsics.resolveIntrinsic(getMetaAccess(), intrinsic);
if (!method.isNative()) {
StructuredGraph graph = compiler.getIntrinsicGraph(method, providers, INVALID_COMPILATION_ID, options, debug);
getCode(method, graph);
}
}
}
}
}
Aggregations