本文整理汇总了Java中com.squareup.haha.perflib.ClassInstance类的典型用法代码示例。如果您正苦于以下问题:Java ClassInstance类的具体用法?Java ClassInstance怎么用?Java ClassInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassInstance类属于com.squareup.haha.perflib包,在下文中一共展示了ClassInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readStringOffsetFromHeapDumpInstance
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
@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"));
}
示例2: defaultToZeroStringOffsetWhenHeapDumpInstanceIsMissingOffsetValue
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
@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"));
}
示例3: defaultToZeroStringOffsetWhenReadingMPreview2HeapDump
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
@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"));
}
示例4: throwExceptionWhenMissingCharArrayValueForStringInMPreview2HeapDump
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
@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));
}
}
示例5: readStringOffsetFromHeapDumpInstance_pre_O
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
@Test public void readStringOffsetFromHeapDumpInstance_pre_O() {
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"));
}
示例6: readStringAsByteArrayFromHeapDumpInstance_O
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
@Test public void readStringAsByteArrayFromHeapDumpInstance_O() {
// O uses default charset UTF-8
buffer = new FakeHprofBuffer("UTF-8");
initSnapshot(buffer);
buffer.setIntsToRead(COUNT_VALUE, VALUE_ARRAY_INSTANCE_ID);
buffer.setStringsToRead("abcdef");
addStringClassToSnapshotWithFields_O(snapshot, new Field[]{
new Field(Type.INT, "count"),
new Field(Type.OBJECT, "value")
});
ClassInstance stringInstance = createStringInstance();
createByteArrayValueInstance();
String actual = HahaHelper.asString(stringInstance);
assertTrue(actual.equals("abcde"));
}
示例7: throwExceptionWhenNotArrayValueForString
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
@Test public void throwExceptionWhenNotArrayValueForString() {
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();
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));
}
}
示例8: threadName
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
static String threadName(Instance holder) {
List<ClassInstance.FieldValue> values = classInstanceValues(holder);
Object nameField = fieldValue(values, "name");
if (nameField == null) {
// Sometimes we can't find the String at the expected memory address in the heap dump.
// See https://github.com/square/leakcanary/issues/417 .
return "Thread name not available";
}
return asString(nameField);
}
示例9: hasField
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
static boolean hasField(List<ClassInstance.FieldValue> values, String fieldName) {
for (ClassInstance.FieldValue fieldValue : values) {
if (fieldValue.getField().getName().equals(fieldName)) {
//noinspection unchecked
return true;
}
}
return false;
}
示例10: findLeakingReference
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
private Instance findLeakingReference(String key, Snapshot snapshot) {
ClassObj refClass = snapshot.findClass(KeyedWeakReference.class.getName());
List<String> keysFound = new ArrayList<String>();
for (Instance instance : refClass.getInstancesList()) {
List<ClassInstance.FieldValue> values = classInstanceValues(instance);
String keyCandidate = asString(fieldValue(values, "key"));
if (keyCandidate.equals(key)) {
return fieldValue(values, "referent");
}
keysFound.add(keyCandidate);
}
throw new IllegalStateException(
"Could not find weak reference with key " + key + " in " + keysFound);
}
示例11: findTrackedReferences
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
public List<TrackedReference> findTrackedReferences(File heapDumpFile) {
if (!heapDumpFile.exists()) {
throw new IllegalArgumentException("File does not exist: " + heapDumpFile);
}
try {
HprofBuffer buffer = new MemoryMappedFileBuffer(heapDumpFile);
HprofParser parser = new HprofParser(buffer);
Snapshot snapshot = parser.parse();
deduplicateGcRoots(snapshot);
ClassObj refClass = snapshot.findClass(KeyedWeakReference.class.getName());
List<TrackedReference> references = new ArrayList<>();
for (Instance weakRef : refClass.getInstancesList()) {
List<ClassInstance.FieldValue> values = classInstanceValues(weakRef);
String key = asString(fieldValue(values, "key"));
String name =
hasField(values, "name") ? asString(fieldValue(values, "name")) : "(No name field)";
Instance instance = fieldValue(values, "referent");
if (instance != null) {
String className = getClassName(instance);
List<String> fields = describeFields(instance);
references.add(new TrackedReference(key, name, className, fields));
}
}
return references;
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
示例12: findLeakingReference
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
private Instance findLeakingReference(String key, Snapshot snapshot) {
ClassObj refClass = snapshot.findClass(KeyedWeakReference.class.getName());
List<String> keysFound = new ArrayList<>();
for (Instance instance : refClass.getInstancesList()) {
List<ClassInstance.FieldValue> values = classInstanceValues(instance);
String keyCandidate = asString(fieldValue(values, "key"));
if (keyCandidate.equals(key)) {
return fieldValue(values, "referent");
}
keysFound.add(keyCandidate);
}
throw new IllegalStateException(
"Could not find weak reference with key " + key + " in " + keysFound);
}
示例13: defaultToZeroStringOffsetWhenHeapDumpInstanceIsMissingOffsetValue_pre_O
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
@Test public void defaultToZeroStringOffsetWhenHeapDumpInstanceIsMissingOffsetValue_pre_O() {
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"));
}
示例14: findPath
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
Result findPath(Snapshot snapshot, Instance leakingRef) {
clearState();
canIgnoreStrings = !isString(leakingRef);
enqueueGcRoots(snapshot);
boolean excludingKnownLeaks = false;
LeakNode leakingNode = null;
while (!toVisitQueue.isEmpty() || !toVisitIfNoPathQueue.isEmpty()) {
LeakNode node;
if (!toVisitQueue.isEmpty()) {
node = toVisitQueue.poll();
} else {
node = toVisitIfNoPathQueue.poll();
if (node.exclusion == null) {
throw new IllegalStateException("Expected node to have an exclusion " + node);
}
excludingKnownLeaks = true;
}
// Termination
if (node.instance == leakingRef) {
leakingNode = node;
break;
}
if (checkSeen(node)) {
continue;
}
if (node.instance instanceof RootObj) {
visitRootObj(node);
} else if (node.instance instanceof ClassObj) {
visitClassObj(node);
} else if (node.instance instanceof ClassInstance) {
visitClassInstance(node);
} else if (node.instance instanceof ArrayInstance) {
visitArrayInstance(node);
} else {
throw new IllegalStateException("Unexpected type for " + node.instance);
}
}
return new Result(leakingNode, excludingKnownLeaks);
}
示例15: fieldToString
import com.squareup.haha.perflib.ClassInstance; //导入依赖的package包/类
static String fieldToString(ClassInstance.FieldValue fieldValue) {
return fieldToString(fieldValue.getField(), fieldValue.getValue());
}