Search in sources :

Example 6 with ClassInstance

use of com.squareup.haha.perflib.ClassInstance in project leakcanary by square.

the class HahaHelperTest method createObjectValueInstance_M_Preview2.

private void createObjectValueInstance_M_Preview2() {
    ClassInstance valueInstance = new ClassInstance(0, null, 0);
    snapshot.addInstance(STRING_INSTANCE_ID + 16, valueInstance);
}
Also used : ClassInstance(com.squareup.haha.perflib.ClassInstance)

Example 7 with ClassInstance

use of com.squareup.haha.perflib.ClassInstance in project leakcanary by square.

the class HahaHelperTest method defaultToZeroStringOffsetWhenHeapDumpInstanceIsMissingOffsetValue.

@Test
public void defaultToZeroStringOffsetWhenHeapDumpInstanceIsMissingOffsetValue() {
    buffer.setIntsToRead(COUNT_VALUE, VALUE_ARRAY_INSTANCE_ID);
    buffer.setStringsToRead("abcdef");
    addStringClassToSnapshotWithFields(snapshot, new Field[] { new Field(Type.INT, "count"), new Field(Type.OBJECT, "value") });
    ClassInstance stringInstance = createStringInstance();
    createCharArrayValueInstance();
    String actual = HahaHelper.asString(stringInstance);
    assertTrue(actual.equals("abcde"));
}
Also used : Field(com.squareup.haha.perflib.Field) ClassInstance(com.squareup.haha.perflib.ClassInstance) Test(org.junit.Test)

Example 8 with ClassInstance

use of com.squareup.haha.perflib.ClassInstance in project leakcanary by square.

the class HeapAnalyzer method describeFields.

private List<String> describeFields(Instance instance) {
    List<String> fields = new ArrayList<>();
    if (instance instanceof ClassObj) {
        ClassObj classObj = (ClassObj) instance;
        for (Map.Entry<Field, Object> entry : classObj.getStaticFieldValues().entrySet()) {
            Field field = entry.getKey();
            Object value = entry.getValue();
            fields.add("static " + field.getName() + " = " + value);
        }
    } else if (instance instanceof ArrayInstance) {
        ArrayInstance arrayInstance = (ArrayInstance) instance;
        if (arrayInstance.getArrayType() == Type.OBJECT) {
            Object[] values = arrayInstance.getValues();
            for (int i = 0; i < values.length; i++) {
                fields.add("[" + i + "] = " + values[i]);
            }
        }
    } else {
        ClassObj classObj = instance.getClassObj();
        for (Map.Entry<Field, Object> entry : classObj.getStaticFieldValues().entrySet()) {
            fields.add("static " + fieldToString(entry));
        }
        ClassInstance classInstance = (ClassInstance) instance;
        for (ClassInstance.FieldValue field : classInstance.getValues()) {
            fields.add(fieldToString(field));
        }
    }
    return fields;
}
Also used : ClassObj(com.squareup.haha.perflib.ClassObj) Field(com.squareup.haha.perflib.Field) HahaHelper.hasField(com.squareup.leakcanary.HahaHelper.hasField) ArrayList(java.util.ArrayList) HahaHelper.fieldToString(com.squareup.leakcanary.HahaHelper.fieldToString) HahaHelper.asString(com.squareup.leakcanary.HahaHelper.asString) ArrayInstance(com.squareup.haha.perflib.ArrayInstance) THashMap(com.squareup.haha.trove.THashMap) Map(java.util.Map) ClassInstance(com.squareup.haha.perflib.ClassInstance)

Aggregations

ClassInstance (com.squareup.haha.perflib.ClassInstance)8 Field (com.squareup.haha.perflib.Field)6 Test (org.junit.Test)4 ArrayInstance (com.squareup.haha.perflib.ArrayInstance)2 ClassObj (com.squareup.haha.perflib.ClassObj)2 Instance (com.squareup.haha.perflib.Instance)1 THashMap (com.squareup.haha.trove.THashMap)1 HahaHelper.asString (com.squareup.leakcanary.HahaHelper.asString)1 HahaHelper.fieldToString (com.squareup.leakcanary.HahaHelper.fieldToString)1 HahaHelper.hasField (com.squareup.leakcanary.HahaHelper.hasField)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1