summaryrefslogtreecommitdiffstats
path: root/hit
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-01-15 16:12:07 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-01-15 16:12:07 -0800
commit066bed5fb19102e4f560f242b0cee645f1ed8b31 (patch)
treec632a498859bbec0136e7295ccd05a9ad9685276 /hit
parentcc05ad238516f1303687aba4a978e24e57c0c07a (diff)
downloadandroid_dalvik-066bed5fb19102e4f560f242b0cee645f1ed8b31.tar.gz
android_dalvik-066bed5fb19102e4f560f242b0cee645f1ed8b31.tar.bz2
android_dalvik-066bed5fb19102e4f560f242b0cee645f1ed8b31.zip
auto import from //branches/cupcake/...@126645
Diffstat (limited to 'hit')
-rw-r--r--hit/src/com/android/hit/ArrayInstance.java51
-rw-r--r--hit/src/com/android/hit/ClassInstance.java53
-rw-r--r--hit/src/com/android/hit/Instance.java8
-rw-r--r--hit/src/com/android/hit/Queries.java30
4 files changed, 142 insertions, 0 deletions
diff --git a/hit/src/com/android/hit/ArrayInstance.java b/hit/src/com/android/hit/ArrayInstance.java
index ab07714a6..cdb56167f 100644
--- a/hit/src/com/android/hit/ArrayInstance.java
+++ b/hit/src/com/android/hit/ArrayInstance.java
@@ -134,4 +134,55 @@ public class ArrayInstance extends Instance {
public final String toString() {
return String.format("%s@0x08x", getTypeName(), mId);
}
+
+ @Override
+ public String describeReferenceTo(long referent) {
+ // If this isn't an object array then we can't refer to an object
+ if (mType != Types.OBJECT) {
+ return super.describeReferenceTo(referent);
+ }
+
+ int idSize = Types.getTypeSize(mType);
+ final int N = mNumEntries;
+ int numRefs = 0;
+ StringBuilder result = new StringBuilder("Elements [");
+ ByteArrayInputStream bais = new ByteArrayInputStream(mData);
+ DataInputStream dis = new DataInputStream(bais);
+
+ /*
+ * Spin through all the objects and build up a string describing
+ * all of the array elements that refer to the target object.
+ */
+ for (int i = 0; i < N; i++) {
+ long id;
+
+ try {
+ if (idSize == 4) {
+ id = dis.readInt();
+ } else {
+ id = dis.readLong();
+ }
+
+ if (id == referent) {
+ numRefs++;
+
+ if (numRefs > 1) {
+ result.append(", ");
+ }
+
+ result.append(i);
+ }
+ } catch (java.io.IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ if (numRefs == 0) {
+ return super.describeReferenceTo(referent);
+ }
+
+ result.append("]");
+
+ return result.toString();
+ }
}
diff --git a/hit/src/com/android/hit/ClassInstance.java b/hit/src/com/android/hit/ClassInstance.java
index a9029491d..36525bef3 100644
--- a/hit/src/com/android/hit/ClassInstance.java
+++ b/hit/src/com/android/hit/ClassInstance.java
@@ -152,4 +152,57 @@ public class ClassInstance extends Instance {
public final String toString() {
return String.format("%s@0x%08x", getTypeName(), mId);
}
+
+ @Override
+ public String describeReferenceTo(long referent) {
+ ClassObj isa = mHeap.mState.findClass(mClassId);
+ int[] types = isa.mFieldTypes;
+ String[] fieldNames = isa.mFieldNames;
+ ByteArrayInputStream bais = new ByteArrayInputStream(mFieldValues);
+ DataInputStream dis = new DataInputStream(bais);
+ final int N = types.length;
+ StringBuilder result = new StringBuilder("Referenced in field(s):");
+ int numReferences = 0;
+
+ /*
+ * Spin through the list of fields, add info about the field
+ * references to the output text.
+ */
+ try {
+ for (int i = 0; i < N; i++) {
+ int type = types[i];
+ int size = Types.getTypeSize(type);
+
+ if (type == Types.OBJECT) {
+ long id;
+
+ if (size == 4) {
+ id = dis.readInt();
+ } else {
+ id = dis.readLong();
+ }
+
+ if (id == referent) {
+ numReferences++;
+ result.append("\n ");
+ result.append(fieldNames[i]);
+ }
+ } else {
+ dis.skipBytes(size);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ /*
+ * TODO: perform a similar loop over the static fields of isa
+ */
+
+ if (numReferences == 0) {
+ return super.describeReferenceTo(referent);
+ }
+
+ return result.toString();
+ }
}
diff --git a/hit/src/com/android/hit/Instance.java b/hit/src/com/android/hit/Instance.java
index e06a4275a..24db38d1b 100644
--- a/hit/src/com/android/hit/Instance.java
+++ b/hit/src/com/android/hit/Instance.java
@@ -106,4 +106,12 @@ public abstract class Instance {
return mParents;
}
+
+ /*
+ * If this object has a reference to the object identified by id, return
+ * a String describing the reference in detail.
+ */
+ public String describeReferenceTo(long id) {
+ return "No reference to 0x" + Long.toHexString(id);
+ }
}
diff --git a/hit/src/com/android/hit/Queries.java b/hit/src/com/android/hit/Queries.java
index c0a40d57d..cc692b043 100644
--- a/hit/src/com/android/hit/Queries.java
+++ b/hit/src/com/android/hit/Queries.java
@@ -26,6 +26,36 @@ import java.util.TreeMap;
import java.util.TreeSet;
public class Queries {
+ /*
+ * NOTES: Here's a list of the queries that can be done in hat and
+ * how you'd perform a similar query here in hit:
+ *
+ * hat hit
+ * ------------------------------------------------------------------------
+ * allClasses classes
+ * allClassesWithPlatform allClasses
+ * class findClass
+ * instances instancesOf
+ * allInstances allInstancesOf
+ * object findObject
+ * showRoots getRoots
+ * newInstances newInstances
+ *
+ * reachableFrom make a call to findObject to get the target
+ * parent object, this will give you an Instance.
+ * Then call visit(Set, Filter) on that to have
+ * it build the set of objects in its subgraph.
+ *
+ * rootsTo make a call to findObject on the leaf node
+ * in question, this will give you an Instance.
+ * Instances have an ArrayList of all of the
+ * parent objects that refer to it. You can
+ * follow those parent links until you hit an
+ * object whose parent is null or a ThreadObj.
+ * You've not successfully traced the paths to
+ * the roots.
+ */
+
private static final String DEFAULT_PACKAGE = "<default>";
/*