use of com.squareup.haha.perflib.Field 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.Field 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.Field 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.Field in project leakcanary by square.
the class ShortestPathFinder method visitClassObj.
private void visitClassObj(LeakNode node) {
ClassObj classObj = (ClassObj) node.instance;
Map<String, Exclusion> ignoredStaticFields = excludedRefs.staticFieldNameByClassName.get(classObj.getClassName());
for (Map.Entry<Field, Object> entry : classObj.getStaticFieldValues().entrySet()) {
Field field = entry.getKey();
if (field.getType() != Type.OBJECT) {
continue;
}
String fieldName = field.getName();
if (fieldName.equals("$staticOverhead")) {
continue;
}
Instance child = (Instance) entry.getValue();
boolean visit = true;
if (ignoredStaticFields != null) {
Exclusion params = ignoredStaticFields.get(fieldName);
if (params != null) {
visit = false;
if (!params.alwaysExclude) {
enqueue(params, node, child, fieldName, STATIC_FIELD);
}
}
}
if (visit) {
enqueue(null, node, child, fieldName, STATIC_FIELD);
}
}
}
use of com.squareup.haha.perflib.Field 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