Пример #1
0
 private void outputGeneralObjectInfo(IObject object, String identation) throws SnapshotException {
   String clazzName = object.getClazz().getName();
   String gcRootInfo = "";
   if (snapshot.isGCRoot(object.getObjectId())) {
     gcRootInfo =
         GCRootInfo.getTypeSetAsString(snapshot.getGCRootInfo(object.getObjectId())) + " ";
   }
   if (snapshot.isClass(object.getObjectId())) {
     clazzName = "[Class] " + ((IClass) object).getName();
   }
   String objAddr = Long.toString(object.getObjectAddress(), 16);
   out.println(
       String.format(
           "%s<class><![CDATA[%s @ 0x%s]]></class>", identation, gcRootInfo + clazzName, objAddr));
   out.println(String.format("%s<id>0x%s</id>", identation.toString(), objAddr));
 }
 /**
  * Get the only object field from the object Used for finding the HashMap from the HashSet
  *
  * @param source
  * @return null if non or duplicates found
  * @throws SnapshotException
  */
 private IInstance resolveNextField(IObject source) throws SnapshotException {
   final ISnapshot snapshot = source.getSnapshot();
   IInstance ret = null;
   for (int i : snapshot.getOutboundReferentIds(source.getObjectId())) {
     if (!snapshot.isArray(i) && !snapshot.isClass(i)) {
       IObject o = snapshot.getObject(i);
       if (o instanceof IInstance) {
         if (ret != null) {
           ret = null;
           break;
         }
         ret = (IInstance) o;
       }
     }
   }
   return ret;
 }
Пример #3
0
  public ClassloaderLeakDetector(File f) throws Exception {
    IProgressListener listener = new ConsoleProgressListener(System.out);

    SnapshotFactory sf = new SnapshotFactory();
    snapshot = sf.openSnapshot(f, new HashMap<String, String>(), listener);
    int[] retainedSet = snapshot.getRetainedSet(snapshot.getGCRoots(), listener);

    for (int obj : retainedSet) {
      if (snapshot.isClass(obj)) continue;
      int clId = snapshot.getClassOf(obj).getClassLoaderId();
      if (snapshot.getObject(clId).getClazz().getName().startsWith("sun.")) {
        continue;
      }
      Boolean dominatedAllSoFar = clDominationFlags.get(clId);
      if (dominatedAllSoFar != null && !dominatedAllSoFar) continue;

      boolean clDominates = firstObjectDominatesSecond(clId, obj, snapshot);

      if (!clDominates) {
        boolean objDominates = firstObjectDominatesSecond(obj, clId, snapshot);
        if (objDominates) {
          //					System.out.println(String.format(
          //							"Classloader %s IS NOT dominating: %s, but viceversa is true!", snapshot
          //							.getObject(clId).getTechnicalName(), snapshot
          //							.getObject(obj).getTechnicalName()));
          //					printPathToGCRoot(snapshot, obj, false);
          clDominates = true;
        }
      }

      if (dominatedAllSoFar == null) {
        clDominationFlags.put(clId, clDominates);
      } else {
        // If classloader is not dominating the object and
        // it has been dominating everything it loaded so far
        // Then this classloader is no longer dominating.
        if (!clDominates && dominatedAllSoFar) {
          clDominationFlags.put(clId, Boolean.FALSE);
        }
      }
    }
  }