< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/CachingPEGraphDecoder.java

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.replacements;
  26 
  27 import static org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext.CompilationContext.INLINE_AFTER_PARSING;
  28 
  29 import jdk.internal.vm.compiler.collections.EconomicMap;
  30 import org.graalvm.compiler.bytecode.BytecodeProvider;
  31 import org.graalvm.compiler.debug.DebugContext;
  32 import org.graalvm.compiler.graph.SourceLanguagePositionProvider;
  33 import org.graalvm.compiler.java.GraphBuilderPhase;

  34 import org.graalvm.compiler.nodes.EncodedGraph;
  35 import org.graalvm.compiler.nodes.GraphEncoder;
  36 import org.graalvm.compiler.nodes.StructuredGraph;
  37 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  38 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  39 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
  40 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
  41 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  42 import org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin;
  43 import org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin;
  44 import org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin;
  45 import org.graalvm.compiler.phases.OptimisticOptimizations;
  46 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  47 import org.graalvm.compiler.loop.phases.ConvertDeoptimizeToGuardPhase;
  48 import org.graalvm.compiler.phases.tiers.PhaseContext;
  49 import org.graalvm.compiler.phases.util.Providers;
  50 
  51 import jdk.vm.ci.code.Architecture;
  52 import jdk.vm.ci.meta.ResolvedJavaMethod;
  53 
  54 /**
  55  * A graph decoder that provides all necessary encoded graphs on-the-fly (by parsing the methods and
  56  * encoding the graphs).
  57  */
  58 public class CachingPEGraphDecoder extends PEGraphDecoder {
  59 
  60     protected final Providers providers;
  61     protected final GraphBuilderConfiguration graphBuilderConfig;
  62     protected final OptimisticOptimizations optimisticOpts;
  63     private final AllowAssumptions allowAssumptions;
  64     private final EconomicMap<ResolvedJavaMethod, EncodedGraph> graphCache;
  65 
  66     public CachingPEGraphDecoder(Architecture architecture, StructuredGraph graph, Providers providers, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts,
  67                     AllowAssumptions allowAssumptions, LoopExplosionPlugin loopExplosionPlugin, InvocationPlugins invocationPlugins, InlineInvokePlugin[] inlineInvokePlugins,
  68                     ParameterPlugin parameterPlugin,
  69                     NodePlugin[] nodePlugins, ResolvedJavaMethod callInlinedMethod, SourceLanguagePositionProvider sourceLanguagePositionProvider) {
  70         super(architecture, graph, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), loopExplosionPlugin,
  71                         invocationPlugins, inlineInvokePlugins, parameterPlugin, nodePlugins, callInlinedMethod, sourceLanguagePositionProvider);
  72 
  73         this.providers = providers;
  74         this.graphBuilderConfig = graphBuilderConfig;
  75         this.optimisticOpts = optimisticOpts;
  76         this.allowAssumptions = allowAssumptions;
  77         this.graphCache = EconomicMap.create();
  78     }
  79 
  80     protected GraphBuilderPhase.Instance createGraphBuilderPhaseInstance(IntrinsicContext initialIntrinsicContext) {
  81         return new GraphBuilderPhase.Instance(providers.getMetaAccess(), providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), graphBuilderConfig,
  82                         optimisticOpts, initialIntrinsicContext);
  83     }
  84 
  85     @SuppressWarnings("try")
  86     private EncodedGraph createGraph(ResolvedJavaMethod method, ResolvedJavaMethod originalMethod, BytecodeProvider intrinsicBytecodeProvider, boolean isSubstitution) {
  87         // @formatter:off
  88         StructuredGraph graphToEncode = new StructuredGraph.Builder(options, debug, allowAssumptions).
  89                         useProfilingInfo(false).
  90                         trackNodeSourcePosition(graphBuilderConfig.trackNodeSourcePosition()).
  91                         method(method).
  92                         setIsSubstitution(isSubstitution).
  93                         cancellable(graph.getCancellable()).
  94                         build();
  95         // @formatter:on
  96         try (DebugContext.Scope scope = debug.scope("createGraph", graphToEncode)) {
  97             IntrinsicContext initialIntrinsicContext = intrinsicBytecodeProvider != null ? new IntrinsicContext(originalMethod, method, intrinsicBytecodeProvider, INLINE_AFTER_PARSING) : null;
  98             GraphBuilderPhase.Instance graphBuilderPhaseInstance = createGraphBuilderPhaseInstance(initialIntrinsicContext);
  99             graphBuilderPhaseInstance.apply(graphToEncode);
 100 
 101             PhaseContext context = new PhaseContext(providers);
 102             new CanonicalizerPhase().apply(graphToEncode, context);




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.replacements;
  26 
  27 import static org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext.CompilationContext.INLINE_AFTER_PARSING;
  28 
  29 import jdk.internal.vm.compiler.collections.EconomicMap;
  30 import org.graalvm.compiler.bytecode.BytecodeProvider;
  31 import org.graalvm.compiler.debug.DebugContext;
  32 import org.graalvm.compiler.graph.SourceLanguagePositionProvider;
  33 import org.graalvm.compiler.java.GraphBuilderPhase;
  34 import org.graalvm.compiler.loop.phases.ConvertDeoptimizeToGuardPhase;
  35 import org.graalvm.compiler.nodes.EncodedGraph;
  36 import org.graalvm.compiler.nodes.GraphEncoder;
  37 import org.graalvm.compiler.nodes.StructuredGraph;
  38 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  39 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
  40 import org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin;
  41 import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
  42 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins;
  43 import org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin;
  44 import org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin;
  45 import org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin;
  46 import org.graalvm.compiler.phases.OptimisticOptimizations;
  47 import org.graalvm.compiler.phases.common.CanonicalizerPhase;

  48 import org.graalvm.compiler.phases.tiers.PhaseContext;
  49 import org.graalvm.compiler.phases.util.Providers;
  50 
  51 import jdk.vm.ci.code.Architecture;
  52 import jdk.vm.ci.meta.ResolvedJavaMethod;
  53 
  54 /**
  55  * A graph decoder that provides all necessary encoded graphs on-the-fly (by parsing the methods and
  56  * encoding the graphs).
  57  */
  58 public class CachingPEGraphDecoder extends PEGraphDecoder {
  59 
  60     protected final Providers providers;
  61     protected final GraphBuilderConfiguration graphBuilderConfig;
  62     protected final OptimisticOptimizations optimisticOpts;
  63     private final AllowAssumptions allowAssumptions;
  64     private final EconomicMap<ResolvedJavaMethod, EncodedGraph> graphCache;
  65 
  66     public CachingPEGraphDecoder(Architecture architecture, StructuredGraph graph, Providers providers, GraphBuilderConfiguration graphBuilderConfig, OptimisticOptimizations optimisticOpts,
  67                     AllowAssumptions allowAssumptions, LoopExplosionPlugin loopExplosionPlugin, InvocationPlugins invocationPlugins, InlineInvokePlugin[] inlineInvokePlugins,
  68                     ParameterPlugin parameterPlugin,
  69                     NodePlugin[] nodePlugins, ResolvedJavaMethod callInlinedMethod, SourceLanguagePositionProvider sourceLanguagePositionProvider) {
  70         super(architecture, graph, providers, loopExplosionPlugin,
  71                         invocationPlugins, inlineInvokePlugins, parameterPlugin, nodePlugins, callInlinedMethod, sourceLanguagePositionProvider);
  72 
  73         this.providers = providers;
  74         this.graphBuilderConfig = graphBuilderConfig;
  75         this.optimisticOpts = optimisticOpts;
  76         this.allowAssumptions = allowAssumptions;
  77         this.graphCache = EconomicMap.create();
  78     }
  79 
  80     protected GraphBuilderPhase.Instance createGraphBuilderPhaseInstance(IntrinsicContext initialIntrinsicContext) {
  81         return new GraphBuilderPhase.Instance(providers, graphBuilderConfig, optimisticOpts, initialIntrinsicContext);

  82     }
  83 
  84     @SuppressWarnings("try")
  85     private EncodedGraph createGraph(ResolvedJavaMethod method, ResolvedJavaMethod originalMethod, BytecodeProvider intrinsicBytecodeProvider, boolean isSubstitution) {
  86         // @formatter:off
  87         StructuredGraph graphToEncode = new StructuredGraph.Builder(options, debug, allowAssumptions).
  88                         useProfilingInfo(false).
  89                         trackNodeSourcePosition(graphBuilderConfig.trackNodeSourcePosition()).
  90                         method(method).
  91                         setIsSubstitution(isSubstitution).
  92                         cancellable(graph.getCancellable()).
  93                         build();
  94         // @formatter:on
  95         try (DebugContext.Scope scope = debug.scope("createGraph", graphToEncode)) {
  96             IntrinsicContext initialIntrinsicContext = intrinsicBytecodeProvider != null ? new IntrinsicContext(originalMethod, method, intrinsicBytecodeProvider, INLINE_AFTER_PARSING) : null;
  97             GraphBuilderPhase.Instance graphBuilderPhaseInstance = createGraphBuilderPhaseInstance(initialIntrinsicContext);
  98             graphBuilderPhaseInstance.apply(graphToEncode);
  99 
 100             PhaseContext context = new PhaseContext(providers);
 101             new CanonicalizerPhase().apply(graphToEncode, context);


< prev index next >