agent/src/share/classes/sun/jvm/hotspot/jdi/ClassTypeImpl.java

Print this page
rev 5684 : 4990369: visibleMethods() and methodsByName() return wrong visible methods
Reviewed-by:


   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 import sun.jvm.hotspot.oops.Klass;







  29 import sun.jvm.hotspot.oops.InstanceKlass;
  30 
  31 import java.util.*;
  32 import java.lang.ref.SoftReference;











  33 
  34 public class ClassTypeImpl extends ReferenceTypeImpl
  35     implements ClassType
  36 {
  37     private SoftReference interfacesCache    = null;
  38     private SoftReference allInterfacesCache = null;
  39     private SoftReference subclassesCache    = null;
  40 
  41     protected ClassTypeImpl(VirtualMachine aVm, InstanceKlass aRef) {
  42         super(aVm, aRef);
  43     }
  44 
  45     public ClassType superclass() {
  46         InstanceKlass kk = (InstanceKlass)ref().getSuper();
  47         if (kk == null) {
  48             return null;
  49         }
  50         return (ClassType) vm.referenceType(kk);
  51     }
  52 


 178                               List arguments, int options)
 179                                    throws InvalidTypeException,
 180                                           ClassNotLoadedException,
 181                                           IncompatibleThreadStateException,
 182                                           InvocationException {
 183         vm.throwNotReadOnlyException("ClassType.invokeMethod(...)");
 184         return null;
 185     }
 186 
 187     public ObjectReference newInstance(ThreadReference threadIntf,
 188                                        Method methodIntf,
 189                                        List arguments, int options)
 190                                    throws InvalidTypeException,
 191                                           ClassNotLoadedException,
 192                                           IncompatibleThreadStateException,
 193                                           InvocationException {
 194         vm.throwNotReadOnlyException("ClassType.newInstance(...)");
 195         return null;
 196     }
 197 
 198     void addVisibleMethods(Map methodMap) {

 199         /*
 200          * Add methods from
 201          * parent types first, so that the methods in this class will
 202          * overwrite them in the hash table
 203          */
 204 
 205         Iterator iter = interfaces().iterator();
 206         while (iter.hasNext()) {
 207             InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
 208             interfaze.addVisibleMethods(methodMap);



 209         }
 210 
 211         ClassTypeImpl clazz = (ClassTypeImpl)superclass();
 212         if (clazz != null) {
 213             clazz.addVisibleMethods(methodMap);
 214         }
 215 
 216         addToMethodMap(methodMap, methods());
 217     }
 218 
 219     boolean isAssignableTo(ReferenceType type) {
 220         ClassTypeImpl superclazz = (ClassTypeImpl)superclass();
 221         if (this.equals(type)) {
 222             return true;
 223         } else if ((superclazz != null) && superclazz.isAssignableTo(type)) {
 224             return true;
 225         } else {
 226             List interfaces = interfaces();
 227             Iterator iter = interfaces.iterator();
 228             while (iter.hasNext()) {
 229                 InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
 230                 if (interfaze.isAssignableTo(type)) {
 231                     return true;
 232                 }
 233             }


   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.lang.ref.SoftReference;
  28 import java.util.ArrayList;
  29 import java.util.Collections;
  30 import java.util.HashSet;
  31 import java.util.Iterator;
  32 import java.util.List;
  33 import java.util.Map;
  34 import java.util.Set;
  35 
  36 import sun.jvm.hotspot.oops.InstanceKlass;
  37 
  38 import com.sun.jdi.ClassNotLoadedException;
  39 import com.sun.jdi.ClassType;
  40 import com.sun.jdi.Field;
  41 import com.sun.jdi.IncompatibleThreadStateException;
  42 import com.sun.jdi.InterfaceType;
  43 import com.sun.jdi.InvalidTypeException;
  44 import com.sun.jdi.InvocationException;
  45 import com.sun.jdi.Method;
  46 import com.sun.jdi.ObjectReference;
  47 import com.sun.jdi.ReferenceType;
  48 import com.sun.jdi.ThreadReference;
  49 import com.sun.jdi.Value;
  50 import com.sun.jdi.VirtualMachine;
  51 
  52 public class ClassTypeImpl extends ReferenceTypeImpl
  53     implements ClassType
  54 {
  55     private SoftReference interfacesCache    = null;
  56     private SoftReference allInterfacesCache = null;
  57     private SoftReference subclassesCache    = null;
  58 
  59     protected ClassTypeImpl(VirtualMachine aVm, InstanceKlass aRef) {
  60         super(aVm, aRef);
  61     }
  62 
  63     public ClassType superclass() {
  64         InstanceKlass kk = (InstanceKlass)ref().getSuper();
  65         if (kk == null) {
  66             return null;
  67         }
  68         return (ClassType) vm.referenceType(kk);
  69     }
  70 


 196                               List arguments, int options)
 197                                    throws InvalidTypeException,
 198                                           ClassNotLoadedException,
 199                                           IncompatibleThreadStateException,
 200                                           InvocationException {
 201         vm.throwNotReadOnlyException("ClassType.invokeMethod(...)");
 202         return null;
 203     }
 204 
 205     public ObjectReference newInstance(ThreadReference threadIntf,
 206                                        Method methodIntf,
 207                                        List arguments, int options)
 208                                    throws InvalidTypeException,
 209                                           ClassNotLoadedException,
 210                                           IncompatibleThreadStateException,
 211                                           InvocationException {
 212         vm.throwNotReadOnlyException("ClassType.newInstance(...)");
 213         return null;
 214     }
 215 
 216     @Override
 217     void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
 218         /*
 219          * Add methods from
 220          * parent types first, so that the methods in this class will
 221          * overwrite them in the hash table
 222          */
 223 
 224         Iterator<InterfaceType> iter = interfaces().iterator();
 225         while (iter.hasNext()) {
 226             InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
 227             if (!seenInterfaces.contains(interfaze)) {
 228                 interfaze.addVisibleMethods(methodMap, seenInterfaces);
 229                 seenInterfaces.add(interfaze);
 230             }
 231         }
 232 
 233         ClassTypeImpl clazz = (ClassTypeImpl)superclass();
 234         if (clazz != null) {
 235             clazz.addVisibleMethods(methodMap, seenInterfaces);
 236         }
 237 
 238         addToMethodMap(methodMap, methods());
 239     }
 240 
 241     boolean isAssignableTo(ReferenceType type) {
 242         ClassTypeImpl superclazz = (ClassTypeImpl)superclass();
 243         if (this.equals(type)) {
 244             return true;
 245         } else if ((superclazz != null) && superclazz.isAssignableTo(type)) {
 246             return true;
 247         } else {
 248             List interfaces = interfaces();
 249             Iterator iter = interfaces.iterator();
 250             while (iter.hasNext()) {
 251                 InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
 252                 if (interfaze.isAssignableTo(type)) {
 253                     return true;
 254                 }
 255             }