annotate agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.oops;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.code.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.interpreter.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public class ConstMethod extends Oop {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43 });
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // anon-enum constants for _flags.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private static int HAS_LINENUMBER_TABLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private static int HAS_CHECKED_EXCEPTIONS;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private static int HAS_LOCALVARIABLE_TABLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 Type type = db.lookupType("constMethodOopDesc");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // Backpointer to non-const methodOop
a61af66fc99e Initial load
duke
parents:
diff changeset
54 method = new OopField(type.getOopField("_method"), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // The exception handler table. 4-tuples of ints [start_pc, end_pc,
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // handler_pc, catch_type index] For methods with no exceptions the
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // table is pointing to Universe::the_empty_int_array
a61af66fc99e Initial load
duke
parents:
diff changeset
58 exceptionTable = new OopField(type.getOopField("_exception_table"), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 constMethodSize = new CIntField(type.getCIntegerField("_constMethod_size"), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 flags = new ByteField(type.getJByteField("_flags"), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // enum constants for flags
a61af66fc99e Initial load
duke
parents:
diff changeset
63 HAS_LINENUMBER_TABLE = db.lookupIntConstant("constMethodOopDesc::_has_linenumber_table").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
64 HAS_CHECKED_EXCEPTIONS = db.lookupIntConstant("constMethodOopDesc::_has_checked_exceptions").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 HAS_LOCALVARIABLE_TABLE = db.lookupIntConstant("constMethodOopDesc::_has_localvariable_table").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Size of Java bytecodes allocated immediately after constMethodOop.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 codeSize = new CIntField(type.getCIntegerField("_code_size"), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 nameIndex = new CIntField(type.getCIntegerField("_name_index"), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 signatureIndex = new CIntField(type.getCIntegerField("_signature_index"), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 genericSignatureIndex = new CIntField(type.getCIntegerField("_generic_signature_index"),0);
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // start of byte code
a61af66fc99e Initial load
duke
parents:
diff changeset
74 bytecodeOffset = type.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 type = db.lookupType("CheckedExceptionElement");
a61af66fc99e Initial load
duke
parents:
diff changeset
77 checkedExceptionElementSize = type.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 type = db.lookupType("LocalVariableTableElement");
a61af66fc99e Initial load
duke
parents:
diff changeset
80 localVariableTableElementSize = type.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 ConstMethod(OopHandle handle, ObjectHeap heap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 super(handle, heap);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Fields
a61af66fc99e Initial load
duke
parents:
diff changeset
88 private static OopField method;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 private static OopField exceptionTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 private static CIntField constMethodSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 private static ByteField flags;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 private static CIntField codeSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 private static CIntField nameIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 private static CIntField signatureIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 private static CIntField genericSignatureIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // start of bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
98 private static long bytecodeOffset;
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 private static long checkedExceptionElementSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 private static long localVariableTableElementSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Accessors for declared fields
a61af66fc99e Initial load
duke
parents:
diff changeset
104 public Method getMethod() {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 return (Method) method.getValue(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public TypeArray getExceptionTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return (TypeArray) exceptionTable.getValue(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 public long getConstMethodSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 return constMethodSize.getValue(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public byte getFlags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return flags.getValue(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 public long getCodeSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return codeSize.getValue(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 public long getNameIndex() {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return nameIndex.getValue(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 public long getSignatureIndex() {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 return signatureIndex.getValue(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public long getGenericSignatureIndex() {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return genericSignatureIndex.getValue(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 public Symbol getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return getMethod().getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 public Symbol getSignature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return getMethod().getSignature();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 public Symbol getGenericSignature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return getMethod().getGenericSignature();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // bytecode accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 /** Get a bytecode or breakpoint at the given bci */
a61af66fc99e Initial load
duke
parents:
diff changeset
151 public int getBytecodeOrBPAt(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return getHandle().getJByteAt(bytecodeOffset + bci) & 0xFF;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 public byte getBytecodeByteArg(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return (byte) getBytecodeOrBPAt(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 /** Fetches a 16-bit big-endian ("Java ordered") value from the
a61af66fc99e Initial load
duke
parents:
diff changeset
160 bytecode stream */
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public short getBytecodeShortArg(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 int hi = getBytecodeOrBPAt(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 int lo = getBytecodeOrBPAt(bci + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return (short) ((hi << 8) | lo);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 /** Fetches a 32-bit big-endian ("Java ordered") value from the
a61af66fc99e Initial load
duke
parents:
diff changeset
168 bytecode stream */
a61af66fc99e Initial load
duke
parents:
diff changeset
169 public int getBytecodeIntArg(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 int b4 = getBytecodeOrBPAt(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 int b3 = getBytecodeOrBPAt(bci + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
172 int b2 = getBytecodeOrBPAt(bci + 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 int b1 = getBytecodeOrBPAt(bci + 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 public byte[] getByteCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 byte[] bc = new byte[ (int) getCodeSize() ];
a61af66fc99e Initial load
duke
parents:
diff changeset
180 for( int i=0; i < bc.length; i++ )
a61af66fc99e Initial load
duke
parents:
diff changeset
181 {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 long offs = bytecodeOffset + i;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 bc[i] = getHandle().getJByteAt( offs );
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return bc;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 public long getObjectSize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 return getConstMethodSize() * getHeap().getOopSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 public void printValueOn(PrintStream tty) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 tty.print("ConstMethod " + getName().asString() + getSignature().asString() + "@" + getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 super.iterateFields(visitor, doVMFields);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 if (doVMFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 visitor.doOop(method, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 visitor.doOop(exceptionTable, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 visitor.doCInt(constMethodSize, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 visitor.doByte(flags, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 visitor.doCInt(codeSize, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
204 visitor.doCInt(nameIndex, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 visitor.doCInt(signatureIndex, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 visitor.doCInt(genericSignatureIndex, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 visitor.doCInt(codeSize, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // Accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 public boolean hasLineNumberTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 return (getFlags() & HAS_LINENUMBER_TABLE) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 public int getLineNumberFromBCI(int bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (!VM.getVM().isCore()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 if (bci == DebugInformationRecorder.SYNCHRONIZATION_ENTRY_BCI) bci = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 if (isNative()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 Assert.that(bci == 0 || 0 <= bci && bci < getCodeSize(), "illegal bci");
a61af66fc99e Initial load
duke
parents:
diff changeset
228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 int bestBCI = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 int bestLine = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 if (hasLineNumberTable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // The line numbers are a short array of 2-tuples [start_pc, line_number].
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // Not necessarily sorted and not necessarily one-to-one.
a61af66fc99e Initial load
duke
parents:
diff changeset
234 CompressedLineNumberReadStream stream =
a61af66fc99e Initial load
duke
parents:
diff changeset
235 new CompressedLineNumberReadStream(getHandle(), (int) offsetOfCompressedLineNumberTable());
a61af66fc99e Initial load
duke
parents:
diff changeset
236 while (stream.readPair()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 if (stream.bci() == bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // perfect match
a61af66fc99e Initial load
duke
parents:
diff changeset
239 return stream.line();
a61af66fc99e Initial load
duke
parents:
diff changeset
240 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // update best_bci/line
a61af66fc99e Initial load
duke
parents:
diff changeset
242 if (stream.bci() < bci && stream.bci() >= bestBCI) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 bestBCI = stream.bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
244 bestLine = stream.line();
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 return bestLine;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 }
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 public LineNumberTableElement[] getLineNumberTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 Assert.that(hasLineNumberTable(),
a61af66fc99e Initial load
duke
parents:
diff changeset
255 "should only be called if table is present");
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257 int len = getLineNumberTableLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
258 CompressedLineNumberReadStream stream =
a61af66fc99e Initial load
duke
parents:
diff changeset
259 new CompressedLineNumberReadStream(getHandle(), (int) offsetOfCompressedLineNumberTable());
a61af66fc99e Initial load
duke
parents:
diff changeset
260 LineNumberTableElement[] ret = new LineNumberTableElement[len];
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 for (int idx = 0; idx < len; idx++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 stream.readPair();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 ret[idx] = new LineNumberTableElement(stream.bci(), stream.line());
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 public boolean hasLocalVariableTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 return (getFlags() & HAS_LOCALVARIABLE_TABLE) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 public Symbol getLocalVariableName(int bci, int slot) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 return getMethod().getLocalVariableName(bci, slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 /** Should only be called if table is present */
a61af66fc99e Initial load
duke
parents:
diff changeset
278 public LocalVariableTableElement[] getLocalVariableTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 Assert.that(hasLocalVariableTable(), "should only be called if table is present");
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 LocalVariableTableElement[] ret = new LocalVariableTableElement[getLocalVariableTableLength()];
a61af66fc99e Initial load
duke
parents:
diff changeset
283 long offset = offsetOfLocalVariableTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
284 for (int i = 0; i < ret.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 ret[i] = new LocalVariableTableElement(getHandle(), offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 offset += localVariableTableElementSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 public boolean hasCheckedExceptions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 return (getFlags() & HAS_CHECKED_EXCEPTIONS) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 public CheckedExceptionElement[] getCheckedExceptions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
297 Assert.that(hasCheckedExceptions(), "should only be called if table is present");
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 CheckedExceptionElement[] ret = new CheckedExceptionElement[getCheckedExceptionsLength()];
a61af66fc99e Initial load
duke
parents:
diff changeset
300 long offset = offsetOfCheckedExceptions();
a61af66fc99e Initial load
duke
parents:
diff changeset
301 for (int i = 0; i < ret.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
302 ret[i] = new CheckedExceptionElement(getHandle(), offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
303 offset += checkedExceptionElementSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 //---------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
311 //
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 private boolean isNative() {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 return getMethod().isNative();
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 // Offset of end of code
a61af66fc99e Initial load
duke
parents:
diff changeset
318 private long offsetOfCodeEnd() {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return bytecodeOffset + getCodeSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // Offset of start of compressed line number table (see methodOop.hpp)
a61af66fc99e Initial load
duke
parents:
diff changeset
323 private long offsetOfCompressedLineNumberTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return offsetOfCodeEnd() + (isNative() ? 2 * VM.getVM().getAddressSize() : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // Offset of last short in methodOop
a61af66fc99e Initial load
duke
parents:
diff changeset
328 private long offsetOfLastU2Element() {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 return getObjectSize() - 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 private long offsetOfCheckedExceptionsLength() {
a61af66fc99e Initial load
duke
parents:
diff changeset
333 return offsetOfLastU2Element();
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 private int getCheckedExceptionsLength() {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 if (hasCheckedExceptions()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 return (int) getHandle().getCIntegerAt(offsetOfCheckedExceptionsLength(), 2, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
339 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
340 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
343
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // Offset of start of checked exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
345 private long offsetOfCheckedExceptions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 long offset = offsetOfCheckedExceptionsLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
347 long length = getCheckedExceptionsLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
348 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 Assert.that(length > 0, "should only be called if table is present");
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 offset -= length * checkedExceptionElementSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
352 return offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 private int getLineNumberTableLength() {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 int len = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (hasLineNumberTable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 CompressedLineNumberReadStream stream =
a61af66fc99e Initial load
duke
parents:
diff changeset
359 new CompressedLineNumberReadStream(getHandle(), (int) offsetOfCompressedLineNumberTable());
a61af66fc99e Initial load
duke
parents:
diff changeset
360 while (stream.readPair()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 len += 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364 return len;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 private int getLocalVariableTableLength() {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 if (hasLocalVariableTable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 return (int) getHandle().getCIntegerAt(offsetOfLocalVariableTableLength(), 2, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
370 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
371 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
374
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // Offset of local variable table length
a61af66fc99e Initial load
duke
parents:
diff changeset
376 private long offsetOfLocalVariableTableLength() {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 Assert.that(hasLocalVariableTable(), "should only be called if table is present");
a61af66fc99e Initial load
duke
parents:
diff changeset
379 }
a61af66fc99e Initial load
duke
parents:
diff changeset
380 if (hasCheckedExceptions()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 return offsetOfCheckedExceptions() - 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 return offsetOfLastU2Element();
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
386
a61af66fc99e Initial load
duke
parents:
diff changeset
387 private long offsetOfLocalVariableTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
388 long offset = offsetOfLocalVariableTableLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
389 long length = getLocalVariableTableLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
390 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
391 Assert.that(length > 0, "should only be called if table is present");
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393 offset -= length * localVariableTableElementSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
394 return offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }