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 void reset() { 53 call = new CallSite(); 54 lateInlineCall = new CallSite(); 55 phases = new ArrayList<Phase>(4); 56 } 57 58 Phase getPhase(String s) { 59 for (Phase p : getPhases()) { 60 if (p.getName().equals(s)) { 61 return p; 62 } 63 } 64 return null; 65 } 66 67 double getRegallocTime() { 68 return getPhase("regalloc").getElapsedTime(); 69 } 70 71 public double getStart() { 72 return start; 73 } 74 75 @Override 76 public String toString() { 77 StringBuilder sb = new StringBuilder(); 78 sb.append(getId()); 79 sb.append(" "); 80 sb.append(getMethod()); 81 sb.append(" "); 82 sb.append(getIcount()); 83 sb.append("+"); 84 sb.append(getBcount()); 85 sb.append("\n"); 86 for (CallSite site : getCall().getCalls()) { 87 sb.append(site); 88 sb.append("\n"); 89 } 90 if (getLateInlineCall().getCalls() != null) { 91 sb.append("late inline:\n"); 92 for (CallSite site : getLateInlineCall().getCalls()) { 93 sb.append(site); 94 sb.append("\n"); 95 } 96 } 97 return sb.toString(); 98 } 99 100 public void printShort(PrintStream stream) { 101 if (getMethod() == null) { 102 stream.println(getSpecial()); 103 } else { 104 int bc = isOsr() ? getOsr_bci() : -1; 105 stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc)); 106 } 107 } 108 109 public void print(PrintStream stream) { 110 print(stream, 0, false); 111 } 112 113 public void print(PrintStream stream, boolean printInlining) { 114 print(stream, 0, printInlining); 115 } 116 117 public void print(PrintStream stream, int indent, boolean printInlining) { 118 if (getMethod() == null) { 119 stream.println(getSpecial()); 120 } else { 121 int bc = isOsr() ? getOsr_bci() : -1; 122 stream.print(getId() + getMethod().decodeFlags(bc) + getMethod().format(bc)); 123 stream.println(); 124 if (getFailureReason() != null) { 125 stream.println("COMPILE FAILED " + getFailureReason()); 126 } 127 if (printInlining && call.getCalls() != null) { 128 for (CallSite site : call.getCalls()) { 129 site.print(stream, indent + 2); 130 } 131 } 132 if (printInlining && lateInlineCall.getCalls() != null) { 133 stream.println("late inline:"); 134 for (CallSite site : lateInlineCall.getCalls()) { 135 site.print(stream, indent + 2); 136 } 137 } 138 } 139 } 140 141 public int getId() { 142 return id; 143 } 144 145 public void setId(int id) { 146 this.id = id; 147 } 148 149 public boolean isOsr() { 150 return osr; 151 } 152 153 public void setOsr(boolean osr) { 154 this.osr = osr; 155 } 156 157 public int getOsr_bci() { 158 return osrBci; 159 } 160 161 public void setOsr_bci(int osrBci) { 162 this.osrBci = osrBci; 163 } 164 165 public String getIcount() { 166 return icount; 167 } 168 169 public void setICount(String icount) { 170 this.icount = icount; 171 } 172 173 public String getBcount() { 174 return bcount; 175 } 176 177 public void setBCount(String bcount) { 178 this.bcount = bcount; 179 } 180 181 public String getSpecial() { 182 return special; 183 } 184 185 public void setSpecial(String special) { 186 this.special = special; 187 } 188 189 public void setStart(double start) { 190 this.start = start; 191 } 192 193 public double getEnd() { 194 return end; 195 } 196 197 public void setEnd(double end) { 198 this.end = end; 199 } 200 201 public int getAttempts() { 202 return attempts; 203 } 204 205 public void setAttempts(int attempts) { 206 this.attempts = attempts; 207 } 208 209 public NMethod getNMethod() { 210 return nmethod; 211 } 212 213 public void setNMethod(NMethod NMethod) { 214 this.nmethod = NMethod; 215 } 216 217 public ArrayList<Phase> getPhases() { 218 return phases; 219 } 220 221 public String getFailureReason() { 222 return failureReason; 223 } 224 225 public void setFailureReason(String failureReason) { 226 this.failureReason = failureReason; 227 } 228 229 public Method getMethod() { 230 return method; 231 } 232 233 public void setMethod(Method method) { 234 // Don't change method if it is already set to avoid changing 235 // it by post parse inlining info. 236 if (getMethod() == null) { 237 this.method = method; 238 } 239 } 240 241 public CallSite getCall() { 242 return call; 243 } 244 245 public CallSite getLateInlineCall() { 246 return lateInlineCall; 247 } 248 249 public double getElapsedTime() { 250 return end - start; 251 } 252 253 public Compilation getCompilation() { 254 return this; 255 } 256 }