Skip to content

Commit

Permalink
573598: Display unindexed objects for dumps with discarded objects
Browse files Browse the repository at this point in the history
Fix minor error with go back for inspector view.
Show icons for unindexed objects returned from OQL
Allow OQL union for unindexed objects
Icons for unindexed objects returned from OQL
OQL convert to objects for unindexed
ObjectReference hashCode and equals

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=573598
Change-Id: Ib40ba0e8a6fad5d132afca41d8d7e1d3b941c447
  • Loading branch information
ajohnson1 committed May 22, 2021
1 parent d3edd88 commit 4cf2bda
Show file tree
Hide file tree
Showing 11 changed files with 722 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.List;

import org.eclipse.mat.SnapshotException;
Expand All @@ -23,6 +24,7 @@
import org.eclipse.mat.query.IContextObject;
import org.eclipse.mat.query.IContextObjectSet;
import org.eclipse.mat.query.IDecorator;
import org.eclipse.mat.query.IIconProvider;
import org.eclipse.mat.query.IQuery;
import org.eclipse.mat.query.IResultTable;
import org.eclipse.mat.query.IResultTree;
Expand All @@ -38,7 +40,13 @@
import org.eclipse.mat.snapshot.ISnapshot;
import org.eclipse.mat.snapshot.OQL;
import org.eclipse.mat.snapshot.SnapshotFactory;
import org.eclipse.mat.snapshot.model.GCRootInfo;
import org.eclipse.mat.snapshot.model.IArray;
import org.eclipse.mat.snapshot.model.IClass;
import org.eclipse.mat.snapshot.model.IClassLoader;
import org.eclipse.mat.snapshot.model.IObject;
import org.eclipse.mat.snapshot.model.ObjectReference;
import org.eclipse.mat.snapshot.query.Icons;
import org.eclipse.mat.snapshot.query.ObjectListResult;
import org.eclipse.mat.util.IProgressListener;

Expand Down Expand Up @@ -156,7 +164,7 @@ public String getOQLQuery()


static class ObjectTableResultImpl implements IOQLQuery.Result,
IResultTable, IDecorator
IResultTable, IDecorator, IIconProvider
{
String queryString;
List<?>objs;
Expand All @@ -168,7 +176,7 @@ public ObjectTableResultImpl(ISnapshot snapshot, String queryString, List<?>objs
this.objs = objs;
for (Object o : objs)
{
if (o instanceof IObject)
if (o instanceof ObjectReference)
{
hasIObjects = true;
break;
Expand All @@ -195,7 +203,7 @@ public Column[] getColumns()
new Column(Messages.Column_ShallowHeap, Bytes.class).noTotals(), //
new Column(Messages.Column_RetainedHeap, Bytes.class).noTotals() };
else
return new Column[] { new Column(Messages.Column_ClassName) };
return new Column[] { new Column(Messages.OQLQuery_Column_Value) };
}

@Override
Expand All @@ -207,8 +215,17 @@ public Object getColumnValue(Object row, int columnIndex)
{
case 0:
Object o = objs.get(rw);
if (o instanceof IObject)
return ((IObject)o).getDisplayName();
if (o instanceof ObjectReference)
{
try
{
return ((ObjectReference)o).getObject().getDisplayName();
}
catch (SnapshotException e)
{
return new IllegalStateException(e);
}
}
else if (o != null)
return o.toString();
else
Expand All @@ -218,15 +235,33 @@ else if (o != null)
throw new IllegalArgumentException();
o = objs.get(rw);
if (o instanceof IObject)
return ((IObject)o).getUsedHeapSize();
{
try
{
return ((ObjectReference)o).getObject().getUsedHeapSize();
}
catch (SnapshotException e)
{
return new IllegalStateException(e);
}
}
else
return null;
case 2:
if (!hasIObjects)
throw new IllegalArgumentException();
o = objs.get(rw);
if (o instanceof IObject)
return ((IObject)o).getRetainedHeapSize();
{
try
{
return ((ObjectReference)o).getObject().getRetainedHeapSize();
}
catch (SnapshotException e)
{
return new IllegalStateException(e);
}
}
else
return null;
default:
Expand All @@ -246,32 +281,34 @@ public IContextObject getContext(Object row)
public int getObjectId()
{
Object o = objs.get(rw);
if (o instanceof IObject)
try
if (o instanceof ObjectReference)
try
{
return ((IObject)o).getObjectId();
return ((ObjectReference)o).getObjectId();
}
catch (RuntimeException e)
catch (SnapshotException e)
{
if (e.getCause() instanceof SnapshotException)
return -1;
throw e;
return -1;
}
return -1;
}

@Override
public int[] getObjectIds()
{
return new int[0];
int objId = getObjectId();
if (objId == -1)
return new int[0];
else
return new int[] {objId};
}

@Override
public String getOQL()
{
Object o = objs.get(rw);
if (o instanceof IObject)
return OQL.forAddress(((IObject)o).getObjectAddress());
if (o instanceof ObjectReference)
return OQL.forAddress(((ObjectReference)o).getObjectAddress());
else
return null;
}
Expand Down Expand Up @@ -299,6 +336,67 @@ public String prefix(Object row)
@Override
public String suffix(Object row)
{
if (!hasIObjects)
return null;
int rw = (Integer)row;
Object o = objs.get(rw);
if (o instanceof ObjectReference)
{
try
{

GCRootInfo gc[] = ((ObjectReference) o).getObject().getGCRootInfo();
if (gc != null)
return GCRootInfo.getTypeSetAsString(gc);
else
return null;
}
catch (SnapshotException e)
{
// $JL-EXC$
}
return Messages.OQLQuery_Unindexed;
}
return null;
}

@Override
public URL getIcon(Object row)
{
if (!hasIObjects)
return null;
int rw = (Integer)row;
Object o = objs.get(rw);
if (o instanceof ObjectReference)
{
try
{
IObject o2 = ((ObjectReference) o).getObject();
try
{
int objectId = o2.getObjectId();
return Icons.forObject(o2.getSnapshot(), objectId);
}
catch (RuntimeException e)
{
if (!(e.getCause() instanceof SnapshotException))
throw e;
}

if (o2 instanceof IClassLoader)
return Icons.CLASSLOADER_INSTANCE;
else if (o2 instanceof IClass)
return Icons.CLASS_INSTANCE;
else if (o2 instanceof IArray)
return Icons.ARRAY_INSTANCE;
else
return Icons.OBJECT_INSTANCE;
}
catch (SnapshotException e)
{

}
}
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,11 @@ public class Messages extends NLS
public static String ObjectTreeFactory_ErrorMsg_addChild;
public static String ObjectTreeFactory_ErrorMsg_addChildren;

public static String OQLQuery_Column_Value;
public static String OQLQuery_ExecutedQuery;
public static String OQLQuery_NoResult;
public static String OQLQuery_ProblemReported;
public static String OQLQuery_Unindexed;

public static String ParseSnapshotApp_ErrorMsg_FileNotFound;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,11 @@ MultiplePath2GCRootsQuery_ReferencedObjects=Referenced Objects
ObjectTreeFactory_Column_Percentage=Percentage
ObjectTreeFactory_ErrorMsg_addChild=\#addChild must be called after a root object has been added.
ObjectTreeFactory_ErrorMsg_addChildren=\#addChildren must be called after a root object has been added.
OQLQuery_Column_Value=Value
OQLQuery_ExecutedQuery=Executed Query:
OQLQuery_NoResult=Your Query did not yield any result.
OQLQuery_ProblemReported=Problem reported:
OQLQuery_ProblemReported=Problem reported:
OQLQuery_Unindexed=Unindexed
ParseSnapshotApp_ErrorMsg_FileNotFound=File not found: {0}
ParseSnapshotApp_ErrorMsg_ReportNotFound=Report not found: {0}
ParseSnapshotApp_Usage=Usage: [options] <snapshot> [(<report id>)*]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2010 SAP AG and others.
* Copyright (c) 2008, 2021 SAP AG, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -9,9 +9,12 @@
*
* Contributors:
* SAP AG - initial API and implementation
* Andrew Johnson (IBM Corporation) - hashCode and equals
*******************************************************************************/
package org.eclipse.mat.snapshot.model;

import java.util.Objects;

import org.eclipse.mat.snapshot.ISnapshot;

/**
Expand Down Expand Up @@ -43,4 +46,26 @@ public String getName()
{
return name;
}

@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + Objects.hash(name);
return result;
}

@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
NamedReference other = (NamedReference) obj;
return Objects.equals(name, other.name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.mat.snapshot.model;

import java.io.Serializable;
import java.util.Objects;

import org.eclipse.mat.SnapshotException;
import org.eclipse.mat.snapshot.ISnapshot;
Expand Down Expand Up @@ -95,4 +96,23 @@ public String toString()
{
return "0x" + Long.toHexString(address); //$NON-NLS-1$
}

@Override
public int hashCode()
{
return Objects.hash(address);
}

@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ObjectReference other = (ObjectReference) obj;
return address == other.address;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2010 SAP AG and others.
* Copyright (c) 2008, 2021 SAP AG, IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -9,6 +9,7 @@
*
* Contributors:
* SAP AG - initial API and implementation
* Andrew Johnson (IBM Corporation) - hashCode and equals
*******************************************************************************/
package org.eclipse.mat.snapshot.model;

Expand All @@ -34,4 +35,22 @@ public PseudoReference(ISnapshot snapshot, long address, String name)
{
super(snapshot, address, name);
}

@Override
public int hashCode()
{
return super.hashCode();
}

@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,15 @@ public long getRetainedHeapSize(int objectId) throws SnapshotException

public boolean isArray(int objectId)
{
// Add a useful error message - snapshotInfo.getNumberOfObjecs
// isn't set early on
int nobjs = indexManager.idx.size();
if (objectId > nobjs)
{
SnapshotException e = new SnapshotException(
MessageUtil.format(Messages.SnapshotImpl_Error_ObjectNotFound, new Object[] { objectId }));
throw new IllegalArgumentException(e);
}
if (arrayObjects.get(objectId))
{
// Variable size, so see if actually an array
Expand Down

0 comments on commit 4cf2bda

Please sign in to comment.