Search in sources :

Example 1 with GraphEncoder

use of org.graalvm.compiler.nodes.GraphEncoder in project graal by oracle.

the class RuntimeStrengthenStampsPhase method beforeCompilation.

@Override
@SuppressWarnings("try")
public void beforeCompilation(BeforeCompilationAccess c) {
    CompilationAccessImpl config = (CompilationAccessImpl) c;
    if (Options.PrintRuntimeCompileMethods.getValue()) {
        printCallTree();
    }
    System.out.println(methods.size() + " method(s) included for runtime compilation");
    if (Options.PrintStaticTruffleBoundaries.getValue()) {
        printStaticTruffleBoundaries();
    }
    Integer maxMethods = Options.MaxRuntimeCompileMethods.getValue();
    if (maxMethods != 0 && methods.size() > maxMethods) {
        printDeepestLevelPath();
        throw VMError.shouldNotReachHere("Number of methods for runtime compilation exceeds the allowed limit: " + methods.size() + " > " + maxMethods);
    }
    HostedMetaAccess hMetaAccess = config.getMetaAccess();
    runtimeConfigBuilder.updateLazyState(hMetaAccess);
    /*
         * Start fresh with a new GraphEncoder, since we are going to optimize all graphs now that
         * the static analysis results are available.
         */
    graphEncoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
    StrengthenStampsPhase strengthenStamps = new RuntimeStrengthenStampsPhase(config.getUniverse(), objectReplacer);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext phaseContext = new PhaseContext(hostedProviders);
    for (CallTreeNode node : methods.values()) {
        StructuredGraph graph = node.graph;
        if (graph != null) {
            DebugContext debug = graph.getDebug();
            try (DebugContext.Scope scope = debug.scope("RuntimeOptimize", graph)) {
                removeUnreachableInvokes(node);
                strengthenStamps.apply(graph);
                canonicalizer.apply(graph, phaseContext);
                GraalConfiguration.instance().runAdditionalCompilerPhases(graph, this);
                canonicalizer.apply(graph, phaseContext);
                graphEncoder.prepare(graph);
            } catch (Throwable ex) {
                debug.handle(ex);
            }
        }
    }
    graphEncoder.finishPrepare();
    for (CallTreeNode node : methods.values()) {
        if (node.graph != null) {
            registerDeoptEntries(node);
            long startOffset = graphEncoder.encode(node.graph);
            objectReplacer.createMethod(node.implementationMethod).setEncodedGraphStartOffset(startOffset);
            /* We do not need the graph anymore, let the GC do it's work. */
            node.graph = null;
        }
    }
    GraalSupport.setGraphEncoding(graphEncoder.getEncoding(), graphEncoder.getObjects(), graphEncoder.getNodeClasses());
    objectReplacer.updateDataDuringAnalysis((AnalysisMetaAccess) hMetaAccess.getWrapped());
}
Also used : CompilationAccessImpl(com.oracle.svm.hosted.FeatureImpl.CompilationAccessImpl) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) DebugContext(org.graalvm.compiler.debug.DebugContext) HostedMetaAccess(com.oracle.svm.hosted.meta.HostedMetaAccess) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) StrengthenStampsPhase(com.oracle.svm.hosted.phases.StrengthenStampsPhase)

Example 2 with GraphEncoder

use of org.graalvm.compiler.nodes.GraphEncoder 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 3 with GraphEncoder

use of org.graalvm.compiler.nodes.GraphEncoder in project graal by oracle.

the class GraphEncoderTest method testStringMethods.

public void testStringMethods(boolean canonicalize) {
    /* Encode and decode all methods of java.lang.String. */
    List<StructuredGraph> originalGraphs = new ArrayList<>();
    for (Method method : String.class.getDeclaredMethods()) {
        ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method);
        if (javaMethod.hasBytecodes()) {
            StructuredGraph originalGraph = parseEager(javaMethod, AllowAssumptions.YES);
            if (canonicalize) {
                PhaseContext context = new PhaseContext(getProviders());
                new CanonicalizerPhase().apply(originalGraph, context);
            }
            originalGraphs.add(originalGraph);
        }
    }
    GraphEncoder encoder = new GraphEncoder(getTarget().arch);
    for (StructuredGraph originalGraph : originalGraphs) {
        encoder.prepare(originalGraph);
    }
    encoder.finishPrepare();
    Map<StructuredGraph, Integer> startOffsets = new HashMap<>();
    for (StructuredGraph originalGraph : originalGraphs) {
        startOffsets.put(originalGraph, encoder.encode(originalGraph));
    }
    for (StructuredGraph originalGraph : originalGraphs) {
        EncodedGraph encodedGraph = new EncodedGraph(encoder.getEncoding(), startOffsets.get(originalGraph), encoder.getObjects(), encoder.getNodeClasses(), originalGraph);
        GraphEncoder.verifyEncoding(originalGraph, encodedGraph, getTarget().arch);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HashMap(java.util.HashMap) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) ArrayList(java.util.ArrayList) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 4 with GraphEncoder

use of org.graalvm.compiler.nodes.GraphEncoder in project graal by oracle.

the class RuntimeStrengthenStampsPhase method beforeAnalysis.

@Override
public void beforeAnalysis(BeforeAnalysisAccess c) {
    BeforeAnalysisAccessImpl config = (BeforeAnalysisAccessImpl) c;
    GraalSupport.allocatePhaseStatisticsCache();
    populateMatchRuleRegistry();
    Function<Providers, Backend> backendProvider = GraalSupport.getRuntimeBackendProvider();
    Providers originalProviders = GraalAccess.getOriginalProviders();
    runtimeConfigBuilder = new SubstrateRuntimeConfigurationBuilder(RuntimeOptionValues.singleton(), config.getHostVM(), config.getUniverse(), config.getMetaAccess(), originalProviders.getConstantReflection(), backendProvider).build();
    RuntimeConfiguration runtimeConfig = runtimeConfigBuilder.getRuntimeConfig();
    Providers runtimeProviders = runtimeConfig.getProviders();
    WordTypes wordTypes = runtimeConfigBuilder.getWordTypes();
    hostedProviders = new HostedProviders(runtimeProviders.getMetaAccess(), runtimeProviders.getCodeCache(), runtimeProviders.getConstantReflection(), runtimeProviders.getConstantFieldProvider(), runtimeProviders.getForeignCalls(), runtimeProviders.getLowerer(), runtimeProviders.getReplacements(), runtimeProviders.getStampProvider(), runtimeConfig.getSnippetReflection(), wordTypes);
    SubstrateGraalRuntime graalRuntime = new SubstrateGraalRuntime();
    objectReplacer.setGraalRuntime(graalRuntime);
    ImageSingletons.add(GraalRuntime.class, graalRuntime);
    RuntimeSupport.getRuntimeSupport().addShutdownHook(new GraalSupport.GraalShutdownHook());
    FeatureHandler featureHandler = config.getFeatureHandler();
    NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, runtimeConfig, hostedProviders, config.getMetaAccess(), config.getUniverse(), null, null, config.getNativeLibraries(), config.getImageClassLoader(), false, false);
    DebugContext debug = DebugContext.forCurrentThread();
    NativeImageGenerator.registerReplacements(debug, featureHandler, runtimeConfig, runtimeConfig.getProviders(), runtimeConfig.getSnippetReflection(), false);
    featureHandler.forEachGraalFeature(feature -> feature.registerCodeObserver(runtimeConfig));
    Suites suites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
    LIRSuites lirSuites = NativeImageGenerator.createLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
    GraalSupport.setRuntimeConfig(runtimeConfig, suites, lirSuites);
    NodeClass<?>[] snippetNodeClasses = ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetNodeClasses();
    for (NodeClass<?> nodeClass : snippetNodeClasses) {
        config.getMetaAccess().lookupJavaType(nodeClass.getClazz()).registerAsAllocated(null);
    }
    /* Initialize configuration with reasonable default values. */
    graphBuilderConfig = GraphBuilderConfiguration.getDefault(hostedProviders.getGraphBuilderPlugins()).withBytecodeExceptionMode(BytecodeExceptionMode.ExplicitOnly);
    includeCalleePredicate = GraalFeature::defaultIncludeCallee;
    optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
    methods = new LinkedHashMap<>();
    graphEncoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
    /*
         * Ensure that all snippet methods have their SubstrateMethod object created by the object
         * replacer, to avoid corner cases later when writing the native image.
         */
    for (ResolvedJavaMethod method : ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetMethods()) {
        objectReplacer.apply(method);
    }
}
Also used : BeforeAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl) SubstrateGraalRuntime(com.oracle.svm.graal.SubstrateGraalRuntime) GraalSupport(com.oracle.svm.graal.GraalSupport) WordTypes(org.graalvm.compiler.word.WordTypes) DebugContext(org.graalvm.compiler.debug.DebugContext) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Providers(org.graalvm.compiler.phases.util.Providers) RuntimeConfiguration(com.oracle.svm.core.graal.meta.RuntimeConfiguration) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) NodeClass(org.graalvm.compiler.graph.NodeClass) Backend(org.graalvm.compiler.core.target.Backend) SubstrateReplacements(com.oracle.svm.core.graal.meta.SubstrateReplacements) FeatureHandler(com.oracle.svm.hosted.FeatureHandler) SubstrateRuntimeConfigurationBuilder(com.oracle.svm.graal.meta.SubstrateRuntimeConfigurationBuilder) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Aggregations

GraphEncoder (org.graalvm.compiler.nodes.GraphEncoder)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)3 HashMap (java.util.HashMap)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)2 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)2 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 RuntimeConfiguration (com.oracle.svm.core.graal.meta.RuntimeConfiguration)1 SubstrateReplacements (com.oracle.svm.core.graal.meta.SubstrateReplacements)1 GraalSupport (com.oracle.svm.graal.GraalSupport)1 SubstrateGraalRuntime (com.oracle.svm.graal.SubstrateGraalRuntime)1 SubstrateRuntimeConfigurationBuilder (com.oracle.svm.graal.meta.SubstrateRuntimeConfigurationBuilder)1 FeatureHandler (com.oracle.svm.hosted.FeatureHandler)1 BeforeAnalysisAccessImpl (com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl)1 CompilationAccessImpl (com.oracle.svm.hosted.FeatureImpl.CompilationAccessImpl)1 HostedMetaAccess (com.oracle.svm.hosted.meta.HostedMetaAccess)1 StrengthenStampsPhase (com.oracle.svm.hosted.phases.StrengthenStampsPhase)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1