0
|
1 /*
|
|
2 * Copyright 2002-2005 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.jdi;
|
|
26
|
|
27 import com.sun.jdi.*;
|
|
28 import sun.jvm.hotspot.oops.Symbol;
|
|
29 import sun.jvm.hotspot.oops.LocalVariableTableElement;
|
|
30 import java.util.List;
|
|
31 import java.util.Iterator;
|
|
32 import java.util.ArrayList;
|
|
33 import java.util.Comparator;
|
|
34 import java.lang.ref.SoftReference;
|
|
35 import java.util.Collections;
|
|
36
|
|
37 public abstract class MethodImpl extends TypeComponentImpl implements Method {
|
|
38 private JNITypeParser signatureParser;
|
|
39 protected sun.jvm.hotspot.oops.Method saMethod;
|
|
40
|
|
41 abstract int argSlotCount() throws AbsentInformationException;
|
|
42 abstract List allLineLocations(SDE.Stratum stratum,
|
|
43 String sourceName)
|
|
44 throws AbsentInformationException;
|
|
45 abstract List locationsOfLine(SDE.Stratum stratum,
|
|
46 String sourceName,
|
|
47 int lineNumber)
|
|
48 throws AbsentInformationException;
|
|
49
|
|
50 static MethodImpl createMethodImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,
|
|
51 sun.jvm.hotspot.oops.Method saMethod) {
|
|
52 // Someday might have to add concrete and non-concrete subclasses.
|
|
53 if (saMethod.isNative() || saMethod.isAbstract()) {
|
|
54 return new NonConcreteMethodImpl(vm, declaringType, saMethod);
|
|
55 } else {
|
|
56 return new ConcreteMethodImpl(vm, declaringType, saMethod);
|
|
57 }
|
|
58 }
|
|
59
|
|
60 MethodImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,
|
|
61 sun.jvm.hotspot.oops.Method saMethod ) {
|
|
62 super(vm, declaringType);
|
|
63 this.saMethod = saMethod;
|
|
64 getParser();
|
|
65 }
|
|
66
|
|
67 private JNITypeParser getParser() {
|
|
68 if (signatureParser == null) {
|
|
69 Symbol sig1 = saMethod.getSignature();
|
|
70 signature = sig1.asString();
|
|
71 signatureParser = new JNITypeParser(signature);
|
|
72 }
|
|
73 return signatureParser;
|
|
74 }
|
|
75
|
|
76 // Object ref() {
|
|
77 sun.jvm.hotspot.oops.Method ref() {
|
|
78 return saMethod;
|
|
79 }
|
|
80
|
|
81 public String genericSignature() {
|
|
82 Symbol genSig = saMethod.getGenericSignature();
|
|
83 return (genSig != null)? genSig.asString() : null;
|
|
84 }
|
|
85
|
|
86 public String returnTypeName() {
|
|
87 return getParser().typeName();
|
|
88 }
|
|
89
|
|
90 public Type returnType() throws ClassNotLoadedException {
|
|
91 return findType(getParser().signature());
|
|
92 }
|
|
93
|
|
94 private Type findType(String signature) throws ClassNotLoadedException {
|
|
95 ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();
|
|
96 return enclosing.findType(signature);
|
|
97 }
|
|
98
|
|
99 public List argumentTypeNames() {
|
|
100 return getParser().argumentTypeNames();
|
|
101 }
|
|
102
|
|
103 List argumentSignatures() {
|
|
104 return getParser().argumentSignatures();
|
|
105 }
|
|
106
|
|
107 Type argumentType(int index) throws ClassNotLoadedException {
|
|
108 ReferenceTypeImpl enclosing = (ReferenceTypeImpl)declaringType();
|
|
109 String signature = (String)argumentSignatures().get(index);
|
|
110 return enclosing.findType(signature);
|
|
111 }
|
|
112
|
|
113 public List argumentTypes() throws ClassNotLoadedException {
|
|
114 int size = argumentSignatures().size();
|
|
115 ArrayList types = new ArrayList(size);
|
|
116 for (int i = 0; i < size; i++) {
|
|
117 Type type = argumentType(i);
|
|
118 types.add(type);
|
|
119 }
|
|
120 return types;
|
|
121 }
|
|
122
|
|
123 public boolean isAbstract() {
|
|
124 return saMethod.isAbstract();
|
|
125 }
|
|
126
|
|
127 public boolean isBridge() {
|
|
128 return saMethod.isBridge();
|
|
129 }
|
|
130
|
|
131 public boolean isSynchronized() {
|
|
132 return saMethod.isSynchronized();
|
|
133 }
|
|
134
|
|
135 public boolean isNative() {
|
|
136 return saMethod.isNative();
|
|
137 }
|
|
138
|
|
139 public boolean isVarArgs() {
|
|
140 return saMethod.isVarArgs();
|
|
141 }
|
|
142
|
|
143 public boolean isConstructor() {
|
|
144 return saMethod.isConstructor();
|
|
145 }
|
|
146
|
|
147 public boolean isStaticInitializer() {
|
|
148 return saMethod.isStaticInitializer();
|
|
149 }
|
|
150
|
|
151 public boolean isObsolete() {
|
|
152 return saMethod.isObsolete();
|
|
153 }
|
|
154
|
|
155 public final List allLineLocations()
|
|
156 throws AbsentInformationException {
|
|
157 return allLineLocations(vm.getDefaultStratum(), null);
|
|
158 }
|
|
159
|
|
160 public List allLineLocations(String stratumID,
|
|
161 String sourceName)
|
|
162 throws AbsentInformationException {
|
|
163 return allLineLocations(declaringType.stratum(stratumID),
|
|
164 sourceName);
|
|
165 }
|
|
166
|
|
167 public final List locationsOfLine(int lineNumber)
|
|
168 throws AbsentInformationException {
|
|
169 return locationsOfLine(vm.getDefaultStratum(),
|
|
170 null, lineNumber);
|
|
171 }
|
|
172
|
|
173 public List locationsOfLine(String stratumID,
|
|
174 String sourceName,
|
|
175 int lineNumber)
|
|
176 throws AbsentInformationException {
|
|
177 return locationsOfLine(declaringType.stratum(stratumID),
|
|
178 sourceName, lineNumber);
|
|
179 }
|
|
180
|
|
181 LineInfo codeIndexToLineInfo(SDE.Stratum stratum,
|
|
182 long codeIndex) {
|
|
183 if (stratum.isJava()) {
|
|
184 return new BaseLineInfo(-1, declaringType);
|
|
185 } else {
|
|
186 return new StratumLineInfo(stratum.id(), -1,
|
|
187 null, null);
|
|
188 }
|
|
189 }
|
|
190
|
|
191 public boolean equals(Object obj) {
|
|
192 if ((obj != null) && (obj instanceof MethodImpl)) {
|
|
193 MethodImpl other = (MethodImpl)obj;
|
|
194 return (declaringType().equals(other.declaringType())) &&
|
|
195 (ref().equals(other.ref())) &&
|
|
196 super.equals(obj);
|
|
197 } else {
|
|
198 return false;
|
|
199 }
|
|
200 }
|
|
201
|
|
202 // From interface Comparable
|
|
203 public int compareTo(Object object) {
|
|
204 Method method = (Method)object;
|
|
205 ReferenceTypeImpl declaringType = (ReferenceTypeImpl)declaringType();
|
|
206 int rc = declaringType.compareTo(method.declaringType());
|
|
207 if (rc == 0) {
|
|
208 rc = declaringType.indexOf(this) -
|
|
209 declaringType.indexOf(method);
|
|
210 }
|
|
211 return rc;
|
|
212 }
|
|
213
|
|
214 // from interface Mirror
|
|
215 public String toString() {
|
|
216 StringBuffer sb = new StringBuffer();
|
|
217 sb.append(declaringType().name());
|
|
218 sb.append(".");
|
|
219 sb.append(name());
|
|
220 sb.append("(");
|
|
221 boolean first = true;
|
|
222 for (Iterator it = argumentTypeNames().iterator(); it.hasNext();) {
|
|
223 if (!first) {
|
|
224 sb.append(", ");
|
|
225 }
|
|
226 sb.append((String)it.next());
|
|
227 first = false;
|
|
228 }
|
|
229 sb.append(")");
|
|
230 return sb.toString();
|
|
231 }
|
|
232
|
|
233 public String name() {
|
|
234 Symbol myName = saMethod.getName();
|
|
235 return myName.asString();
|
|
236 }
|
|
237
|
|
238 public int modifiers() {
|
|
239 return saMethod.getAccessFlagsObj().getStandardFlags();
|
|
240 }
|
|
241
|
|
242 public boolean isPackagePrivate() {
|
|
243 return saMethod.isPackagePrivate();
|
|
244 }
|
|
245
|
|
246 public boolean isPrivate() {
|
|
247 return saMethod.isPrivate();
|
|
248 }
|
|
249
|
|
250 public boolean isProtected() {
|
|
251 return saMethod.isProtected();
|
|
252 }
|
|
253
|
|
254 public boolean isPublic() {
|
|
255 return saMethod.isPublic();
|
|
256 }
|
|
257
|
|
258 public boolean isStatic() {
|
|
259 return saMethod.isStatic();
|
|
260 }
|
|
261
|
|
262 public boolean isSynthetic() {
|
|
263 return saMethod.isSynthetic();
|
|
264 }
|
|
265
|
|
266 public boolean isFinal() {
|
|
267 return saMethod.isFinal();
|
|
268 }
|
|
269
|
|
270 public int hashCode() {
|
|
271 return saMethod.hashCode();
|
|
272 }
|
|
273 }
|