1 /* 2 * Copyright (c) 2011, 2020, 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 sun.jvm.hotspot.opto; 26 27 import java.util.*; 28 import java.io.PrintStream; 29 import sun.jvm.hotspot.ci.*; 30 import sun.jvm.hotspot.debugger.*; 31 import sun.jvm.hotspot.runtime.*; 32 import sun.jvm.hotspot.oops.*; 33 import sun.jvm.hotspot.utilities.GrowableArray; 34 import sun.jvm.hotspot.types.*; 35 import sun.jvm.hotspot.utilities.Observable; 36 import sun.jvm.hotspot.utilities.Observer; 37 38 public class InlineTree extends VMObject { 39 static { VM.registerVMInitializedObserver(new Observer() { public void update(Observable o, Object data) { initialize(VM.getVM().getTypeDataBase()); } })40 VM.registerVMInitializedObserver(new Observer() { 41 public void update(Observable o, Object data) { 42 initialize(VM.getVM().getTypeDataBase()); 43 } 44 }); 45 } 46 initialize(TypeDataBase db)47 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { 48 Type type = db.lookupType("InlineTree"); 49 callerJvmsField = type.getAddressField("_caller_jvms"); 50 methodField = type.getAddressField("_method"); 51 callerTreeField = type.getAddressField("_caller_tree"); 52 subtreesField = type.getAddressField("_subtrees"); 53 } 54 55 private static AddressField callerJvmsField; 56 private static AddressField methodField; 57 private static AddressField callerTreeField; 58 private static AddressField subtreesField; 59 60 private static StaticBaseConstructor<InlineTree> inlineTreeConstructor = new StaticBaseConstructor<>(InlineTree.class); 61 InlineTree(Address addr)62 public InlineTree(Address addr) { 63 super(addr); 64 } 65 callerTree()66 public InlineTree callerTree() { 67 Address addr = callerTreeField.getValue(getAddress()); 68 if (addr == null) return null; 69 70 return new InlineTree(addr); 71 } 72 method()73 public ciMethod method() { 74 return (ciMethod) ciObjectFactory.getMetadata(methodField.getValue(getAddress())); 75 } 76 callerJvms()77 public JVMState callerJvms() { 78 return JVMState.create(callerJvmsField.getValue(getAddress())); 79 } 80 callerBci()81 public int callerBci() { 82 JVMState jvms = callerJvms(); 83 return (jvms != null) ? jvms.bci() : -1; 84 } 85 subtrees()86 public GrowableArray<InlineTree> subtrees() { 87 Address addr = getAddress().addOffsetTo(subtreesField.getOffset()); 88 89 return GrowableArray.create(addr, inlineTreeConstructor); 90 } 91 inlineLevel()92 public int inlineLevel() { 93 JVMState jvms = callerJvms(); 94 return (jvms != null) ? jvms.depth() : 0; 95 } 96 printImpl(PrintStream st, int indent)97 public void printImpl(PrintStream st, int indent) { 98 for (int i = 0; i < indent; i++) st.print(" "); 99 st.printf(" @ %d ", callerBci()); 100 method().printShortName(st); 101 st.println(); 102 103 GrowableArray<InlineTree> subt = subtrees(); 104 for (int i = 0 ; i < subt.length(); i++) { 105 subt.at(i).printImpl(st, indent + 2); 106 } 107 } print(PrintStream st)108 public void print(PrintStream st) { 109 printImpl(st, 2); 110 } 111 112 // Count number of nodes in this subtree count()113 public int count() { 114 int result = 1; 115 GrowableArray<InlineTree> subt = subtrees(); 116 for (int i = 0 ; i < subt.length(); i++) { 117 result += subt.at(i).count(); 118 } 119 return result; 120 } 121 dumpReplayData(PrintStream out)122 public void dumpReplayData(PrintStream out) { 123 out.printf(" %d %d ", inlineLevel(), callerBci()); 124 Method method = (Method)method().getMetadata(); 125 Klass holder = method.getMethodHolder(); 126 out.print(holder.getName().asString() + " " + 127 OopUtilities.escapeString(method.getName().asString()) + " " + 128 method.getSignature().asString()); 129 130 GrowableArray<InlineTree> subt = subtrees(); 131 for (int i = 0 ; i < subt.length(); i++) { 132 subt.at(i).dumpReplayData(out); 133 } 134 } 135 } 136