changeset 14188:29985fccf378

4990369: visibleMethods() and methodsByName() return wrong visible methods Reviewed-by: sspitsyn, coleenp
author sla
date Tue, 07 Jan 2014 10:50:28 +0100
parents e89b54bf4e51
children 1a899ea6b7ed
files agent/src/share/classes/sun/jvm/hotspot/jdi/ArrayTypeImpl.java agent/src/share/classes/sun/jvm/hotspot/jdi/ClassTypeImpl.java agent/src/share/classes/sun/jvm/hotspot/jdi/InterfaceTypeImpl.java agent/src/share/classes/sun/jvm/hotspot/jdi/ReferenceTypeImpl.java
diffstat 4 files changed, 105 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/agent/src/share/classes/sun/jvm/hotspot/jdi/ArrayTypeImpl.java	Mon Jan 06 08:44:24 2014 -0500
+++ b/agent/src/share/classes/sun/jvm/hotspot/jdi/ArrayTypeImpl.java	Tue Jan 07 10:50:28 2014 +0100
@@ -24,19 +24,29 @@
 
 package sun.jvm.hotspot.jdi;
 
-import com.sun.jdi.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import sun.jvm.hotspot.oops.ArrayKlass;
+import sun.jvm.hotspot.oops.Instance;
 import sun.jvm.hotspot.oops.InstanceKlass;
-import sun.jvm.hotspot.oops.ObjArrayKlass;
-import sun.jvm.hotspot.oops.TypeArrayKlass;
 import sun.jvm.hotspot.oops.Klass;
-import sun.jvm.hotspot.oops.Instance;
+import sun.jvm.hotspot.oops.ObjArrayKlass;
 import sun.jvm.hotspot.oops.Symbol;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map;
+import sun.jvm.hotspot.oops.TypeArrayKlass;
+
+import com.sun.jdi.ArrayReference;
+import com.sun.jdi.ArrayType;
+import com.sun.jdi.ClassLoaderReference;
+import com.sun.jdi.ClassNotLoadedException;
+import com.sun.jdi.InterfaceType;
+import com.sun.jdi.Method;
+import com.sun.jdi.PrimitiveType;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.Type;
+import com.sun.jdi.VirtualMachine;
 
 public class ArrayTypeImpl extends ReferenceTypeImpl implements ArrayType {
   protected ArrayTypeImpl(VirtualMachine aVm, ArrayKlass aRef) {
@@ -75,7 +85,8 @@
         }
     }
 
-    void addVisibleMethods(Map methodMap) {
+    @Override
+    void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> handledInterfaces) {
         // arrays don't have methods
     }
 
--- a/agent/src/share/classes/sun/jvm/hotspot/jdi/ClassTypeImpl.java	Mon Jan 06 08:44:24 2014 -0500
+++ b/agent/src/share/classes/sun/jvm/hotspot/jdi/ClassTypeImpl.java	Tue Jan 07 10:50:28 2014 +0100
@@ -24,12 +24,30 @@
 
 package sun.jvm.hotspot.jdi;
 
-import com.sun.jdi.*;
-import sun.jvm.hotspot.oops.Klass;
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import sun.jvm.hotspot.oops.InstanceKlass;
 
-import java.util.*;
-import java.lang.ref.SoftReference;
+import com.sun.jdi.ClassNotLoadedException;
+import com.sun.jdi.ClassType;
+import com.sun.jdi.Field;
+import com.sun.jdi.IncompatibleThreadStateException;
+import com.sun.jdi.InterfaceType;
+import com.sun.jdi.InvalidTypeException;
+import com.sun.jdi.InvocationException;
+import com.sun.jdi.Method;
+import com.sun.jdi.ObjectReference;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.ThreadReference;
+import com.sun.jdi.Value;
+import com.sun.jdi.VirtualMachine;
 
 public class ClassTypeImpl extends ReferenceTypeImpl
     implements ClassType
@@ -195,22 +213,26 @@
         return null;
     }
 
-    void addVisibleMethods(Map methodMap) {
+    @Override
+    void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
         /*
          * Add methods from
          * parent types first, so that the methods in this class will
          * overwrite them in the hash table
          */
 
-        Iterator iter = interfaces().iterator();
+        Iterator<InterfaceType> iter = interfaces().iterator();
         while (iter.hasNext()) {
             InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
-            interfaze.addVisibleMethods(methodMap);
+            if (!seenInterfaces.contains(interfaze)) {
+                interfaze.addVisibleMethods(methodMap, seenInterfaces);
+                seenInterfaces.add(interfaze);
+            }
         }
 
         ClassTypeImpl clazz = (ClassTypeImpl)superclass();
         if (clazz != null) {
-            clazz.addVisibleMethods(methodMap);
+            clazz.addVisibleMethods(methodMap, seenInterfaces);
         }
 
         addToMethodMap(methodMap, methods());
--- a/agent/src/share/classes/sun/jvm/hotspot/jdi/InterfaceTypeImpl.java	Mon Jan 06 08:44:24 2014 -0500
+++ b/agent/src/share/classes/sun/jvm/hotspot/jdi/InterfaceTypeImpl.java	Tue Jan 07 10:50:28 2014 +0100
@@ -24,15 +24,22 @@
 
 package sun.jvm.hotspot.jdi;
 
-import com.sun.jdi.*;
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import sun.jvm.hotspot.oops.InstanceKlass;
 
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.Iterator;
-import java.util.Collections;
-import java.lang.ref.SoftReference;
+import com.sun.jdi.ClassNotPreparedException;
+import com.sun.jdi.ClassType;
+import com.sun.jdi.InterfaceType;
+import com.sun.jdi.Method;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.VirtualMachine;
 
 public class InterfaceTypeImpl extends ReferenceTypeImpl
                                implements InterfaceType {
@@ -96,16 +103,20 @@
         return implementors;
     }
 
-    void addVisibleMethods(Map methodMap) {
+    @Override
+    void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces) {
         /*
          * Add methods from
          * parent types first, so that the methods in this class will
          * overwrite them in the hash table
          */
-        Iterator iter = superinterfaces().iterator();
+        Iterator<InterfaceType> iter = superinterfaces().iterator();
         while (iter.hasNext()) {
             InterfaceTypeImpl interfaze = (InterfaceTypeImpl)iter.next();
-            interfaze.addVisibleMethods(methodMap);
+            if (!seenInterfaces.contains(interfaze)) {
+                interfaze.addVisibleMethods(methodMap, seenInterfaces);
+                seenInterfaces.add(interfaze);
+            }
         }
 
         addToMethodMap(methodMap, methods());
--- a/agent/src/share/classes/sun/jvm/hotspot/jdi/ReferenceTypeImpl.java	Mon Jan 06 08:44:24 2014 -0500
+++ b/agent/src/share/classes/sun/jvm/hotspot/jdi/ReferenceTypeImpl.java	Tue Jan 07 10:50:28 2014 +0100
@@ -24,24 +24,45 @@
 
 package sun.jvm.hotspot.jdi;
 
-import java.io.*;
-
-import com.sun.jdi.*;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.ref.SoftReference;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import sun.jvm.hotspot.memory.SystemDictionary;
+import sun.jvm.hotspot.oops.ArrayKlass;
+import sun.jvm.hotspot.oops.DefaultHeapVisitor;
 import sun.jvm.hotspot.oops.Instance;
 import sun.jvm.hotspot.oops.InstanceKlass;
-import sun.jvm.hotspot.oops.ArrayKlass;
 import sun.jvm.hotspot.oops.JVMDIClassStatus;
 import sun.jvm.hotspot.oops.Klass;
-import sun.jvm.hotspot.oops.ObjArray;
 import sun.jvm.hotspot.oops.Oop;
 import sun.jvm.hotspot.oops.Symbol;
-import sun.jvm.hotspot.oops.DefaultHeapVisitor;
 import sun.jvm.hotspot.utilities.Assert;
 
-import java.util.*;
-import java.lang.ref.SoftReference;
+import com.sun.jdi.AbsentInformationException;
+import com.sun.jdi.ArrayType;
+import com.sun.jdi.ClassLoaderReference;
+import com.sun.jdi.ClassNotLoadedException;
+import com.sun.jdi.ClassNotPreparedException;
+import com.sun.jdi.ClassObjectReference;
+import com.sun.jdi.Field;
+import com.sun.jdi.InterfaceType;
+import com.sun.jdi.Method;
+import com.sun.jdi.ObjectReference;
+import com.sun.jdi.PrimitiveType;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.Type;
+import com.sun.jdi.Value;
+import com.sun.jdi.VirtualMachine;
 
 public abstract class ReferenceTypeImpl extends TypeImpl
 implements ReferenceType {
@@ -421,7 +442,8 @@
         }
     }
 
-    abstract void addVisibleMethods(Map methodMap);
+    abstract void addVisibleMethods(Map<String, Method> methodMap, Set<InterfaceType> seenInterfaces);
+
     public final List visibleMethods() throws ClassNotPreparedException {
         checkPrepared();
         /*
@@ -430,8 +452,8 @@
          * concatenation of name and signature.
          */
         //System.out.println("jj: RTI: Calling addVisibleMethods for:" + this);
-        Map map = new HashMap();
-        addVisibleMethods(map);
+        Map<String, Method> map = new HashMap<String, Method>();
+        addVisibleMethods(map, new HashSet<InterfaceType>());
 
         /*
          * ... but the hash map destroys order. Methods should be
@@ -441,7 +463,7 @@
          */
         //System.out.println("jj: RTI: Calling allMethods for:" + this);
 
-        List list = new ArrayList(allMethods());
+        List<Method> list = new ArrayList<Method>(allMethods());
         //System.out.println("jj: allMethods = " + jjstr(list));
         //System.out.println("jj: map = " + map.toString());
         //System.out.println("jj: map = " + jjstr(map.values()));