agent/src/share/classes/sun/jvm/hotspot/jdi/ReferenceTypeImpl.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 java.io.*;
  28 
  29 import com.sun.jdi.*;









  30 
  31 import sun.jvm.hotspot.memory.SystemDictionary;


  32 import sun.jvm.hotspot.oops.Instance;
  33 import sun.jvm.hotspot.oops.InstanceKlass;
  34 import sun.jvm.hotspot.oops.ArrayKlass;
  35 import sun.jvm.hotspot.oops.JVMDIClassStatus;
  36 import sun.jvm.hotspot.oops.Klass;
  37 import sun.jvm.hotspot.oops.ObjArray;
  38 import sun.jvm.hotspot.oops.Oop;
  39 import sun.jvm.hotspot.oops.Symbol;
  40 import sun.jvm.hotspot.oops.DefaultHeapVisitor;
  41 import sun.jvm.hotspot.utilities.Assert;
  42 
  43 import java.util.*;
  44 import java.lang.ref.SoftReference;













  45 
  46 public abstract class ReferenceTypeImpl extends TypeImpl
  47 implements ReferenceType {
  48     protected Klass       saKlass;          // This can be an InstanceKlass or an ArrayKlass
  49     protected Symbol      typeNameSymbol;   // This is used in vm.classesByName to speedup search
  50     private int           modifiers = -1;
  51     private String        signature = null;
  52     private SoftReference sdeRef = null;
  53     private SoftReference fieldsCache;
  54     private SoftReference allFieldsCache;
  55     private SoftReference methodsCache;
  56     private SoftReference allMethodsCache;
  57     private SoftReference nestedTypesCache;
  58     private SoftReference methodInvokesCache;
  59 
  60     /* to mark when no info available */
  61     static final SDE NO_SDE_INFO_MARK = new SDE();
  62 
  63     protected ReferenceTypeImpl(VirtualMachine aVm, sun.jvm.hotspot.oops.Klass klass) {
  64         super(aVm);


 404         if (allMethods == null) {
 405             checkPrepared();
 406             allMethods = Collections.unmodifiableList(getAllMethods());
 407             allMethodsCache = new SoftReference(allMethods);
 408         }
 409         return allMethods;
 410     }
 411 
 412     /*
 413      * Utility method used by subclasses to build lists of visible
 414      * methods.
 415      */
 416     void addToMethodMap(Map methodMap, List methodList) {
 417         Iterator iter = methodList.iterator();
 418         while (iter.hasNext()) {
 419             Method method = (Method)iter.next();
 420             methodMap.put(method.name().concat(method.signature()), method);
 421         }
 422     }
 423 
 424     abstract void addVisibleMethods(Map methodMap);

 425     public final List visibleMethods() throws ClassNotPreparedException {
 426         checkPrepared();
 427         /*
 428          * Build a collection of all visible methods. The hash
 429          * map allows us to do this efficiently by keying on the
 430          * concatenation of name and signature.
 431          */
 432         //System.out.println("jj: RTI: Calling addVisibleMethods for:" + this);
 433         Map map = new HashMap();
 434         addVisibleMethods(map);
 435 
 436         /*
 437          * ... but the hash map destroys order. Methods should be
 438          * returned in a sensible order, as they are in allMethods().
 439          * So, start over with allMethods() and use the hash map
 440          * to filter that ordered collection.
 441          */
 442         //System.out.println("jj: RTI: Calling allMethods for:" + this);
 443 
 444         List list = new ArrayList(allMethods());
 445         //System.out.println("jj: allMethods = " + jjstr(list));
 446         //System.out.println("jj: map = " + map.toString());
 447         //System.out.println("jj: map = " + jjstr(map.values()));
 448         list.retainAll(map.values());
 449         //System.out.println("jj: map = " + jjstr(list));
 450         //System.exit(0);
 451         return list;
 452     }
 453 
 454     static Object prev;
 455 
 456     static public String jjstr(Collection cc) {
 457         StringBuffer buf = new StringBuffer();
 458         buf.append("[");
 459         Iterator i = cc.iterator();
 460         boolean hasNext = i.hasNext();
 461         while (hasNext) {
 462             Object o = i.next();
 463             if (prev == null) {
 464                 prev = o;




   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.io.ByteArrayOutputStream;
  28 import java.io.IOException;
  29 import java.lang.ref.SoftReference;
  30 import java.util.ArrayList;
  31 import java.util.Collection;
  32 import java.util.Collections;
  33 import java.util.HashMap;
  34 import java.util.HashSet;
  35 import java.util.Iterator;
  36 import java.util.List;
  37 import java.util.Map;
  38 import java.util.Set;
  39 
  40 import sun.jvm.hotspot.memory.SystemDictionary;
  41 import sun.jvm.hotspot.oops.ArrayKlass;
  42 import sun.jvm.hotspot.oops.DefaultHeapVisitor;
  43 import sun.jvm.hotspot.oops.Instance;
  44 import sun.jvm.hotspot.oops.InstanceKlass;

  45 import sun.jvm.hotspot.oops.JVMDIClassStatus;
  46 import sun.jvm.hotspot.oops.Klass;

  47 import sun.jvm.hotspot.oops.Oop;
  48 import sun.jvm.hotspot.oops.Symbol;

  49 import sun.jvm.hotspot.utilities.Assert;
  50 
  51 import com.sun.jdi.AbsentInformationException;
  52 import com.sun.jdi.ArrayType;
  53 import com.sun.jdi.ClassLoaderReference;
  54 import com.sun.jdi.ClassNotLoadedException;
  55 import com.sun.jdi.ClassNotPreparedException;
  56 import com.sun.jdi.ClassObjectReference;
  57 import com.sun.jdi.Field;
  58 import com.sun.jdi.InterfaceType;
  59 import com.sun.jdi.Method;
  60 import com.sun.jdi.ObjectReference;
  61 import com.sun.jdi.PrimitiveType;
  62 import com.sun.jdi.ReferenceType;
  63 import com.sun.jdi.Type;
  64 import com.sun.jdi.Value;
  65 import com.sun.jdi.VirtualMachine;
  66 
  67 public abstract class ReferenceTypeImpl extends TypeImpl
  68 implements ReferenceType {
  69     protected Klass       saKlass;          // This can be an InstanceKlass or an ArrayKlass
  70     protected Symbol      typeNameSymbol;   // This is used in vm.classesByName to speedup search
  71     private int           modifiers = -1;
  72     private String        signature = null;
  73     private SoftReference sdeRef = null;
  74     private SoftReference fieldsCache;
  75     private SoftReference allFieldsCache;
  76     private SoftReference methodsCache;
  77     private SoftReference allMethodsCache;
  78     private SoftReference nestedTypesCache;
  79     private SoftReference methodInvokesCache;
  80 
  81     /* to mark when no info available */
  82     static final SDE NO_SDE_INFO_MARK = new SDE();
  83 
  84     protected ReferenceTypeImpl(VirtualMachine aVm, sun.jvm.hotspot.oops.Klass klass) {
  85         super(aVm);


 425         if (allMethods == null) {
 426             checkPrepared();
 427             allMethods = Collections.unmodifiableList(getAllMethods());
 428             allMethodsCache = new SoftReference(allMethods);
 429         }
 430         return allMethods;
 431     }
 432 
 433     /*
 434      * Utility method used by subclasses to build lists of visible
 435      * methods.
 436      */
 437     void addToMethodMap(Map methodMap, List methodList) {
 438         Iterator iter = methodList.iterator();
 439         while (iter.hasNext()) {
 440             Method method = (Method)iter.next();
 441             methodMap.put(method.name().concat(method.signature()), method);
 442         }
 443     }
 444 
 445     abstract void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces);
 446     
 447     public final List visibleMethods() throws ClassNotPreparedException {
 448         checkPrepared();
 449         /*
 450          * Build a collection of all visible methods. The hash
 451          * map allows us to do this efficiently by keying on the
 452          * concatenation of name and signature.
 453          */
 454         //System.out.println("jj: RTI: Calling addVisibleMethods for:" + this);
 455         Map<String, Method> map = new HashMap<String, Method>();
 456         addVisibleMethods(map, new HashSet<InterfaceType>());
 457 
 458         /*
 459          * ... but the hash map destroys order. Methods should be
 460          * returned in a sensible order, as they are in allMethods().
 461          * So, start over with allMethods() and use the hash map
 462          * to filter that ordered collection.
 463          */
 464         //System.out.println("jj: RTI: Calling allMethods for:" + this);
 465 
 466         List<Method> list = new ArrayList<Method>(allMethods());
 467         //System.out.println("jj: allMethods = " + jjstr(list));
 468         //System.out.println("jj: map = " + map.toString());
 469         //System.out.println("jj: map = " + jjstr(map.values()));
 470         list.retainAll(map.values());
 471         //System.out.println("jj: map = " + jjstr(list));
 472         //System.exit(0);
 473         return list;
 474     }
 475 
 476     static Object prev;
 477 
 478     static public String jjstr(Collection cc) {
 479         StringBuffer buf = new StringBuffer();
 480         buf.append("[");
 481         Iterator i = cc.iterator();
 482         boolean hasNext = i.hasNext();
 483         while (hasNext) {
 484             Object o = i.next();
 485             if (prev == null) {
 486                 prev = o;