Exemplo n.º 1
0
  public IResult execute(IProgressListener listener) throws Exception {
    int[] retainedSet;

    if (fieldNames == null)
      retainedSet = snapshot.getRetainedSet(objects.getIds(listener), listener);
    else retainedSet = snapshot.getRetainedSet(objects.getIds(listener), fieldNames, listener);

    if (listener.isCanceled()) throw new IProgressListener.OperationCanceledException();

    Histogram histogram = snapshot.getHistogram(retainedSet, listener);

    if (listener.isCanceled()) throw new IProgressListener.OperationCanceledException();

    histogram.setLabel(
        MessageUtil.format(Messages.RetainedSetQuery_RetainedBy, objects.getLabel()));
    return histogram;
  }
Exemplo n.º 2
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);
        }
      }
    }
  }