1 /* 2 * Copyright (c) 2009, 2011, 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 import java.util.List; 30 31 public class CallSite { 32 33 private int bci; 34 private Method method; 35 private int count; 36 private String receiver; 37 private int receiver_count; 38 private String reason; 39 private List<CallSite> calls; 40 private int endNodes; 41 private int endLiveNodes; 42 private double timeStamp; 43 44 CallSite() { 45 } 46 47 CallSite(int bci, Method m) { 48 this.bci = bci; 49 this.method = m; 50 } 51 52 void add(CallSite site) { 53 if (getCalls() == null) { 54 setCalls(new ArrayList<CallSite>()); 55 } 56 getCalls().add(site); 57 } 58 59 CallSite last() { 60 return last(-1); 61 } 62 63 CallSite last(int fromEnd) { 64 return getCalls().get(getCalls().size() + fromEnd); 65 } 66 67 public String toString() { 68 StringBuilder sb = new StringBuilder(); 69 if (getReason() == null) { 70 sb.append(" @ " + getBci() + " " + getMethod()); 71 } else { 72 sb.append("- @ " + getBci() + " " + getMethod() + " " + getReason()); 73 } 74 sb.append("\n"); 75 if (getCalls() != null) { 76 for (CallSite site : getCalls()) { 77 sb.append(site); 78 sb.append("\n"); 79 } 80 } 81 return sb.toString(); 82 } 83 84 public void print(PrintStream stream) { 85 print(stream, 0); 86 } 87 88 void emit(PrintStream stream, int indent) { 89 for (int i = 0; i < indent; i++) { 90 stream.print(' '); 91 } 92 } 93 private static boolean compat = true; 94 95 public void print(PrintStream stream, int indent) { 96 emit(stream, indent); 97 String m = getMethod().getHolder().replace('/', '.') + "::" + getMethod().getName(); 98 if (getReason() == null) { 99 stream.print(" @ " + getBci() + " " + m + " (" + getMethod().getBytes() + " bytes)"); 100 101 } else { 102 if (isCompat()) { 103 stream.print(" @ " + getBci() + " " + m + " " + getReason()); 104 } else { 105 stream.print("- @ " + getBci() + " " + m + 106 " (" + getMethod().getBytes() + " bytes) " + getReason()); 107 } 108 } 109 if (getEndNodes() > 0) { 110 stream.printf(" (end time: %6.4f nodes: %d live: %d)", getTimeStamp(), getEndNodes(), getEndLiveNodes()); 111 } 112 stream.println(""); 113 if (getReceiver() != null) { 114 emit(stream, indent + 4); 115 // stream.println("type profile " + method.holder + " -> " + receiver + " (" + 116 // receiver_count + "/" + count + "," + (receiver_count * 100 / count) + "%)"); 117 stream.println("type profile " + getMethod().getHolder() + " -> " + getReceiver() + " (" + 118 (getReceiverCount() * 100 / getCount()) + "%)"); 119 } 120 if (getCalls() != null) { 121 for (CallSite site : getCalls()) { 122 site.print(stream, indent + 2); 123 } 124 } 125 } 126 127 public int getBci() { 128 return bci; 129 } 130 131 public void setBci(int bci) { 132 this.bci = bci; 133 } 134 135 public Method getMethod() { 136 return method; 137 } 138 139 public void setMethod(Method method) { 140 this.method = method; 141 } 142 143 public int getCount() { 144 return count; 145 } 146 147 public void setCount(int count) { 148 this.count = count; 149 } 150 151 public String getReceiver() { 152 return receiver; 153 } 154 155 public void setReceiver(String receiver) { 156 this.receiver = receiver; 157 } 158 159 public int getReceiverCount() { 160 return receiver_count; 161 } 162 163 public void setReceiver_count(int receiver_count) { 164 this.receiver_count = receiver_count; 165 } 166 167 public String getReason() { 168 return reason; 169 } 170 171 public void setReason(String reason) { 172 this.reason = reason; 173 } 174 175 public List<CallSite> getCalls() { 176 return calls; 177 } 178 179 public void setCalls(List<CallSite> calls) { 180 this.calls = calls; 181 } 182 183 public static boolean isCompat() { 184 return compat; 185 } 186 187 public static void setCompat(boolean aCompat) { 188 compat = aCompat; 189 } 190 191 void setEndNodes(int n) { 192 endNodes = n; 193 } 194 195 public int getEndNodes() { 196 return endNodes; 197 } 198 199 void setEndLiveNodes(int n) { 200 endLiveNodes = n; 201 } 202 203 public int getEndLiveNodes() { 204 return endLiveNodes; 205 } 206 207 void setTimeStamp(double time) { 208 timeStamp = time; 209 } 210 211 public double getTimeStamp() { 212 return timeStamp; 213 } 214 215 }