src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/CachingPEGraphDecoder.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54601 c40b2a190173
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    44 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
    44 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
    45 import org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin;
    45 import org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin;
    46 import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
    46 import org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin;
    47 import org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin;
    47 import org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin;
    48 import org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin;
    48 import org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin;
       
    49 import org.graalvm.compiler.nodes.spi.CoreProviders;
       
    50 import org.graalvm.compiler.phases.BasePhase;
    49 import org.graalvm.compiler.phases.OptimisticOptimizations;
    51 import org.graalvm.compiler.phases.OptimisticOptimizations;
    50 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
    52 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
    51 import org.graalvm.compiler.phases.tiers.PhaseContext;
       
    52 import org.graalvm.compiler.phases.util.Providers;
    53 import org.graalvm.compiler.phases.util.Providers;
    53 
    54 
    54 import jdk.vm.ci.code.Architecture;
    55 import jdk.vm.ci.code.Architecture;
    55 import jdk.vm.ci.meta.ResolvedJavaMethod;
    56 import jdk.vm.ci.meta.ResolvedJavaMethod;
    56 
    57 
    63     protected final Providers providers;
    64     protected final Providers providers;
    64     protected final GraphBuilderConfiguration graphBuilderConfig;
    65     protected final GraphBuilderConfiguration graphBuilderConfig;
    65     protected final OptimisticOptimizations optimisticOpts;
    66     protected final OptimisticOptimizations optimisticOpts;
    66     private final AllowAssumptions allowAssumptions;
    67     private final AllowAssumptions allowAssumptions;
    67     private final EconomicMap<ResolvedJavaMethod, EncodedGraph> graphCache;
    68     private final EconomicMap<ResolvedJavaMethod, EncodedGraph> graphCache;
       
    69     private final BasePhase<? super CoreProviders> postParsingPhase;
    68 
    70 
    69     public CachingPEGraphDecoder(Architecture architecture, StructuredGraph graph, Providers providers, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts,
    71     public CachingPEGraphDecoder(Architecture architecture, StructuredGraph graph, Providers providers, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts,
    70                     AllowAssumptions allowAssumptions, LoopExplosionPlugin loopExplosionPlugin, InvocationPlugins invocationPlugins, InlineInvokePlugin[] inlineInvokePlugins,
    72                     AllowAssumptions allowAssumptions, LoopExplosionPlugin loopExplosionPlugin, InvocationPlugins invocationPlugins, InlineInvokePlugin[] inlineInvokePlugins,
    71                     ParameterPlugin parameterPlugin,
    73                     ParameterPlugin parameterPlugin,
    72                     NodePlugin[] nodePlugins, ResolvedJavaMethod callInlinedMethod, SourceLanguagePositionProvider sourceLanguagePositionProvider) {
    74                     NodePlugin[] nodePlugins, ResolvedJavaMethod callInlinedMethod, ResolvedJavaMethod callInlinedAgnosticMethod, SourceLanguagePositionProvider sourceLanguagePositionProvider,
       
    75                     BasePhase<? super CoreProviders> postParsingPhase, EconomicMap<ResolvedJavaMethod, EncodedGraph> graphCache) {
    73         super(architecture, graph, providers, loopExplosionPlugin,
    76         super(architecture, graph, providers, loopExplosionPlugin,
    74                         invocationPlugins, inlineInvokePlugins, parameterPlugin, nodePlugins, callInlinedMethod, sourceLanguagePositionProvider);
    77                         invocationPlugins, inlineInvokePlugins, parameterPlugin, nodePlugins, callInlinedMethod, callInlinedAgnosticMethod, sourceLanguagePositionProvider);
    75 
    78 
    76         this.providers = providers;
    79         this.providers = providers;
    77         this.graphBuilderConfig = graphBuilderConfig;
    80         this.graphBuilderConfig = graphBuilderConfig;
    78         this.optimisticOpts = optimisticOpts;
    81         this.optimisticOpts = optimisticOpts;
    79         this.allowAssumptions = allowAssumptions;
    82         this.allowAssumptions = allowAssumptions;
    80         this.graphCache = EconomicMap.create();
    83         this.graphCache = graphCache;
       
    84         this.postParsingPhase = postParsingPhase;
    81     }
    85     }
    82 
    86 
    83     protected GraphBuilderPhase.Instance createGraphBuilderPhaseInstance(IntrinsicContext initialIntrinsicContext) {
    87     protected GraphBuilderPhase.Instance createGraphBuilderPhaseInstance(IntrinsicContext initialIntrinsicContext) {
    84         return new GraphBuilderPhase.Instance(providers, graphBuilderConfig, optimisticOpts, initialIntrinsicContext);
    88         return new GraphBuilderPhase.Instance(providers, graphBuilderConfig, optimisticOpts, initialIntrinsicContext);
    85     }
    89     }
    88     private EncodedGraph createGraph(ResolvedJavaMethod method, MethodSubstitutionPlugin plugin, BytecodeProvider intrinsicBytecodeProvider, boolean isSubstitution) {
    92     private EncodedGraph createGraph(ResolvedJavaMethod method, MethodSubstitutionPlugin plugin, BytecodeProvider intrinsicBytecodeProvider, boolean isSubstitution) {
    89         StructuredGraph graphToEncode;
    93         StructuredGraph graphToEncode;
    90         if (isSubstitution && (UseEncodedGraphs.getValue(options) || IS_IN_NATIVE_IMAGE)) {
    94         if (isSubstitution && (UseEncodedGraphs.getValue(options) || IS_IN_NATIVE_IMAGE)) {
    91             // These must go through Replacements to find the graph to use.
    95             // These must go through Replacements to find the graph to use.
    92             graphToEncode = providers.getReplacements().getMethodSubstitution(plugin, method, INLINE_AFTER_PARSING, allowAssumptions,
    96             graphToEncode = providers.getReplacements().getMethodSubstitution(plugin, method, INLINE_AFTER_PARSING, allowAssumptions,
    93                             options);
    97                             null, options);
    94         } else {
    98         } else {
    95             graphToEncode = buildGraph(method, plugin, intrinsicBytecodeProvider, isSubstitution);
    99             graphToEncode = buildGraph(method, plugin, intrinsicBytecodeProvider, isSubstitution);
    96         }
   100         }
    97 
   101 
    98         /*
   102         /*
    99          * ConvertDeoptimizeToGuardPhase reduces the number of merges in the graph, so that fewer
   103          * ConvertDeoptimizeToGuardPhase reduces the number of merges in the graph, so that fewer
   100          * frame states will be created. This significantly reduces the number of nodes in the
   104          * frame states will be created. This significantly reduces the number of nodes in the
   101          * initial graph.
   105          * initial graph.
   102          */
   106          */
   103         try (DebugContext.Scope scope = debug.scope("createGraph", graphToEncode)) {
   107         try (DebugContext.Scope scope = debug.scope("createGraph", graphToEncode)) {
   104             PhaseContext context = new PhaseContext(providers);
   108             new ConvertDeoptimizeToGuardPhase().apply(graphToEncode, providers);
   105             new ConvertDeoptimizeToGuardPhase().apply(graphToEncode, context);
       
   106         } catch (Throwable t) {
   109         } catch (Throwable t) {
   107             throw debug.handle(t);
   110             throw debug.handle(t);
   108         }
   111         }
   109 
   112 
   110         EncodedGraph encodedGraph = GraphEncoder.encodeSingleGraph(graphToEncode, architecture);
   113         EncodedGraph encodedGraph = GraphEncoder.encodeSingleGraph(graphToEncode, architecture);
   123                 cancellable(graph.getCancellable()).
   126                 cancellable(graph.getCancellable()).
   124                 build();
   127                 build();
   125         // @formatter:on
   128         // @formatter:on
   126         try (DebugContext.Scope scope = debug.scope("createGraph", graphToEncode)) {
   129         try (DebugContext.Scope scope = debug.scope("createGraph", graphToEncode)) {
   127             IntrinsicContext initialIntrinsicContext = intrinsicBytecodeProvider != null
   130             IntrinsicContext initialIntrinsicContext = intrinsicBytecodeProvider != null
   128                             ? new IntrinsicContext(method, plugin.getSubstitute(providers.getMetaAccess()), intrinsicBytecodeProvider, INLINE_AFTER_PARSING) : null;
   131                             ? new IntrinsicContext(method, plugin.getSubstitute(providers.getMetaAccess()), intrinsicBytecodeProvider, INLINE_AFTER_PARSING)
       
   132                             : null;
   129             GraphBuilderPhase.Instance graphBuilderPhaseInstance = createGraphBuilderPhaseInstance(initialIntrinsicContext);
   133             GraphBuilderPhase.Instance graphBuilderPhaseInstance = createGraphBuilderPhaseInstance(initialIntrinsicContext);
   130             graphBuilderPhaseInstance.apply(graphToEncode);
   134             graphBuilderPhaseInstance.apply(graphToEncode);
   131 
   135             new CanonicalizerPhase().apply(graphToEncode, providers);
   132             PhaseContext context = new PhaseContext(providers);
   136             if (postParsingPhase != null) {
   133             new CanonicalizerPhase().apply(graphToEncode, context);
   137                 postParsingPhase.apply(graphToEncode, providers);
   134 
   138             }
   135         } catch (Throwable ex) {
   139         } catch (Throwable ex) {
   136             throw debug.handle(ex);
   140             throw debug.handle(ex);
   137         }
   141         }
   138         return graphToEncode;
   142         return graphToEncode;
   139     }
   143     }