1 /* 2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 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 com.sun.hotspot.tools.compiler; 26 27 import java.io.PrintStream; 28 import java.util.ArrayList; 29 30 public class Compilation implements LogEvent { 31 32 private int id; 33 private boolean osr; 34 private Method method; 35 private CallSite call = new CallSite(); 36 private CallSite lateInlineCall = new CallSite(); 37 private int osrBci; 38 private String icount; 39 private String bcount; 40 private String special; 41 private double start; 42 private double end; 43 private int attempts; 44 private NMethod nmethod; 45 private ArrayList<Phase> phases = new ArrayList<Phase>(4); 46 private String failureReason; 47 48 Compilation(int id) { 49 this.id = id; 50 } 51 52 Phase getPhase(String s) { 53 for (Phase p : getPhases()) { 54 if (p.getName().equals(s)) { 55 return p; 56 } 57 } 58 return null; 59 } 60 61 double getRegallocTime() { 62 return getPhase("regalloc").getElapsedTime(); 63 } 64 65 public double getStart() { 66 return start; 67 } 68 69 @Override 70 public String toString() { 71 StringBuilder sb = new StringBuilder(); 72 sb.append(getId()); 73 sb.append(" "); 74 sb.append(getMethod()); 75 sb.append(" "); 76 sb.append(getIcount()); 77 sb.append("+"); 78 sb.append(getBcount()); 79 sb.append("\n"); 80 for (CallSite site : getCall().getCalls()) { 81 sb.append(site); 82 sb.append("\n"); 83 } 84 if (getLateInlineCall().getCalls() != null) { 85 sb.append("late inline:\n"); 86 for (CallSite site : getLateInlineCall().getCalls()) { 87 sb.append(site); 88 sb.append("\n"); 89 } 90 } 91 return sb.toString(); 92 } 93 94 public void printShort(PrintStream stream) { 95 if (getMethod() == null) { 96 stream.println(getSpecial()); 97 } else { 98 int bc = isOsr() ? getOsr_bci() : -1; 99 stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc)); 100 } 101 } 102 103 public void print(PrintStream stream) { 104 print(stream, 0, false); 105 } 106 107 public void print(PrintStream stream, boolean printInlining) { 108 print(stream, 0, printInlining); 109 } 110 111 public void print(PrintStream stream, int indent, boolean printInlining) { 112 if (getMethod() == null) { 113 stream.println(getSpecial()); 114 } else { 115 int bc = isOsr() ? getOsr_bci() : -1; 116 stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc)); 117 stream.println(); 118 if (getFailureReason() != null) { 119 stream.println("COMPILE FAILED " + getFailureReason()); 120 } 121 if (printInlining && call.getCalls() != null) { 122 for (CallSite site : call.getCalls()) { 123 site.print(stream, indent + 2); 124 } 125 } 126 if (printInlining && lateInlineCall.getCalls() != null) { 127 stream.println("late inline:"); 128 for (CallSite site : lateInlineCall.getCalls()) { 129 site.print(stream, indent + 2); 130 } 131 } 132 } 133 } 134 135 public int getId() { 136 return id; 137 } 138 139 public void setId(int id) { 140 this.id = id; 141 } 142 143 public boolean isOsr() { 144 return osr; 145 } 146 147 public void setOsr(boolean osr) { 148 this.osr = osr; 149 } 150 151 public int getOsr_bci() { 152 return osrBci; 153 } 154 155 public void setOsr_bci(int osrBci) { 156 this.osrBci = osrBci; 157 } 158 159 public String getIcount() { 160 return icount; 161 } 162 163 public void setICount(String icount) { 164 this.icount = icount; 165 } 166 167 public String getBcount() { 168 return bcount; 169 } 170 171 public void setBCount(String bcount) { 172 this.bcount = bcount; 173 } 174 175 public String getSpecial() { 176 return special; 177 } 178 179 public void setSpecial(String special) { 180 this.special = special; 181 } 182 183 public void setStart(double start) { 184 this.start = start; 185 } 186 187 public double getEnd() { 188 return end; 189 } 190 191 public void setEnd(double end) { 192 this.end = end; 193 } 194 195 public int getAttempts() { 196 return attempts; 197 } 198 199 public void setAttempts(int attempts) { 200 this.attempts = attempts; 201 } 202 203 public NMethod getNMethod() { 204 return nmethod; 205 } 206 207 public void setNMethod(NMethod NMethod) { 208 this.nmethod = NMethod; 209 } 210 211 public ArrayList<Phase> getPhases() { 212 return phases; 213 } 214 215 public void setPhases(ArrayList<Phase> phases) { 216 this.setPhases(phases); 217 } 218 219 public String getFailureReason() { 220 return failureReason; 221 } 222 223 public void setFailureReason(String failureReason) { 224 this.failureReason = failureReason; 225 } 226 227 public Method getMethod() { 228 return method; 229 } 230 231 public void setMethod(Method method) { 232 // Don't change method if it is already set to avoid changing 233 // it by post parse inlining info. 234 if (getMethod() == null) { 235 this.method = method; 236 } 237 } 238 239 public CallSite getCall() { 240 return call; 241 } 242 243 public void setCall(CallSite call) { 244 this.call = call; 245 } 246 247 public CallSite getLateInlineCall() { 248 return lateInlineCall; 249 } 250 251 public double getElapsedTime() { 252 return end - start; 253 } 254 255 public Compilation getCompilation() { 256 return this; 257 } 258 }