当前位置: 首页>>代码示例>>Java>>正文


Java Instance类代码示例

本文整理汇总了Java中com.squareup.haha.perflib.Instance的典型用法代码示例。如果您正苦于以下问题:Java Instance类的具体用法?Java Instance怎么用?Java Instance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Instance类属于com.squareup.haha.perflib包,在下文中一共展示了Instance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitRootObj

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
private void visitRootObj(LeakNode node) {
  RootObj rootObj = (RootObj) node.instance;
  Instance child = rootObj.getReferredInstance();

  Exclusion exclusion = rootSuperClassAlwaysIgnored(child);

  if (exclusion != null && exclusion.alwaysExclude) {
    return;
  }

  if (rootObj.getRootType() == RootType.JAVA_LOCAL) {
    Instance holder = HahaSpy.allocatingThread(rootObj);
    // We switch the parent node with the thread instance that holds
    // the local reference.
    LeakNode parent = new LeakNode(null, holder, null, null, null);
    if (node.exclusion != null) {
      exclusion = node.exclusion;
    }
    enqueue(exclusion, parent, child, "<Java Local>", LOCAL);
  } else {
    enqueue(exclusion, node, child, null, null);
  }
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:24,代码来源:ShortestPathFinder.java

示例2: rootSuperClassAlwaysIgnored

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
private Exclusion rootSuperClassAlwaysIgnored(Instance child) {
  if (child == null) {
    return null;
  }
  Exclusion matchingParams = null;
  ClassObj superClassObj = child.getClassObj();
  while (superClassObj != null) {
    Exclusion params = excludedRefs.rootClassNames.get(superClassObj.getClassName());
    if (params != null) {
      // true overrides null or false.
      if (matchingParams == null || !matchingParams.alwaysExclude) {
        matchingParams = params;
      }
    }
    superClassObj = superClassObj.getSuperClassObj();
  }
  return matchingParams;
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:19,代码来源:ShortestPathFinder.java

示例3: computeIgnoredBitmapRetainedSize

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
/**
 * Bitmaps and bitmap byte arrays are sometimes held by native gc roots, so they aren't included
 * in the retained size because their root dominator is a native gc root.
 * To fix this, we check if the leaking instance is a dominator for each bitmap instance and then
 * add the bitmap size.
 *
 * From experience, we've found that bitmap created in code (Bitmap.createBitmap()) are correctly
 * accounted for, however bitmaps set in layouts are not.
 */
private int computeIgnoredBitmapRetainedSize(Snapshot snapshot, Instance leakingInstance) {
  int bitmapRetainedSize = 0;
  ClassObj bitmapClass = snapshot.findClass("android.graphics.Bitmap");

  for (Instance bitmapInstance : bitmapClass.getInstancesList()) {
    if (isIgnoredDominator(leakingInstance, bitmapInstance)) {
      ArrayInstance mBufferInstance = fieldValue(classInstanceValues(bitmapInstance), "mBuffer");
      // Native bitmaps have mBuffer set to null. We sadly can't account for them.
      if (mBufferInstance == null) {
        continue;
      }
      long bufferSize = mBufferInstance.getTotalRetainedSize();
      long bitmapSize = bitmapInstance.getTotalRetainedSize();
      // Sometimes the size of the buffer isn't accounted for in the bitmap retained size. Since
      // the buffer is large, it's easy to detect by checking for bitmap size < buffer size.
      if (bitmapSize < bufferSize) {
        bitmapSize += bufferSize;
      }
      bitmapRetainedSize += bitmapSize;
    }
  }
  return bitmapRetainedSize;
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:33,代码来源:HeapAnalyzer.java

示例4: isIgnoredDominator

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
private boolean isIgnoredDominator(Instance dominator, Instance instance) {
  boolean foundNativeRoot = false;
  while (true) {
    Instance immediateDominator = instance.getImmediateDominator();
    if (immediateDominator instanceof RootObj
        && ((RootObj) immediateDominator).getRootType() == RootType.UNKNOWN) {
      // Ignore native roots
      instance = instance.getNextInstanceToGcRoot();
      foundNativeRoot = true;
    } else {
      instance = immediateDominator;
    }
    if (instance == null) {
      return false;
    }
    if (instance == dominator) {
      return foundNativeRoot;
    }
  }
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:21,代码来源:HeapAnalyzer.java

示例5: visitRootObj

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
private void visitRootObj(LeakNode node) {
  RootObj rootObj = (RootObj) node.instance;
  Instance child = rootObj.getReferredInstance();

  if (rootObj.getRootType() == RootType.JAVA_LOCAL) {
    Instance holder = HahaSpy.allocatingThread(rootObj);
    // We switch the parent node with the thread instance that holds
    // the local reference.
    Exclusion exclusion = null;
    if (node.exclusion != null) {
      exclusion = node.exclusion;
    }
    LeakNode parent = new LeakNode(null, holder, null, null, null);
    enqueue(exclusion, parent, child, "<Java Local>", LOCAL);
  } else {
    enqueue(null, node, child, null, null);
  }
}
 
开发者ID:square,项目名称:leakcanary,代码行数:19,代码来源:ShortestPathFinder.java

示例6: computeIgnoredBitmapRetainedSize

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
/**
 * Bitmaps and bitmap byte arrays are sometimes held by native gc roots, so they aren't included
 * in the retained size because their root dominator is a native gc root.
 * To fix this, we check if the leaking instance is a dominator for each bitmap instance and then
 * add the bitmap size.
 *
 * From experience, we've found that bitmap created in code (Bitmap.createBitmap()) are correctly
 * accounted for, however bitmaps set in layouts are not.
 */
private long computeIgnoredBitmapRetainedSize(Snapshot snapshot, Instance leakingInstance) {
  long bitmapRetainedSize = 0;
  ClassObj bitmapClass = snapshot.findClass("android.graphics.Bitmap");

  for (Instance bitmapInstance : bitmapClass.getInstancesList()) {
    if (isIgnoredDominator(leakingInstance, bitmapInstance)) {
      ArrayInstance mBufferInstance = fieldValue(classInstanceValues(bitmapInstance), "mBuffer");
      // Native bitmaps have mBuffer set to null. We sadly can't account for them.
      if (mBufferInstance == null) {
        continue;
      }
      long bufferSize = mBufferInstance.getTotalRetainedSize();
      long bitmapSize = bitmapInstance.getTotalRetainedSize();
      // Sometimes the size of the buffer isn't accounted for in the bitmap retained size. Since
      // the buffer is large, it's easy to detect by checking for bitmap size < buffer size.
      if (bitmapSize < bufferSize) {
        bitmapSize += bufferSize;
      }
      bitmapRetainedSize += bitmapSize;
    }
  }
  return bitmapRetainedSize;
}
 
开发者ID:square,项目名称:leakcanary,代码行数:33,代码来源:HeapAnalyzer.java

示例7: ShortestPathFinder

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
ShortestPathFinder(ExcludedRefs excludedRefs) {
  this.excludedRefs = excludedRefs;
  toVisitQueue = new LinkedList<LeakNode>();
  toVisitIfNoPathQueue = new LinkedList<LeakNode>();
  toVisitSet = new LinkedHashSet<Instance>();
  toVisitIfNoPathSet = new LinkedHashSet<Instance>();
  visitedSet = new LinkedHashSet<Instance>();
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:9,代码来源:ShortestPathFinder.java

示例8: visitClassObj

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
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);
    }
  }
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:30,代码来源:ShortestPathFinder.java

示例9: visitArrayInstance

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
private void visitArrayInstance(LeakNode node) {
  ArrayInstance arrayInstance = (ArrayInstance) node.instance;
  Type arrayType = arrayInstance.getArrayType();
  if (arrayType == Type.OBJECT) {
    Object[] values = arrayInstance.getValues();
    for (int i = 0; i < values.length; i++) {
      Instance child = (Instance) values[i];
      enqueue(null, node, child, "[" + i + "]", ARRAY_ENTRY);
    }
  }
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:12,代码来源:ShortestPathFinder.java

示例10: enqueue

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
private void enqueue(Exclusion exclusion, LeakNode parent, Instance child, String referenceName,
    LeakTraceElement.Type referenceType) {
  if (child == null) {
    return;
  }
  if (isPrimitiveOrWrapperArray(child) || isPrimitiveWrapper(child)) {
    return;
  }
  // Whether we want to visit now or later, we should skip if this is already to visit.
  if (toVisitSet.contains(child)) {
    return;
  }
  boolean visitNow = exclusion == null;
  if (!visitNow && toVisitIfNoPathSet.contains(child)) {
    return;
  }
  if (canIgnoreStrings && isString(child)) {
    return;
  }
  if (visitedSet.contains(child)) {
    return;
  }
  LeakNode childNode = new LeakNode(exclusion, child, parent, referenceName, referenceType);
  if (visitNow) {
    toVisitSet.add(child);
    toVisitQueue.add(childNode);
  } else {
    toVisitIfNoPathSet.add(child);
    toVisitIfNoPathQueue.add(childNode);
  }
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:32,代码来源:ShortestPathFinder.java

示例11: threadName

import com.squareup.haha.perflib.Instance; //导入依赖的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);
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:11,代码来源:HahaHelper.java

示例12: checkForLeak

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
/**
 * Searches the heap dump for a {@link KeyedWeakReference} instance with the corresponding key,
 * and then computes the shortest strong reference path from that instance to the GC roots.
 */
public AnalysisResult checkForLeak(File heapDumpFile, String referenceKey) {
  long analysisStartNanoTime = System.nanoTime();

  if (!heapDumpFile.exists()) {
    Exception exception = new IllegalArgumentException("File does not exist: " + heapDumpFile);
    return failure(exception, since(analysisStartNanoTime));
  }

  try {
    HprofBuffer buffer = new MemoryMappedFileBuffer(heapDumpFile);
    HprofParser parser = new HprofParser(buffer);
    Snapshot snapshot = parser.parse();
    deduplicateGcRoots(snapshot);

    Instance leakingRef = findLeakingReference(referenceKey, snapshot);

    // False alarm, weak reference was cleared in between key check and heap dump.
    if (leakingRef == null) {
      return noLeak(since(analysisStartNanoTime));
    }

    return findLeakTrace(analysisStartNanoTime, snapshot, leakingRef);
  } catch (Throwable e) {
    return failure(e, since(analysisStartNanoTime));
  }
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:31,代码来源:HeapAnalyzer.java

示例13: findLeakingReference

import com.squareup.haha.perflib.Instance; //导入依赖的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);
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:15,代码来源:HeapAnalyzer.java

示例14: LeakNode

import com.squareup.haha.perflib.Instance; //导入依赖的package包/类
LeakNode(Exclusion exclusion, Instance instance, LeakNode parent,
    String referenceName, LeakTraceElement.Type referenceType) {
  this.exclusion = exclusion;
  this.instance = instance;
  this.parent = parent;
  this.referenceName = referenceName;
  this.referenceType = referenceType;
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:9,代码来源:LeakNode.java

示例15: findTrackedReferences

import com.squareup.haha.perflib.Instance; //导入依赖的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);
  }
}
 
开发者ID:square,项目名称:leakcanary,代码行数:30,代码来源:HeapAnalyzer.java


注:本文中的com.squareup.haha.perflib.Instance类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。