src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/PartialEscapePhase.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 52910 583fd71c47d6
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2011, 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.
    30 import jdk.internal.vm.compiler.collections.EconomicSet;
    30 import jdk.internal.vm.compiler.collections.EconomicSet;
    31 import org.graalvm.compiler.graph.Node;
    31 import org.graalvm.compiler.graph.Node;
    32 import org.graalvm.compiler.nodes.StructuredGraph;
    32 import org.graalvm.compiler.nodes.StructuredGraph;
    33 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
    33 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
    34 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
    34 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
       
    35 import org.graalvm.compiler.nodes.spi.CoreProviders;
    35 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
    36 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
    36 import org.graalvm.compiler.options.Option;
    37 import org.graalvm.compiler.options.Option;
    37 import org.graalvm.compiler.options.OptionKey;
    38 import org.graalvm.compiler.options.OptionKey;
    38 import org.graalvm.compiler.options.OptionType;
    39 import org.graalvm.compiler.options.OptionType;
    39 import org.graalvm.compiler.options.OptionValues;
    40 import org.graalvm.compiler.options.OptionValues;
    40 import org.graalvm.compiler.phases.BasePhase;
    41 import org.graalvm.compiler.phases.BasePhase;
    41 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
    42 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
    42 import org.graalvm.compiler.phases.tiers.PhaseContext;
       
    43 
    43 
    44 public class PartialEscapePhase extends EffectsPhase<PhaseContext> {
    44 public class PartialEscapePhase extends EffectsPhase<CoreProviders> {
    45 
    45 
    46     static class Options {
    46     static class Options {
    47         //@formatter:off
    47         //@formatter:off
    48         @Option(help = "", type = OptionType.Debug)
    48         @Option(help = "", type = OptionType.Debug)
    49         public static final OptionKey<Boolean> OptEarlyReadElimination = new OptionKey<>(true);
    49         public static final OptionKey<Boolean> OptEarlyReadElimination = new OptionKey<>(true);
    50         //@formatter:on
    50         //@formatter:on
    51     }
    51     }
    52 
    52 
    53     private final boolean readElimination;
    53     private final boolean readElimination;
    54     private final BasePhase<PhaseContext> cleanupPhase;
    54     private final BasePhase<CoreProviders> cleanupPhase;
    55 
    55 
    56     public PartialEscapePhase(boolean iterative, CanonicalizerPhase canonicalizer, OptionValues options) {
    56     public PartialEscapePhase(boolean iterative, CanonicalizerPhase canonicalizer, OptionValues options) {
    57         this(iterative, Options.OptEarlyReadElimination.getValue(options), canonicalizer, null, options);
    57         this(iterative, Options.OptEarlyReadElimination.getValue(options), canonicalizer, null, options);
    58     }
    58     }
    59 
    59 
    60     public PartialEscapePhase(boolean iterative, CanonicalizerPhase canonicalizer, BasePhase<PhaseContext> cleanupPhase, OptionValues options) {
    60     public PartialEscapePhase(boolean iterative, CanonicalizerPhase canonicalizer, BasePhase<CoreProviders> cleanupPhase, OptionValues options) {
    61         this(iterative, Options.OptEarlyReadElimination.getValue(options), canonicalizer, cleanupPhase, options);
    61         this(iterative, Options.OptEarlyReadElimination.getValue(options), canonicalizer, cleanupPhase, options);
    62     }
    62     }
    63 
    63 
    64     public PartialEscapePhase(boolean iterative, boolean readElimination, CanonicalizerPhase canonicalizer, BasePhase<PhaseContext> cleanupPhase, OptionValues options) {
    64     public PartialEscapePhase(boolean iterative, boolean readElimination, CanonicalizerPhase canonicalizer, BasePhase<CoreProviders> cleanupPhase, OptionValues options) {
    65         super(iterative ? EscapeAnalysisIterations.getValue(options) : 1, canonicalizer);
    65         super(iterative ? EscapeAnalysisIterations.getValue(options) : 1, canonicalizer);
    66         this.readElimination = readElimination;
    66         this.readElimination = readElimination;
    67         this.cleanupPhase = cleanupPhase;
    67         this.cleanupPhase = cleanupPhase;
    68     }
    68     }
    69 
    69 
    70     @Override
    70     @Override
    71     protected void postIteration(StructuredGraph graph, PhaseContext context, EconomicSet<Node> changedNodes) {
    71     protected void postIteration(StructuredGraph graph, CoreProviders context, EconomicSet<Node> changedNodes) {
    72         super.postIteration(graph, context, changedNodes);
    72         super.postIteration(graph, context, changedNodes);
    73         if (cleanupPhase != null) {
    73         if (cleanupPhase != null) {
    74             cleanupPhase.apply(graph, context);
    74             cleanupPhase.apply(graph, context);
    75         }
    75         }
    76     }
    76     }
    77 
    77 
    78     @Override
    78     @Override
    79     protected void run(StructuredGraph graph, PhaseContext context) {
    79     protected void run(StructuredGraph graph, CoreProviders context) {
    80         if (VirtualUtil.matches(graph, EscapeAnalyzeOnly.getValue(graph.getOptions()))) {
    80         if (VirtualUtil.matches(graph, EscapeAnalyzeOnly.getValue(graph.getOptions()))) {
    81             if (readElimination || graph.hasVirtualizableAllocation()) {
    81             if (readElimination || graph.hasVirtualizableAllocation()) {
    82                 runAnalysis(graph, context);
    82                 runAnalysis(graph, context);
    83             }
    83             }
    84         }
    84         }
    85     }
    85     }
    86 
    86 
    87     @Override
    87     @Override
    88     protected Closure<?> createEffectsClosure(PhaseContext context, ScheduleResult schedule, ControlFlowGraph cfg) {
    88     protected Closure<?> createEffectsClosure(CoreProviders context, ScheduleResult schedule, ControlFlowGraph cfg) {
    89         for (VirtualObjectNode virtual : cfg.graph.getNodes(VirtualObjectNode.TYPE)) {
    89         for (VirtualObjectNode virtual : cfg.graph.getNodes(VirtualObjectNode.TYPE)) {
    90             virtual.resetObjectId();
    90             virtual.resetObjectId();
    91         }
    91         }
    92         assert schedule != null;
    92         assert schedule != null;
    93         if (readElimination) {
    93         if (readElimination) {