src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/StructuredGraph.java
changeset 48861 47f19ff9903c
parent 48190 25cfedf27edc
child 49451 e06f9607f370
equal deleted inserted replaced
48860:5bce1b7e7800 48861:47f19ff9903c
    26 import java.util.Iterator;
    26 import java.util.Iterator;
    27 import java.util.List;
    27 import java.util.List;
    28 import java.util.concurrent.atomic.AtomicLong;
    28 import java.util.concurrent.atomic.AtomicLong;
    29 import java.util.function.Consumer;
    29 import java.util.function.Consumer;
    30 
    30 
       
    31 import org.graalvm.collections.EconomicMap;
       
    32 import org.graalvm.collections.EconomicSet;
       
    33 import org.graalvm.collections.Equivalence;
       
    34 import org.graalvm.collections.UnmodifiableEconomicMap;
    31 import org.graalvm.compiler.core.common.CancellationBailoutException;
    35 import org.graalvm.compiler.core.common.CancellationBailoutException;
    32 import org.graalvm.compiler.core.common.CompilationIdentifier;
    36 import org.graalvm.compiler.core.common.CompilationIdentifier;
    33 import org.graalvm.compiler.core.common.GraalOptions;
    37 import org.graalvm.compiler.core.common.GraalOptions;
    34 import org.graalvm.compiler.core.common.cfg.BlockMap;
    38 import org.graalvm.compiler.core.common.cfg.BlockMap;
    35 import org.graalvm.compiler.core.common.type.Stamp;
    39 import org.graalvm.compiler.core.common.type.Stamp;
    36 import org.graalvm.compiler.debug.DebugContext;
    40 import org.graalvm.compiler.debug.DebugContext;
    37 import org.graalvm.compiler.debug.JavaMethodContext;
    41 import org.graalvm.compiler.debug.JavaMethodContext;
    38 import org.graalvm.compiler.graph.Graph;
    42 import org.graalvm.compiler.graph.Graph;
    39 import org.graalvm.compiler.graph.Node;
    43 import org.graalvm.compiler.graph.Node;
    40 import org.graalvm.compiler.graph.NodeMap;
    44 import org.graalvm.compiler.graph.NodeMap;
       
    45 import org.graalvm.compiler.graph.NodeSourcePosition;
    41 import org.graalvm.compiler.nodes.calc.FloatingNode;
    46 import org.graalvm.compiler.nodes.calc.FloatingNode;
    42 import org.graalvm.compiler.nodes.cfg.Block;
    47 import org.graalvm.compiler.nodes.cfg.Block;
    43 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
    48 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
    44 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
    49 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
    45 import org.graalvm.compiler.nodes.spi.VirtualizableAllocation;
    50 import org.graalvm.compiler.nodes.spi.VirtualizableAllocation;
    46 import org.graalvm.compiler.nodes.util.GraphUtil;
    51 import org.graalvm.compiler.nodes.util.GraphUtil;
    47 import org.graalvm.compiler.options.OptionValues;
    52 import org.graalvm.compiler.options.OptionValues;
    48 import org.graalvm.util.EconomicMap;
       
    49 import org.graalvm.util.EconomicSet;
       
    50 import org.graalvm.util.Equivalence;
       
    51 import org.graalvm.util.UnmodifiableEconomicMap;
       
    52 
    53 
    53 import jdk.vm.ci.meta.Assumptions;
    54 import jdk.vm.ci.meta.Assumptions;
    54 import jdk.vm.ci.meta.Assumptions.Assumption;
    55 import jdk.vm.ci.meta.Assumptions.Assumption;
    55 import jdk.vm.ci.meta.DefaultProfilingInfo;
    56 import jdk.vm.ci.meta.DefaultProfilingInfo;
    56 import jdk.vm.ci.meta.JavaMethod;
    57 import jdk.vm.ci.meta.JavaMethod;
   167         private int entryBCI = JVMCICompiler.INVOCATION_ENTRY_BCI;
   168         private int entryBCI = JVMCICompiler.INVOCATION_ENTRY_BCI;
   168         private boolean useProfilingInfo = true;
   169         private boolean useProfilingInfo = true;
   169         private final OptionValues options;
   170         private final OptionValues options;
   170         private Cancellable cancellable = null;
   171         private Cancellable cancellable = null;
   171         private final DebugContext debug;
   172         private final DebugContext debug;
       
   173         private NodeSourcePosition callerContext;
   172 
   174 
   173         /**
   175         /**
   174          * Creates a builder for a graph.
   176          * Creates a builder for a graph.
   175          */
   177          */
   176         public Builder(OptionValues options, DebugContext debug, AllowAssumptions allowAssumptions) {
   178         public Builder(OptionValues options, DebugContext debug, AllowAssumptions allowAssumptions) {
   253         public Builder useProfilingInfo(boolean flag) {
   255         public Builder useProfilingInfo(boolean flag) {
   254             this.useProfilingInfo = flag;
   256             this.useProfilingInfo = flag;
   255             return this;
   257             return this;
   256         }
   258         }
   257 
   259 
       
   260         public Builder callerContext(NodeSourcePosition context) {
       
   261             this.callerContext = context;
       
   262             return this;
       
   263         }
       
   264 
   258         public StructuredGraph build() {
   265         public StructuredGraph build() {
   259             return new StructuredGraph(name, rootMethod, entryBCI, assumptions, speculationLog, useProfilingInfo, compilationId, options, debug, cancellable);
   266             return new StructuredGraph(name, rootMethod, entryBCI, assumptions, speculationLog, useProfilingInfo, compilationId, options, debug, cancellable, callerContext);
   260         }
   267         }
   261     }
   268     }
   262 
   269 
   263     public static final long INVALID_GRAPH_ID = -1;
   270     public static final long INVALID_GRAPH_ID = -1;
   264     private static final AtomicLong uniqueGraphIds = new AtomicLong();
   271     private static final AtomicLong uniqueGraphIds = new AtomicLong();
   282 
   289 
   283     private SpeculationLog speculationLog;
   290     private SpeculationLog speculationLog;
   284 
   291 
   285     private ScheduleResult lastSchedule;
   292     private ScheduleResult lastSchedule;
   286 
   293 
       
   294     private final InliningLog inliningLog;
       
   295 
       
   296     /**
       
   297      * Call stack (context) leading to construction of this graph.
       
   298      */
       
   299     private final NodeSourcePosition callerContext;
       
   300 
   287     /**
   301     /**
   288      * Records the methods that were used while constructing this graph, one entry for each time a
   302      * Records the methods that were used while constructing this graph, one entry for each time a
   289      * specific method is used.
   303      * specific method is used.
   290      */
   304      */
   291     private final List<ResolvedJavaMethod> methods = new ArrayList<>();
   305     private final List<ResolvedJavaMethod> methods = new ArrayList<>();
   315                     SpeculationLog speculationLog,
   329                     SpeculationLog speculationLog,
   316                     boolean useProfilingInfo,
   330                     boolean useProfilingInfo,
   317                     CompilationIdentifier compilationId,
   331                     CompilationIdentifier compilationId,
   318                     OptionValues options,
   332                     OptionValues options,
   319                     DebugContext debug,
   333                     DebugContext debug,
   320                     Cancellable cancellable) {
   334                     Cancellable cancellable,
       
   335                     NodeSourcePosition context) {
   321         super(name, options, debug);
   336         super(name, options, debug);
   322         this.setStart(add(new StartNode()));
   337         this.setStart(add(new StartNode()));
   323         this.rootMethod = method;
   338         this.rootMethod = method;
   324         this.graphId = uniqueGraphIds.incrementAndGet();
   339         this.graphId = uniqueGraphIds.incrementAndGet();
   325         this.compilationId = compilationId;
   340         this.compilationId = compilationId;
   326         this.entryBCI = entryBCI;
   341         this.entryBCI = entryBCI;
   327         this.assumptions = assumptions;
   342         this.assumptions = assumptions;
   328         this.speculationLog = speculationLog;
   343         this.speculationLog = speculationLog;
   329         this.useProfilingInfo = useProfilingInfo;
   344         this.useProfilingInfo = useProfilingInfo;
   330         this.cancellable = cancellable;
   345         this.cancellable = cancellable;
       
   346         this.inliningLog = new InliningLog();
       
   347         this.callerContext = context;
   331     }
   348     }
   332 
   349 
   333     public void setLastSchedule(ScheduleResult result) {
   350     public void setLastSchedule(ScheduleResult result) {
   334         lastSchedule = result;
   351         lastSchedule = result;
   335     }
   352     }
   434 
   451 
   435     public void setStart(StartNode start) {
   452     public void setStart(StartNode start) {
   436         this.start = start;
   453         this.start = start;
   437     }
   454     }
   438 
   455 
       
   456     public InliningLog getInliningLog() {
       
   457         return inliningLog;
       
   458     }
       
   459 
   439     /**
   460     /**
   440      * Creates a copy of this graph.
   461      * Creates a copy of this graph.
   441      *
   462      *
   442      * @param newName the name of the copy, used for debugging purposes (can be null)
   463      * @param newName the name of the copy, used for debugging purposes (can be null)
   443      * @param duplicationMapCallback consumer of the duplication map created during the copying
   464      * @param duplicationMapCallback consumer of the duplication map created during the copying
   457                         entryBCI,
   478                         entryBCI,
   458                         assumptions == null ? null : new Assumptions(),
   479                         assumptions == null ? null : new Assumptions(),
   459                         speculationLog,
   480                         speculationLog,
   460                         useProfilingInfo,
   481                         useProfilingInfo,
   461                         newCompilationId,
   482                         newCompilationId,
   462                         getOptions(), debugForCopy, null);
   483                         getOptions(), debugForCopy, null, callerContext);
   463         if (allowAssumptions == AllowAssumptions.YES && assumptions != null) {
   484         if (allowAssumptions == AllowAssumptions.YES && assumptions != null) {
   464             copy.assumptions.record(assumptions);
   485             copy.assumptions.record(assumptions);
   465         }
   486         }
   466         copy.hasUnsafeAccess = hasUnsafeAccess;
   487         copy.hasUnsafeAccess = hasUnsafeAccess;
   467         copy.setGuardsStage(getGuardsStage());
   488         copy.setGuardsStage(getGuardsStage());
   929 
   950 
   930     @Override
   951     @Override
   931     protected void afterRegister(Node node) {
   952     protected void afterRegister(Node node) {
   932         assert hasValueProxies() || !(node instanceof ValueProxyNode);
   953         assert hasValueProxies() || !(node instanceof ValueProxyNode);
   933     }
   954     }
       
   955 
       
   956     public NodeSourcePosition getCallerContext() {
       
   957         return callerContext;
       
   958     }
   934 }
   959 }