1 /* 2 * Copyright (c) 2000, 2004, 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.interpreter; 26 27 import java.io.*; 28 import java.util.*; 29 30 import sun.jvm.hotspot.code.*; 31 import sun.jvm.hotspot.debugger.*; 32 import sun.jvm.hotspot.runtime.*; 33 import sun.jvm.hotspot.types.*; 34 import sun.jvm.hotspot.utilities.*; 35 36 /** An InterpreterCodelet is a piece of interpreter code. All 37 interpreter code is generated into little codelets which contain 38 extra information for debugging and printing purposes. */ 39 40 public class InterpreterCodelet extends Stub { 41 private static long instanceSize; 42 private static CIntegerField sizeField; // the size in bytes 43 private static AddressField descriptionField; // a description of the codelet, for debugging & printing 44 private static CIntegerField bytecodeField; // associated bytecode if any 45 46 static { VM.registerVMInitializedObserver(new Observer() { public void update(Observable o, Object data) { initialize(VM.getVM().getTypeDataBase()); } })47 VM.registerVMInitializedObserver(new Observer() { 48 public void update(Observable o, Object data) { 49 initialize(VM.getVM().getTypeDataBase()); 50 } 51 }); 52 } 53 initialize(TypeDataBase db)54 private static synchronized void initialize(TypeDataBase db) { 55 Type type = db.lookupType("InterpreterCodelet"); 56 57 sizeField = type.getCIntegerField("_size"); 58 descriptionField = type.getAddressField("_description"); 59 bytecodeField = type.getCIntegerField("_bytecode"); 60 61 instanceSize = type.getSize(); 62 } 63 InterpreterCodelet(Address addr)64 public InterpreterCodelet(Address addr) { 65 super(addr); 66 } 67 getSize()68 public long getSize() { 69 return sizeField.getValue(addr); 70 } 71 codeBegin()72 public Address codeBegin() { 73 return addr.addOffsetTo(instanceSize); 74 } 75 codeEnd()76 public Address codeEnd() { 77 return addr.addOffsetTo(getSize()); 78 } 79 codeSize()80 public long codeSize() { 81 return codeEnd().minus(codeBegin()); 82 } 83 getDescription()84 public String getDescription() { 85 return CStringUtilities.getString(descriptionField.getValue(addr)); 86 } 87 verify()88 public void verify() { 89 } 90 printOn(PrintStream tty)91 public void printOn(PrintStream tty) { 92 String desc = getDescription(); 93 if (desc != null) { 94 tty.print(desc); 95 } 96 // FIXME: add printing of bytecode 97 tty.println(" [" + codeBegin() + ", " + codeEnd() + ") " + 98 codeSize() + " bytes "); 99 // FIXME: add disassembly 100 } 101 } 102