Skip to content

Commit

Permalink
Bug 582556 Leak suspects should include group of objects for remaining
Browse files Browse the repository at this point in the history
Include the remaining objects, and sort group of suspects
with single object suspects.

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=582556
Change-Id: I24ad4b4062db84cf70b6d092be8398ca4deb534d
  • Loading branch information
ajohnson1 committed Oct 21, 2023
1 parent 89d05b2 commit 3a6703e
Showing 1 changed file with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -129,7 +130,11 @@ public IResult execute(IProgressListener listener) throws Exception
*/
listener.subTask(Messages.FindLeaksQuery_SearchingGroupsOfObjects);

Histogram histogram = groupByClasses(topDominators, new SilentProgressListener(listener));
/*
* Remove single suspects from list.
*/
int topDominatorsX[] = Arrays.copyOfRange(topDominators, i, topDominators.length);
Histogram histogram = groupByClasses(topDominatorsX, new SilentProgressListener(listener));
ArrayList<ClassHistogramRecord> suspiciousClasses = new ArrayList<ClassHistogramRecord>();

ClassHistogramRecord[] classRecords = histogram.getClassHistogramRecords().toArray(new ClassHistogramRecord[0]);
Expand All @@ -138,12 +143,11 @@ public IResult execute(IProgressListener listener) throws Exception
int k = 0;
while (k < classRecords.length && classRecords[k].getRetainedHeapSize() > threshold)
{
// avoid showing class-suspect for s.th. which was found on object
// level
if (!suspectNames.contains(classRecords[k].getLabel()))
{
suspiciousClasses.add(classRecords[k]);
}
/*
* No need to avoid showing class-suspect for s.th. which was found on object
* level as we excluded the objects earlier.
*/
suspiciousClasses.add(classRecords[k]);
k++;
}

Expand Down Expand Up @@ -375,6 +379,8 @@ private IResult buildResult(ArrayInt suspiciousObjects, ArrayList<ClassHistogram
listener.worked(1);
}

// Have single and group of suspects all arranged by size
Arrays.sort(allSuspects, Comparator.reverseOrder());
listener.done();
return new SuspectsResultTable(allSuspects, totalHeap);
}
Expand Down Expand Up @@ -490,7 +496,7 @@ public int[] getSuspectInstances()

}

public static class SuspectRecord
public static class SuspectRecord implements Comparable<SuspectRecord>
{
IObject suspect;

Expand Down Expand Up @@ -518,6 +524,32 @@ public AccumulationPoint getAccumulationPoint()
{
return accumulationPoint;
}

@Override
public int compareTo(SuspectRecord o)
{
// First compare retained size
int r = Long.compare(getSuspectRetained(), o.getSuspectRetained());
if (r != 0)
return r;
boolean g1 = getClass() == SuspectRecord.class;
boolean g2 = o.getClass() == SuspectRecord.class;
// Single suspect 'bigger'
if (g1 && !g2)
return 1;
if (!g1 && g2)
return -1;
// Now compare simple size
r = Long.compare(getSuspect().getUsedHeapSize(), o.getSuspect().getUsedHeapSize());
if (r != 0)
return r;
// Just to get some sort of comparison
r = getSuspect().getClazz().getName().compareTo(o.getSuspect().getClazz().getName());
if (r != 0)
return r;
r = Integer.compare(getSuspect().getObjectId(), o.getSuspect().getObjectId());
return r;
}
}

public static class SuspectsResultTable implements IResultTable
Expand Down

0 comments on commit 3a6703e

Please sign in to comment.