use of com.squareup.haha.perflib.ClassInstance in project leakcanary by square.
the class ShortestPathFinder method visitClassInstance.
private void visitClassInstance(LeakNode node) {
ClassInstance classInstance = (ClassInstance) node.instance;
Map<String, Exclusion> ignoredFields = new LinkedHashMap<>();
ClassObj superClassObj = classInstance.getClassObj();
Exclusion classExclusion = null;
while (superClassObj != null) {
Exclusion params = excludedRefs.classNames.get(superClassObj.getClassName());
if (params != null) {
// true overrides null or false.
if (classExclusion == null || !classExclusion.alwaysExclude) {
classExclusion = params;
}
}
Map<String, Exclusion> classIgnoredFields = excludedRefs.fieldNameByClassName.get(superClassObj.getClassName());
if (classIgnoredFields != null) {
ignoredFields.putAll(classIgnoredFields);
}
superClassObj = superClassObj.getSuperClassObj();
}
if (classExclusion != null && classExclusion.alwaysExclude) {
return;
}
for (ClassInstance.FieldValue fieldValue : classInstance.getValues()) {
Exclusion fieldExclusion = classExclusion;
Field field = fieldValue.getField();
if (field.getType() != Type.OBJECT) {
continue;
}
Instance child = (Instance) fieldValue.getValue();
String fieldName = field.getName();
Exclusion params = ignoredFields.get(fieldName);
// If we found a field exclusion and it's stronger than a class exclusion
if (params != null && (fieldExclusion == null || (params.alwaysExclude && !fieldExclusion.alwaysExclude))) {
fieldExclusion = params;
}
enqueue(fieldExclusion, node, child, fieldName, INSTANCE_FIELD);
}
}
use of com.squareup.haha.perflib.ClassInstance in project leakcanary by square.
the class HahaHelperTest method defaultToZeroStringOffsetWhenReadingMPreview2HeapDump.
@Test
public void defaultToZeroStringOffsetWhenReadingMPreview2HeapDump() {
buffer.setIntsToRead(COUNT_VALUE, OFFSET_VALUE, VALUE_ARRAY_INSTANCE_ID);
buffer.setStringsToRead("abcdef");
addStringClassToSnapshotWithFields(snapshot, new Field[] { new Field(Type.INT, "count"), new Field(Type.INT, "offset"), new Field(Type.OBJECT, "value") });
ClassInstance stringInstance = createStringInstance();
createCharArrayValueInstance_M_Preview2();
String actual = HahaHelper.asString(stringInstance);
assertTrue(actual.equals("abcde"));
}
use of com.squareup.haha.perflib.ClassInstance in project leakcanary by square.
the class HahaHelperTest method createStringInstance.
private ClassInstance createStringInstance() {
ClassInstance stringInstance = new ClassInstance(STRING_INSTANCE_ID, null, 100);
stringInstance.setClassId(STRING_CLASS_ID);
snapshot.addInstance(0, stringInstance);
return stringInstance;
}
use of com.squareup.haha.perflib.ClassInstance in project leakcanary by square.
the class HahaHelperTest method throwExceptionWhenMissingCharArrayValueForStringInMPreview2HeapDump.
@Test
public void throwExceptionWhenMissingCharArrayValueForStringInMPreview2HeapDump() {
buffer.setIntsToRead(COUNT_VALUE, OFFSET_VALUE, VALUE_ARRAY_INSTANCE_ID);
buffer.setStringsToRead("abcdef");
addStringClassToSnapshotWithFields(snapshot, new Field[] { new Field(Type.INT, "count"), new Field(Type.INT, "offset"), new Field(Type.OBJECT, "value") });
ClassInstance stringInstance = createStringInstance();
createObjectValueInstance_M_Preview2();
try {
HahaHelper.asString(stringInstance);
fail("this test should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
String message = uoe.getMessage();
assertTrue(message.equals("Could not find char array in " + stringInstance));
}
}
use of com.squareup.haha.perflib.ClassInstance in project leakcanary by square.
the class HahaHelperTest method readStringOffsetFromHeapDumpInstance.
@Test
public void readStringOffsetFromHeapDumpInstance() {
buffer.setIntsToRead(COUNT_VALUE, OFFSET_VALUE, VALUE_ARRAY_INSTANCE_ID);
buffer.setStringsToRead("abcdef");
addStringClassToSnapshotWithFields(snapshot, new Field[] { new Field(Type.INT, "count"), new Field(Type.INT, "offset"), new Field(Type.OBJECT, "value") });
ClassInstance stringInstance = createStringInstance();
createCharArrayValueInstance();
String actual = HahaHelper.asString(stringInstance);
assertTrue(actual.equals("bcdef"));
}
Aggregations