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


Java ArrayInstance类代码示例

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


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

示例1: computeIgnoredBitmapRetainedSize

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的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

示例2: computeIgnoredBitmapRetainedSize

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的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

示例3: visitArrayInstance

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的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

示例4: isPrimitiveOrWrapperArray

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的package包/类
public static boolean isPrimitiveOrWrapperArray(Object value) {
  if (!(value instanceof ArrayInstance)) {
    return false;
  }
  ArrayInstance arrayInstance = (ArrayInstance) value;
  if (arrayInstance.getArrayType() != Type.OBJECT) {
    return true;
  }
  return WRAPPER_TYPES.contains(arrayInstance.getClassObj().getClassName());
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:11,代码来源:HahaHelper.java

示例5: findPath

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

示例6: isCharArray

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的package包/类
private static boolean isCharArray(Object value) {
  return value instanceof ArrayInstance && ((ArrayInstance) value).getArrayType() == Type.CHAR;
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:4,代码来源:HahaHelper.java

示例7: createCharArrayValueInstance

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的package包/类
private void createCharArrayValueInstance() {
  ArrayInstance valueArrayInstance = new ArrayInstance(0, null, Type.CHAR, VALUE_ARRAY_LENGTH, 0);
  snapshot.addInstance(VALUE_ARRAY_INSTANCE_ID, valueArrayInstance);
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:5,代码来源:HahaHelperTest.java

示例8: createCharArrayValueInstance_M_Preview2

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的package包/类
private void createCharArrayValueInstance_M_Preview2() {
  ArrayInstance valueInstance = new ArrayInstance(0, null, Type.CHAR, VALUE_ARRAY_LENGTH, 0);
  snapshot.addInstance(STRING_INSTANCE_ID + 16, valueInstance);
}
 
开发者ID:shengxiadeyu,项目名称:leakcannary,代码行数:5,代码来源:HahaHelperTest.java

示例9: isByteArray

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的package包/类
private static boolean isByteArray(Object value) {
  return value instanceof ArrayInstance && ((ArrayInstance) value).getArrayType() == Type.BYTE;
}
 
开发者ID:square,项目名称:leakcanary,代码行数:4,代码来源:HahaHelper.java

示例10: buildLeakElement

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的package包/类
private LeakTraceElement buildLeakElement(LeakNode node) {
  if (node.parent == null) {
    // Ignore any root node.
    return null;
  }
  Instance holder = node.parent.instance;

  if (holder instanceof RootObj) {
    return null;
  }
  LeakTraceElement.Type type = node.referenceType;
  String referenceName = node.referenceName;

  LeakTraceElement.Holder holderType;
  String className;
  String extra = null;
  List<String> fields = describeFields(holder);

  className = getClassName(holder);

  if (holder instanceof ClassObj) {
    holderType = CLASS;
  } else if (holder instanceof ArrayInstance) {
    holderType = ARRAY;
  } else {
    ClassObj classObj = holder.getClassObj();
    if (extendsThread(classObj)) {
      holderType = THREAD;
      String threadName = threadName(holder);
      extra = "(named '" + threadName + "')";
    } else if (className.matches(ANONYMOUS_CLASS_NAME_PATTERN)) {
      String parentClassName = classObj.getSuperClassObj().getClassName();
      if (Object.class.getName().equals(parentClassName)) {
        holderType = OBJECT;
        try {
          // This is an anonymous class implementing an interface. The API does not give access
          // to the interfaces implemented by the class. We check if it's in the class path and
          // use that instead.
          Class<?> actualClass = Class.forName(classObj.getClassName());
          Class<?>[] interfaces = actualClass.getInterfaces();
          if (interfaces.length > 0) {
            Class<?> implementedInterface = interfaces[0];
            extra = "(anonymous implementation of " + implementedInterface.getName() + ")";
          } else {
            extra = "(anonymous subclass of java.lang.Object)";
          }
        } catch (ClassNotFoundException ignored) {
        }
      } else {
        holderType = OBJECT;
        // Makes it easier to figure out which anonymous class we're looking at.
        extra = "(anonymous subclass of " + parentClassName + ")";
      }
    } else {
      holderType = OBJECT;
    }
  }
  return new LeakTraceElement(referenceName, type, holderType, className, extra, node.exclusion,
      fields);
}
 
开发者ID:square,项目名称:leakcanary,代码行数:61,代码来源:HeapAnalyzer.java

示例11: createByteArrayValueInstance

import com.squareup.haha.perflib.ArrayInstance; //导入依赖的package包/类
private void createByteArrayValueInstance() {
  ArrayInstance valueArrayInstance = new ArrayInstance(0, null, Type.BYTE, VALUE_ARRAY_LENGTH, 0);
  snapshot.addInstance(VALUE_ARRAY_INSTANCE_ID, valueArrayInstance);
}
 
开发者ID:square,项目名称:leakcanary,代码行数:5,代码来源:HahaHelperTest.java


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