annotate agent/src/share/classes/sun/jvm/hotspot/jdi/ArrayTypeImpl.java @ 14188:29985fccf378

4990369: visibleMethods() and methodsByName() return wrong visible methods Reviewed-by: sspitsyn, coleenp
author sla
date Tue, 07 Jan 2014 10:50:28 +0100
parents c18cbe5936b8
children 4ca6dc0799b6
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
14188
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
27 import java.util.ArrayList;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
28 import java.util.List;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
29 import java.util.Map;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
30 import java.util.Set;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.oops.ArrayKlass;
14188
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
33 import sun.jvm.hotspot.oops.Instance;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.oops.InstanceKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.oops.Klass;
14188
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
36 import sun.jvm.hotspot.oops.ObjArrayKlass;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.oops.Symbol;
14188
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
38 import sun.jvm.hotspot.oops.TypeArrayKlass;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
39
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
40 import com.sun.jdi.ArrayReference;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
41 import com.sun.jdi.ArrayType;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
42 import com.sun.jdi.ClassLoaderReference;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
43 import com.sun.jdi.ClassNotLoadedException;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
44 import com.sun.jdi.InterfaceType;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
45 import com.sun.jdi.Method;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
46 import com.sun.jdi.PrimitiveType;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
47 import com.sun.jdi.ReferenceType;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
48 import com.sun.jdi.Type;
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
49 import com.sun.jdi.VirtualMachine;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public class ArrayTypeImpl extends ReferenceTypeImpl implements ArrayType {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 protected ArrayTypeImpl(VirtualMachine aVm, ArrayKlass aRef) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 super(aVm, aRef);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public ArrayReference newInstance(int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 vm.throwNotReadOnlyException("ArrayType.newInstance(int)");
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public String componentSignature() {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 return signature().substring(1); // Just skip the leading '['
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 public String componentTypeName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 JNITypeParser parser = new JNITypeParser(componentSignature());
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return parser.typeName();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 public ClassLoaderReference classLoader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 if (ref() instanceof TypeArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // primitive array klasses are loaded by bootstrap loader
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 Klass bottomKlass = ((ObjArrayKlass)ref()).getBottomKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if (bottomKlass instanceof TypeArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // multidimensional primitive array klasses are loaded by bootstrap loader
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // class loader of any other obj array klass is same as the loader
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // that loaded the bottom InstanceKlass
a61af66fc99e Initial load
duke
parents:
diff changeset
82 Instance xx = (Instance)(((InstanceKlass) bottomKlass).getClassLoader());
a61af66fc99e Initial load
duke
parents:
diff changeset
83 return vm.classLoaderMirror(xx);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
14188
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
88 @Override
29985fccf378 4990369: visibleMethods() and methodsByName() return wrong visible methods
sla
parents: 1552
diff changeset
89 void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> handledInterfaces) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // arrays don't have methods
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 List getAllMethods() {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // arrays don't have methods
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // JLS says arrays have methods of java.lang.Object. But
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // JVMDI-JDI returns zero size list. We do the same here
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // for consistency.
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
102 * Find the type object, if any, of a component type of this array.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 * The component type does not have to be immediate; e.g. this method
a61af66fc99e Initial load
duke
parents:
diff changeset
104 * can be used to find the component Foo of Foo[][].
a61af66fc99e Initial load
duke
parents:
diff changeset
105 */
a61af66fc99e Initial load
duke
parents:
diff changeset
106 public Type componentType() throws ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 ArrayKlass k = (ArrayKlass) ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (k instanceof ObjArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 Klass elementKlass = ((ObjArrayKlass)k).getElementKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (elementKlass == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 throw new ClassNotLoadedException(componentSignature());
a61af66fc99e Initial load
duke
parents:
diff changeset
112 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 return vm.referenceType(elementKlass);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // It's a primitive type
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return vm.primitiveTypeMirror(signature().charAt(1));
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 static boolean isComponentAssignable(Type destination, Type source) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (source instanceof PrimitiveType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Assignment of primitive arrays requires identical
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // component types.
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return source.equals(destination);
a61af66fc99e Initial load
duke
parents:
diff changeset
126 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if (destination instanceof PrimitiveType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 ReferenceTypeImpl refSource = (ReferenceTypeImpl)source;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 ReferenceTypeImpl refDestination = (ReferenceTypeImpl)destination;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // Assignment of object arrays requires availability
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // of widening conversion of component types
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return refSource.isAssignableTo(refDestination);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
141 * Return true if an instance of the given reference type
a61af66fc99e Initial load
duke
parents:
diff changeset
142 * can be assigned to a variable of this type
a61af66fc99e Initial load
duke
parents:
diff changeset
143 */
a61af66fc99e Initial load
duke
parents:
diff changeset
144 boolean isAssignableTo(ReferenceType destType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (destType instanceof ArrayType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 Type destComponentType = ((ArrayType)destType).componentType();
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return isComponentAssignable(destComponentType, componentType());
a61af66fc99e Initial load
duke
parents:
diff changeset
149 } catch (ClassNotLoadedException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // One or both component types has not yet been
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // loaded => can't assign
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 Symbol typeName = ((ReferenceTypeImpl)destType).typeNameAsSymbol();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (destType instanceof InterfaceType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // Every array type implements java.io.Serializable and
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // java.lang.Cloneable. fixme in JVMDI-JDI, includes only
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Cloneable but not Serializable.
a61af66fc99e Initial load
duke
parents:
diff changeset
160 return typeName.equals(vm.javaLangCloneable()) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
161 typeName.equals(vm.javaIoSerializable());
a61af66fc99e Initial load
duke
parents:
diff changeset
162 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Only valid ClassType assignee is Object
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return typeName.equals(vm.javaLangObject());
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 List inheritedTypes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // arrays are derived from java.lang.Object and
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // B[] is derived from A[] if B is derived from A.
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // But JVMDI-JDI returns zero sized list and we do the
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // same for consistency.
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 int getModifiers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
179 * For object arrays, the return values for Interface
a61af66fc99e Initial load
duke
parents:
diff changeset
180 * Accessible.isPrivate(), Accessible.isProtected(),
a61af66fc99e Initial load
duke
parents:
diff changeset
181 * etc... are the same as would be returned for the
a61af66fc99e Initial load
duke
parents:
diff changeset
182 * component type. Fetch the modifier bits from the
a61af66fc99e Initial load
duke
parents:
diff changeset
183 * component type and use those.
a61af66fc99e Initial load
duke
parents:
diff changeset
184 *
a61af66fc99e Initial load
duke
parents:
diff changeset
185 * For primitive arrays, the modifiers are always
a61af66fc99e Initial load
duke
parents:
diff changeset
186 * VMModifiers.FINAL | VMModifiers.PUBLIC
a61af66fc99e Initial load
duke
parents:
diff changeset
187 *
a61af66fc99e Initial load
duke
parents:
diff changeset
188 * Reference com.sun.jdi.Accessible.java.
a61af66fc99e Initial load
duke
parents:
diff changeset
189 */
a61af66fc99e Initial load
duke
parents:
diff changeset
190 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 Type t = componentType();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 if (t instanceof PrimitiveType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return VMModifiers.FINAL | VMModifiers.PUBLIC;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 ReferenceType rt = (ReferenceType)t;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return rt.modifiers();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 } catch (ClassNotLoadedException cnle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 cnle.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 return "array class " + name() + " (" + loaderString() + ")";
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
209 * Save a pointless trip over the wire for these methods
a61af66fc99e Initial load
duke
parents:
diff changeset
210 * which have undefined results for arrays.
a61af66fc99e Initial load
duke
parents:
diff changeset
211 */
a61af66fc99e Initial load
duke
parents:
diff changeset
212 public boolean isPrepared() { return true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 public boolean isVerified() { return true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 public boolean isInitialized() { return true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 public boolean failedToInitialize() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 public boolean isAbstract() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
219 * Defined always to be true for arrays
a61af66fc99e Initial load
duke
parents:
diff changeset
220 */
a61af66fc99e Initial load
duke
parents:
diff changeset
221 public boolean isFinal() { return true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }