CallSite.java revision 1472:c18cbe5936b8
1/* 2 * Copyright (c) 2009, 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 25package com.sun.hotspot.tools.compiler; 26 27import java.io.PrintStream; 28import java.util.ArrayList; 29import java.util.List; 30 31public 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 41 CallSite() { 42 } 43 44 CallSite(int bci, Method m) { 45 this.bci = bci; 46 this.method = m; 47 } 48 49 void add(CallSite site) { 50 if (getCalls() == null) { 51 setCalls(new ArrayList<CallSite>()); 52 } 53 getCalls().add(site); 54 } 55 56 CallSite last() { 57 return last(-1); 58 } 59 60 CallSite last(int fromEnd) { 61 return getCalls().get(getCalls().size() + fromEnd); 62 } 63 64 public String toString() { 65 StringBuilder sb = new StringBuilder(); 66 if (getReason() == null) { 67 sb.append(" @ " + getBci() + " " + getMethod()); 68 } else { 69 sb.append("- @ " + getBci() + " " + getMethod() + " " + getReason()); 70 } 71 sb.append("\n"); 72 if (getCalls() != null) { 73 for (CallSite site : getCalls()) { 74 sb.append(site); 75 sb.append("\n"); 76 } 77 } 78 return sb.toString(); 79 } 80 81 public void print(PrintStream stream) { 82 print(stream, 0); 83 } 84 85 void emit(PrintStream stream, int indent) { 86 for (int i = 0; i < indent; i++) { 87 stream.print(' '); 88 } 89 } 90 private static boolean compat = true; 91 92 public void print(PrintStream stream, int indent) { 93 emit(stream, indent); 94 String m = getMethod().getHolder().replace('/', '.') + "::" + getMethod().getName(); 95 if (getReason() == null) { 96 stream.println(" @ " + getBci() + " " + m + " (" + getMethod().getBytes() + " bytes)"); 97 98 } else { 99 if (isCompat()) { 100 stream.println(" @ " + getBci() + " " + m + " " + getReason()); 101 } else { 102 stream.println("- @ " + getBci() + " " + m + 103 " (" + getMethod().getBytes() + " bytes) " + getReason()); 104 } 105 } 106 if (getReceiver() != null) { 107 emit(stream, indent + 3); 108 // stream.println("type profile " + method.holder + " -> " + receiver + " (" + 109 // receiver_count + "/" + count + "," + (receiver_count * 100 / count) + "%)"); 110 stream.println("type profile " + getMethod().getHolder() + " -> " + getReceiver() + " (" + 111 (getReceiverCount() * 100 / getCount()) + "%)"); 112 } 113 if (getCalls() != null) { 114 for (CallSite site : getCalls()) { 115 site.print(stream, indent + 2); 116 } 117 } 118 } 119 120 public int getBci() { 121 return bci; 122 } 123 124 public void setBci(int bci) { 125 this.bci = bci; 126 } 127 128 public Method getMethod() { 129 return method; 130 } 131 132 public void setMethod(Method method) { 133 this.method = method; 134 } 135 136 public int getCount() { 137 return count; 138 } 139 140 public void setCount(int count) { 141 this.count = count; 142 } 143 144 public String getReceiver() { 145 return receiver; 146 } 147 148 public void setReceiver(String receiver) { 149 this.receiver = receiver; 150 } 151 152 public int getReceiverCount() { 153 return receiver_count; 154 } 155 156 public void setReceiver_count(int receiver_count) { 157 this.receiver_count = receiver_count; 158 } 159 160 public String getReason() { 161 return reason; 162 } 163 164 public void setReason(String reason) { 165 this.reason = reason; 166 } 167 168 public List<CallSite> getCalls() { 169 return calls; 170 } 171 172 public void setCalls(List<CallSite> calls) { 173 this.calls = calls; 174 } 175 176 public static boolean isCompat() { 177 return compat; 178 } 179 180 public static void setCompat(boolean aCompat) { 181 compat = aCompat; 182 } 183} 184