annotate agent/src/share/classes/sun/jvm/hotspot/jdi/ArrayTypeImpl.java @ 1913:3b2dea75431e

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