1 /* 2 * Copyright (c) 2009, 2013, 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 stream.printf(" (end time: %6.4f", getTimeStamp()); 110 if (getEndNodes() > 0) { 111 stream.printf(" nodes: %d live: %d", getEndNodes(), getEndLiveNodes()); 112 } 113 stream.println(")"); 114 115 if (getReceiver() != null) { 116 emit(stream, indent + 4); 117 // stream.println("type profile " + method.holder + " -> " + receiver + " (" + 118 // receiver_count + "/" + count + "," + (receiver_count * 100 / count) + "%)"); 119 stream.println("type profile " + getMethod().getHolder() + " -> " + getReceiver() + " (" + 120 (getReceiverCount() * 100 / getCount()) + "%)"); 121 } 122 if (getCalls() != null) { 123 for (CallSite site : getCalls()) { 124 site.print(stream, indent + 2); 125 } 126 } 127 } 128 129 public int getBci() { 130 return bci; 131 } 132 133 public void setBci(int bci) { 134 this.bci = bci; 135 } 136 137 public Method getMethod() { 138 return method; 139 } 140 141 public void setMethod(Method method) { 142 this.method = method; 143 } 144 145 public int getCount() { 146 return count; 147 } 148 149 public void setCount(int count) { 150 this.count = count; 151 } 152 153 public String getReceiver() { 154 return receiver; 155 } 156 157 public void setReceiver(String receiver) { 158 this.receiver = receiver; 159 } 160 161 public int getReceiverCount() { 162 return receiver_count; 163 } 164 165 public void setReceiver_count(int receiver_count) { 166 this.receiver_count = receiver_count; 167 } 168 169 public String getReason() { 170 return reason; 171 } 172 173 public void setReason(String reason) { 174 this.reason = reason; 175 } 176 177 public List<CallSite> getCalls() { 178 return calls; 179 } 180 181 public void setCalls(List<CallSite> calls) { 182 this.calls = calls; 183 } 184 185 public static boolean isCompat() { 186 return compat; 187 } 188 189 public static void setCompat(boolean aCompat) { 190 compat = aCompat; 191 } 192 193 void setEndNodes(int n) { 194 endNodes = n; 195 } 196 197 public int getEndNodes() { 198 return endNodes; 199 } 200 201 void setEndLiveNodes(int n) { 202 endLiveNodes = n; 203 } 204 205 public int getEndLiveNodes() { 206 return endLiveNodes; 207 } 208 209 void setTimeStamp(double time) { 210 timeStamp = time; 211 } 212 213 public double getTimeStamp() { 214 return timeStamp; 215 } 216 217 }