agent/src/share/classes/sun/jvm/hotspot/jdi/InterfaceTypeImpl.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.InstanceKlass;
  29 
  30 import java.util.List;
  31 import java.util.ArrayList;
  32 import java.util.Map;
  33 import java.util.Iterator;
  34 import java.util.Collections;
  35 import java.lang.ref.SoftReference;












  36 
  37 public class InterfaceTypeImpl extends ReferenceTypeImpl
  38                                implements InterfaceType {
  39     private SoftReference superInterfacesCache = null;
  40     private SoftReference subInterfacesCache = null;
  41     private SoftReference implementorsCache = null;
  42 
  43     protected InterfaceTypeImpl(VirtualMachine aVm, InstanceKlass aRef) {
  44         super(aVm, aRef);
  45     }
  46 
  47     public List superinterfaces() throws ClassNotPreparedException {
  48         List superinterfaces = (superInterfacesCache != null)? (List) superInterfacesCache.get() : null;
  49         if (superinterfaces == null) {
  50             checkPrepared();
  51             superinterfaces = Collections.unmodifiableList(getInterfaces());
  52             superInterfacesCache = new SoftReference(superinterfaces);
  53         }
  54         return superinterfaces;
  55     }


  79         List implementors = (implementorsCache != null)? (List) implementorsCache.get() : null;
  80         if (implementors == null) {
  81             List all = vm.allClasses();
  82             implementors = new ArrayList();
  83             Iterator iter = all.iterator();
  84             while (iter.hasNext()) {
  85                 ReferenceType refType = (ReferenceType)iter.next();
  86                 if (refType instanceof ClassType) {
  87                     ClassType clazz = (ClassType)refType;
  88                     if (clazz.isPrepared() && clazz.interfaces().contains(this)) {
  89                         implementors.add(clazz);
  90                     }
  91                 }
  92             }
  93             implementors = Collections.unmodifiableList(implementors);
  94             implementorsCache = new SoftReference(implementors);
  95         }
  96         return implementors;
  97     }
  98 
  99     void addVisibleMethods(Map methodMap) {

 100         /*
 101          * Add methods from
 102          * parent types first, so that the methods in this class will
 103          * overwrite them in the hash table
 104          */
 105         Iterator iter = superinterfaces().iterator();
 106         while (iter.hasNext()) {
 107             InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
 108             interfaze.addVisibleMethods(methodMap);



 109         }
 110 
 111         addToMethodMap(methodMap, methods());
 112     }
 113 
 114     List getAllMethods() {
 115         ArrayList list = new ArrayList(methods());
 116         /*
 117          * It's more efficient if don't do this
 118          * recursively.
 119          */
 120         List interfaces = allSuperinterfaces();
 121         Iterator iter = interfaces.iterator();
 122         while (iter.hasNext()) {
 123             InterfaceType interfaze = (InterfaceType)iter.next();
 124             list.addAll(interfaze.methods());
 125         }
 126 
 127         return list;
 128     }




   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.Iterator;
  31 import java.util.List;
  32 import java.util.Map;
  33 import java.util.Set;
  34 
  35 import sun.jvm.hotspot.oops.InstanceKlass;
  36 
  37 import com.sun.jdi.ClassNotPreparedException;
  38 import com.sun.jdi.ClassType;
  39 import com.sun.jdi.InterfaceType;
  40 import com.sun.jdi.Method;
  41 import com.sun.jdi.ReferenceType;
  42 import com.sun.jdi.VirtualMachine;
  43 
  44 public class InterfaceTypeImpl extends ReferenceTypeImpl
  45                                implements InterfaceType {
  46     private SoftReference superInterfacesCache = null;
  47     private SoftReference subInterfacesCache = null;
  48     private SoftReference implementorsCache = null;
  49 
  50     protected InterfaceTypeImpl(VirtualMachine aVm, InstanceKlass aRef) {
  51         super(aVm, aRef);
  52     }
  53 
  54     public List superinterfaces() throws ClassNotPreparedException {
  55         List superinterfaces = (superInterfacesCache != null)? (List) superInterfacesCache.get() : null;
  56         if (superinterfaces == null) {
  57             checkPrepared();
  58             superinterfaces = Collections.unmodifiableList(getInterfaces());
  59             superInterfacesCache = new SoftReference(superinterfaces);
  60         }
  61         return superinterfaces;
  62     }


  86         List implementors = (implementorsCache != null)? (List) implementorsCache.get() : null;
  87         if (implementors == null) {
  88             List all = vm.allClasses();
  89             implementors = new ArrayList();
  90             Iterator iter = all.iterator();
  91             while (iter.hasNext()) {
  92                 ReferenceType refType = (ReferenceType)iter.next();
  93                 if (refType instanceof ClassType) {
  94                     ClassType clazz = (ClassType)refType;
  95                     if (clazz.isPrepared() && clazz.interfaces().contains(this)) {
  96                         implementors.add(clazz);
  97                     }
  98                 }
  99             }
 100             implementors = Collections.unmodifiableList(implementors);
 101             implementorsCache = new SoftReference(implementors);
 102         }
 103         return implementors;
 104     }
 105 
 106     @Override
 107     void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
 108         /*
 109          * Add methods from
 110          * parent types first, so that the methods in this class will
 111          * overwrite them in the hash table
 112          */
 113         Iterator<InterfaceType> iter = superinterfaces().iterator();
 114         while (iter.hasNext()) {
 115             InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
 116             if (!seenInterfaces.contains(interfaze)) {
 117                 interfaze.addVisibleMethods(methodMap, seenInterfaces);
 118                 seenInterfaces.add(interfaze);
 119             }
 120         }
 121 
 122         addToMethodMap(methodMap, methods());
 123     }
 124 
 125     List getAllMethods() {
 126         ArrayList list = new ArrayList(methods());
 127         /*
 128          * It's more efficient if don't do this
 129          * recursively.
 130          */
 131         List interfaces = allSuperinterfaces();
 132         Iterator iter = interfaces.iterator();
 133         while (iter.hasNext()) {
 134             InterfaceType interfaze = (InterfaceType)iter.next();
 135             list.addAll(interfaze.methods());
 136         }
 137 
 138         return list;
 139     }