Skip to content

Commit

Permalink
Bug 582212 Support static fields in paths to GC roots' custom excludes
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Grigorenko <kevin.grigorenko@us.ibm.com>
Change-Id: I2ed205cd4f2ecb5edaf6b3f20aa2d59d442b87fc
  • Loading branch information
kgibm committed Jul 25, 2023
1 parent 8a35d97 commit ddf8a00
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,7 @@ private class PathsFromGCRootsComputerImpl implements IPathsFromGCRootsComputer
LinkedList<Path> fifo = new LinkedList<Path>();
BitField visited = new BitField(indexManager.o2address().size());
BitField excludeInstances;
SetInt excludeClasses;
IIndexReader.IOne2ManyIndex inboundIndex; // to avoid method calls to

int currentId;
Expand All @@ -2071,7 +2072,7 @@ public PathsFromGCRootsComputerImpl(int objectId, Map<IClass, Set<String>> exclu

if (excludeMap != null)
{
initExcludeInstances();
initExcludes();
}

currentId = objectId;
Expand All @@ -2087,26 +2088,43 @@ public PathsFromGCRootsComputerImpl(int objectId, Map<IClass, Set<String>> exclu
}
}

private void initExcludeInstances() throws SnapshotException
private void initExcludes() throws SnapshotException
{
excludeInstances = new BitField(indexManager.o2address().size());
excludeClasses = new SetInt();
for (IClass clazz : excludeMap.keySet())
{
int[] objects = clazz.getObjectIds();
for (int objId : objects)
{
excludeInstances.set(objId);
}
excludeClasses.add(clazz.getObjectId());
}
}

private boolean refersOnlyThroughExcluded(int referrerId, int referentId) throws SnapshotException
{
if (!excludeInstances.get(referrerId))
if (excludeInstances.get(referrerId))
{
IObject referrerObject = getObject(referrerId);
return checkExcludeFields(referrerId, referentId, referrerObject, referrerObject.getClazz());
}
else if (excludeClasses.contains(referrerId))
{
IClass referrerObject = (IClass) getObject(referrerId);
return checkExcludeFields(referrerId, referentId, referrerObject, referrerObject);
}
else
{
return false;
}
}

IObject referrerObject = getObject(referrerId);
Set<String> excludeFields = excludeMap.get(referrerObject.getClazz());
private boolean checkExcludeFields(int referrerId, int referentId, IObject referrerObject, IClass referrerClass)
throws SnapshotException
{
Set<String> excludeFields = excludeMap.get(referrerClass);
if (excludeFields == null)
return true; // treat null as all fields

Expand All @@ -2115,7 +2133,8 @@ private boolean refersOnlyThroughExcluded(int referrerId, int referentId) throws
List<NamedReference> refs = referrerObject.getOutboundReferences();
for (NamedReference reference : refs)
{
if (referentAddr == reference.getObjectAddress() && !excludeFields.contains(reference.getName())) { return false; }
if (referentAddr == reference.getObjectAddress() && !excludeFields.contains(reference.getName()))
{ return false; }
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.mat.collect.ArrayInt;
import org.eclipse.mat.collect.BitField;
import org.eclipse.mat.collect.QueueInt;
import org.eclipse.mat.collect.SetInt;
import org.eclipse.mat.parser.index.IIndexReader;
import org.eclipse.mat.parser.internal.Messages;
import org.eclipse.mat.parser.internal.SnapshotImpl;
Expand All @@ -47,6 +48,7 @@ public class MultiplePathsFromGCRootsComputerImpl implements IMultiplePathsFromG
IIndexReader.IOne2ManyIndex outboundIndex; // outbound references index

private BitField excludeInstances;
private SetInt excludeClasses;
private Map<IClass, Set<String>> excludeMap;

private boolean pathsCalculated;
Expand All @@ -63,20 +65,22 @@ public MultiplePathsFromGCRootsComputerImpl(int[] objectIds, Map<IClass, Set<Str

if (excludeMap != null)
{
initExcludeInstances();
initExcludes();
}
}

private void initExcludeInstances() throws SnapshotException
private void initExcludes() throws SnapshotException
{
excludeInstances = new BitField(snapshot.getIndexManager().o2address().size());
excludeClasses = new SetInt();
for (IClass clazz : excludeMap.keySet())
{
int[] objects = clazz.getObjectIds();
for (int objId : objects)
{
excludeInstances.set(objId);
}
excludeClasses.add(clazz.getObjectId());
}
}

Expand Down Expand Up @@ -156,11 +160,26 @@ public MultiplePathsFromGCRootsClassRecord[] getPathsGroupedByClass(boolean star
private boolean refersOnlyThroughExcluded(int referrerId, int referentId, List<NamedReference> refCache)
throws SnapshotException
{
if (!excludeInstances.get(referrerId))
if (excludeInstances.get(referrerId))
{
IObject referrerObject = snapshot.getObject(referrerId);
return checkExcludeFields(referrerId, referentId, refCache, referrerObject, referrerObject.getClazz());
}
else if (excludeClasses.contains(referrerId))
{
IClass referrerObject = (IClass) snapshot.getObject(referrerId);
return checkExcludeFields(referrerId, referentId, refCache, referrerObject, referrerObject);
}
else
{
return false;
}
}

IObject referrerObject = snapshot.getObject(referrerId);
Set<String> excludeFields = excludeMap.get(referrerObject.getClazz());
private boolean checkExcludeFields(int referrerId, int referentId, List<NamedReference> refCache,
IObject referrerObject, IClass referrerClass) throws SnapshotException
{
Set<String> excludeFields = excludeMap.get(referrerClass);
if (excludeFields == null)
return true; // treat null as all fields

Expand Down

0 comments on commit ddf8a00

Please sign in to comment.