Search in sources :

Example 1 with Platforms

use of org.graalvm.nativeimage.Platforms in project graal by oracle.

the class EncodedLineNumberTable method encode.

@Platforms(Platform.HOSTED_ONLY.class)
public static byte[] encode(LineNumberTable table) {
    if (table == null) {
        return null;
    }
    int[] lineNumbers = table.getLineNumbers();
    int[] bcis = table.getBcis();
    assert lineNumbers.length == bcis.length;
    UnsafeArrayTypeWriter encodingBuffer = UnsafeArrayTypeWriter.create(ByteArrayReader.supportsUnalignedMemoryAccess());
    int lastLineNumber = 0;
    int lastBci = 0;
    encodingBuffer.putUV(lineNumbers.length);
    for (int i = 0; i < lineNumbers.length; i++) {
        encodingBuffer.putSV(lineNumbers[i] - lastLineNumber);
        encodingBuffer.putSV(bcis[i] - lastBci);
        lastLineNumber = lineNumbers[i];
        lastBci = bcis[i];
    }
    byte[] encodedTable = encodingBuffer.toArray(new byte[TypeConversion.asS4(encodingBuffer.getBytesWritten())]);
    assert verifyTable(table, decode(encodedTable));
    return encodedTable;
}
Also used : UnsafeArrayTypeWriter(org.graalvm.compiler.core.common.util.UnsafeArrayTypeWriter) Platforms(org.graalvm.nativeimage.Platforms)

Example 2 with Platforms

use of org.graalvm.nativeimage.Platforms in project graal by oracle.

the class SubstrateReplacements method registerSnippet.

/**
 * Compiles the snippet and stores the graph.
 */
@Platforms(Platform.HOSTED_ONLY.class)
@Override
public void registerSnippet(ResolvedJavaMethod method, boolean trackNodeSourcePosition) {
    assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
    assert method.hasBytecodes() : "Snippet must not be abstract or native";
    assert builder.graphs.get(method) == null : "snippet registered twice: " + method.getName();
    try (DebugContext debug = openDebugContext("Snippet_", method)) {
        StructuredGraph graph = makeGraph(debug, defaultBytecodeProvider, method, null, null, trackNodeSourcePosition, null);
        // Check if all methods which should be inlined are really inlined.
        for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
            ResolvedJavaMethod callee = callTarget.targetMethod();
            if (!builder.delayedInvocationPluginMethods.contains(callee)) {
                throw shouldNotReachHere("method " + callee.getName() + " not inlined in snippet " + method.getName() + " (maybe not final?)");
            }
        }
        builder.graphs.put(method, graph);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) Snippet(org.graalvm.compiler.api.replacements.Snippet) DebugContext(org.graalvm.compiler.debug.DebugContext) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Platforms(org.graalvm.nativeimage.Platforms)

Example 3 with Platforms

use of org.graalvm.nativeimage.Platforms 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);
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) HashMap(java.util.HashMap) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Platforms(org.graalvm.nativeimage.Platforms)

Example 4 with Platforms

use of org.graalvm.nativeimage.Platforms 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());
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) HashMap(java.util.HashMap) Map(java.util.Map) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Platforms(org.graalvm.nativeimage.Platforms)

Example 5 with Platforms

use of org.graalvm.nativeimage.Platforms in project graal by oracle.

the class SubstrateTruffleRuntime method initTruffleCompiler.

@Platforms(Platform.HOSTED_ONLY.class)
public SubstrateTruffleCompiler initTruffleCompiler() {
    assert truffleCompiler == null : "Cannot re-initialize Substrate TruffleCompiler";
    GraalFeature graalFeature = ImageSingletons.lookup(GraalFeature.class);
    SnippetReflectionProvider snippetReflection = graalFeature.getHostedProviders().getSnippetReflection();
    SubstrateTruffleCompiler compiler = new SubstrateTruffleCompiler(this, graalFeature.getHostedProviders().getGraphBuilderPlugins(), GraalSupport.getSuites(), GraalSupport.getLIRSuites(), GraalSupport.getRuntimeConfig().getBackendForNormalMethod(), snippetReflection);
    truffleCompiler = compiler;
    return compiler;
}
Also used : SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) GraalFeature(com.oracle.svm.graal.hosted.GraalFeature) Platforms(org.graalvm.nativeimage.Platforms)

Aggregations

Platforms (org.graalvm.nativeimage.Platforms)10 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 GraalFeature (com.oracle.svm.graal.hosted.GraalFeature)2 HashMap (java.util.HashMap)2 SnippetReflectionProvider (org.graalvm.compiler.api.replacements.SnippetReflectionProvider)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)2 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)1 VMError (com.oracle.svm.core.util.VMError)1 HostedUniverse (com.oracle.svm.hosted.meta.HostedUniverse)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 Snippet (org.graalvm.compiler.api.replacements.Snippet)1 UnsafeArrayTypeWriter (org.graalvm.compiler.core.common.util.UnsafeArrayTypeWriter)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 GraphEncoder (org.graalvm.compiler.nodes.GraphEncoder)1 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)1 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)1 OptionDescriptor (org.graalvm.compiler.options.OptionDescriptor)1