Skip to content

Commit

Permalink
Merge pull request #63 from eclipse-mat/slow-object-marker-cleanup
Browse files Browse the repository at this point in the history
perf: use Set instead of List to track subClasses in GarbageCleaner
  • Loading branch information
jasonk000 authored Aug 12, 2024
2 parents 9a7e6e7 + a55f8ac commit b55b54a
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;

Expand Down Expand Up @@ -67,7 +69,7 @@ public class ClassImpl extends AbstractObjectImpl implements IClass, Comparable<
protected volatile long totalSize;
protected boolean isArrayType;

private List<IClass> subClasses;
private Set<IClass> subClasses;

private Serializable cacheEntry;

Expand Down Expand Up @@ -392,14 +394,14 @@ void removeInstanceBulk(int instanceCount, long heapSize)
@SuppressWarnings("unchecked")
public List<IClass> getSubclasses()
{
return subClasses != null ? subClasses : Collections.EMPTY_LIST;
return (subClasses == null) ? Collections.emptyList() : new ArrayList<>(subClasses);
}

@Override
public List<IClass> getAllSubclasses()
{
if (subClasses == null || subClasses.isEmpty())
return new ArrayList<IClass>();
return Collections.emptyList();

List<IClass> answer = new ArrayList<IClass>(subClasses.size() * 2);
answer.addAll(this.subClasses);
Expand Down Expand Up @@ -453,7 +455,7 @@ public int getClassLoaderId()
public void addSubClass(ClassImpl clazz)
{
if (subClasses == null)
subClasses = new ArrayList<IClass>();
subClasses = new LinkedHashSet<IClass>();
subClasses.add(clazz);
}

Expand Down

0 comments on commit b55b54a

Please sign in to comment.