summaryrefslogtreecommitdiffstats
path: root/hit
diff options
context:
space:
mode:
authorCarl Shapiro <cshapiro@google.com>2010-06-08 16:37:12 -0700
committerCarl Shapiro <cshapiro@google.com>2010-06-08 17:04:11 -0700
commitde75089fb7216d19e9c22cce4dc62a49513477d3 (patch)
tree8c4035cc05218ddb7595e9a5c5997b53e58c2572 /hit
parent52ec072cc4dd215ff541a0b0842e91ea529a6e5d (diff)
downloadandroid_dalvik-de75089fb7216d19e9c22cce4dc62a49513477d3.tar.gz
android_dalvik-de75089fb7216d19e9c22cce4dc62a49513477d3.tar.bz2
android_dalvik-de75089fb7216d19e9c22cce4dc62a49513477d3.zip
Remove trailing whitespace.
Change-Id: I95534bb2b88eaf48f2329282041118cd034c812b
Diffstat (limited to 'hit')
-rw-r--r--hit/src/com/android/hit/ArrayInstance.java42
-rw-r--r--hit/src/com/android/hit/ClassInstance.java36
-rw-r--r--hit/src/com/android/hit/ClassObj.java44
-rw-r--r--hit/src/com/android/hit/Heap.java36
-rw-r--r--hit/src/com/android/hit/HprofParser.java174
-rw-r--r--hit/src/com/android/hit/Instance.java24
-rw-r--r--hit/src/com/android/hit/Main.java28
-rw-r--r--hit/src/com/android/hit/Queries.java68
-rw-r--r--hit/src/com/android/hit/RootObj.java14
-rw-r--r--hit/src/com/android/hit/RootType.java8
-rw-r--r--hit/src/com/android/hit/StackFrame.java14
-rw-r--r--hit/src/com/android/hit/StackTrace.java14
-rw-r--r--hit/src/com/android/hit/State.java50
-rw-r--r--hit/src/com/android/hit/Types.java10
14 files changed, 281 insertions, 281 deletions
diff --git a/hit/src/com/android/hit/ArrayInstance.java b/hit/src/com/android/hit/ArrayInstance.java
index cdb56167f..42e880357 100644
--- a/hit/src/com/android/hit/ArrayInstance.java
+++ b/hit/src/com/android/hit/ArrayInstance.java
@@ -24,8 +24,8 @@ public class ArrayInstance extends Instance {
private int mType;
private int mNumEntries;
private byte[] mData;
-
- public ArrayInstance(long id, StackTrace stack, int type, int numEntries,
+
+ public ArrayInstance(long id, StackTrace stack, int type, int numEntries,
byte[] data) {
mId = id;
mStack = stack;
@@ -38,17 +38,17 @@ public class ArrayInstance extends Instance {
if (mType != Types.OBJECT) {
return;
}
-
+
/*
* mData holds a stream of object instance ids
* Spin through them all and list ourselves as a reference holder.
*/
int idSize = Types.getTypeSize(mType);
final int N = mNumEntries;
-
+
ByteArrayInputStream bais = new ByteArrayInputStream(mData);
DataInputStream dis = new DataInputStream(bais);
-
+
for (int i = 0; i < N; i++) {
long id;
@@ -60,7 +60,7 @@ public class ArrayInstance extends Instance {
}
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.addParent(this);
}
@@ -81,7 +81,7 @@ public class ArrayInstance extends Instance {
if (resultSet.contains(this)) {
return;
}
-
+
if (null != filter) {
if (filter.accept(this)) {
resultSet.add(this);
@@ -93,30 +93,30 @@ public class ArrayInstance extends Instance {
if (mType != Types.OBJECT) {
return;
}
-
+
/*
* mData holds a stream of object instance ids
* Spin through them all and visit them
*/
int idSize = Types.getTypeSize(mType);
final int N = mNumEntries;
-
+
ByteArrayInputStream bais = new ByteArrayInputStream(mData);
DataInputStream dis = new DataInputStream(bais);
State state = mHeap.mState;
-
+
for (int i = 0; i < N; i++) {
long id;
-
+
try {
if (idSize == 4) {
id = dis.readInt();
} else {
id = dis.readLong();
}
-
+
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.visit(resultSet, filter);
}
@@ -141,48 +141,48 @@ public class ArrayInstance extends Instance {
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 36525bef3..086976960 100644
--- a/hit/src/com/android/hit/ClassInstance.java
+++ b/hit/src/com/android/hit/ClassInstance.java
@@ -29,7 +29,7 @@ public class ClassInstance extends Instance {
mStack = stack;
mClassId = classId;
}
-
+
public final void loadFieldData(DataInputStream in, int numBytes)
throws IOException {
mFieldValues = new byte[numBytes];
@@ -44,7 +44,7 @@ public class ClassInstance extends Instance {
resolve(state, isa, isa.mFieldTypes, mFieldValues);
}
- private void resolve(State state, ClassObj isa, int[] types,
+ private void resolve(State state, ClassObj isa, int[] types,
byte[] values) {
ByteArrayInputStream bais = new ByteArrayInputStream(values);
DataInputStream dis = new DataInputStream(bais);
@@ -61,15 +61,15 @@ public class ClassInstance extends Instance {
if (type == Types.OBJECT) {
long id;
-
+
if (size == 4) {
id = dis.readInt();
} else {
id = dis.readLong();
}
-
+
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.addParent(this);
}
@@ -85,7 +85,7 @@ public class ClassInstance extends Instance {
@Override
public final int getSize() {
ClassObj isa = mHeap.mState.findClass(mClassId);
-
+
return isa.getSize();
}
@@ -94,7 +94,7 @@ public class ClassInstance extends Instance {
if (resultSet.contains(this)) {
return;
}
-
+
if (filter != null) {
if (filter.accept(this)) {
resultSet.add(this);
@@ -109,7 +109,7 @@ public class ClassInstance extends Instance {
ByteArrayInputStream bais = new ByteArrayInputStream(mFieldValues);
DataInputStream dis = new DataInputStream(bais);
final int N = types.length;
-
+
/*
* Spin through the list of fields, find all object references,
* and list ourselves as a reference holder.
@@ -118,18 +118,18 @@ public class ClassInstance extends Instance {
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();
}
-
+
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.visit(resultSet, filter);
}
@@ -145,7 +145,7 @@ public class ClassInstance extends Instance {
@Override
public final String getTypeName() {
ClassObj theClass = mHeap.mState.findClass(mClassId);
-
+
return theClass.mClassName;
}
@@ -163,7 +163,7 @@ public class ClassInstance extends Instance {
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.
@@ -172,16 +172,16 @@ public class ClassInstance extends Instance {
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 ");
@@ -202,7 +202,7 @@ public class ClassInstance extends Instance {
if (numReferences == 0) {
return super.describeReferenceTo(referent);
}
-
+
return result.toString();
}
}
diff --git a/hit/src/com/android/hit/ClassObj.java b/hit/src/com/android/hit/ClassObj.java
index 388af4acf..1e3ac280d 100644
--- a/hit/src/com/android/hit/ClassObj.java
+++ b/hit/src/com/android/hit/ClassObj.java
@@ -51,7 +51,7 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
DataInputStream dis = new DataInputStream(bais);
int[] types = mStaticFieldTypes;
final int N = types.length;
-
+
/*
* Spin through the list of static fields, find all object references,
* and list ourselves as a reference holder. Also add them to
@@ -61,18 +61,18 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
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();
}
-
+
RootObj root = new RootObj(RootType.JAVA_STATIC, id);
-
+
if (id == 0) {
root.mComment = String.format(
"Static field %s:%s null",
@@ -80,9 +80,9 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
mStaticFieldNames[i]);
} else {
Instance instance = state.findReference(id);
-
+
instance.addParent(this);
-
+
root.mComment = String.format(
"Static field %s:%s %s [%s] 0x%08x",
mClassName,
@@ -105,7 +105,7 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
// Lastly, add ourself as a subclass of our superclass
if (mSuperclassId != 0) {
ClassObj superclass = state.findClass(mSuperclassId);
-
+
superclass.addSubclass(this);
}
}
@@ -135,7 +135,7 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
public final void setFieldNames(String[] names) {
mFieldNames = names;
}
-
+
public final void setFieldTypes(int[] types) {
mFieldTypes = types;
}
@@ -143,11 +143,11 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
public final void setStaticFieldNames(String[] names) {
mStaticFieldNames = names;
}
-
+
public final void setStaticFieldTypes(int[] types) {
mStaticFieldTypes = types;
}
-
+
public final void setStaticFieldValues(byte[] values) {
mStaticFieldValues = values;
}
@@ -156,14 +156,14 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
System.out.println("+---------- ClassObj dump for: " + mClassName);
System.out.println("+----- Static fields");
-
+
for (int i = 0; i < mStaticFieldNames.length; i++) {
- System.out.println(mStaticFieldNames[i] + ": "
+ System.out.println(mStaticFieldNames[i] + ": "
+ mStaticFieldTypes[i]);
}
System.out.println("+----- Instance fields");
-
+
for (int i = 0; i < mFieldNames.length; i++) {
System.out.println(mFieldNames[i] + ": " + mFieldTypes[i]);
}
@@ -179,7 +179,7 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
if (resultSet.contains(this)) {
return;
}
-
+
if (filter != null) {
if (filter.accept(this)) {
resultSet.add(this);
@@ -187,14 +187,14 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
} else {
resultSet.add(this);
}
-
+
ByteArrayInputStream bais =
new ByteArrayInputStream(mStaticFieldValues);
DataInputStream dis = new DataInputStream(bais);
int[] types = mStaticFieldTypes;
final int N = types.length;
State state = mHeap.mState;
-
+
/*
* Spin through the list of static fields, find all object references,
* and visit them.
@@ -203,18 +203,18 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
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();
}
-
+
Instance instance = state.findReference(id);
-
+
if (instance != null) {
instance.visit(resultSet, filter);
}
@@ -235,7 +235,7 @@ public class ClassObj extends Instance implements Comparable<ClassObj> {
if (! (o instanceof ClassObj)) {
return false;
}
-
+
return 0 == compareTo((ClassObj) o);
}
}
diff --git a/hit/src/com/android/hit/Heap.java b/hit/src/com/android/hit/Heap.java
index 82dde8eb1..37b15ddc5 100644
--- a/hit/src/com/android/hit/Heap.java
+++ b/hit/src/com/android/hit/Heap.java
@@ -21,16 +21,16 @@ import java.util.HashMap;
public class Heap {
String mName;
-
+
// List of individual stack frames
HashMap<Long, StackFrame> mFrames = new HashMap<Long, StackFrame>();
-
+
// List stack traces, which are lists of stack frames
HashMap<Integer, StackTrace> mTraces = new HashMap<Integer, StackTrace>();
-
+
// Root objects such as interned strings, jni locals, etc
ArrayList<RootObj> mRoots = new ArrayList<RootObj>();
-
+
// List of threads
HashMap<Integer, ThreadObj> mThreads = new HashMap<Integer, ThreadObj>();
@@ -47,7 +47,7 @@ public class Heap {
public Heap(String name) {
mName = name;
}
-
+
public final void addStackFrame(StackFrame theFrame) {
mFrames.put(theFrame.mId, theFrame);
}
@@ -64,14 +64,14 @@ public class Heap {
return mTraces.get(traceSerialNumber);
}
- public final StackTrace getStackTraceAtDepth(int traceSerialNumber,
+ public final StackTrace getStackTraceAtDepth(int traceSerialNumber,
int depth) {
StackTrace trace = mTraces.get(traceSerialNumber);
-
+
if (trace != null) {
trace = trace.fromDepth(depth);
}
-
+
return trace;
}
@@ -83,7 +83,7 @@ public class Heap {
public final void addThread(ThreadObj thread, int serialNumber) {
mThreads.put(serialNumber, thread);
}
-
+
public final ThreadObj getThread(int serialNumber) {
return mThreads.get(serialNumber);
}
@@ -91,7 +91,7 @@ public class Heap {
public final void addInstance(long id, Instance instance) {
mInstances.put(id, instance);
}
-
+
public final Instance getInstance(long id) {
return mInstances.get(id);
}
@@ -100,7 +100,7 @@ public class Heap {
mClassesById.put(id, theClass);
mClassesByName.put(theClass.mClassName, theClass);
}
-
+
public final ClassObj getClass(long id) {
return mClassesById.get(id);
}
@@ -112,7 +112,7 @@ public class Heap {
public final void dumpInstanceCounts() {
for (ClassObj theClass: mClassesById.values()) {
int count = theClass.mInstances.size();
-
+
if (count > 0) {
System.out.println(theClass + ": " + count);
}
@@ -122,18 +122,18 @@ public class Heap {
public final void dumpSubclasses() {
for (ClassObj theClass: mClassesById.values()) {
int count = theClass.mSubclasses.size();
-
+
if (count > 0) {
System.out.println(theClass);
theClass.dumpSubclasses();
}
}
}
-
+
public final void dumpSizes() {
for (ClassObj theClass: mClassesById.values()) {
int size = 0;
-
+
for (Instance instance: theClass.mInstances) {
size += instance.getCompositeSize();
}
@@ -144,7 +144,7 @@ public class Heap {
}
}
}
-
+
/*
* Spin through all of the class instances and link them to their
* parent class definition objects. Then have each instance resolve
@@ -161,11 +161,11 @@ public class Heap {
String name = theClass.mClassName;
String superclassName = "none";
ClassObj superClass = mClassesById.get(theClass.mSuperclassId);
-
+
if (superClass != null) {
superclassName = superClass.mClassName;
}
-
+
theClass.addInstance(instance);
instance.resolveReferences(state);
}
diff --git a/hit/src/com/android/hit/HprofParser.java b/hit/src/com/android/hit/HprofParser.java
index 2226001ff..98fef1e12 100644
--- a/hit/src/com/android/hit/HprofParser.java
+++ b/hit/src/com/android/hit/HprofParser.java
@@ -53,7 +53,7 @@ public class HprofParser
private static final int ROOT_INSTANCE_DUMP = 0x21;
private static final int ROOT_OBJECT_ARRAY_DUMP = 0x22;
private static final int ROOT_PRIMITIVE_ARRAY_DUMP = 0x23;
-
+
/**
* Android format addition
*
@@ -63,7 +63,7 @@ public class HprofParser
* associated with the specified heap. The HEAP_DUMP_INFO data is reset
* at the end of the HEAP_DUMP[_SEGMENT]. Multiple HEAP_DUMP_INFO entries
* may appear in a single HEAP_DUMP[_SEGMENT].
- *
+ *
* Format:
* u1: Tag value (0xFE)
* u4: heap ID
@@ -103,12 +103,12 @@ public class HprofParser
try {
String s = readNullTerminatedString();
DataInputStream in = mInput;
-
+
mIdSize = in.readInt();
Types.setIdSize(mIdSize);
-
+
in.readLong(); // Timestamp, ignored for now
-
+
while (true) {
int tag = in.readUnsignedByte();
int timestamp = in.readInt();
@@ -118,7 +118,7 @@ public class HprofParser
case STRING_IN_UTF8:
loadString(length - 4);
break;
-
+
case LOAD_CLASS:
loadClass();
break;
@@ -135,7 +135,7 @@ public class HprofParser
loadHeapDump(length);
mState.setToDefaultHeap();
break;
-
+
case HEAP_DUMP_SEGMENT:
loadHeapDump(length);
mState.setToDefaultHeap();
@@ -153,7 +153,7 @@ public class HprofParser
}
mState.resolveReferences();
-
+
return state;
}
@@ -164,7 +164,7 @@ public class HprofParser
for (int c = in.read(); c != 0; c = in.read()) {
s.append((char) c);
}
-
+
return s.toString();
}
@@ -175,13 +175,13 @@ public class HprofParser
case 4: return ((long) mInput.readInt()) & 0x00000000ffffffffL;
case 8: return mInput.readLong();
}
-
+
throw new IllegalArgumentException("ID Length must be 1, 2, 4, or 8");
}
private String readUTF8(int length) throws IOException {
byte[] b = new byte[length];
-
+
mInput.read(b);
return new String(b, "utf-8");
@@ -190,7 +190,7 @@ public class HprofParser
private void loadString(int length) throws IOException {
long id = readId();
String string = readUTF8(length);
-
+
mStrings.put(id, string);
}
@@ -200,7 +200,7 @@ public class HprofParser
long id = readId();
int stackTrace = in.readInt(); // unused
String name = mStrings.get(readId());
-
+
mClassNames.put(id, name);
}
@@ -211,8 +211,8 @@ public class HprofParser
String sourceFile = mStrings.get(readId());
int serial = mInput.readInt();
int lineNumber = mInput.readInt();
-
- StackFrame frame = new StackFrame(id, methodName, methodSignature,
+
+ StackFrame frame = new StackFrame(id, methodName, methodSignature,
sourceFile, serial, lineNumber);
mState.addStackFrame(frame);
@@ -223,12 +223,12 @@ public class HprofParser
int threadSerialNumber = mInput.readInt();
final int numFrames = mInput.readInt();
StackFrame[] frames = new StackFrame[numFrames];
-
+
for (int i = 0; i < numFrames; i++) {
frames[i] = mState.getStackFrame(readId());
}
-
- StackTrace trace = new StackTrace(serialNumber, threadSerialNumber,
+
+ StackTrace trace = new StackTrace(serialNumber, threadSerialNumber,
frames);
mState.addStackTrace(trace);
@@ -236,62 +236,62 @@ public class HprofParser
private void loadHeapDump(int length) throws IOException {
DataInputStream in = mInput;
-
+
while (length > 0) {
int tag = in.readUnsignedByte();
length--;
-
+
switch (tag) {
case ROOT_UNKNOWN:
length -= loadBasicObj(RootType.UNKNOWN);
break;
-
+
case ROOT_JNI_GLOBAL:
length -= loadBasicObj(RootType.NATIVE_STATIC);
readId(); // ignored
length -= mIdSize;
break;
-
+
case ROOT_JNI_LOCAL:
length -= loadJniLocal();
break;
-
+
case ROOT_JAVA_FRAME:
length -= loadJavaFrame();
break;
-
+
case ROOT_NATIVE_STACK:
length -= loadNativeStack();
break;
-
+
case ROOT_STICKY_CLASS:
length -= loadBasicObj(RootType.SYSTEM_CLASS);
break;
-
+
case ROOT_THREAD_BLOCK:
length -= loadThreadBlock();
break;
-
+
case ROOT_MONITOR_USED:
length -= loadBasicObj(RootType.BUSY_MONITOR);
break;
-
+
case ROOT_THREAD_OBJECT:
length -= loadThreadObject();
break;
-
+
case ROOT_CLASS_DUMP:
length -= loadClassDump();
break;
-
+
case ROOT_INSTANCE_DUMP:
length -= loadInstanceDump();
break;
-
+
case ROOT_OBJECT_ARRAY_DUMP:
length -= loadObjectArrayDump();
break;
-
+
case ROOT_PRIMITIVE_ARRAY_DUMP:
length -= loadPrimitiveArrayDump();
break;
@@ -302,66 +302,66 @@ public class HprofParser
throw new IllegalArgumentException(
"Don't know how to load a nodata array");
-
+
case ROOT_HEAP_DUMP_INFO:
int heapId = mInput.readInt();
long heapNameId = readId();
String heapName = mStrings.get(heapNameId);
-
+
mState.setHeapTo(heapId, heapName);
length -= 4 + mIdSize;
break;
-
+
case ROOT_INTERNED_STRING:
length -= loadBasicObj(RootType.INTERNED_STRING);
break;
-
+
case ROOT_FINALIZING:
length -= loadBasicObj(RootType.FINALIZING);
break;
-
+
case ROOT_DEBUGGER:
length -= loadBasicObj(RootType.DEBUGGER);
break;
-
+
case ROOT_REFERENCE_CLEANUP:
length -= loadBasicObj(RootType.REFERENCE_CLEANUP);
break;
-
+
case ROOT_VM_INTERNAL:
length -= loadBasicObj(RootType.VM_INTERNAL);
break;
-
+
case ROOT_JNI_MONITOR:
length -= loadJniMonitor();
break;
-
+
case ROOT_UNREACHABLE:
length -= loadBasicObj(RootType.UNREACHABLE);
break;
-
+
default:
throw new IllegalArgumentException(
- "loadHeapDump loop with unknown tag " + tag
- + " with " + mInput.available()
+ "loadHeapDump loop with unknown tag " + tag
+ + " with " + mInput.available()
+ " bytes possibly remaining");
}
}
}
-
+
private int loadJniLocal() throws IOException {
long id = readId();
int threadSerialNumber = mInput.readInt();
int stackFrameNumber = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
- StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
+ StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
stackFrameNumber);
- RootObj root = new RootObj(RootType.NATIVE_LOCAL, id,
+ RootObj root = new RootObj(RootType.NATIVE_LOCAL, id,
threadSerialNumber, trace);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4 + 4;
}
@@ -370,38 +370,38 @@ public class HprofParser
int threadSerialNumber = mInput.readInt();
int stackFrameNumber = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
- StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
+ StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
stackFrameNumber);
- RootObj root = new RootObj(RootType.JAVA_LOCAL, id, threadSerialNumber,
+ RootObj root = new RootObj(RootType.JAVA_LOCAL, id, threadSerialNumber,
trace);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4 + 4;
}
-
+
private int loadNativeStack() throws IOException {
long id = readId();
int threadSerialNumber = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
StackTrace trace = mState.getStackTrace(thread.mStackTrace);
- RootObj root = new RootObj(RootType.NATIVE_STACK, id,
+ RootObj root = new RootObj(RootType.NATIVE_STACK, id,
threadSerialNumber, trace);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4;
}
private int loadBasicObj(RootType type) throws IOException {
long id = readId();
RootObj root = new RootObj(type, id);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize;
}
@@ -410,12 +410,12 @@ public class HprofParser
int threadSerialNumber = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
StackTrace stack = mState.getStackTrace(thread.mStackTrace);
- RootObj root = new RootObj(RootType.THREAD_BLOCK, id,
+ RootObj root = new RootObj(RootType.THREAD_BLOCK, id,
threadSerialNumber, stack);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4;
}
@@ -424,9 +424,9 @@ public class HprofParser
int threadSerialNumber = mInput.readInt();
int stackSerialNumber = mInput.readInt();
ThreadObj thread = new ThreadObj(id, stackSerialNumber);
-
+
mState.addThread(thread, threadSerialNumber);
-
+
return mIdSize + 4 + 4;
}
@@ -449,7 +449,7 @@ public class HprofParser
// Skip over the constant pool
int numEntries = in.readUnsignedShort();
bytesRead += 2;
-
+
for (int i = 0; i < numEntries; i++) {
in.readUnsignedShort();
bytesRead += 2 + skipValue();
@@ -463,7 +463,7 @@ public class HprofParser
int[] staticFieldTypes = new int[numEntries];
ByteArrayOutputStream staticFieldValues = new ByteArrayOutputStream();
byte[] buffer = mFieldBuffer;
-
+
for (int i = 0; i < numEntries; i++) {
staticFieldNames[i] = mStrings.get(readId());
@@ -476,14 +476,14 @@ public class HprofParser
bytesRead += mIdSize + 1 + fieldSize;
}
-
+
// Instance fields
numEntries = in.readUnsignedShort();
bytesRead += 2;
-
+
String[] names = new String[numEntries];
int[] types = new int[numEntries];
-
+
for (int i = 0; i < numEntries; i++) {
long fieldName = readId();
int type = in.readUnsignedByte();
@@ -493,7 +493,7 @@ public class HprofParser
bytesRead += mIdSize + 1;
}
-
+
ClassObj theClass = new ClassObj(id, stack, mClassNames.get(id));
theClass.setStaticFieldNames(staticFieldNames);
@@ -504,11 +504,11 @@ public class HprofParser
theClass.setFieldNames(names);
theClass.setFieldTypes(types);
theClass.setSize(instanceSize);
-
+
theClass.setHeap(mState.mCurrentHeap);
mState.addClass(id, theClass);
-
+
return bytesRead;
}
@@ -523,7 +523,7 @@ public class HprofParser
instance.loadFieldData(mInput, remaining);
instance.setHeap(mState.mCurrentHeap);
mState.addInstance(id, instance);
-
+
return mIdSize + 4 + mIdSize + 4 + remaining;
}
@@ -536,19 +536,19 @@ public class HprofParser
int totalBytes = numElements * mIdSize;
byte[] data = new byte[totalBytes];
String className = mClassNames.get(classId);
-
+
mInput.readFully(data);
- ArrayInstance array = new ArrayInstance(id, stack, Types.OBJECT,
+ ArrayInstance array = new ArrayInstance(id, stack, Types.OBJECT,
numElements, data);
-
+
array.mClassId = classId;
array.setHeap(mState.mCurrentHeap);
mState.addInstance(id, array);
return mIdSize + 4 + 4 + mIdSize + totalBytes;
}
-
+
private int loadPrimitiveArrayDump() throws IOException {
long id = readId();
int stackId = mInput.readInt();
@@ -558,15 +558,15 @@ public class HprofParser
int size = Types.getTypeSize(type);
int totalBytes = numElements * size;
byte[] data = new byte[totalBytes];
-
+
mInput.readFully(data);
- ArrayInstance array = new ArrayInstance(id, stack, type, numElements,
+ ArrayInstance array = new ArrayInstance(id, stack, type, numElements,
data);
-
+
array.setHeap(mState.mCurrentHeap);
mState.addInstance(id, array);
-
+
return mIdSize + 4 + 4 + 1 + totalBytes;
}
@@ -575,21 +575,21 @@ public class HprofParser
int threadSerialNumber = mInput.readInt();
int stackDepth = mInput.readInt();
ThreadObj thread = mState.getThread(threadSerialNumber);
- StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
+ StackTrace trace = mState.getStackTraceAtDepth(thread.mStackTrace,
stackDepth);
- RootObj root = new RootObj(RootType.NATIVE_MONITOR, id,
+ RootObj root = new RootObj(RootType.NATIVE_MONITOR, id,
threadSerialNumber, trace);
-
+
root.setHeap(mState.mCurrentHeap);
mState.addRoot(root);
-
+
return mIdSize + 4 + 4;
}
private int skipValue() throws IOException {
int type = mInput.readUnsignedByte();
int size = Types.getTypeSize(type);
-
+
skipFully(size);
return size + 1;
@@ -604,7 +604,7 @@ public class HprofParser
private void skipFully(long numBytes) throws IOException {
while (numBytes > 0) {
long skipped = mInput.skip(numBytes);
-
+
numBytes -= skipped;
}
}
diff --git a/hit/src/com/android/hit/Instance.java b/hit/src/com/android/hit/Instance.java
index 24db38d1b..6afa2b26a 100644
--- a/hit/src/com/android/hit/Instance.java
+++ b/hit/src/com/android/hit/Instance.java
@@ -25,10 +25,10 @@ public abstract class Instance {
// Id of the ClassObj of which this object is an instance
long mClassId;
-
+
// The stack in which this object was allocated
StackTrace mStack;
-
+
// The heap in which this object was allocated (app, zygote, etc)
Heap mHeap;
@@ -41,7 +41,7 @@ public abstract class Instance {
// List of all objects that hold a live reference to this object
private ArrayList<Instance> mParents;
-
+
/*
* After the whole HPROF file is read and parsed this method will be
* called on all heap objects so that they can resolve their internal
@@ -67,15 +67,15 @@ public abstract class Instance {
public final int getCompositeSize() {
HashSet<Instance> set = new HashSet<Instance>();
-
+
visit(set, null);
-
+
int size = 0;
-
+
for (Instance instance: set) {
size += instance.getSize();
}
-
+
return size;
}
@@ -89,21 +89,21 @@ public abstract class Instance {
public void setHeap(Heap heap) {
mHeap = heap;
}
-
+
// Add to the list of objects that have a hard reference to this Instance
public void addParent(Instance parent) {
if (mParents == null) {
mParents = new ArrayList<Instance>();
}
-
+
mParents.add(parent);
}
-
+
public ArrayList<Instance> getParents() {
if (mParents == null) {
mParents = new ArrayList<Instance>();
}
-
+
return mParents;
}
@@ -112,6 +112,6 @@ public abstract class Instance {
* a String describing the reference in detail.
*/
public String describeReferenceTo(long id) {
- return "No reference to 0x" + Long.toHexString(id);
+ return "No reference to 0x" + Long.toHexString(id);
}
}
diff --git a/hit/src/com/android/hit/Main.java b/hit/src/com/android/hit/Main.java
index eebadfe1a..4ed5c11c9 100644
--- a/hit/src/com/android/hit/Main.java
+++ b/hit/src/com/android/hit/Main.java
@@ -28,16 +28,16 @@ public class Main
FileInputStream fis;
BufferedInputStream bis;
DataInputStream dis;
-
+
try {
fis = new FileInputStream(argv[0]);
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
-
+
State state = (new HprofParser(dis)).parse();
dis.close();
-
+
testClassesQuery(state);
testAllClassesQuery(state);
testFindInstancesOf(state);
@@ -53,28 +53,28 @@ public class Main
"javax.",
"org.xml.sax"
};
-
+
Map<String, Set<ClassObj>> someClasses = Queries.classes(state, x);
-
+
for (String thePackage: someClasses.keySet()) {
System.out.println("------------------- " + thePackage);
-
+
Set<ClassObj> classes = someClasses.get(thePackage);
-
+
for (ClassObj theClass: classes) {
System.out.println(" " + theClass.mClassName);
}
}
}
-
+
private static void testAllClassesQuery(State state) {
Map<String, Set<ClassObj>> allClasses = Queries.allClasses(state);
-
+
for (String thePackage: allClasses.keySet()) {
System.out.println("------------------- " + thePackage);
-
+
Set<ClassObj> classes = allClasses.get(thePackage);
-
+
for (ClassObj theClass: classes) {
System.out.println(" " + theClass.mClassName);
}
@@ -83,14 +83,14 @@ public class Main
private static void testFindInstancesOf(State state) {
Instance[] instances = Queries.instancesOf(state, "java.lang.String");
-
+
System.out.println("There are " + instances.length + " Strings.");
}
private static void testFindAllInstancesOf(State state) {
- Instance[] instances = Queries.allInstancesOf(state,
+ Instance[] instances = Queries.allInstancesOf(state,
"android.graphics.drawable.Drawable");
-
+
System.out.println("There are " + instances.length
+ " instances of Drawables and its subclasses.");
}
diff --git a/hit/src/com/android/hit/Queries.java b/hit/src/com/android/hit/Queries.java
index cc692b043..0dac79647 100644
--- a/hit/src/com/android/hit/Queries.java
+++ b/hit/src/com/android/hit/Queries.java
@@ -27,7 +27,7 @@ import java.util.TreeSet;
public class Queries {
/*
- * NOTES: Here's a list of the queries that can be done in hat and
+ * 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
@@ -67,7 +67,7 @@ public class Queries {
return classes(state, null);
}
- public static Map<String, Set<ClassObj>> classes(State state,
+ public static Map<String, Set<ClassObj>> classes(State state,
String[] excludedPrefixes) {
TreeMap<String, Set<ClassObj>> result =
new TreeMap<String, Set<ClassObj>>();
@@ -78,16 +78,16 @@ public class Queries {
for (Heap heap: state.mHeaps.values()) {
classes.addAll(heap.mClassesById.values());
}
-
+
// Filter it if needed
if (excludedPrefixes != null) {
final int N = excludedPrefixes.length;
Iterator<ClassObj> iter = classes.iterator();
-
+
while (iter.hasNext()) {
ClassObj theClass = iter.next();
String classPath = theClass.toString();
-
+
for (int i = 0; i < N; i++) {
if (classPath.startsWith(excludedPrefixes[i])) {
iter.remove();
@@ -96,29 +96,29 @@ public class Queries {
}
}
}
-
+
// Now that we have a final list of classes, group them by package
for (ClassObj theClass: classes) {
String packageName = DEFAULT_PACKAGE;
int lastDot = theClass.mClassName.lastIndexOf('.');
-
+
if (lastDot != -1) {
packageName = theClass.mClassName.substring(0, lastDot);
}
-
+
Set<ClassObj> classSet = result.get(packageName);
-
+
if (classSet == null) {
classSet = new TreeSet<ClassObj>();
result.put(packageName, classSet);
}
-
+
classSet.add(theClass);
}
-
+
return result;
}
-
+
/*
* It's sorta sad that this is a pass-through call, but it seems like
* having all of the hat-like query methods in one place is a good thing
@@ -134,14 +134,14 @@ public class Queries {
*/
public static Instance[] instancesOf(State state, String baseClassName) {
ClassObj theClass = state.findClass(baseClassName);
-
+
if (theClass == null) {
throw new IllegalArgumentException("Class not found: "
+ baseClassName);
}
-
+
Instance[] instances = new Instance[theClass.mInstances.size()];
-
+
return theClass.mInstances.toArray(instances);
}
@@ -151,38 +151,38 @@ public class Queries {
*/
public static Instance[] allInstancesOf(State state, String baseClassName) {
ClassObj theClass = state.findClass(baseClassName);
-
+
if (theClass == null) {
throw new IllegalArgumentException("Class not found: "
+ baseClassName);
}
ArrayList<ClassObj> classList = new ArrayList<ClassObj>();
-
+
classList.add(theClass);
classList.addAll(traverseSubclasses(theClass));
-
+
ArrayList<Instance> instanceList = new ArrayList<Instance>();
-
+
for (ClassObj someClass: classList) {
instanceList.addAll(someClass.mInstances);
}
-
+
Instance[] result = new Instance[instanceList.size()];
-
+
instanceList.toArray(result);
-
+
return result;
}
-
+
private static ArrayList<ClassObj> traverseSubclasses(ClassObj base) {
ArrayList<ClassObj> result = new ArrayList<ClassObj>();
-
+
for (ClassObj subclass: base.mSubclasses) {
result.add(subclass);
result.addAll(traverseSubclasses(subclass));
}
-
+
return result;
}
@@ -192,33 +192,33 @@ public class Queries {
*/
public static Instance findObject(State state, String id) {
long id2 = Long.parseLong(id, 16);
-
+
return state.findReference(id2);
}
public static Collection<RootObj> getRoots(State state) {
HashSet<RootObj> result = new HashSet<RootObj>();
-
+
for (Heap heap: state.mHeaps.values()) {
result.addAll(heap.mRoots);
}
-
+
return result;
}
public static final Instance[] newInstances(State older, State newer) {
ArrayList<Instance> resultList = new ArrayList<Instance>();
-
+
for (Heap newHeap: newer.mHeaps.values()) {
Heap oldHeap = older.getHeap(newHeap.mName);
-
+
if (oldHeap == null) {
continue;
}
-
+
for (Instance instance: newHeap.mInstances.values()) {
Instance oldInstance = oldHeap.getInstance(instance.mId);
-
+
/*
* If this instance wasn't in the old heap, or was there,
* but that ID was for an obj of a different type, then we have
@@ -231,9 +231,9 @@ public class Queries {
}
}
}
-
+
Instance[] resultArray = new Instance[resultList.size()];
-
+
return resultList.toArray(resultArray);
}
}
diff --git a/hit/src/com/android/hit/RootObj.java b/hit/src/com/android/hit/RootObj.java
index 1f9d53912..a9acd3544 100644
--- a/hit/src/com/android/hit/RootObj.java
+++ b/hit/src/com/android/hit/RootObj.java
@@ -37,7 +37,7 @@ public class RootObj extends Instance {
public RootObj(RootType type, long id) {
this(type, id, 0, null);
}
-
+
public RootObj(RootType type, long id, int thread, StackTrace stack) {
mType = type;
mId = id;
@@ -47,7 +47,7 @@ public class RootObj extends Instance {
public final String getClassName(State state) {
ClassObj theClass;
-
+
if (mType == RootType.SYSTEM_CLASS) {
theClass = state.findClass(mId);
} else {
@@ -59,24 +59,24 @@ public class RootObj extends Instance {
if (theClass == null) {
return "no class defined!!";
}
-
+
return theClass.mClassName;
}
@Override
public final int getSize() {
Instance instance = null;
-
+
if (mType == RootType.SYSTEM_CLASS) {
instance = mHeap.mState.findClass(mId);
} else {
instance = mHeap.mState.findReference(mId);
}
-
+
if (instance == null) {
return 0;
}
-
+
return instance.getSize();
}
@@ -85,7 +85,7 @@ public class RootObj extends Instance {
if (resultSet.contains(this)) {
return;
}
-
+
if (filter != null) {
if (filter.accept(this)) {
resultSet.add(this);
diff --git a/hit/src/com/android/hit/RootType.java b/hit/src/com/android/hit/RootType.java
index 01ebefff6..209ed1be0 100644
--- a/hit/src/com/android/hit/RootType.java
+++ b/hit/src/com/android/hit/RootType.java
@@ -34,19 +34,19 @@ public enum RootType {
JAVA_LOCAL (14, "java local"),
NATIVE_STACK (15, "native stack"),
JAVA_STATIC (16, "java static");
-
+
private final int mType;
private final String mName;
-
+
RootType(int type, String name) {
mType = type;
mName = name;
}
-
+
public final int getType() {
return mType;
}
-
+
public final String getName() {
return mName;
}
diff --git a/hit/src/com/android/hit/StackFrame.java b/hit/src/com/android/hit/StackFrame.java
index a40f607e3..2ae7f326e 100644
--- a/hit/src/com/android/hit/StackFrame.java
+++ b/hit/src/com/android/hit/StackFrame.java
@@ -21,7 +21,7 @@ public class StackFrame {
public static final int UNKNOWN_LOCATION = -1;
public static final int COMPILED_METHOD = -2;
public static final int NATIVE_METHOD = -3;
-
+
long mId;
String mMethodName;
String mSignature;
@@ -29,7 +29,7 @@ public class StackFrame {
int mSerialNumber;
int mLineNumber;
- public StackFrame(long id, String method, String sig, String file,
+ public StackFrame(long id, String method, String sig, String file,
int serial, int line) {
mId = id;
mMethodName = method;
@@ -45,16 +45,16 @@ public class StackFrame {
case UNKNOWN_LOCATION: return "Unknown line number";
case COMPILED_METHOD: return "Compiled method";
case NATIVE_METHOD: return "Native method";
-
+
default: return String.valueOf(mLineNumber);
}
}
public final String toString() {
- return mMethodName
- + mSignature.replace('/', '.')
- + " - "
- + mFilename + ":"
+ return mMethodName
+ + mSignature.replace('/', '.')
+ + " - "
+ + mFilename + ":"
+ lineNumberString();
}
}
diff --git a/hit/src/com/android/hit/StackTrace.java b/hit/src/com/android/hit/StackTrace.java
index 239a7b818..53cb86dbe 100644
--- a/hit/src/com/android/hit/StackTrace.java
+++ b/hit/src/com/android/hit/StackTrace.java
@@ -31,9 +31,9 @@ public class StackTrace {
int mOffset = 0;
private StackTrace() {
-
+
}
-
+
public StackTrace(int serial, int thread, StackFrame[] frames) {
mSerialNumber = serial;
mThreadSerialNumber = thread;
@@ -42,21 +42,21 @@ public class StackTrace {
public final StackTrace fromDepth(int startingDepth) {
StackTrace result = new StackTrace();
-
+
if (mParent != null) {
result.mParent = mParent;
} else {
result.mParent = this;
}
-
+
result.mOffset = startingDepth + mOffset;
-
+
return result;
}
-
+
public final void dump() {
final int N = mFrames.length;
-
+
for (int i = 0; i < N; i++) {
System.out.println(mFrames[i].toString());
}
diff --git a/hit/src/com/android/hit/State.java b/hit/src/com/android/hit/State.java
index 9b2060d41..96c944d91 100644
--- a/hit/src/com/android/hit/State.java
+++ b/hit/src/com/android/hit/State.java
@@ -41,13 +41,13 @@ public class State {
public Heap setHeapTo(int id, String name) {
Heap heap = mHeaps.get(id);
-
+
if (heap == null) {
heap = new Heap(name);
heap.mState = this;
mHeaps.put(id, heap);
}
-
+
mCurrentHeap = heap;
return mCurrentHeap;
@@ -56,54 +56,54 @@ public class State {
public Heap getHeap(int id) {
return mHeaps.get(id);
}
-
+
public Heap getHeap(String name) {
for (Heap heap: mHeaps.values()) {
if (heap.mName.equals(name)) {
return heap;
}
}
-
+
return null;
}
public final void addStackFrame(StackFrame theFrame) {
mCurrentHeap.addStackFrame(theFrame);
}
-
+
public final StackFrame getStackFrame(long id) {
return mCurrentHeap.getStackFrame(id);
}
-
+
public final void addStackTrace(StackTrace theTrace) {
mCurrentHeap.addStackTrace(theTrace);
}
-
+
public final StackTrace getStackTrace(int traceSerialNumber) {
return mCurrentHeap.getStackTrace(traceSerialNumber);
}
-
- public final StackTrace getStackTraceAtDepth(int traceSerialNumber,
+
+ public final StackTrace getStackTraceAtDepth(int traceSerialNumber,
int depth) {
return mCurrentHeap.getStackTraceAtDepth(traceSerialNumber, depth);
}
-
+
public final void addRoot(RootObj root) {
mCurrentHeap.addRoot(root);
}
-
+
public final void addThread(ThreadObj thread, int serialNumber) {
mCurrentHeap.addThread(thread, serialNumber);
}
-
+
public final ThreadObj getThread(int serialNumber) {
return mCurrentHeap.getThread(serialNumber);
}
-
+
public final void addInstance(long id, Instance instance) {
mCurrentHeap.addInstance(id, instance);
}
-
+
public final void addClass(long id, ClassObj theClass) {
mCurrentHeap.addClass(id, theClass);
}
@@ -111,40 +111,40 @@ public class State {
public final Instance findReference(long id) {
for (Heap heap: mHeaps.values()) {
Instance instance = heap.getInstance(id);
-
+
if (instance != null) {
return instance;
}
}
-
+
// Couldn't find an instance of a class, look for a class object
return findClass(id);
}
-
+
public final ClassObj findClass(long id) {
for (Heap heap: mHeaps.values()) {
ClassObj theClass = heap.getClass(id);
-
+
if (theClass != null) {
return theClass;
}
}
-
+
return null;
}
-
+
public final ClassObj findClass(String name) {
for (Heap heap: mHeaps.values()) {
ClassObj theClass = heap.getClass(name);
-
+
if (theClass != null) {
return theClass;
}
}
-
+
return null;
}
-
+
public final void dumpInstanceCounts() {
for (Heap heap: mHeaps.values()) {
System.out.println(
@@ -152,7 +152,7 @@ public class State {
heap.dumpInstanceCounts();
}
}
-
+
public final void dumpSizes() {
for (Heap heap: mHeaps.values()) {
System.out.println(
@@ -168,7 +168,7 @@ public class State {
heap.dumpSubclasses();
}
}
-
+
public final void resolveReferences() {
for (Heap heap: mHeaps.values()) {
heap.resolveInstanceRefs(this);
diff --git a/hit/src/com/android/hit/Types.java b/hit/src/com/android/hit/Types.java
index ef316a94b..62228cea6 100644
--- a/hit/src/com/android/hit/Types.java
+++ b/hit/src/com/android/hit/Types.java
@@ -45,7 +45,7 @@ public class Types {
case 'S': return 2; // short
case 'I': return 4; // int
case 'J': return 8; // long
-
+
case OBJECT: return mIdSize;
case BOOLEAN: return 1;
case CHAR: return 2;
@@ -56,10 +56,10 @@ public class Types {
case INT: return 4;
case LONG: return 8;
}
-
+
throw new IllegalArgumentException("Illegal type signature: " + type);
}
-
+
public static final String getTypeName(int type) {
switch (type) {
case '[': return "array";
@@ -72,7 +72,7 @@ public class Types {
case 'S': return "short";
case 'I': return "int";
case 'J': return "long";
-
+
case OBJECT: return "object";
case BOOLEAN: return "boolean";
case CHAR: return "char";
@@ -83,7 +83,7 @@ public class Types {
case INT: return "int";
case LONG: return "long";
}
-
+
throw new IllegalArgumentException("Illegal type signature: " + type);
}
}