7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 package sun.jvm.hotspot.jdi;
26
27 import com.sun.jdi.*;
28
29 import sun.jvm.hotspot.oops.ArrayKlass;
30 import sun.jvm.hotspot.oops.InstanceKlass;
31 import sun.jvm.hotspot.oops.ObjArrayKlass;
32 import sun.jvm.hotspot.oops.TypeArrayKlass;
33 import sun.jvm.hotspot.oops.Klass;
34 import sun.jvm.hotspot.oops.Instance;
35 import sun.jvm.hotspot.oops.Symbol;
36 import java.util.List;
37 import java.util.ArrayList;
38 import java.util.Iterator;
39 import java.util.Map;
40
41 public class ArrayTypeImpl extends ReferenceTypeImpl implements ArrayType {
42 protected ArrayTypeImpl(VirtualMachine aVm, ArrayKlass aRef) {
43 super(aVm, aRef);
44 }
45
46 public ArrayReference newInstance(int length) {
47 vm.throwNotReadOnlyException("ArrayType.newInstance(int)");
48 return null;
49 }
50
51 public String componentSignature() {
52 return signature().substring(1); // Just skip the leading '['
53 }
54
55 public String componentTypeName() {
56 JNITypeParser parser = new JNITypeParser(componentSignature());
57 return parser.typeName();
58 }
59
60 public ClassLoaderReference classLoader() {
61 if (ref() instanceof TypeArrayKlass) {
62 // primitive array klasses are loaded by bootstrap loader
63 return null;
64 } else {
65 Klass bottomKlass = ((ObjArrayKlass)ref()).getBottomKlass();
66 if (bottomKlass instanceof TypeArrayKlass) {
67 // multidimensional primitive array klasses are loaded by bootstrap loader
68 return null;
69 } else {
70 // class loader of any other obj array klass is same as the loader
71 // that loaded the bottom InstanceKlass
72 Instance xx = (Instance)(((InstanceKlass) bottomKlass).getClassLoader());
73 return vm.classLoaderMirror(xx);
74 }
75 }
76 }
77
78 void addVisibleMethods(Map methodMap) {
79 // arrays don't have methods
80 }
81
82 List getAllMethods() {
83 // arrays don't have methods
84 // JLS says arrays have methods of java.lang.Object. But
85 // JVMDI-JDI returns zero size list. We do the same here
86 // for consistency.
87 return new ArrayList(0);
88 }
89
90 /*
91 * Find the type object, if any, of a component type of this array.
92 * The component type does not have to be immediate; e.g. this method
93 * can be used to find the component Foo of Foo[][].
94 */
95 public Type componentType() throws ClassNotLoadedException {
96 ArrayKlass k = (ArrayKlass) ref();
97 if (k instanceof ObjArrayKlass) {
98 Klass elementKlass = ((ObjArrayKlass)k).getElementKlass();
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 package sun.jvm.hotspot.jdi;
26
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Set;
31
32 import sun.jvm.hotspot.oops.ArrayKlass;
33 import sun.jvm.hotspot.oops.Instance;
34 import sun.jvm.hotspot.oops.InstanceKlass;
35 import sun.jvm.hotspot.oops.Klass;
36 import sun.jvm.hotspot.oops.ObjArrayKlass;
37 import sun.jvm.hotspot.oops.Symbol;
38 import sun.jvm.hotspot.oops.TypeArrayKlass;
39
40 import com.sun.jdi.ArrayReference;
41 import com.sun.jdi.ArrayType;
42 import com.sun.jdi.ClassLoaderReference;
43 import com.sun.jdi.ClassNotLoadedException;
44 import com.sun.jdi.InterfaceType;
45 import com.sun.jdi.Method;
46 import com.sun.jdi.PrimitiveType;
47 import com.sun.jdi.ReferenceType;
48 import com.sun.jdi.Type;
49 import com.sun.jdi.VirtualMachine;
50
51 public class ArrayTypeImpl extends ReferenceTypeImpl implements ArrayType {
52 protected ArrayTypeImpl(VirtualMachine aVm, ArrayKlass aRef) {
53 super(aVm, aRef);
54 }
55
56 public ArrayReference newInstance(int length) {
57 vm.throwNotReadOnlyException("ArrayType.newInstance(int)");
58 return null;
59 }
60
61 public String componentSignature() {
62 return signature().substring(1); // Just skip the leading '['
63 }
64
65 public String componentTypeName() {
66 JNITypeParser parser = new JNITypeParser(componentSignature());
67 return parser.typeName();
68 }
69
70 public ClassLoaderReference classLoader() {
71 if (ref() instanceof TypeArrayKlass) {
72 // primitive array klasses are loaded by bootstrap loader
73 return null;
74 } else {
75 Klass bottomKlass = ((ObjArrayKlass)ref()).getBottomKlass();
76 if (bottomKlass instanceof TypeArrayKlass) {
77 // multidimensional primitive array klasses are loaded by bootstrap loader
78 return null;
79 } else {
80 // class loader of any other obj array klass is same as the loader
81 // that loaded the bottom InstanceKlass
82 Instance xx = (Instance)(((InstanceKlass) bottomKlass).getClassLoader());
83 return vm.classLoaderMirror(xx);
84 }
85 }
86 }
87
88 @Override
89 void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> handledInterfaces) {
90 // arrays don't have methods
91 }
92
93 List getAllMethods() {
94 // arrays don't have methods
95 // JLS says arrays have methods of java.lang.Object. But
96 // JVMDI-JDI returns zero size list. We do the same here
97 // for consistency.
98 return new ArrayList(0);
99 }
100
101 /*
102 * Find the type object, if any, of a component type of this array.
103 * The component type does not have to be immediate; e.g. this method
104 * can be used to find the component Foo of Foo[][].
105 */
106 public Type componentType() throws ClassNotLoadedException {
107 ArrayKlass k = (ArrayKlass) ref();
108 if (k instanceof ObjArrayKlass) {
109 Klass elementKlass = ((ObjArrayKlass)k).getElementKlass();
|