0
|
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.oops;
|
|
26
|
|
27 import java.io.*;
|
|
28 import java.util.*;
|
|
29 import sun.jvm.hotspot.code.*;
|
|
30 import sun.jvm.hotspot.debugger.*;
|
|
31 import sun.jvm.hotspot.interpreter.*;
|
|
32 import sun.jvm.hotspot.memory.*;
|
|
33 import sun.jvm.hotspot.runtime.*;
|
|
34 import sun.jvm.hotspot.types.*;
|
|
35 import sun.jvm.hotspot.utilities.*;
|
|
36
|
|
37 // A Method represents a Java method
|
|
38
|
|
39 public class Method extends Oop {
|
|
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 synchronized void initialize(TypeDataBase db) throws WrongTypeException {
|
|
49 Type type = db.lookupType("methodOopDesc");
|
|
50 constMethod = new OopField(type.getOopField("_constMethod"), 0);
|
|
51 constants = new OopField(type.getOopField("_constants"), 0);
|
|
52 methodSize = new CIntField(type.getCIntegerField("_method_size"), 0);
|
|
53 maxStack = new CIntField(type.getCIntegerField("_max_stack"), 0);
|
|
54 maxLocals = new CIntField(type.getCIntegerField("_max_locals"), 0);
|
|
55 sizeOfParameters = new CIntField(type.getCIntegerField("_size_of_parameters"), 0);
|
|
56 accessFlags = new CIntField(type.getCIntegerField("_access_flags"), 0);
|
|
57 code = type.getAddressField("_code");
|
|
58 vtableIndex = new CIntField(type.getCIntegerField("_vtable_index"), 0);
|
|
59 if (!VM.getVM().isCore()) {
|
|
60 invocationCounter = new CIntField(type.getCIntegerField("_invocation_counter"), 0);
|
|
61 }
|
|
62 bytecodeOffset = type.getSize();
|
|
63
|
|
64 /*
|
|
65 interpreterEntry = type.getAddressField("_interpreter_entry");
|
|
66 fromCompiledCodeEntryPoint = type.getAddressField("_from_compiled_code_entry_point");
|
|
67
|
|
68 */
|
|
69 objectInitializerName = null;
|
|
70 classInitializerName = null;
|
|
71 }
|
|
72
|
|
73 Method(OopHandle handle, ObjectHeap heap) {
|
|
74 super(handle, heap);
|
|
75 }
|
|
76
|
|
77 public boolean isMethod() { return true; }
|
|
78
|
|
79 // Fields
|
|
80 private static OopField constMethod;
|
|
81 private static OopField constants;
|
|
82 private static CIntField methodSize;
|
|
83 private static CIntField maxStack;
|
|
84 private static CIntField maxLocals;
|
|
85 private static CIntField sizeOfParameters;
|
|
86 private static CIntField accessFlags;
|
|
87 private static CIntField vtableIndex;
|
|
88 private static CIntField invocationCounter;
|
|
89 private static long bytecodeOffset;
|
|
90
|
|
91 private static AddressField code;
|
|
92
|
|
93 // constant method names - <init>, <clinit>
|
|
94 // Initialized lazily to avoid initialization ordering dependencies between Method and SymbolTable
|
|
95 private static Symbol objectInitializerName;
|
|
96 private static Symbol classInitializerName;
|
|
97 private static Symbol objectInitializerName() {
|
|
98 if (objectInitializerName == null) {
|
|
99 objectInitializerName = VM.getVM().getSymbolTable().probe("<init>");
|
|
100 }
|
|
101 return objectInitializerName;
|
|
102 }
|
|
103 private static Symbol classInitializerName() {
|
|
104 if (classInitializerName == null) {
|
|
105 classInitializerName = VM.getVM().getSymbolTable().probe("<clinit>");
|
|
106 }
|
|
107 return classInitializerName;
|
|
108 }
|
|
109
|
|
110
|
|
111 /*
|
|
112 private static AddressCField interpreterEntry;
|
|
113 private static AddressCField fromCompiledCodeEntryPoint;
|
|
114 */
|
|
115
|
|
116 // Accessors for declared fields
|
|
117 public ConstMethod getConstMethod() { return (ConstMethod) constMethod.getValue(this); }
|
|
118 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
|
|
119 public TypeArray getExceptionTable() { return getConstMethod().getExceptionTable(); }
|
|
120 /** WARNING: this is in words, not useful in this system; use getObjectSize() instead */
|
|
121 public long getMethodSize() { return methodSize.getValue(this); }
|
|
122 public long getMaxStack() { return maxStack.getValue(this); }
|
|
123 public long getMaxLocals() { return maxLocals.getValue(this); }
|
|
124 public long getSizeOfParameters() { return sizeOfParameters.getValue(this); }
|
|
125 public long getNameIndex() { return getConstMethod().getNameIndex(); }
|
|
126 public long getSignatureIndex() { return getConstMethod().getSignatureIndex(); }
|
|
127 public long getGenericSignatureIndex() { return getConstMethod().getGenericSignatureIndex(); }
|
|
128 public long getAccessFlags() { return accessFlags.getValue(this); }
|
|
129 public long getCodeSize() { return getConstMethod().getCodeSize(); }
|
|
130 public long getVtableIndex() { return vtableIndex.getValue(this); }
|
|
131 public long getInvocationCounter() {
|
|
132 if (Assert.ASSERTS_ENABLED) {
|
|
133 Assert.that(!VM.getVM().isCore(), "must not be used in core build");
|
|
134 }
|
|
135 return invocationCounter.getValue(this);
|
|
136 }
|
|
137
|
|
138 // get associated compiled native method, if available, else return null.
|
|
139 public NMethod getNativeMethod() {
|
|
140 Address addr = code.getValue(getHandle());
|
|
141 return (NMethod) VMObjectFactory.newObject(NMethod.class, addr);
|
|
142 }
|
|
143
|
|
144 // Convenience routine
|
|
145 public AccessFlags getAccessFlagsObj() {
|
|
146 return new AccessFlags(getAccessFlags());
|
|
147 }
|
|
148
|
|
149 /** Get a bytecode or breakpoint at the given bci */
|
|
150 public int getBytecodeOrBPAt(int bci) {
|
|
151 return getConstMethod().getBytecodeOrBPAt(bci);
|
|
152 }
|
|
153
|
|
154 /** Fetch the original non-breakpoint bytecode at the specified
|
|
155 bci. It is required that there is currently a bytecode at this
|
|
156 bci. */
|
|
157 public int getOrigBytecodeAt(int bci) {
|
|
158 BreakpointInfo bp = ((InstanceKlass) getMethodHolder()).getBreakpoints();
|
|
159 for (; bp != null; bp = bp.getNext()) {
|
|
160 if (bp.match(this, bci)) {
|
|
161 return bp.getOrigBytecode();
|
|
162 }
|
|
163 }
|
|
164 System.err.println("Requested bci " + bci);
|
|
165 for (; bp != null; bp = bp.getNext()) {
|
|
166 System.err.println("Breakpoint at bci " + bp.getBCI() + ", bytecode " +
|
|
167 bp.getOrigBytecode());
|
|
168 }
|
|
169 Assert.that(false, "Should not reach here");
|
|
170 return -1; // not reached
|
|
171 }
|
|
172
|
|
173 public byte getBytecodeByteArg(int bci) {
|
|
174 return getConstMethod().getBytecodeByteArg(bci);
|
|
175 }
|
|
176
|
|
177 /** Fetches a 16-bit big-endian ("Java ordered") value from the
|
|
178 bytecode stream */
|
|
179 public short getBytecodeShortArg(int bci) {
|
|
180 return getConstMethod().getBytecodeShortArg(bci);
|
|
181 }
|
|
182
|
|
183 /** Fetches a 32-bit big-endian ("Java ordered") value from the
|
|
184 bytecode stream */
|
|
185 public int getBytecodeIntArg(int bci) {
|
|
186 return getConstMethod().getBytecodeIntArg(bci);
|
|
187 }
|
|
188
|
|
189 public byte[] getByteCode() {
|
|
190 return getConstMethod().getByteCode();
|
|
191 }
|
|
192
|
|
193 /*
|
|
194 public Address getCode() { return codeField.getValue(this); }
|
|
195 public Address getInterpreterEntry() { return interpreterEntryField.getValue(this); }
|
|
196 public Address getFromCompiledCodeEntryPoint() { return fromCompiledCodeEntryPointField.getValue(this); }
|
|
197 */
|
|
198 // Accessors
|
|
199 public Symbol getName() { return (Symbol) getConstants().getObjAt(getNameIndex()); }
|
|
200 public Symbol getSignature() { return (Symbol) getConstants().getObjAt(getSignatureIndex()); }
|
|
201 public Symbol getGenericSignature() {
|
|
202 long index = getGenericSignatureIndex();
|
|
203 return (index != 0L) ? (Symbol) getConstants().getObjAt(index) : null;
|
|
204 }
|
|
205
|
|
206 // Method holder (the Klass holding this method)
|
|
207 public Klass getMethodHolder() { return getConstants().getPoolHolder(); }
|
|
208
|
|
209 // Access flags
|
|
210 public boolean isPublic() { return getAccessFlagsObj().isPublic(); }
|
|
211 public boolean isPrivate() { return getAccessFlagsObj().isPrivate(); }
|
|
212 public boolean isProtected() { return getAccessFlagsObj().isProtected(); }
|
|
213 public boolean isPackagePrivate() { AccessFlags af = getAccessFlagsObj();
|
|
214 return (!af.isPublic() && !af.isPrivate() && !af.isProtected()); }
|
|
215 public boolean isStatic() { return getAccessFlagsObj().isStatic(); }
|
|
216 public boolean isFinal() { return getAccessFlagsObj().isFinal(); }
|
|
217 public boolean isSynchronized() { return getAccessFlagsObj().isSynchronized(); }
|
|
218 public boolean isBridge() { return getAccessFlagsObj().isBridge(); }
|
|
219 public boolean isVarArgs() { return getAccessFlagsObj().isVarArgs(); }
|
|
220 public boolean isNative() { return getAccessFlagsObj().isNative(); }
|
|
221 public boolean isAbstract() { return getAccessFlagsObj().isAbstract(); }
|
|
222 public boolean isStrict() { return getAccessFlagsObj().isStrict(); }
|
|
223 public boolean isSynthetic() { return getAccessFlagsObj().isSynthetic(); }
|
|
224
|
|
225 public boolean isConstructor() {
|
|
226 return (!isStatic()) && getName().equals(objectInitializerName());
|
|
227 }
|
|
228
|
|
229 public boolean isStaticInitializer() {
|
|
230 return isStatic() && getName().equals(classInitializerName());
|
|
231 }
|
|
232
|
|
233 public boolean isObsolete() {
|
|
234 return getAccessFlagsObj().isObsolete();
|
|
235 }
|
|
236
|
|
237 public OopMapCacheEntry getMaskFor(int bci) {
|
|
238 OopMapCacheEntry entry = new OopMapCacheEntry();
|
|
239 entry.fill(this, bci);
|
|
240 return entry;
|
|
241 }
|
|
242
|
|
243 public long getObjectSize() {
|
|
244 return getMethodSize() * getHeap().getOopSize();
|
|
245 }
|
|
246
|
|
247 public void printValueOn(PrintStream tty) {
|
|
248 tty.print("Method " + getName().asString() + getSignature().asString() + "@" + getHandle());
|
|
249 }
|
|
250
|
|
251 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
|
|
252 super.iterateFields(visitor, doVMFields);
|
|
253 if (doVMFields) {
|
|
254 visitor.doOop(constMethod, true);
|
|
255 visitor.doOop(constants, true);
|
|
256 visitor.doCInt(methodSize, true);
|
|
257 visitor.doCInt(maxStack, true);
|
|
258 visitor.doCInt(maxLocals, true);
|
|
259 visitor.doCInt(sizeOfParameters, true);
|
|
260 visitor.doCInt(accessFlags, true);
|
|
261 }
|
|
262 }
|
|
263
|
|
264 public boolean hasLineNumberTable() {
|
|
265 return getConstMethod().hasLineNumberTable();
|
|
266 }
|
|
267
|
|
268 public int getLineNumberFromBCI(int bci) {
|
|
269 return getConstMethod().getLineNumberFromBCI(bci);
|
|
270 }
|
|
271
|
|
272 public LineNumberTableElement[] getLineNumberTable() {
|
|
273 return getConstMethod().getLineNumberTable();
|
|
274 }
|
|
275
|
|
276 public boolean hasLocalVariableTable() {
|
|
277 return getConstMethod().hasLocalVariableTable();
|
|
278 }
|
|
279
|
|
280 /** Should only be called if table is present */
|
|
281 public LocalVariableTableElement[] getLocalVariableTable() {
|
|
282 return getConstMethod().getLocalVariableTable();
|
|
283 }
|
|
284
|
|
285 public Symbol getLocalVariableName(int bci, int slot) {
|
|
286 if (! hasLocalVariableTable()) {
|
|
287 return null;
|
|
288 }
|
|
289
|
|
290 LocalVariableTableElement[] locals = getLocalVariableTable();
|
|
291 for (int l = 0; l < locals.length; l++) {
|
|
292 LocalVariableTableElement local = locals[l];
|
|
293 if ((bci >= local.getStartBCI()) &&
|
|
294 (bci < (local.getStartBCI() + local.getLength())) &&
|
|
295 slot == local.getSlot()) {
|
|
296 return getConstants().getSymbolAt(local.getNameCPIndex());
|
|
297 }
|
|
298 }
|
|
299
|
|
300 return null;
|
|
301 }
|
|
302
|
|
303 public boolean hasCheckedExceptions() {
|
|
304 return getConstMethod().hasCheckedExceptions();
|
|
305 }
|
|
306
|
|
307 /** Should only be called if table is present */
|
|
308 public CheckedExceptionElement[] getCheckedExceptions() {
|
|
309 return getConstMethod().getCheckedExceptions();
|
|
310 }
|
|
311
|
|
312 /** Returns name and signature in external form for debugging
|
|
313 purposes */
|
|
314 public String externalNameAndSignature() {
|
|
315 final StringBuffer buf = new StringBuffer();
|
|
316 buf.append(getMethodHolder().getName().asString());
|
|
317 buf.append(".");
|
|
318 buf.append(getName().asString());
|
|
319 buf.append("(");
|
|
320 new SignatureConverter(getSignature(), buf).iterateParameters();
|
|
321 buf.append(")");
|
|
322 return buf.toString().replace('/', '.');
|
|
323 }
|
|
324 }
|