0N/A/*
1472N/A * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
0N/Apackage sun.jvm.hotspot.jdi;
0N/A
0N/Aimport com.sun.jdi.*;
0N/A
0N/Aimport sun.jvm.hotspot.oops.ArrayKlass;
0N/Aimport sun.jvm.hotspot.oops.InstanceKlass;
0N/Aimport sun.jvm.hotspot.oops.ObjArrayKlass;
0N/Aimport sun.jvm.hotspot.oops.TypeArrayKlass;
0N/Aimport sun.jvm.hotspot.oops.Klass;
0N/Aimport sun.jvm.hotspot.oops.Instance;
0N/Aimport sun.jvm.hotspot.oops.Symbol;
0N/Aimport java.util.List;
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.Map;
0N/A
0N/Apublic class ArrayTypeImpl extends ReferenceTypeImpl implements ArrayType {
0N/A protected ArrayTypeImpl(VirtualMachine aVm, ArrayKlass aRef) {
0N/A super(aVm, aRef);
0N/A }
0N/A
0N/A public ArrayReference newInstance(int length) {
0N/A vm.throwNotReadOnlyException("ArrayType.newInstance(int)");
0N/A return null;
0N/A }
0N/A
0N/A public String componentSignature() {
0N/A return signature().substring(1); // Just skip the leading '['
0N/A }
0N/A
0N/A public String componentTypeName() {
0N/A JNITypeParser parser = new JNITypeParser(componentSignature());
0N/A return parser.typeName();
0N/A }
0N/A
0N/A public ClassLoaderReference classLoader() {
0N/A if (ref() instanceof TypeArrayKlass) {
0N/A // primitive array klasses are loaded by bootstrap loader
0N/A return null;
0N/A } else {
0N/A Klass bottomKlass = ((ObjArrayKlass)ref()).getBottomKlass();
0N/A if (bottomKlass instanceof TypeArrayKlass) {
0N/A // multidimensional primitive array klasses are loaded by bootstrap loader
0N/A return null;
0N/A } else {
0N/A // class loader of any other obj array klass is same as the loader
0N/A // that loaded the bottom InstanceKlass
0N/A Instance xx = (Instance)(((InstanceKlass) bottomKlass).getClassLoader());
0N/A return vm.classLoaderMirror(xx);
0N/A }
0N/A }
0N/A }
0N/A
0N/A void addVisibleMethods(Map methodMap) {
0N/A // arrays don't have methods
0N/A }
0N/A
0N/A List getAllMethods() {
0N/A // arrays don't have methods
0N/A // JLS says arrays have methods of java.lang.Object. But
0N/A // JVMDI-JDI returns zero size list. We do the same here
0N/A // for consistency.
0N/A return new ArrayList(0);
0N/A }
0N/A
0N/A /*
0N/A * Find the type object, if any, of a component type of this array.
0N/A * The component type does not have to be immediate; e.g. this method
0N/A * can be used to find the component Foo of Foo[][].
0N/A */
0N/A public Type componentType() throws ClassNotLoadedException {
0N/A ArrayKlass k = (ArrayKlass) ref();
0N/A if (k instanceof ObjArrayKlass) {
0N/A Klass elementKlass = ((ObjArrayKlass)k).getElementKlass();
0N/A if (elementKlass == null) {
0N/A throw new ClassNotLoadedException(componentSignature());
0N/A } else {
0N/A return vm.referenceType(elementKlass);
0N/A }
0N/A } else {
0N/A // It's a primitive type
0N/A return vm.primitiveTypeMirror(signature().charAt(1));
0N/A }
0N/A }
0N/A
0N/A static boolean isComponentAssignable(Type destination, Type source) {
0N/A if (source instanceof PrimitiveType) {
0N/A // Assignment of primitive arrays requires identical
0N/A // component types.
0N/A return source.equals(destination);
0N/A } else {
0N/A if (destination instanceof PrimitiveType) {
0N/A return false;
0N/A }
0N/A
0N/A ReferenceTypeImpl refSource = (ReferenceTypeImpl)source;
0N/A ReferenceTypeImpl refDestination = (ReferenceTypeImpl)destination;
0N/A // Assignment of object arrays requires availability
0N/A // of widening conversion of component types
0N/A return refSource.isAssignableTo(refDestination);
0N/A }
0N/A }
0N/A
0N/A
0N/A /*
0N/A * Return true if an instance of the given reference type
0N/A * can be assigned to a variable of this type
0N/A */
0N/A boolean isAssignableTo(ReferenceType destType) {
0N/A if (destType instanceof ArrayType) {
0N/A try {
0N/A Type destComponentType = ((ArrayType)destType).componentType();
0N/A return isComponentAssignable(destComponentType, componentType());
0N/A } catch (ClassNotLoadedException e) {
0N/A // One or both component types has not yet been
0N/A // loaded => can't assign
0N/A return false;
0N/A }
0N/A } else {
0N/A Symbol typeName = ((ReferenceTypeImpl)destType).typeNameAsSymbol();
0N/A if (destType instanceof InterfaceType) {
0N/A // Every array type implements java.io.Serializable and
0N/A // java.lang.Cloneable. fixme in JVMDI-JDI, includes only
0N/A // Cloneable but not Serializable.
0N/A return typeName.equals(vm.javaLangCloneable()) ||
0N/A typeName.equals(vm.javaIoSerializable());
0N/A } else {
0N/A // Only valid ClassType assignee is Object
0N/A return typeName.equals(vm.javaLangObject());
0N/A }
0N/A }
0N/A }
0N/A
0N/A List inheritedTypes() {
0N/A // arrays are derived from java.lang.Object and
0N/A // B[] is derived from A[] if B is derived from A.
0N/A // But JVMDI-JDI returns zero sized list and we do the
0N/A // same for consistency.
0N/A return new ArrayList(0);
0N/A }
0N/A
0N/A int getModifiers() {
0N/A /*
0N/A * For object arrays, the return values for Interface
0N/A * Accessible.isPrivate(), Accessible.isProtected(),
0N/A * etc... are the same as would be returned for the
0N/A * component type. Fetch the modifier bits from the
0N/A * component type and use those.
0N/A *
0N/A * For primitive arrays, the modifiers are always
0N/A * VMModifiers.FINAL | VMModifiers.PUBLIC
0N/A *
0N/A * Reference com.sun.jdi.Accessible.java.
0N/A */
0N/A try {
0N/A Type t = componentType();
0N/A if (t instanceof PrimitiveType) {
0N/A return VMModifiers.FINAL | VMModifiers.PUBLIC;
0N/A } else {
0N/A ReferenceType rt = (ReferenceType)t;
0N/A return rt.modifiers();
0N/A }
0N/A } catch (ClassNotLoadedException cnle) {
0N/A cnle.printStackTrace();
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A public String toString() {
0N/A return "array class " + name() + " (" + loaderString() + ")";
0N/A }
0N/A
0N/A /*
0N/A * Save a pointless trip over the wire for these methods
0N/A * which have undefined results for arrays.
0N/A */
0N/A public boolean isPrepared() { return true; }
0N/A public boolean isVerified() { return true; }
0N/A public boolean isInitialized() { return true; }
0N/A public boolean failedToInitialize() { return false; }
0N/A public boolean isAbstract() { return false; }
0N/A
0N/A /*
0N/A * Defined always to be true for arrays
0N/A */
0N/A public boolean isFinal() { return true; }
0N/A}