< prev index next >

src/share/tools/LogCompilation/src/com/sun/hotspot/tools/compiler/Compilation.java

Print this page
rev 8632 : 6900757: minor bug fixes to LogCompilation tool
* improve internal error reporting (point to XML element causing trouble)
* fix comparator for sorting by name and start
* make tool more robust wrt. incorrect options and files not found
* make inlining decision output more clear
* adopt uncommon traps history printing
* properly mention compiler in generated logs
* add options for printing time stamps and omitting compilation IDs
* add option for comparing compilation logs
* overall code cleanup and API documentation

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -25,38 +25,118 @@
 package com.sun.hotspot.tools.compiler;
 
 import java.io.PrintStream;
 import java.util.ArrayList;
 
+/**
+ * One particular compilation, represented in the compilation log file as a
+ * {@code task} element.
+ */
 public class Compilation implements LogEvent {
 
+    /**
+     * The compilation ID.
+     */
     private int id;
+    
+    /**
+     * Whether this is a compilation for on-stack replacement (OSR).
+     */
     private boolean osr;
+    
+    /**
+     * The method being compiled.
+     */
     private Method method;
+    
+    /**
+     * The {@linkplain CallSite scope} of this compilation. This is created as
+     * an empty {@link CallSite} instance, to be filled with data (and
+     * meaning) later on.
+     */
     private CallSite call = new CallSite();
+    
+    /**
+     * In case a {@code late_inline} event occurs during the compilation, this
+     * field holds the information about it.
+     */
     private CallSite lateInlineCall = new CallSite();
-    private int osrBci;
+    
+    /**
+     * The bytecode instruction index for on-stack replacement compilations; -1
+     * if this is not an OSR compilation.
+     */
+    private int bci;
+    
+    /**
+     * The method under compilation's invocation count.
+     */
     private String icount;
+    
+    /**
+     * The method under compilation's backedge count.
+     */
     private String bcount;
+    
+    /**
+     * Additional information for special compilations (e.g., adapters).
+     */
     private String special;
+    
+    /**
+     * The name of the compiler performing this compilation.
+     */
+    private String compiler;
+    
+    /**
+     * Start time stamp.
+     */
     private double start;
+    
+    /**
+     * End time stamp.
+     */
     private double end;
+    
+    /**
+     * Trip count of the register allocator.
+     */
     private int attempts;
+    
+    /**
+     * The compilation result (a native method).
+     */
     private NMethod nmethod;
-    private ArrayList<Phase> phases = new ArrayList<Phase>(4);
+    
+    /**
+     * The phases through which this compilation goes.
+     */
+    private ArrayList<Phase> phases = new ArrayList<>(4);
+    
+    /**
+     * In case this compilation fails, the reason for that.
+     */
     private String failureReason;
 
     Compilation(int id) {
         this.id = id;
     }
 
     void reset() {
         call = new CallSite();
         lateInlineCall = new CallSite();
-        phases = new ArrayList<Phase>(4);
+        phases = new ArrayList<>(4);
     }
 
+    /**
+     * Get a compilation phase by name, or {@code null}.
+     * 
+     * @param s the name of the phase to retrieve in this compilation.
+     * 
+     * @return a compilation phase, or {@code null} if no phase with the given
+     *         name is found.
+     */
     Phase getPhase(String s) {
         for (Phase p : getPhases()) {
             if (p.getName().equals(s)) {
                 return p;
             }

@@ -70,25 +150,37 @@
 
     public double getStart() {
         return start;
     }
 
+    public void setCompiler(String compiler) {
+        this.compiler = compiler;
+    }
+    
+    public String getCompiler() {
+        return compiler;
+    }
+
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append(getId());
         sb.append(" ");
+        sb.append(getCompiler());
+        sb.append(" ");
         sb.append(getMethod());
         sb.append(" ");
         sb.append(getIcount());
         sb.append("+");
         sb.append(getBcount());
         sb.append("\n");
+        if (getCall() != null && getCall().getCalls() != null) {
         for (CallSite site : getCall().getCalls()) {
             sb.append(site);
             sb.append("\n");
         }
+        }
         if (getLateInlineCall().getCalls() != null) {
             sb.append("late inline:\n");
             for (CallSite site : getLateInlineCall().getCalls()) {
                 sb.append(site);
                 sb.append("\n");

@@ -99,42 +191,54 @@
 
     public void printShort(PrintStream stream) {
         if (getMethod() == null) {
             stream.println(getSpecial());
         } else {
-            int bc = isOsr() ? getOsr_bci() : -1;
-            stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc));
+            int bc = isOsr() ? getBCI() : -1;
+            stream.print(getId() + getMethod().decodeFlags(bc) + " " + compiler + " " + getMethod().format(bc));
+        }
         }
+
+    public void print(PrintStream stream, boolean printID) {
+        print(stream, 0, printID, true, false);
     }
 
-    public void print(PrintStream stream) {
-        print(stream, 0, false);
+    public void print(PrintStream stream, boolean printID, boolean printInlining) {
+        print(stream, 0, printID, printInlining, false);
     }
 
-    public void print(PrintStream stream, boolean printInlining) {
-        print(stream, 0, printInlining);
+    public void print(PrintStream stream, boolean printID, boolean printInlining, boolean printUncommonTraps) {
+        print(stream, 0, printID, printInlining, printUncommonTraps);
     }
 
-    public void print(PrintStream stream, int indent, boolean printInlining) {
+    public void print(PrintStream stream, int indent, boolean printID, boolean printInlining, boolean printUncommonTraps) {
         if (getMethod() == null) {
             stream.println(getSpecial());
         } else {
-            int bc = isOsr() ? getOsr_bci() : -1;
-            stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc));
+            if (printID) {
+                stream.print(getId());
+            }
+            int bc = isOsr() ? getBCI() : -1;
+            stream.print(getMethod().decodeFlags(bc) + " " + compiler + " " + getMethod().format(bc));
             stream.println();
             if (getFailureReason() != null) {
-                stream.println("COMPILE FAILED " + getFailureReason());
+                stream.println("COMPILE SKIPPED: " + getFailureReason() + " (not retryable)");
             }
             if (printInlining && call.getCalls() != null) {
                 for (CallSite site : call.getCalls()) {
+                    site.print(stream, indent + 2, printInlining, printUncommonTraps);
+                }
+            }
+            if (printUncommonTraps && call.getTraps() != null) {
+                for (UncommonTrap site : call.getTraps()) {
                     site.print(stream, indent + 2);
                 }
             }
             if (printInlining && lateInlineCall.getCalls() != null) {
                 stream.println("late inline:");
                 for (CallSite site : lateInlineCall.getCalls()) {
-                    site.print(stream, indent + 2);
+                    site.print(stream, indent + 2, printInlining, printUncommonTraps);
                 }
             }
         }
     }
 

@@ -152,16 +256,16 @@
 
     public void setOsr(boolean osr) {
         this.osr = osr;
     }
 
-    public int getOsr_bci() {
-        return osrBci;
+    public int getBCI() {
+        return bci;
     }
 
-    public void setOsr_bci(int osrBci) {
-        this.osrBci = osrBci;
+    public void setBCI(int osrBci) {
+        this.bci = osrBci;
     }
 
     public String getIcount() {
         return icount;
     }

@@ -228,13 +332,17 @@
 
     public Method getMethod() {
         return method;
     }
 
+    /**
+     * Set the method under compilation. If it is already set, ignore the
+     * argument to avoid changing the method by post-parse inlining info.
+     * 
+     * @param method the method under compilation. May be ignored.
+     */
     public void setMethod(Method method) {
-        // Don't change method if it is already set to avoid changing
-        // it by post parse inlining info.
         if (getMethod() == null) {
             this.method = method;
         }
     }
 
< prev index next >