/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.ddmlib; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * Stores native allocation information. *
Contains number of allocations, their size and the stack trace. * Note: the ddmlib does not resolve the stack trace automatically. While this class provides * storage for resolved stack trace, this is merely for convenience. */ public final class NativeAllocationInfo { /* constants for flag bits */ private static final int FLAG_ZYGOTE_CHILD = (1<<31); private static final int FLAG_MASK = (FLAG_ZYGOTE_CHILD); /** * list of alloc functions that are filtered out when attempting to display * a relevant method responsible for an allocation */ private static ArrayListresolvedStackCall is non null then
* {@link #isStackCallResolved()} will return true after this call.
* @param resolvedStackCall The list of {@link NativeStackCallInfo}.
*/
public synchronized void setResolvedStackCall(Listnull if the stack call
* was not resolved.
* @see #setResolvedStackCall(ArrayList)
* @see #isStackCallResolved()
*/
public synchronized NativeStackCallInfo[] getResolvedStackCall() {
if (mIsStackCallResolved) {
return mResolvedStackCall.toArray(new NativeStackCallInfo[mResolvedStackCall.size()]);
}
return null;
}
/**
* Indicates whether some other object is "equal to" this one.
* @param obj the reference object with which to compare.
* @return true if this object is equal to the obj argument;
* false otherwise.
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj instanceof NativeAllocationInfo) {
NativeAllocationInfo mi = (NativeAllocationInfo)obj;
// quick compare of size, alloc, and stackcall size
if (mSize != mi.mSize || mAllocations != mi.mAllocations ||
mStackCallAddresses.size() != mi.mStackCallAddresses.size()) {
return false;
}
// compare the stack addresses
int count = mStackCallAddresses.size();
for (int i = 0 ; i < count ; i++) {
long a = mStackCallAddresses.get(i);
long b = mi.mStackCallAddresses.get(i);
if (a != b) {
return false;
}
}
return true;
}
return false;
}
/**
* Returns a string representation of the object.
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Allocations: ");
buffer.append(mAllocations);
buffer.append("\n"); //$NON-NLS-1$
buffer.append("Size: ");
buffer.append(mSize);
buffer.append("\n"); //$NON-NLS-1$
buffer.append("Total Size: ");
buffer.append(mSize * mAllocations);
buffer.append("\n"); //$NON-NLS-1$
IteratorNativeStackCallInfo is a stack call that is not deep in the
* lower level of the libc, but the actual method that performed the allocation.
* @return a NativeStackCallInfo or null if the stack call has not
* been processed from the raw addresses.
* @see #setResolvedStackCall(ArrayList)
* @see #isStackCallResolved()
*/
public synchronized NativeStackCallInfo getRelevantStackCallInfo() {
if (mIsStackCallResolved && mResolvedStackCall != null) {
Iterator