jimu-decompiled/sources/com/squareup/haha/perflib/Instance.java
2025-05-13 19:24:51 +02:00

268 lines
7.8 KiB
Java

package com.squareup.haha.perflib;
import com.squareup.haha.guava.collect.ImmutableList;
import com.squareup.haha.perflib.io.HprofBuffer;
import java.util.ArrayList;
import java.util.Arrays;
/* loaded from: classes.dex */
public abstract class Instance {
static final /* synthetic */ boolean $assertionsDisabled = false;
long mClassId;
Heap mHeap;
protected final long mId;
private Instance mImmediateDominator;
private long[] mRetainedSizes;
int mSize;
protected final StackTrace mStack;
int mTopologicalOrder;
int mDistanceToGcRoot = Integer.MAX_VALUE;
boolean mReferencesAdded = false;
Instance mNextInstanceToGcRoot = null;
private final ArrayList<Instance> mHardReferences = new ArrayList<>();
private ArrayList<Instance> mSoftReferences = null;
/* renamed from: com.squareup.haha.perflib.Instance$1, reason: invalid class name */
static /* synthetic */ class AnonymousClass1 {
static final /* synthetic */ int[] $SwitchMap$com$android$tools$perflib$heap$Type = new int[Type.values().length];
static {
try {
$SwitchMap$com$android$tools$perflib$heap$Type[Type.OBJECT.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$android$tools$perflib$heap$Type[Type.BOOLEAN.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
$SwitchMap$com$android$tools$perflib$heap$Type[Type.CHAR.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$com$android$tools$perflib$heap$Type[Type.FLOAT.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
$SwitchMap$com$android$tools$perflib$heap$Type[Type.DOUBLE.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
try {
$SwitchMap$com$android$tools$perflib$heap$Type[Type.BYTE.ordinal()] = 6;
} catch (NoSuchFieldError unused6) {
}
try {
$SwitchMap$com$android$tools$perflib$heap$Type[Type.SHORT.ordinal()] = 7;
} catch (NoSuchFieldError unused7) {
}
try {
$SwitchMap$com$android$tools$perflib$heap$Type[Type.INT.ordinal()] = 8;
} catch (NoSuchFieldError unused8) {
}
try {
$SwitchMap$com$android$tools$perflib$heap$Type[Type.LONG.ordinal()] = 9;
} catch (NoSuchFieldError unused9) {
}
}
}
public static class CompositeSizeVisitor extends NonRecursiveVisitor {
int mSize = 0;
@Override // com.squareup.haha.perflib.NonRecursiveVisitor
protected void defaultAction(Instance instance) {
this.mSize += instance.getSize();
}
public int getCompositeSize() {
return this.mSize;
}
}
Instance(long j, StackTrace stackTrace) {
this.mId = j;
this.mStack = stackTrace;
}
public abstract void accept(Visitor visitor);
public void addReference(Field field, Instance instance) {
if (!instance.getIsSoftReference() || field == null || !field.getName().equals("referent")) {
this.mHardReferences.add(instance);
return;
}
if (this.mSoftReferences == null) {
this.mSoftReferences = new ArrayList<>();
}
this.mSoftReferences.add(instance);
}
public void addRetainedSize(int i, long j) {
long[] jArr = this.mRetainedSizes;
jArr[i] = jArr[i] + j;
}
protected HprofBuffer getBuffer() {
return this.mHeap.mSnapshot.mBuffer;
}
public ClassObj getClassObj() {
return this.mHeap.mSnapshot.findClass(this.mClassId);
}
public final int getCompositeSize() {
CompositeSizeVisitor compositeSizeVisitor = new CompositeSizeVisitor();
compositeSizeVisitor.doVisit(ImmutableList.of(this));
return compositeSizeVisitor.getCompositeSize();
}
public int getDistanceToGcRoot() {
return this.mDistanceToGcRoot;
}
public ArrayList<Instance> getHardReferences() {
return this.mHardReferences;
}
public Heap getHeap() {
return this.mHeap;
}
public long getId() {
return this.mId;
}
public Instance getImmediateDominator() {
return this.mImmediateDominator;
}
public boolean getIsSoftReference() {
return false;
}
public Instance getNextInstanceToGcRoot() {
return this.mNextInstanceToGcRoot;
}
public long getRetainedSize(int i) {
return this.mRetainedSizes[i];
}
public int getSize() {
return this.mSize;
}
public ArrayList<Instance> getSoftReferences() {
return this.mSoftReferences;
}
public int getTopologicalOrder() {
return this.mTopologicalOrder;
}
public long getTotalRetainedSize() {
long[] jArr = this.mRetainedSizes;
long j = 0;
if (jArr == null) {
return 0L;
}
for (long j2 : jArr) {
j += j2;
}
return j;
}
public long getUniqueId() {
return getId() & this.mHeap.mSnapshot.getIdSizeMask();
}
protected long readId() {
int typeSize = this.mHeap.mSnapshot.getTypeSize(Type.OBJECT);
if (typeSize == 1) {
return getBuffer().readByte();
}
if (typeSize == 2) {
return getBuffer().readShort();
}
if (typeSize == 4) {
return getBuffer().readInt();
}
if (typeSize != 8) {
return 0L;
}
return getBuffer().readLong();
}
protected int readUnsignedByte() {
return getBuffer().readByte() & 255;
}
protected int readUnsignedShort() {
return getBuffer().readShort() & 65535;
}
protected Object readValue(Type type) {
switch (AnonymousClass1.$SwitchMap$com$android$tools$perflib$heap$Type[type.ordinal()]) {
case 1:
return this.mHeap.mSnapshot.findInstance(readId());
case 2:
return Boolean.valueOf(getBuffer().readByte() != 0);
case 3:
return Character.valueOf(getBuffer().readChar());
case 4:
return Float.valueOf(getBuffer().readFloat());
case 5:
return Double.valueOf(getBuffer().readDouble());
case 6:
return Byte.valueOf(getBuffer().readByte());
case 7:
return Short.valueOf(getBuffer().readShort());
case 8:
return Integer.valueOf(getBuffer().readInt());
case 9:
return Long.valueOf(getBuffer().readLong());
default:
return null;
}
}
public void resetRetainedSize() {
ArrayList<Heap> arrayList = this.mHeap.mSnapshot.mHeaps;
long[] jArr = this.mRetainedSizes;
if (jArr == null) {
this.mRetainedSizes = new long[arrayList.size()];
} else {
Arrays.fill(jArr, 0L);
}
this.mRetainedSizes[arrayList.indexOf(this.mHeap)] = getSize();
}
public void setClassId(long j) {
this.mClassId = j;
}
public void setDistanceToGcRoot(int i) {
this.mDistanceToGcRoot = i;
}
public void setHeap(Heap heap) {
this.mHeap = heap;
}
public void setImmediateDominator(Instance instance) {
this.mImmediateDominator = instance;
}
public void setNextInstanceToGcRoot(Instance instance) {
this.mNextInstanceToGcRoot = instance;
}
public void setSize(int i) {
this.mSize = i;
}
public void setTopologicalOrder(int i) {
this.mTopologicalOrder = i;
}
}