annotate agent/src/share/classes/sun/jvm/hotspot/jdi/InterfaceTypeImpl.java @ 17587:561045d22599 jdk8u11-b07

Added tag jdk8u11-b06 for changeset b73ee2b9027c
author katleman
date Tue, 29 Apr 2014 12:51:45 -0700
parents c18cbe5936b8
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, 2004, 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.InstanceKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.util.List;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import java.util.ArrayList;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import java.util.Map;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import java.util.Iterator;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import java.util.Collections;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import java.lang.ref.SoftReference;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public class InterfaceTypeImpl extends ReferenceTypeImpl
a61af66fc99e Initial load
duke
parents:
diff changeset
38 implements InterfaceType {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private SoftReference superInterfacesCache = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private SoftReference subInterfacesCache = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private SoftReference implementorsCache = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 protected InterfaceTypeImpl(VirtualMachine aVm, InstanceKlass aRef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 super(aVm, aRef);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public List superinterfaces() throws ClassNotPreparedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 List superinterfaces = (superInterfacesCache != null)? (List) superInterfacesCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (superinterfaces == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 checkPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 superinterfaces = Collections.unmodifiableList(getInterfaces());
a61af66fc99e Initial load
duke
parents:
diff changeset
52 superInterfacesCache = new SoftReference(superinterfaces);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54 return superinterfaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public List subinterfaces() {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 List subinterfaces = (subInterfacesCache != null)? (List) subInterfacesCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if (subinterfaces == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 List all = vm.allClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 subinterfaces = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
62 Iterator iter = all.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 ReferenceType refType = (ReferenceType)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if (refType instanceof InterfaceType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 InterfaceType interfaze = (InterfaceType)refType;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if (interfaze.isPrepared() && interfaze.superinterfaces().contains(this)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 subinterfaces.add(interfaze);
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 subinterfaces = Collections.unmodifiableList(subinterfaces);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 subInterfacesCache = new SoftReference(subinterfaces);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 return subinterfaces;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 public List implementors() {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 List implementors = (implementorsCache != null)? (List) implementorsCache.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (implementors == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 List all = vm.allClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 implementors = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 Iterator iter = all.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 ReferenceType refType = (ReferenceType)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (refType instanceof ClassType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 ClassType clazz = (ClassType)refType;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (clazz.isPrepared() && clazz.interfaces().contains(this)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 implementors.add(clazz);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 implementors = Collections.unmodifiableList(implementors);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 implementorsCache = new SoftReference(implementors);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return implementors;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 void addVisibleMethods(Map methodMap) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
101 * Add methods from
a61af66fc99e Initial load
duke
parents:
diff changeset
102 * parent types first, so that the methods in this class will
a61af66fc99e Initial load
duke
parents:
diff changeset
103 * overwrite them in the hash table
a61af66fc99e Initial load
duke
parents:
diff changeset
104 */
a61af66fc99e Initial load
duke
parents:
diff changeset
105 Iterator iter = superinterfaces().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 interfaze.addVisibleMethods(methodMap);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 addToMethodMap(methodMap, methods());
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 List getAllMethods() {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 ArrayList list = new ArrayList(methods());
a61af66fc99e Initial load
duke
parents:
diff changeset
116 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
117 * It's more efficient if don't do this
a61af66fc99e Initial load
duke
parents:
diff changeset
118 * recursively.
a61af66fc99e Initial load
duke
parents:
diff changeset
119 */
a61af66fc99e Initial load
duke
parents:
diff changeset
120 List interfaces = allSuperinterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 Iterator iter = interfaces.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 InterfaceType interfaze = (InterfaceType)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 list.addAll(interfaze.methods());
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return list;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 List allSuperinterfaces() {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 ArrayList list = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 addSuperinterfaces(list);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return list;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 void addSuperinterfaces(List list) {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
138 * This code is a little strange because it
a61af66fc99e Initial load
duke
parents:
diff changeset
139 * builds the list with a more suitable order than the
a61af66fc99e Initial load
duke
parents:
diff changeset
140 * depth-first approach a normal recursive solution would
a61af66fc99e Initial load
duke
parents:
diff changeset
141 * take. Instead, all direct superinterfaces precede all
a61af66fc99e Initial load
duke
parents:
diff changeset
142 * indirect ones.
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 * Get a list of direct superinterfaces that's not already in the
a61af66fc99e Initial load
duke
parents:
diff changeset
147 * list being built.
a61af66fc99e Initial load
duke
parents:
diff changeset
148 */
a61af66fc99e Initial load
duke
parents:
diff changeset
149 List immediate = new ArrayList(superinterfaces());
a61af66fc99e Initial load
duke
parents:
diff changeset
150 Iterator iter = immediate.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
151 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 InterfaceType interfaze = (InterfaceType)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (list.contains(interfaze)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 iter.remove();
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
159 * Add all new direct superinterfaces
a61af66fc99e Initial load
duke
parents:
diff changeset
160 */
a61af66fc99e Initial load
duke
parents:
diff changeset
161 list.addAll(immediate);
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
164 * Recurse for all new direct superinterfaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
165 */
a61af66fc99e Initial load
duke
parents:
diff changeset
166 iter = immediate.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
167 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
169 interfaze.addSuperinterfaces(list);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 boolean isAssignableTo(ReferenceType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Exact match?
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (this.equals(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // Try superinterfaces.
a61af66fc99e Initial load
duke
parents:
diff changeset
180 List supers = superinterfaces();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 Iterator iter = supers.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (interfaze.isAssignableTo(type)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return true;
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 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 List inheritedTypes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 return superinterfaces();
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 isInitialized() {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return isPrepared();
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 return "interface " + name() + " (" + loaderString() + ")";
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }