annotate agent/src/share/classes/sun/jvm/hotspot/jdi/ReferenceTypeImpl.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children 37be97a58393
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
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.jdi;
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
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.oops.Instance;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.oops.InstanceKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.oops.ArrayKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.oops.JVMDIClassStatus;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.oops.Klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.oops.Oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.oops.Symbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.oops.DefaultHeapVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.utilities.Assert;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import java.lang.ref.SoftReference;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 public abstract class ReferenceTypeImpl extends TypeImpl
a61af66fc99e Initial load
duke
parents:
diff changeset
45 implements ReferenceType {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 protected Klass saKlass; // This can be an InstanceKlass or an ArrayKlass
a61af66fc99e Initial load
duke
parents:
diff changeset
47 protected Symbol typeNameSymbol; // This is used in vm.classesByName to speedup search
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private int modifiers = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private String signature = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private SoftReference sdeRef = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private SoftReference fieldsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private SoftReference allFieldsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 private SoftReference methodsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private SoftReference allMethodsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 private SoftReference nestedTypesCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 /* to mark when no info available */
a61af66fc99e Initial load
duke
parents:
diff changeset
58 static final SDE NO_SDE_INFO_MARK = new SDE();
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 protected ReferenceTypeImpl(VirtualMachine aVm, sun.jvm.hotspot.oops.Klass klass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 super(aVm);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 saKlass = klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 typeNameSymbol = saKlass.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
64 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 Assert.that(typeNameSymbol != null, "null type name for a Klass");
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 Symbol typeNameAsSymbol() {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return typeNameSymbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 Method getMethodMirror(sun.jvm.hotspot.oops.Method ref) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // SA creates new Method objects when they are referenced which means
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // that the incoming object might not be the same object as on our
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // even though it is the same method. So do an address compare by
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // calling equals rather than just reference compare.
a61af66fc99e Initial load
duke
parents:
diff changeset
78 Iterator it = methods().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 while (it.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 MethodImpl method = (MethodImpl)it.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 if (ref.equals(method.ref())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 return method;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 throw new IllegalArgumentException("Invalid method id: " + ref);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if ((obj != null) && (obj instanceof ReferenceTypeImpl)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 ReferenceTypeImpl other = (ReferenceTypeImpl)obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return (ref().equals(other.ref())) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
92 (vm.equals(other.virtualMachine()));
a61af66fc99e Initial load
duke
parents:
diff changeset
93 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 return saKlass.hashCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 public int compareTo(Object object) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
104 * Note that it is critical that compareTo() == 0
a61af66fc99e Initial load
duke
parents:
diff changeset
105 * implies that equals() == true. Otherwise, TreeSet
a61af66fc99e Initial load
duke
parents:
diff changeset
106 * will collapse classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
107 *
a61af66fc99e Initial load
duke
parents:
diff changeset
108 * (Classes of the same name loaded by different class loaders
a61af66fc99e Initial load
duke
parents:
diff changeset
109 * or in different VMs must not return 0).
a61af66fc99e Initial load
duke
parents:
diff changeset
110 */
a61af66fc99e Initial load
duke
parents:
diff changeset
111 ReferenceTypeImpl other = (ReferenceTypeImpl)object;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int comp = name().compareTo(other.name());
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (comp == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 Oop rf1 = ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
115 Oop rf2 = other.ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // optimize for typical case: refs equal and VMs equal
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (rf1.equals(rf2)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // sequenceNumbers are always positive
a61af66fc99e Initial load
duke
parents:
diff changeset
119 comp = vm.sequenceNumber -
a61af66fc99e Initial load
duke
parents:
diff changeset
120 ((VirtualMachineImpl)(other.virtualMachine())).sequenceNumber;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 comp = rf1.getHandle().minus(rf2.getHandle()) < 0? -1 : 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return comp;
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 String signature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (signature == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 signature = saKlass.signature();
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // refer to JvmtiEnv::GetClassSignature.
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // null is returned for array klasses.
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public String genericSignature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (saKlass instanceof ArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 Symbol genSig = ((InstanceKlass)saKlass).getGenericSignature();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return (genSig != null)? genSig.asString() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 public ClassLoaderReference classLoader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 Instance xx = (Instance)(((InstanceKlass)saKlass).getClassLoader());
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return (ClassLoaderReferenceImpl)vm.classLoaderMirror(xx);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 public boolean isPublic() {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return((modifiers() & VMModifiers.PUBLIC) != 0);
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 boolean isProtected() {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return((modifiers() & VMModifiers.PROTECTED) != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 public boolean isPrivate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 return((modifiers() & VMModifiers.PRIVATE) != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 public boolean isPackagePrivate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return !isPublic() && !isPrivate() && !isProtected();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 public boolean isAbstract() {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 return((modifiers() & VMModifiers.ABSTRACT) != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 public boolean isFinal() {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 return((modifiers() & VMModifiers.FINAL) != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 public boolean isStatic() {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 return((modifiers() & VMModifiers.STATIC) != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 public boolean isPrepared() {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 return (saKlass.getClassStatus() & JVMDIClassStatus.PREPARED) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 final void checkPrepared() throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (! isPrepared()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 throw new ClassNotPreparedException();
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 public boolean isVerified() {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return (saKlass.getClassStatus() & JVMDIClassStatus.VERIFIED) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 public boolean isInitialized() {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 return (saKlass.getClassStatus() & JVMDIClassStatus.INITIALIZED) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 public boolean failedToInitialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return (saKlass.getClassStatus() & JVMDIClassStatus.ERROR) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 private boolean isThrowableBacktraceField(sun.jvm.hotspot.oops.Field fld) {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // refer to JvmtiEnv::GetClassFields in jvmtiEnv.cpp.
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // We want to filter out java.lang.Throwable.backtrace (see 4446677).
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // It contains some methodOops that aren't quite real Objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
205 if (fld.getFieldHolder().getName().equals(vm.javaLangThrowable()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
206 fld.getID().getName().equals("backtrace")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 public final List fields() throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 List fields = (fieldsCache != null)? (List) fieldsCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 if (fields == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
217 if (saKlass instanceof ArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 fields = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
219 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // Get a list of the sa Field types
a61af66fc99e Initial load
duke
parents:
diff changeset
221 List saFields = ((InstanceKlass)saKlass).getImmediateFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // Create a list of our Field types
a61af66fc99e Initial load
duke
parents:
diff changeset
224 int len = saFields.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
225 fields = new ArrayList(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 for (int ii = 0; ii < len; ii++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 sun.jvm.hotspot.oops.Field curField = (sun.jvm.hotspot.oops.Field)saFields.get(ii);
a61af66fc99e Initial load
duke
parents:
diff changeset
228 if (! isThrowableBacktraceField(curField)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 fields.add(new FieldImpl(vm, this, curField));
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 fields = Collections.unmodifiableList(fields);
a61af66fc99e Initial load
duke
parents:
diff changeset
234 fieldsCache = new SoftReference(fields);
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 return fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 public final List allFields() throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 List allFields = (allFieldsCache != null)? (List) allFieldsCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (allFields == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 if (saKlass instanceof ArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // is 'length' a field of array klasses? To maintain
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // consistency with JVMDI-JDI we return 0 size.
a61af66fc99e Initial load
duke
parents:
diff changeset
246 allFields = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 List saFields;
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // Get a list of the sa Field types
a61af66fc99e Initial load
duke
parents:
diff changeset
251 saFields = ((InstanceKlass)saKlass).getAllFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
252
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // Create a list of our Field types
a61af66fc99e Initial load
duke
parents:
diff changeset
254 int len = saFields.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
255 allFields = new ArrayList(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 for (int ii = 0; ii < len; ii++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 sun.jvm.hotspot.oops.Field curField = (sun.jvm.hotspot.oops.Field)saFields.get(ii);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (! isThrowableBacktraceField(curField)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 allFields.add(new FieldImpl(vm, vm.referenceType(curField.getFieldHolder()), curField));
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 allFields = Collections.unmodifiableList(allFields);
a61af66fc99e Initial load
duke
parents:
diff changeset
264 allFieldsCache = new SoftReference(allFields);
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return allFields;
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 abstract List inheritedTypes();
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 void addVisibleFields(List visibleList, Map visibleTable, List ambiguousNames) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 List list = visibleFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
273 Iterator iter = list.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
274 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 Field field = (Field)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
276 String name = field.name();
a61af66fc99e Initial load
duke
parents:
diff changeset
277 if (!ambiguousNames.contains(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 Field duplicate = (Field)visibleTable.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
279 if (duplicate == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 visibleList.add(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 visibleTable.put(name, field);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 } else if (!field.equals(duplicate)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 ambiguousNames.add(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
284 visibleTable.remove(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 visibleList.remove(duplicate);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // identical field from two branches; do nothing
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 public final List visibleFields() throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
295 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
296 * Maintain two different collections of visible fields. The
a61af66fc99e Initial load
duke
parents:
diff changeset
297 * list maintains a reasonable order for return. The
a61af66fc99e Initial load
duke
parents:
diff changeset
298 * hash map provides an efficient way to lookup visible fields
a61af66fc99e Initial load
duke
parents:
diff changeset
299 * by name, important for finding hidden or ambiguous fields.
a61af66fc99e Initial load
duke
parents:
diff changeset
300 */
a61af66fc99e Initial load
duke
parents:
diff changeset
301 List visibleList = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
302 Map visibleTable = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 /* Track fields removed from above collection due to ambiguity */
a61af66fc99e Initial load
duke
parents:
diff changeset
305 List ambiguousNames = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
306
a61af66fc99e Initial load
duke
parents:
diff changeset
307 /* Add inherited, visible fields */
a61af66fc99e Initial load
duke
parents:
diff changeset
308 List types = inheritedTypes();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 Iterator iter = types.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
310 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
312 * TO DO: Be defensive and check for cyclic interface inheritance
a61af66fc99e Initial load
duke
parents:
diff changeset
313 */
a61af66fc99e Initial load
duke
parents:
diff changeset
314 ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
315 type.addVisibleFields(visibleList, visibleTable, ambiguousNames);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
319 * Insert fields from this type, removing any inherited fields they
a61af66fc99e Initial load
duke
parents:
diff changeset
320 * hide.
a61af66fc99e Initial load
duke
parents:
diff changeset
321 */
a61af66fc99e Initial load
duke
parents:
diff changeset
322 List retList = new ArrayList(fields());
a61af66fc99e Initial load
duke
parents:
diff changeset
323 iter = retList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
324 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 Field field = (Field)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
326 Field hidden = (Field)visibleTable.get(field.name());
a61af66fc99e Initial load
duke
parents:
diff changeset
327 if (hidden != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 visibleList.remove(hidden);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 retList.addAll(visibleList);
a61af66fc99e Initial load
duke
parents:
diff changeset
332 return retList;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 public final Field fieldByName(String fieldName) throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 java.util.List searchList;
a61af66fc99e Initial load
duke
parents:
diff changeset
337 Field f;
a61af66fc99e Initial load
duke
parents:
diff changeset
338
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // visibleFields calls checkPrepared
a61af66fc99e Initial load
duke
parents:
diff changeset
340 searchList = visibleFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342 for (int i=0; i<searchList.size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 f = (Field)searchList.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 if (f.name().equals(fieldName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 return f;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349 //throw new NoSuchFieldException("Field '" + fieldName + "' not found in " + name());
a61af66fc99e Initial load
duke
parents:
diff changeset
350 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 public final List methods() throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 List methods = (methodsCache != null)? (List) methodsCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
355 if (methods == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (saKlass instanceof ArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 methods = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
359 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
360 List saMethods;
a61af66fc99e Initial load
duke
parents:
diff changeset
361 // Get a list of the SA Method types
a61af66fc99e Initial load
duke
parents:
diff changeset
362 saMethods = ((InstanceKlass)saKlass).getImmediateMethods();
a61af66fc99e Initial load
duke
parents:
diff changeset
363
a61af66fc99e Initial load
duke
parents:
diff changeset
364 // Create a list of our MethodImpl types
a61af66fc99e Initial load
duke
parents:
diff changeset
365 int len = saMethods.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
366 methods = new ArrayList(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
367 for (int ii = 0; ii < len; ii++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 methods.add(MethodImpl.createMethodImpl(vm, this, (sun.jvm.hotspot.oops.Method)saMethods.get(ii)));
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 methods = Collections.unmodifiableList(methods);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 methodsCache = new SoftReference(methods);
a61af66fc99e Initial load
duke
parents:
diff changeset
373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
374 return methods;
a61af66fc99e Initial load
duke
parents:
diff changeset
375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
376
a61af66fc99e Initial load
duke
parents:
diff changeset
377 abstract List getAllMethods();
a61af66fc99e Initial load
duke
parents:
diff changeset
378 public final List allMethods() throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 List allMethods = (allMethodsCache != null)? (List) allMethodsCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
380 if (allMethods == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
382 allMethods = Collections.unmodifiableList(getAllMethods());
a61af66fc99e Initial load
duke
parents:
diff changeset
383 allMethodsCache = new SoftReference(allMethods);
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385 return allMethods;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387
a61af66fc99e Initial load
duke
parents:
diff changeset
388 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
389 * Utility method used by subclasses to build lists of visible
a61af66fc99e Initial load
duke
parents:
diff changeset
390 * methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
391 */
a61af66fc99e Initial load
duke
parents:
diff changeset
392 void addToMethodMap(Map methodMap, List methodList) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 Iterator iter = methodList.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
394 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
395 Method method = (Method)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
396 methodMap.put(method.name().concat(method.signature()), method);
a61af66fc99e Initial load
duke
parents:
diff changeset
397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
398 }
a61af66fc99e Initial load
duke
parents:
diff changeset
399
a61af66fc99e Initial load
duke
parents:
diff changeset
400 abstract void addVisibleMethods(Map methodMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 public final List visibleMethods() throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
403 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
404 * Build a collection of all visible methods. The hash
a61af66fc99e Initial load
duke
parents:
diff changeset
405 * map allows us to do this efficiently by keying on the
a61af66fc99e Initial load
duke
parents:
diff changeset
406 * concatenation of name and signature.
a61af66fc99e Initial load
duke
parents:
diff changeset
407 */
a61af66fc99e Initial load
duke
parents:
diff changeset
408 //System.out.println("jj: RTI: Calling addVisibleMethods for:" + this);
a61af66fc99e Initial load
duke
parents:
diff changeset
409 Map map = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
410 addVisibleMethods(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
411
a61af66fc99e Initial load
duke
parents:
diff changeset
412 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
413 * ... but the hash map destroys order. Methods should be
a61af66fc99e Initial load
duke
parents:
diff changeset
414 * returned in a sensible order, as they are in allMethods().
a61af66fc99e Initial load
duke
parents:
diff changeset
415 * So, start over with allMethods() and use the hash map
a61af66fc99e Initial load
duke
parents:
diff changeset
416 * to filter that ordered collection.
a61af66fc99e Initial load
duke
parents:
diff changeset
417 */
a61af66fc99e Initial load
duke
parents:
diff changeset
418 //System.out.println("jj: RTI: Calling allMethods for:" + this);
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 List list = new ArrayList(allMethods());
a61af66fc99e Initial load
duke
parents:
diff changeset
421 //System.out.println("jj: allMethods = " + jjstr(list));
a61af66fc99e Initial load
duke
parents:
diff changeset
422 //System.out.println("jj: map = " + map.toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
423 //System.out.println("jj: map = " + jjstr(map.values()));
a61af66fc99e Initial load
duke
parents:
diff changeset
424 list.retainAll(map.values());
a61af66fc99e Initial load
duke
parents:
diff changeset
425 //System.out.println("jj: map = " + jjstr(list));
a61af66fc99e Initial load
duke
parents:
diff changeset
426 //System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
427 return list;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 static Object prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
431
a61af66fc99e Initial load
duke
parents:
diff changeset
432 static public String jjstr(Collection cc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
434 buf.append("[");
a61af66fc99e Initial load
duke
parents:
diff changeset
435 Iterator i = cc.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
436 boolean hasNext = i.hasNext();
a61af66fc99e Initial load
duke
parents:
diff changeset
437 while (hasNext) {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 Object o = i.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
439 if (prev == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 prev = o;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 System.out.println("prev == curr?" + prev.equals(o));
a61af66fc99e Initial load
duke
parents:
diff changeset
443 System.out.println("prev == curr?" + (prev == o));
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 buf.append( o + "@" + o.hashCode());
a61af66fc99e Initial load
duke
parents:
diff changeset
446 //buf.append( ((Object)o).toString());
a61af66fc99e Initial load
duke
parents:
diff changeset
447 hasNext = i.hasNext();
a61af66fc99e Initial load
duke
parents:
diff changeset
448 if (hasNext)
a61af66fc99e Initial load
duke
parents:
diff changeset
449 buf.append(", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 buf.append("]");
a61af66fc99e Initial load
duke
parents:
diff changeset
453 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 public final List methodsByName(String name) throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 // visibleMethods calls checkPrepared
a61af66fc99e Initial load
duke
parents:
diff changeset
458 List methods = visibleMethods();
a61af66fc99e Initial load
duke
parents:
diff changeset
459 ArrayList retList = new ArrayList(methods.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
460 Iterator iter = methods.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
461 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
462 Method candidate = (Method)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
463 if (candidate.name().equals(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
464 retList.add(candidate);
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
467 retList.trimToSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
468 return retList;
a61af66fc99e Initial load
duke
parents:
diff changeset
469 }
a61af66fc99e Initial load
duke
parents:
diff changeset
470
a61af66fc99e Initial load
duke
parents:
diff changeset
471 public final List methodsByName(String name, String signature) throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // visibleMethods calls checkPrepared
a61af66fc99e Initial load
duke
parents:
diff changeset
473 List methods = visibleMethods();
a61af66fc99e Initial load
duke
parents:
diff changeset
474 ArrayList retList = new ArrayList(methods.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
475 Iterator iter = methods.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
476 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
477 Method candidate = (Method)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
478 if (candidate.name().equals(name) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
479 candidate.signature().equals(signature)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
480 retList.add(candidate);
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
483 retList.trimToSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
484 return retList;
a61af66fc99e Initial load
duke
parents:
diff changeset
485 }
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487
a61af66fc99e Initial load
duke
parents:
diff changeset
488 List getInterfaces() {
a61af66fc99e Initial load
duke
parents:
diff changeset
489 List myInterfaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
490 if (saKlass instanceof ArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // Actually, JLS says arrays implement Cloneable and Serializable
a61af66fc99e Initial load
duke
parents:
diff changeset
492 // But, JVMDI-JDI just returns 0 interfaces for arrays. We follow
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // the same for consistency.
a61af66fc99e Initial load
duke
parents:
diff changeset
494 myInterfaces = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
495 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 // Get a list of the sa InstanceKlass types
a61af66fc99e Initial load
duke
parents:
diff changeset
497 List saInterfaces = ((InstanceKlass)saKlass).getDirectImplementedInterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // Create a list of our InterfaceTypes
a61af66fc99e Initial load
duke
parents:
diff changeset
500 int len = saInterfaces.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
501 myInterfaces = new ArrayList(len);
a61af66fc99e Initial load
duke
parents:
diff changeset
502 for (int ii = 0; ii < len; ii++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
503 myInterfaces.add(new InterfaceTypeImpl(vm, (InstanceKlass)saInterfaces.get(ii)));
a61af66fc99e Initial load
duke
parents:
diff changeset
504 }
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506 return myInterfaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
507 }
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 public final List nestedTypes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
510 List nestedTypes = (nestedTypesCache != null)? (List) nestedTypesCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 if (nestedTypes == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
512 if (saKlass instanceof ArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
513 nestedTypes = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
514 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
515 ClassLoaderReference cl = classLoader();
a61af66fc99e Initial load
duke
parents:
diff changeset
516 List classes = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
517 if (cl != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
518 classes = cl.visibleClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
519 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 classes = vm.bootstrapClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
521 }
a61af66fc99e Initial load
duke
parents:
diff changeset
522 nestedTypes = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
523 Iterator iter = classes.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
524 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
525 ReferenceTypeImpl refType = (ReferenceTypeImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
526 Symbol candidateName = refType.ref().getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
527 if (((InstanceKlass)saKlass).isInnerOrLocalClassName(candidateName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
528 nestedTypes.add(refType);
a61af66fc99e Initial load
duke
parents:
diff changeset
529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532 nestedTypes = Collections.unmodifiableList(nestedTypes);
a61af66fc99e Initial load
duke
parents:
diff changeset
533 nestedTypesCache = new SoftReference(nestedTypes);
a61af66fc99e Initial load
duke
parents:
diff changeset
534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
535 return nestedTypes;
a61af66fc99e Initial load
duke
parents:
diff changeset
536 }
a61af66fc99e Initial load
duke
parents:
diff changeset
537
a61af66fc99e Initial load
duke
parents:
diff changeset
538 public Value getValue(Field sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
539 List list = new ArrayList(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
540 list.add(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
541 Map map = getValues(list);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 return(Value)map.get(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
546 * Returns a map of field values
a61af66fc99e Initial load
duke
parents:
diff changeset
547 */
a61af66fc99e Initial load
duke
parents:
diff changeset
548 public Map getValues(List theFields) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 //validateMirrors();
a61af66fc99e Initial load
duke
parents:
diff changeset
550 int size = theFields.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
551 Map map = new HashMap(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
552 for (int ii=0; ii<size; ii++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 FieldImpl fieldImpl = (FieldImpl)theFields.get(ii);
a61af66fc99e Initial load
duke
parents:
diff changeset
554
a61af66fc99e Initial load
duke
parents:
diff changeset
555 validateFieldAccess(fieldImpl);
a61af66fc99e Initial load
duke
parents:
diff changeset
556 // Do more validation specific to ReferenceType field getting
a61af66fc99e Initial load
duke
parents:
diff changeset
557 if (!fieldImpl.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 throw new IllegalArgumentException(
a61af66fc99e Initial load
duke
parents:
diff changeset
559 "Attempt to use non-static field with ReferenceType: " +
a61af66fc99e Initial load
duke
parents:
diff changeset
560 fieldImpl.name());
a61af66fc99e Initial load
duke
parents:
diff changeset
561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
562 map.put(fieldImpl, fieldImpl.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
564 return map;
a61af66fc99e Initial load
duke
parents:
diff changeset
565 }
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 void validateFieldAccess(Field field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
568 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
569 * Field must be in this object's class, a superclass, or
a61af66fc99e Initial load
duke
parents:
diff changeset
570 * implemented interface
a61af66fc99e Initial load
duke
parents:
diff changeset
571 */
a61af66fc99e Initial load
duke
parents:
diff changeset
572 ReferenceTypeImpl declType = (ReferenceTypeImpl)field.declaringType();
a61af66fc99e Initial load
duke
parents:
diff changeset
573 if (!declType.isAssignableFrom(this)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
574 throw new IllegalArgumentException("Invalid field");
a61af66fc99e Initial load
duke
parents:
diff changeset
575 }
a61af66fc99e Initial load
duke
parents:
diff changeset
576 }
a61af66fc99e Initial load
duke
parents:
diff changeset
577
a61af66fc99e Initial load
duke
parents:
diff changeset
578 public ClassObjectReference classObject() {
a61af66fc99e Initial load
duke
parents:
diff changeset
579 return vm.classObjectMirror(ref().getJavaMirror());
a61af66fc99e Initial load
duke
parents:
diff changeset
580 }
a61af66fc99e Initial load
duke
parents:
diff changeset
581
a61af66fc99e Initial load
duke
parents:
diff changeset
582 SDE.Stratum stratum(String stratumID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
583 SDE sde = sourceDebugExtensionInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
584 if (!sde.isValid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 sde = NO_SDE_INFO_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
586 }
a61af66fc99e Initial load
duke
parents:
diff changeset
587 return sde.stratum(stratumID);
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 public String sourceName() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
591 return (String)(sourceNames(vm.getDefaultStratum()).get(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
592 }
a61af66fc99e Initial load
duke
parents:
diff changeset
593
a61af66fc99e Initial load
duke
parents:
diff changeset
594 public List sourceNames(String stratumID)
a61af66fc99e Initial load
duke
parents:
diff changeset
595 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
596 SDE.Stratum stratum = stratum(stratumID);
a61af66fc99e Initial load
duke
parents:
diff changeset
597 if (stratum.isJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 List result = new ArrayList(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 result.add(baseSourceName());
a61af66fc99e Initial load
duke
parents:
diff changeset
600 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
601 }
a61af66fc99e Initial load
duke
parents:
diff changeset
602 return stratum.sourceNames(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
603 }
a61af66fc99e Initial load
duke
parents:
diff changeset
604
a61af66fc99e Initial load
duke
parents:
diff changeset
605 public List sourcePaths(String stratumID)
a61af66fc99e Initial load
duke
parents:
diff changeset
606 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
607 SDE.Stratum stratum = stratum(stratumID);
a61af66fc99e Initial load
duke
parents:
diff changeset
608 if (stratum.isJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 List result = new ArrayList(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
610 result.add(baseSourceDir() + baseSourceName());
a61af66fc99e Initial load
duke
parents:
diff changeset
611 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
612 }
a61af66fc99e Initial load
duke
parents:
diff changeset
613 return stratum.sourcePaths(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
614 }
a61af66fc99e Initial load
duke
parents:
diff changeset
615
a61af66fc99e Initial load
duke
parents:
diff changeset
616 String baseSourceName() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 if (saKlass instanceof ArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
618 throw new AbsentInformationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
619 }
a61af66fc99e Initial load
duke
parents:
diff changeset
620 Symbol sym = ((InstanceKlass)saKlass).getSourceFileName();
a61af66fc99e Initial load
duke
parents:
diff changeset
621 if (sym != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
622 return sym.asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
623 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
624 throw new AbsentInformationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626 }
a61af66fc99e Initial load
duke
parents:
diff changeset
627
a61af66fc99e Initial load
duke
parents:
diff changeset
628 String baseSourcePath() throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 return baseSourceDir() + baseSourceName();
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631
a61af66fc99e Initial load
duke
parents:
diff changeset
632 String baseSourceDir() {
a61af66fc99e Initial load
duke
parents:
diff changeset
633 String typeName = name();
a61af66fc99e Initial load
duke
parents:
diff changeset
634 StringBuffer sb = new StringBuffer(typeName.length() + 10);
a61af66fc99e Initial load
duke
parents:
diff changeset
635 int index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
636 int nextIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
637
a61af66fc99e Initial load
duke
parents:
diff changeset
638 while ((nextIndex = typeName.indexOf('.', index)) > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
639 sb.append(typeName.substring(index, nextIndex));
a61af66fc99e Initial load
duke
parents:
diff changeset
640 sb.append(java.io.File.separatorChar);
a61af66fc99e Initial load
duke
parents:
diff changeset
641 index = nextIndex + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
643 return sb.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
644 }
a61af66fc99e Initial load
duke
parents:
diff changeset
645
a61af66fc99e Initial load
duke
parents:
diff changeset
646 public String sourceDebugExtension()
a61af66fc99e Initial load
duke
parents:
diff changeset
647 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
648 if (!vm.canGetSourceDebugExtension()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
649 throw new UnsupportedOperationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
650 }
a61af66fc99e Initial load
duke
parents:
diff changeset
651 SDE sde = sourceDebugExtensionInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
652 if (sde == NO_SDE_INFO_MARK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
653 throw new AbsentInformationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
654 }
a61af66fc99e Initial load
duke
parents:
diff changeset
655 return sde.sourceDebugExtension;
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657
a61af66fc99e Initial load
duke
parents:
diff changeset
658 private SDE sourceDebugExtensionInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 if (!vm.canGetSourceDebugExtension()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 return NO_SDE_INFO_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
662 SDE sde = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
663 sde = (sdeRef == null) ? null : (SDE)sdeRef.get();
a61af66fc99e Initial load
duke
parents:
diff changeset
664 if (sde == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 String extension = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
666 if (saKlass instanceof InstanceKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
667 Symbol sdeSym = ((InstanceKlass)saKlass).getSourceDebugExtension();
a61af66fc99e Initial load
duke
parents:
diff changeset
668 extension = (sdeSym != null)? sdeSym.asString() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
670 if (extension == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 sde = NO_SDE_INFO_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
672 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
673 sde = new SDE(extension);
a61af66fc99e Initial load
duke
parents:
diff changeset
674 }
a61af66fc99e Initial load
duke
parents:
diff changeset
675 sdeRef = new SoftReference(sde);
a61af66fc99e Initial load
duke
parents:
diff changeset
676 }
a61af66fc99e Initial load
duke
parents:
diff changeset
677 return sde;
a61af66fc99e Initial load
duke
parents:
diff changeset
678 }
a61af66fc99e Initial load
duke
parents:
diff changeset
679
a61af66fc99e Initial load
duke
parents:
diff changeset
680 public List availableStrata() {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 SDE sde = sourceDebugExtensionInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
682 if (sde.isValid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
683 return sde.availableStrata();
a61af66fc99e Initial load
duke
parents:
diff changeset
684 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 List strata = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
686 strata.add(SDE.BASE_STRATUM_NAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
687 return strata;
a61af66fc99e Initial load
duke
parents:
diff changeset
688 }
a61af66fc99e Initial load
duke
parents:
diff changeset
689 }
a61af66fc99e Initial load
duke
parents:
diff changeset
690
a61af66fc99e Initial load
duke
parents:
diff changeset
691 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
692 * Always returns non-null stratumID
a61af66fc99e Initial load
duke
parents:
diff changeset
693 */
a61af66fc99e Initial load
duke
parents:
diff changeset
694 public String defaultStratum() {
a61af66fc99e Initial load
duke
parents:
diff changeset
695 SDE sdei = sourceDebugExtensionInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
696 if (sdei.isValid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
697 return sdei.defaultStratumId;
a61af66fc99e Initial load
duke
parents:
diff changeset
698 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
699 return SDE.BASE_STRATUM_NAME;
a61af66fc99e Initial load
duke
parents:
diff changeset
700 }
a61af66fc99e Initial load
duke
parents:
diff changeset
701 }
a61af66fc99e Initial load
duke
parents:
diff changeset
702
a61af66fc99e Initial load
duke
parents:
diff changeset
703 public final int modifiers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
704 if (modifiers == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
705 modifiers = getModifiers();
a61af66fc99e Initial load
duke
parents:
diff changeset
706 }
a61af66fc99e Initial load
duke
parents:
diff changeset
707 return modifiers;
a61af66fc99e Initial load
duke
parents:
diff changeset
708 }
a61af66fc99e Initial load
duke
parents:
diff changeset
709
a61af66fc99e Initial load
duke
parents:
diff changeset
710 // new method since 1.6.
a61af66fc99e Initial load
duke
parents:
diff changeset
711 // Real body will be supplied later.
a61af66fc99e Initial load
duke
parents:
diff changeset
712 public List instances(long maxInstances) {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 if (!vm.canGetInstanceInfo()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
714 throw new UnsupportedOperationException(
a61af66fc99e Initial load
duke
parents:
diff changeset
715 "target does not support getting instances");
a61af66fc99e Initial load
duke
parents:
diff changeset
716 }
a61af66fc99e Initial load
duke
parents:
diff changeset
717
a61af66fc99e Initial load
duke
parents:
diff changeset
718 if (maxInstances < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
719 throw new IllegalArgumentException("maxInstances is less than zero: "
a61af66fc99e Initial load
duke
parents:
diff changeset
720 + maxInstances);
a61af66fc99e Initial load
duke
parents:
diff changeset
721 }
a61af66fc99e Initial load
duke
parents:
diff changeset
722
a61af66fc99e Initial load
duke
parents:
diff changeset
723 final List objects = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
724 if (isAbstract() || (this instanceof InterfaceType)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
725 return objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
726 }
a61af66fc99e Initial load
duke
parents:
diff changeset
727
a61af66fc99e Initial load
duke
parents:
diff changeset
728 final Klass givenKls = this.ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
729 final long max = maxInstances;
a61af66fc99e Initial load
duke
parents:
diff changeset
730 vm.saObjectHeap().iterate(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 private long instCount=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
732 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
733 if (givenKls.equals(oop.getKlass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
734 objects.add(vm.objectMirror(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
735 instCount++;
a61af66fc99e Initial load
duke
parents:
diff changeset
736 }
a61af66fc99e Initial load
duke
parents:
diff changeset
737 if (max > 0 && instCount >= max) {
a61af66fc99e Initial load
duke
parents:
diff changeset
738 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
739 }
a61af66fc99e Initial load
duke
parents:
diff changeset
740 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
741 }
a61af66fc99e Initial load
duke
parents:
diff changeset
742 });
a61af66fc99e Initial load
duke
parents:
diff changeset
743 return objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
744 }
a61af66fc99e Initial load
duke
parents:
diff changeset
745
a61af66fc99e Initial load
duke
parents:
diff changeset
746 int getModifiers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
747 return (int) saKlass.getClassModifiers();
a61af66fc99e Initial load
duke
parents:
diff changeset
748 }
a61af66fc99e Initial load
duke
parents:
diff changeset
749
a61af66fc99e Initial load
duke
parents:
diff changeset
750 public List allLineLocations()
a61af66fc99e Initial load
duke
parents:
diff changeset
751 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
752 return allLineLocations(vm.getDefaultStratum(), null);
a61af66fc99e Initial load
duke
parents:
diff changeset
753 }
a61af66fc99e Initial load
duke
parents:
diff changeset
754
a61af66fc99e Initial load
duke
parents:
diff changeset
755 public List allLineLocations(String stratumID, String sourceName)
a61af66fc99e Initial load
duke
parents:
diff changeset
756 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
757 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
758 boolean someAbsent = false; // A method that should have info, didn't
a61af66fc99e Initial load
duke
parents:
diff changeset
759 SDE.Stratum stratum = stratum(stratumID);
a61af66fc99e Initial load
duke
parents:
diff changeset
760 List list = new ArrayList(); // location list
a61af66fc99e Initial load
duke
parents:
diff changeset
761
a61af66fc99e Initial load
duke
parents:
diff changeset
762 for (Iterator iter = methods().iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
763 MethodImpl method = (MethodImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
764 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
765 list.addAll(
a61af66fc99e Initial load
duke
parents:
diff changeset
766 method.allLineLocations(stratum.id(), sourceName));
a61af66fc99e Initial load
duke
parents:
diff changeset
767 } catch(AbsentInformationException exc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
768 someAbsent = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
770 }
a61af66fc99e Initial load
duke
parents:
diff changeset
771
a61af66fc99e Initial load
duke
parents:
diff changeset
772 // If we retrieved no line info, and at least one of the methods
a61af66fc99e Initial load
duke
parents:
diff changeset
773 // should have had some (as determined by an
a61af66fc99e Initial load
duke
parents:
diff changeset
774 // AbsentInformationException being thrown) then we rethrow
a61af66fc99e Initial load
duke
parents:
diff changeset
775 // the AbsentInformationException.
a61af66fc99e Initial load
duke
parents:
diff changeset
776 if (someAbsent && list.size() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
777 throw new AbsentInformationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
778 }
a61af66fc99e Initial load
duke
parents:
diff changeset
779 return list;
a61af66fc99e Initial load
duke
parents:
diff changeset
780 }
a61af66fc99e Initial load
duke
parents:
diff changeset
781
a61af66fc99e Initial load
duke
parents:
diff changeset
782 public List locationsOfLine(int lineNumber)
a61af66fc99e Initial load
duke
parents:
diff changeset
783 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
784 return locationsOfLine(vm.getDefaultStratum(),
a61af66fc99e Initial load
duke
parents:
diff changeset
785 null,
a61af66fc99e Initial load
duke
parents:
diff changeset
786 lineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
787 }
a61af66fc99e Initial load
duke
parents:
diff changeset
788
a61af66fc99e Initial load
duke
parents:
diff changeset
789 public List locationsOfLine(String stratumID,
a61af66fc99e Initial load
duke
parents:
diff changeset
790 String sourceName,
a61af66fc99e Initial load
duke
parents:
diff changeset
791 int lineNumber)
a61af66fc99e Initial load
duke
parents:
diff changeset
792 throws AbsentInformationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
793 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
794 // A method that should have info, didn't
a61af66fc99e Initial load
duke
parents:
diff changeset
795 boolean someAbsent = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
796 // A method that should have info, did
a61af66fc99e Initial load
duke
parents:
diff changeset
797 boolean somePresent = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
798 List methods = methods();
a61af66fc99e Initial load
duke
parents:
diff changeset
799 SDE.Stratum stratum = stratum(stratumID);
a61af66fc99e Initial load
duke
parents:
diff changeset
800
a61af66fc99e Initial load
duke
parents:
diff changeset
801 List list = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
802
a61af66fc99e Initial load
duke
parents:
diff changeset
803 Iterator iter = methods.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
804 while(iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
805 MethodImpl method = (MethodImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
806 // eliminate native and abstract to eliminate
a61af66fc99e Initial load
duke
parents:
diff changeset
807 // false positives
a61af66fc99e Initial load
duke
parents:
diff changeset
808 if (!method.isAbstract() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
809 !method.isNative()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
810 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
811 list.addAll(
a61af66fc99e Initial load
duke
parents:
diff changeset
812 method.locationsOfLine(stratum.id(),
a61af66fc99e Initial load
duke
parents:
diff changeset
813 sourceName,
a61af66fc99e Initial load
duke
parents:
diff changeset
814 lineNumber));
a61af66fc99e Initial load
duke
parents:
diff changeset
815 somePresent = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
816 } catch(AbsentInformationException exc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
817 someAbsent = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
818 }
a61af66fc99e Initial load
duke
parents:
diff changeset
819 }
a61af66fc99e Initial load
duke
parents:
diff changeset
820 }
a61af66fc99e Initial load
duke
parents:
diff changeset
821 if (someAbsent && !somePresent) {
a61af66fc99e Initial load
duke
parents:
diff changeset
822 throw new AbsentInformationException();
a61af66fc99e Initial load
duke
parents:
diff changeset
823 }
a61af66fc99e Initial load
duke
parents:
diff changeset
824 return list;
a61af66fc99e Initial load
duke
parents:
diff changeset
825 }
a61af66fc99e Initial load
duke
parents:
diff changeset
826
a61af66fc99e Initial load
duke
parents:
diff changeset
827 Klass ref() {
a61af66fc99e Initial load
duke
parents:
diff changeset
828 return saKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
829 }
a61af66fc99e Initial load
duke
parents:
diff changeset
830
a61af66fc99e Initial load
duke
parents:
diff changeset
831
a61af66fc99e Initial load
duke
parents:
diff changeset
832 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
833 * Return true if an instance of this type
a61af66fc99e Initial load
duke
parents:
diff changeset
834 * can be assigned to a variable of the given type
a61af66fc99e Initial load
duke
parents:
diff changeset
835 */
a61af66fc99e Initial load
duke
parents:
diff changeset
836 abstract boolean isAssignableTo(ReferenceType type);
a61af66fc99e Initial load
duke
parents:
diff changeset
837
a61af66fc99e Initial load
duke
parents:
diff changeset
838 boolean isAssignableFrom(ReferenceType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
839 return ((ReferenceTypeImpl)type).isAssignableTo(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
840 }
a61af66fc99e Initial load
duke
parents:
diff changeset
841
a61af66fc99e Initial load
duke
parents:
diff changeset
842 boolean isAssignableFrom(ObjectReference object) {
a61af66fc99e Initial load
duke
parents:
diff changeset
843 return object == null ||
a61af66fc99e Initial load
duke
parents:
diff changeset
844 isAssignableFrom(object.referenceType());
a61af66fc99e Initial load
duke
parents:
diff changeset
845 }
a61af66fc99e Initial load
duke
parents:
diff changeset
846
a61af66fc99e Initial load
duke
parents:
diff changeset
847 int indexOf(Method method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
848 // Make sure they're all here - the obsolete method
a61af66fc99e Initial load
duke
parents:
diff changeset
849 // won't be found and so will have index -1
a61af66fc99e Initial load
duke
parents:
diff changeset
850 return methods().indexOf(method);
a61af66fc99e Initial load
duke
parents:
diff changeset
851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
852
a61af66fc99e Initial load
duke
parents:
diff changeset
853 int indexOf(Field field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 // Make sure they're all here
a61af66fc99e Initial load
duke
parents:
diff changeset
855 return fields().indexOf(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
856 }
a61af66fc99e Initial load
duke
parents:
diff changeset
857
a61af66fc99e Initial load
duke
parents:
diff changeset
858 private static boolean isPrimitiveArray(String signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
859 int i = signature.lastIndexOf('[');
a61af66fc99e Initial load
duke
parents:
diff changeset
860 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
861 * TO DO: Centralize JNI signature knowledge.
a61af66fc99e Initial load
duke
parents:
diff changeset
862 *
a61af66fc99e Initial load
duke
parents:
diff changeset
863 * Ref:
a61af66fc99e Initial load
duke
parents:
diff changeset
864 * jdk1.4/doc/guide/jpda/jdi/com/sun/jdi/doc-files/signature.html
a61af66fc99e Initial load
duke
parents:
diff changeset
865 */
a61af66fc99e Initial load
duke
parents:
diff changeset
866 boolean isPA;
a61af66fc99e Initial load
duke
parents:
diff changeset
867 if (i < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
868 isPA = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
869 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
870 char c = signature.charAt(i + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
871 isPA = (c != 'L');
a61af66fc99e Initial load
duke
parents:
diff changeset
872 }
a61af66fc99e Initial load
duke
parents:
diff changeset
873 return isPA;
a61af66fc99e Initial load
duke
parents:
diff changeset
874 }
a61af66fc99e Initial load
duke
parents:
diff changeset
875
a61af66fc99e Initial load
duke
parents:
diff changeset
876 Type findType(String signature) throws ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
877 Type type;
a61af66fc99e Initial load
duke
parents:
diff changeset
878 if (signature.length() == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
879 /* OTI FIX: Must be a primitive type or the void type */
a61af66fc99e Initial load
duke
parents:
diff changeset
880 char sig = signature.charAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
881 if (sig == 'V') {
a61af66fc99e Initial load
duke
parents:
diff changeset
882 type = vm.theVoidType();
a61af66fc99e Initial load
duke
parents:
diff changeset
883 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
884 type = vm.primitiveTypeMirror(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
885 }
a61af66fc99e Initial load
duke
parents:
diff changeset
886 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
887 // Must be a reference type.
a61af66fc99e Initial load
duke
parents:
diff changeset
888 ClassLoaderReferenceImpl loader =
a61af66fc99e Initial load
duke
parents:
diff changeset
889 (ClassLoaderReferenceImpl)classLoader();
a61af66fc99e Initial load
duke
parents:
diff changeset
890 if ((loader == null) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
891 (isPrimitiveArray(signature)) //Work around 4450091
a61af66fc99e Initial load
duke
parents:
diff changeset
892 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
893 // Caller wants type of boot class field
a61af66fc99e Initial load
duke
parents:
diff changeset
894 type = vm.findBootType(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
895 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
896 // Caller wants type of non-boot class field
a61af66fc99e Initial load
duke
parents:
diff changeset
897 type = loader.findType(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
898 }
a61af66fc99e Initial load
duke
parents:
diff changeset
899 }
a61af66fc99e Initial load
duke
parents:
diff changeset
900 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
901 }
a61af66fc99e Initial load
duke
parents:
diff changeset
902
a61af66fc99e Initial load
duke
parents:
diff changeset
903 String loaderString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
904 if (classLoader() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
905 return "loaded by " + classLoader().toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
906 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
907 return "loaded by bootstrap loader";
a61af66fc99e Initial load
duke
parents:
diff changeset
908 }
a61af66fc99e Initial load
duke
parents:
diff changeset
909 }
a61af66fc99e Initial load
duke
parents:
diff changeset
910
a61af66fc99e Initial load
duke
parents:
diff changeset
911 long uniqueID() {
a61af66fc99e Initial load
duke
parents:
diff changeset
912 return vm.getAddressValue(ref());
a61af66fc99e Initial load
duke
parents:
diff changeset
913 }
a61af66fc99e Initial load
duke
parents:
diff changeset
914
a61af66fc99e Initial load
duke
parents:
diff changeset
915 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
916 public int majorVersion() {
a61af66fc99e Initial load
duke
parents:
diff changeset
917 if (!vm.canGetClassFileVersion()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
918 throw new UnsupportedOperationException("Cannot get class file version");
a61af66fc99e Initial load
duke
parents:
diff changeset
919 }
a61af66fc99e Initial load
duke
parents:
diff changeset
920 return (int)((InstanceKlass)saKlass).majorVersion();
a61af66fc99e Initial load
duke
parents:
diff changeset
921 }
a61af66fc99e Initial load
duke
parents:
diff changeset
922
a61af66fc99e Initial load
duke
parents:
diff changeset
923 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
924 public int minorVersion() {
a61af66fc99e Initial load
duke
parents:
diff changeset
925 if (!vm.canGetClassFileVersion()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
926 throw new UnsupportedOperationException("Cannot get class file version");
a61af66fc99e Initial load
duke
parents:
diff changeset
927 }
a61af66fc99e Initial load
duke
parents:
diff changeset
928 return (int)((InstanceKlass)saKlass).minorVersion();
a61af66fc99e Initial load
duke
parents:
diff changeset
929 }
a61af66fc99e Initial load
duke
parents:
diff changeset
930
a61af66fc99e Initial load
duke
parents:
diff changeset
931 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
932 public int constantPoolCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
933 if (!vm.canGetConstantPool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
934 throw new UnsupportedOperationException("Cannot get constant pool");
a61af66fc99e Initial load
duke
parents:
diff changeset
935 }
a61af66fc99e Initial load
duke
parents:
diff changeset
936 if (saKlass instanceof ArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
937 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
938 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
939 return (int)((InstanceKlass)saKlass).getConstants().getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
941 }
a61af66fc99e Initial load
duke
parents:
diff changeset
942
a61af66fc99e Initial load
duke
parents:
diff changeset
943 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
944 public byte[] constantPool() {
a61af66fc99e Initial load
duke
parents:
diff changeset
945 if (!vm.canGetConstantPool()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
946 throw new UnsupportedOperationException("Cannot get constant pool");
a61af66fc99e Initial load
duke
parents:
diff changeset
947 }
a61af66fc99e Initial load
duke
parents:
diff changeset
948 if (this instanceof ArrayType || this instanceof PrimitiveType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
949 byte bytes[] = new byte[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
950 return bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
951 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
952 ByteArrayOutputStream bs = new ByteArrayOutputStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
953 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
954 ((InstanceKlass)saKlass).getConstants().writeBytes(bs);
a61af66fc99e Initial load
duke
parents:
diff changeset
955 } catch (IOException ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
956 ex.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
957 byte bytes[] = new byte[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
958 return bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
959 }
a61af66fc99e Initial load
duke
parents:
diff changeset
960 return bs.toByteArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
961 }
a61af66fc99e Initial load
duke
parents:
diff changeset
962 }
a61af66fc99e Initial load
duke
parents:
diff changeset
963 }