src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/GraphPrinterDumpHandler.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54328 37648a9c4a6a
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    35 import java.util.HashMap;
    35 import java.util.HashMap;
    36 import java.util.List;
    36 import java.util.List;
    37 import java.util.Map;
    37 import java.util.Map;
    38 import java.util.WeakHashMap;
    38 import java.util.WeakHashMap;
    39 
    39 
       
    40 import org.graalvm.compiler.core.common.CompilationIdentifier;
    40 import org.graalvm.compiler.debug.DebugContext;
    41 import org.graalvm.compiler.debug.DebugContext;
    41 import org.graalvm.compiler.debug.DebugDumpHandler;
    42 import org.graalvm.compiler.debug.DebugDumpHandler;
    42 import org.graalvm.compiler.debug.DebugDumpScope;
    43 import org.graalvm.compiler.debug.DebugDumpScope;
    43 import org.graalvm.compiler.debug.DebugOptions;
    44 import org.graalvm.compiler.debug.DebugOptions;
       
    45 import org.graalvm.compiler.debug.DebugOptions.PrintGraphTarget;
    44 import org.graalvm.compiler.debug.GraalError;
    46 import org.graalvm.compiler.debug.GraalError;
    45 import org.graalvm.compiler.debug.TTY;
    47 import org.graalvm.compiler.debug.TTY;
    46 import org.graalvm.compiler.debug.DebugOptions.PrintGraphTarget;
       
    47 import org.graalvm.compiler.graph.Graph;
    48 import org.graalvm.compiler.graph.Graph;
    48 import org.graalvm.compiler.nodes.StructuredGraph;
    49 import org.graalvm.compiler.nodes.StructuredGraph;
    49 import org.graalvm.compiler.options.OptionValues;
    50 import org.graalvm.compiler.options.OptionValues;
    50 import org.graalvm.compiler.phases.contract.NodeCostUtil;
    51 import org.graalvm.compiler.phases.contract.NodeCostUtil;
    51 import org.graalvm.compiler.serviceprovider.GraalServices;
    52 import org.graalvm.compiler.serviceprovider.GraalServices;
    64 
    65 
    65     private static final int FAILURE_LIMIT = 8;
    66     private static final int FAILURE_LIMIT = 8;
    66     private final GraphPrinterSupplier printerSupplier;
    67     private final GraphPrinterSupplier printerSupplier;
    67     protected GraphPrinter printer;
    68     protected GraphPrinter printer;
    68     private List<String> previousInlineContext;
    69     private List<String> previousInlineContext;
       
    70     private CompilationIdentifier previousCompilationID = CompilationIdentifier.INVALID_COMPILATION_ID;
    69     private int[] dumpIds = {};
    71     private int[] dumpIds = {};
    70     private int failuresCount;
    72     private int failuresCount;
    71     private Map<Graph, List<String>> inlineContextMap;
    73     private Map<Graph, List<String>> inlineContextMap;
    72     private final String jvmArguments;
    74     private final String jvmArguments;
    73     private final String sunJavaCommand;
    75     private final String sunJavaCommand;
   134             }
   136             }
   135 
   137 
   136             // Get all current JavaMethod instances in the context.
   138             // Get all current JavaMethod instances in the context.
   137             List<String> inlineContext = getInlineContext(graph);
   139             List<String> inlineContext = getInlineContext(graph);
   138 
   140 
   139             if (inlineContext != previousInlineContext) {
   141             if (graph instanceof StructuredGraph) {
       
   142                 CompilationIdentifier compilationID = ((StructuredGraph) graph).compilationId();
       
   143                 // If the graph to be dumped is with an invalid compilation id, it is likely derived
       
   144                 // from inlining.
       
   145                 if (compilationID != CompilationIdentifier.INVALID_COMPILATION_ID) {
       
   146                     if (previousCompilationID != CompilationIdentifier.INVALID_COMPILATION_ID && !compilationID.equals(previousCompilationID)) {
       
   147                         // Compilation ID does not match, close existing scopes.
       
   148                         for (int inlineDepth = previousInlineContext.size() - 1; inlineDepth >= 0; --inlineDepth) {
       
   149                             closeScope(debug, inlineDepth);
       
   150                         }
       
   151                         previousInlineContext = new ArrayList<>();
       
   152                     }
       
   153                     previousCompilationID = compilationID;
       
   154                 }
       
   155             }
       
   156 
       
   157             if (!inlineContext.equals(previousInlineContext)) {
   140                 Map<Object, Object> properties = new HashMap<>();
   158                 Map<Object, Object> properties = new HashMap<>();
   141                 properties.put("graph", graph.toString());
   159                 properties.put("graph", graph.toString());
   142                 addCompilationId(properties, graph);
   160                 addCompilationId(properties, graph);
   143                 if (inlineContext.equals(previousInlineContext)) {
   161                 // Check for method scopes that must be closed since the previous dump.
   144                     /*
   162                 for (int i = 0; i < previousInlineContext.size(); ++i) {
   145                      * two different graphs have the same inline context, so make sure they appear
   163                     if (i >= inlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
   146                      * in different folders by closing and reopening the top scope.
   164                         for (int inlineDepth = previousInlineContext.size() - 1; inlineDepth >= i; --inlineDepth) {
   147                      */
   165                             closeScope(debug, inlineDepth);
   148                     int inlineDepth = previousInlineContext.size() - 1;
       
   149                     closeScope(debug, inlineDepth);
       
   150                     openScope(debug, inlineContext.get(inlineDepth), inlineDepth, properties);
       
   151                 } else {
       
   152                     // Check for method scopes that must be closed since the previous dump.
       
   153                     for (int i = 0; i < previousInlineContext.size(); ++i) {
       
   154                         if (i >= inlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
       
   155                             for (int inlineDepth = previousInlineContext.size() - 1; inlineDepth >= i; --inlineDepth) {
       
   156                                 closeScope(debug, inlineDepth);
       
   157                             }
       
   158                             break;
       
   159                         }
   166                         }
   160                     }
   167                         break;
   161                     // Check for method scopes that must be opened since the previous dump.
   168                     }
   162                     for (int i = 0; i < inlineContext.size(); ++i) {
   169                 }
   163                         if (i >= previousInlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
   170                 // Check for method scopes that must be opened since the previous dump.
   164                             for (int inlineDepth = i; inlineDepth < inlineContext.size(); ++inlineDepth) {
   171                 for (int i = 0; i < inlineContext.size(); ++i) {
   165                                 openScope(debug, inlineContext.get(inlineDepth), inlineDepth, inlineDepth == inlineContext.size() - 1 ? properties : null);
   172                     if (i >= previousInlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
   166                             }
   173                         for (int inlineDepth = i; inlineDepth < inlineContext.size(); ++inlineDepth) {
   167                             break;
   174                             openScope(debug, inlineContext.get(inlineDepth), inlineDepth, inlineDepth == inlineContext.size() - 1 ? properties : null);
   168                         }
   175                         }
       
   176                         break;
   169                     }
   177                     }
   170                 }
   178                 }
   171             }
   179             }
   172 
   180 
   173             // Save inline context for next dump.
   181             // Save inline context for next dump.