use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class SubstrateReplacements method makeInvocationPlugins.
@Platforms(Platform.HOSTED_ONLY.class)
private static InvocationPlugins makeInvocationPlugins(GraphBuilderConfiguration.Plugins plugins, Builder builder, Function<Object, Object> objectReplacer) {
Map<ResolvedJavaMethod, InvocationPlugin> result = new HashMap<>(builder.delayedInvocationPluginMethods.size());
for (ResolvedJavaMethod method : builder.delayedInvocationPluginMethods) {
ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) objectReplacer.apply(method);
InvocationPlugin plugin = plugins.getInvocationPlugins().lookupInvocation(replacedMethod);
assert plugin != null : "expected invocation plugin for " + replacedMethod;
result.put(replacedMethod, plugin);
}
return new InvocationPlugins(result, null);
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class SubstrateReplacements method encodeSnippets.
@Platforms(Platform.HOSTED_ONLY.class)
public void encodeSnippets() {
GraphEncoder encoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
for (StructuredGraph graph : builder.graphs.values()) {
encoder.prepare(graph);
}
encoder.finishPrepare();
snippetStartOffsets = new HashMap<>();
for (Map.Entry<ResolvedJavaMethod, StructuredGraph> entry : builder.graphs.entrySet()) {
snippetStartOffsets.put(entry.getKey(), encoder.encode(entry.getValue()));
}
snippetEncoding = encoder.getEncoding();
snippetObjects = encoder.getObjects();
snippetNodeClasses = encoder.getNodeClasses();
snippetInvocationPlugins = makeInvocationPlugins(getGraphBuilderPlugins(), builder, Function.identity());
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class GraalTutorial method testGetBytecodes.
/*
* Example for the Graal API: access the Graal API metadata object for a method.
*/
@Test
public void testGetBytecodes() throws NoSuchMethodException {
Method reflectionMethod = String.class.getDeclaredMethod("hashCode");
ResolvedJavaMethod method = metaAccess.lookupJavaMethod(reflectionMethod);
/*
* ResolvedJavaMethod provides all information that you want about a method, for example,
* the bytecodes.
*/
byte[] bytecodes = method.getCode();
/*
* BytecodeDisassembler shows you how to iterate bytecodes, how to access type information,
* and more.
*/
String disassembly = new BytecodeDisassembler().disassemble(method);
/*
* We don't want test cases to print any output, so we check the validity of the output
* instead.
*/
Pattern disassemblyLineRE = Pattern.compile(" *\\d+: [a-z][\\w_]+");
for (String line : disassembly.split("\\n")) {
Assert.assertTrue(line, disassemblyLineRE.matcher(line).find());
}
Assert.assertTrue(bytecodes.length > 0);
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class DefaultJavaLoweringProvider method lowerBinaryMath.
private void lowerBinaryMath(BinaryMathIntrinsicNode math, LoweringTool tool) {
if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
return;
}
ResolvedJavaMethod method = math.graph().method();
if (method != null) {
if (method.getAnnotation(Snippet.class) != null) {
/*
* In the context of the snippet use the LIR lowering instead of the Node lowering.
*/
return;
}
if (method.getName().equalsIgnoreCase(math.getOperation().name()) && tool.getMetaAccess().lookupJavaType(Math.class).equals(method.getDeclaringClass())) {
/*
* A root compilation of the intrinsic method should emit the full assembly
* implementation.
*/
return;
}
}
ForeignCallDescriptor foreignCall = toForeignCall(math.getOperation());
if (foreignCall != null) {
StructuredGraph graph = math.graph();
ForeignCallNode call = graph.add(new ForeignCallNode(foreignCalls, toForeignCall(math.getOperation()), math.getX(), math.getY()));
graph.addAfterFixed(tool.lastFixedNode(), call);
math.replaceAtUsages(call);
}
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class GraphKit method inline.
/**
* Inlines a given invocation to a method. The graph of the inlined method is processed in the
* same manner as for snippets and method substitutions.
*/
public void inline(InvokeNode invoke) {
ResolvedJavaMethod method = ((MethodCallTargetNode) invoke.callTarget()).targetMethod();
MetaAccessProvider metaAccess = providers.getMetaAccess();
Plugins plugins = new Plugins(graphBuilderPlugins);
GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
StructuredGraph calleeGraph = new StructuredGraph.Builder(invoke.getOptions(), invoke.getDebug()).method(method).build();
if (invoke.graph().trackNodeSourcePosition()) {
calleeGraph.setTrackNodeSourcePosition();
}
IntrinsicContext initialReplacementContext = new IntrinsicContext(method, method, providers.getReplacements().getDefaultReplacementBytecodeProvider(), INLINE_AFTER_PARSING);
GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialReplacementContext);
instance.apply(calleeGraph);
// Remove all frame states from inlinee
calleeGraph.clearAllStateAfter();
new DeadCodeEliminationPhase(Optionality.Required).apply(calleeGraph);
InliningUtil.inline(invoke, calleeGraph, false, method);
}
Aggregations