1 /* 2 * Copyright 2000-2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20 * CA 95054 USA or visit www.sun.com if you need additional information or 21 * have any questions. 22 * 23 */ 24 25 package sun.jvm.hotspot.code; 26 27 import java.io.*; 28 import java.util.*; 29 import sun.jvm.hotspot.debugger.*; 30 import sun.jvm.hotspot.runtime.*; 31 import sun.jvm.hotspot.types.*; 32 33 /** PcDescs map a physical PC (given as offset from start of nmethod) 34 to the corresponding source scope and byte code index. */ 35 36 public class PCDesc extends VMObject { 37 private static CIntegerField pcOffsetField; 38 private static CIntegerField scopeDecodeOffsetField; 39 40 static { 41 VM.registerVMInitializedObserver(new Observer() { 42 public void update(Observable o, Object data) { 43 initialize(VM.getVM().getTypeDataBase()); 44 } 45 }); 46 } 47 48 private static void initialize(TypeDataBase db) { 49 Type type = db.lookupType("PcDesc"); 50 51 pcOffsetField = type.getCIntegerField("_pc_offset"); 52 scopeDecodeOffsetField = type.getCIntegerField("_scope_decode_offset"); 53 } 54 55 public PCDesc(Address addr) { 56 super(addr); 57 } 58 59 // FIXME: add additional constructor probably needed for ScopeDesc::sender() 60 61 public int getPCOffset() { 62 return (int) pcOffsetField.getValue(addr); 63 } 64 65 public int getScopeDecodeOffset() { 66 return ((int) scopeDecodeOffsetField.getValue(addr)); 67 } 68 69 public Address getRealPC(NMethod code) { 70 return code.instructionsBegin().addOffsetTo(getPCOffset()); 71 } 72 73 public void print(NMethod code) { 74 printOn(System.out, code); 75 } 76 77 public void printOn(PrintStream tty, NMethod code) { 78 tty.println("PCDesc(" + getRealPC(code) + "):"); 79 for (ScopeDesc sd = code.getScopeDescAt(getRealPC(code)); 80 sd != null; 81 sd = sd.sender()) { 82 tty.print(" "); 83 sd.getMethod().printValueOn(tty); 84 tty.print(" @" + sd.getBCI()); 85 tty.print(" reexecute=" + sd.getReexecute()); 86 tty.println(); 87 } 88 } 89 }