/** * this factory method creates {@link Heap} from a memory dump file in Hprof format. * If the memory dump file contains more than one dump, parameter segment is used to * select particular dump. * <br> * <b>This implementation is using temporary disk files for building auxiliary indexes</b> * <br> * Speed: slow * @return implementation of {@link Heap} corresponding to the memory dump * passed in heapDump parameter * @param segment select corresponding dump from multi-dump file * @param heapDump file which contains memory dump * @throws java.io.FileNotFoundException if heapDump file does not exist * @throws java.io.IOException if I/O error occurred while accessing heapDump file */ public static Heap createHeap(File heapDump, int segment) throws FileNotFoundException, IOException { return new HprofHeap(createBuffer(heapDump, DEFAULT_BUFFER), segment); }
public Collection<GCRoot> getGCRoots() { synchronized (gcRootLock) { if (heapDumpSegment == null) { return Collections.emptyList(); } if (gcRoots == null) { gcRoots = computeGCRootsFor(heapTagBounds[ROOT_UNKNOWN]); gcRoots.putAll(computeGCRootsFor(heapTagBounds[ROOT_JNI_GLOBAL])); gcRoots.putAll(computeGCRootsFor(heapTagBounds[ROOT_JNI_LOCAL])); gcRoots.putAll(computeGCRootsFor(heapTagBounds[ROOT_JAVA_FRAME])); gcRoots.putAll(computeGCRootsFor(heapTagBounds[ROOT_NATIVE_STACK])); gcRoots.putAll(computeGCRootsFor(heapTagBounds[ROOT_STICKY_CLASS])); gcRoots.putAll(computeGCRootsFor(heapTagBounds[ROOT_THREAD_BLOCK])); gcRoots.putAll(computeGCRootsFor(heapTagBounds[ROOT_MONITOR_USED])); gcRoots.putAll(computeGCRootsFor(heapTagBounds[ROOT_THREAD_OBJECT])); } return gcRoots.values(); } }
HprofHeap(HprofByteBuffer buffer, int seg) throws FileNotFoundException, IOException { dumpBuffer = buffer; segment = seg; fillTagBounds(dumpBuffer.getHeaderSize()); heapDumpSegment = computeHeapDumpStart(); if (heapDumpSegment != null) { fillHeapTagBounds(); } idToOffsetMap = initIdMap(); nearestGCRoot = new NearestGCRoot(this); }
public List<Instance> getBiggestObjectsByRetainedSize(int number) { long[] ids; List<Instance> bigObjects = new ArrayList<Instance>(number); computeRetainedSize(); ids = idToOffsetMap.getBiggestObjectsByRetainedSize(number); for (int i=0;i<ids.length;i++) { bigObjects.add(getInstanceByID(ids[i])); } return bigObjects; }
synchronized void computeRetainedSizeByClass() { if (retainedSizeByClassComputed) { return; } computeRetainedSize(); long[] offset = new long[] { allInstanceDumpBounds.startOffset }; while (offset[0] < allInstanceDumpBounds.endOffset) { int instanceIdOffset = 0; long start = offset[0]; int tag = readDumpTag(offset); if (tag == INSTANCE_DUMP) { instanceIdOffset = 1; } else if (tag == OBJECT_ARRAY_DUMP) { instanceIdOffset = 1; } else if (tag == PRIMITIVE_ARRAY_DUMP) { instanceIdOffset = 1; } else { continue; } long instanceId = dumpBuffer.getID(start + instanceIdOffset); Instance i = getInstanceByID(instanceId); ClassDump javaClass = (ClassDump) i.getJavaClass(); if (javaClass != null && !domTree.hasInstanceInChain(tag, i)) { javaClass.addSizeForInstance(i); } } // all done, release domTree domTree = null; retainedSizeByClassComputed = true; }
computeInstances(); ClassDumpSegment classDumpBounds = getClassDumpSegment(); int idSize = dumpBuffer.getIDSize(); int classIdOffset = 0; int tag = readDumpTag(offset);
JavaClass ref = heap.getJavaClassByName(REF_CLASSES[i]); if (ref != null) { referenceClasses.add(ref); heap.computeReferences(); // make sure references are computed first allInstances = heap.getSummary().getTotalLiveInstances(); Set<JavaClass> processedClasses = new HashSet<JavaClass>(heap.getAllClasses().size()*4/3);
List<Value> findReferencesFor(long instanceId) { assert instanceId != 0L : "InstanceID is null"; computeReferences(); Iterator<Long> refIdsIt = refIds.iterator(); int idSize = dumpBuffer.getIDSize(); ClassDumpSegment classDumpBounds = getClassDumpSegment(); long[] offset = new long[1]; int instanceIdOffset = 0; long start = offset[0]; int tag = readDumpTag(offset);
HprofHeap(File dumpFile, int seg) throws FileNotFoundException, IOException { dumpBuffer = HprofByteBuffer.createHprofByteBuffer(dumpFile); segment = seg; fillTagBounds(dumpBuffer.getHeaderSize()); heapDumpSegment = computeHeapDumpStart(); if (heapDumpSegment != null) { fillHeapTagBounds(); } idToOffsetMap = new LongMap(idMapSize,dumpBuffer.getIDSize(),dumpBuffer.getFoffsetSize()); nearestGCRoot = new NearestGCRoot(this); }
List<Value> getReferences() { return getHprof().findReferencesFor(getJavaClassId()); }
public int getInstancesCount() { if (instances == 0) { getHprof().computeInstances(); } return instances; }
public long getRetainedSizeByClass() { getHprof().computeRetainedSizeByClass(); return retainedSizeByClass; }
long getRetainedSize(Instance instance) { computeRetainedSize(); return idToOffsetMap.get(instance.getInstanceId()).getRetainedSize(); }
ClassDumpSegment classDumpBounds = getClassDumpSegment(); int idSize = dumpBuffer.getIDSize(); long[] offset = new long[] { allInstanceDumpBounds.startOffset }; Map<Long, JavaClass> classIdToClassMap = classDumpBounds.getClassIdToClassMap(); computeInstances(); for (long counter=0; offset[0] < allInstanceDumpBounds.endOffset; counter++) { long start = offset[0]; int tag = readDumpTag(offset); Iterator<JavaClass> classesIt = getClassDumpSegment().createClassCollection().iterator();
JavaClass ref = heap.getJavaClassByName(REF_CLASSES[i]); if (ref != null) { referenceClasses.add(ref); heap.computeReferences(); // make sure references are computed first allInstances = heap.getSummary().getTotalLiveInstances(); Set processedClasses = new HashSet(heap.getAllClasses().size()*4/3);
synchronized void computeRetainedSizeByClass() { if (retainedSizeByClassComputed) { return; } computeRetainedSize(); long[] offset = new long[] { allInstanceDumpBounds.startOffset }; while (offset[0] < allInstanceDumpBounds.endOffset) { int instanceIdOffset = 0; long start = offset[0]; int tag = readDumpTag(offset); if (tag == INSTANCE_DUMP) { instanceIdOffset = 1; } else if (tag == OBJECT_ARRAY_DUMP) { instanceIdOffset = 1; } else if (tag == PRIMITIVE_ARRAY_DUMP) { instanceIdOffset = 1; } else { continue; } long instanceId = dumpBuffer.getID(start + instanceIdOffset); Instance i = getInstanceByID(instanceId); ClassDump javaClass = (ClassDump) i.getJavaClass(); if (javaClass != null && !domTree.hasInstanceInChain(tag, i)) { javaClass.addSizeForInstance(i); } } // all done, release domTree domTree = null; retainedSizeByClassComputed = true; }
List findReferencesFor(long instanceId) { assert instanceId != 0L : "InstanceID is null"; computeReferences(); Iterator refIdsIt = refIds.iterator(); int idSize = dumpBuffer.getIDSize(); ClassDumpSegment classDumpBounds = getClassDumpSegment(); long[] offset = new long[1]; int instanceIdOffset = 0; long start = offset[0]; int tag = readDumpTag(offset);
public List getBiggestObjectsByRetainedSize(int number) { long[] ids; List bigObjects = new ArrayList(number); computeRetainedSize(); ids = idToOffsetMap.getBiggestObjectsByRetainedSize(number); for (int i=0;i<ids.length;i++) { bigObjects.add(getInstanceByID(ids[i])); } return bigObjects; }
public List<Value> getReferences() { return getHprof().findReferencesFor(getInstanceId()); }
public int getInstancesCount() { if (instances == 0) { getHprof().computeInstances(); } return instances; }