annotate agent/src/share/classes/sun/jvm/hotspot/jdi/ClassTypeImpl.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 29985fccf378
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, 2007, 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 com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.oops.Klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.InstanceKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import java.lang.ref.SoftReference;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 public class ClassTypeImpl extends ReferenceTypeImpl
a61af66fc99e Initial load
duke
parents:
diff changeset
35 implements ClassType
a61af66fc99e Initial load
duke
parents:
diff changeset
36 {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private SoftReference interfacesCache = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private SoftReference allInterfacesCache = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private SoftReference subclassesCache = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 protected ClassTypeImpl(VirtualMachine aVm, InstanceKlass aRef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 super(aVm, aRef);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 public ClassType superclass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 InstanceKlass kk = (InstanceKlass)ref().getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 if (kk == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return (ClassType) vm.referenceType(kk);
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public List interfaces() {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 List interfaces = (interfacesCache != null)? (List) interfacesCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 if (interfaces == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 interfaces = Collections.unmodifiableList(getInterfaces());
a61af66fc99e Initial load
duke
parents:
diff changeset
58 interfacesCache = new SoftReference(interfaces);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return interfaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 void addInterfaces(List list) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 List immediate = interfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 HashSet hashList = new HashSet(list);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 hashList.addAll(immediate);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 list.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 list.addAll(hashList);
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 Iterator iter = immediate.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 interfaze.addSuperinterfaces(list);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 ClassTypeImpl superclass = (ClassTypeImpl)superclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 if (superclass != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 superclass.addInterfaces(list);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 public List allInterfaces() {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 List allinterfaces = (allInterfacesCache != null)? (List) allInterfacesCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (allinterfaces == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
87 allinterfaces = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 addInterfaces(allinterfaces);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 allinterfaces = Collections.unmodifiableList(allinterfaces);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 allInterfacesCache = new SoftReference(allinterfaces);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return allinterfaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public List subclasses() {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 List subclasses = (subclassesCache != null)? (List) subclassesCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (subclasses == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 List all = vm.allClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 subclasses = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 Iterator iter = all.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 ReferenceType refType = (ReferenceType)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (refType instanceof ClassType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 ClassType clazz = (ClassType)refType;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 ClassType superclass = clazz.superclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if ((superclass != null) && superclass.equals(this)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 subclasses.add(refType);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 subclasses = Collections.unmodifiableList(subclasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 subclassesCache = new SoftReference(subclasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return subclasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public Method concreteMethodByName(String name, String signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 List methods = visibleMethods();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 Method method = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 Iterator iter = methods.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 Method candidate = (Method)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (candidate.name().equals(name) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
125 candidate.signature().equals(signature) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
126 !candidate.isAbstract()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 method = candidate;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 return method;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 List getAllMethods() {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 ArrayList list = new ArrayList(methods());
a61af66fc99e Initial load
duke
parents:
diff changeset
137 ClassType clazz = superclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 while (clazz != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 list.addAll(clazz.methods());
a61af66fc99e Initial load
duke
parents:
diff changeset
140 clazz = clazz.superclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
143 * Avoid duplicate checking on each method by iterating through
a61af66fc99e Initial load
duke
parents:
diff changeset
144 * duplicate-free allInterfaces() rather than recursing
a61af66fc99e Initial load
duke
parents:
diff changeset
145 */
a61af66fc99e Initial load
duke
parents:
diff changeset
146 Iterator iter = allInterfaces().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 InterfaceType interfaze = (InterfaceType)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
149 list.addAll(interfaze.methods());
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return list;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 List inheritedTypes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 List inherited = new ArrayList(interfaces());
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (superclass() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 inherited.add(0, superclass()); /* insert at front */
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return inherited;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 public boolean isEnum() {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 ClassTypeImpl superclass = (ClassTypeImpl) superclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
164 if (superclass != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 return superclass.typeNameAsSymbol().equals(vm.javaLangEnum());
a61af66fc99e Initial load
duke
parents:
diff changeset
166 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
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 void setValue(Field field, Value value)
a61af66fc99e Initial load
duke
parents:
diff changeset
172 throws InvalidTypeException, ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 vm.throwNotReadOnlyException("ClassType.setValue(...)");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 public Value invokeMethod(ThreadReference threadIntf, Method methodIntf,
a61af66fc99e Initial load
duke
parents:
diff changeset
178 List arguments, int options)
a61af66fc99e Initial load
duke
parents:
diff changeset
179 throws InvalidTypeException,
a61af66fc99e Initial load
duke
parents:
diff changeset
180 ClassNotLoadedException,
a61af66fc99e Initial load
duke
parents:
diff changeset
181 IncompatibleThreadStateException,
a61af66fc99e Initial load
duke
parents:
diff changeset
182 InvocationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 vm.throwNotReadOnlyException("ClassType.invokeMethod(...)");
a61af66fc99e Initial load
duke
parents:
diff changeset
184 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 public ObjectReference newInstance(ThreadReference threadIntf,
a61af66fc99e Initial load
duke
parents:
diff changeset
188 Method methodIntf,
a61af66fc99e Initial load
duke
parents:
diff changeset
189 List arguments, int options)
a61af66fc99e Initial load
duke
parents:
diff changeset
190 throws InvalidTypeException,
a61af66fc99e Initial load
duke
parents:
diff changeset
191 ClassNotLoadedException,
a61af66fc99e Initial load
duke
parents:
diff changeset
192 IncompatibleThreadStateException,
a61af66fc99e Initial load
duke
parents:
diff changeset
193 InvocationException {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 vm.throwNotReadOnlyException("ClassType.newInstance(...)");
a61af66fc99e Initial load
duke
parents:
diff changeset
195 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 void addVisibleMethods(Map methodMap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
200 * Add methods from
a61af66fc99e Initial load
duke
parents:
diff changeset
201 * parent types first, so that the methods in this class will
a61af66fc99e Initial load
duke
parents:
diff changeset
202 * overwrite them in the hash table
a61af66fc99e Initial load
duke
parents:
diff changeset
203 */
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 Iterator iter = interfaces().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 interfaze.addVisibleMethods(methodMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210
a61af66fc99e Initial load
duke
parents:
diff changeset
211 ClassTypeImpl clazz = (ClassTypeImpl)superclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 if (clazz != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 clazz.addVisibleMethods(methodMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 addToMethodMap(methodMap, methods());
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 boolean isAssignableTo(ReferenceType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 ClassTypeImpl superclazz = (ClassTypeImpl)superclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (this.equals(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 } else if ((superclazz != null) && superclazz.isAssignableTo(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
225 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 List interfaces = interfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
227 Iterator iter = interfaces.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
228 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
230 if (interfaze.isAssignableTo(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 return "class " + name() + "(" + loaderString() + ")";
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }