@Override public void onPath(Instance root, String path, Instance shared) { System.err.println("DEEP REF: " + root.getInstanceId() + " " + HeapWalker.explainPath(root, path)); } }
public boolean containsInstance(Instance i) { return strings.get(i.getInstanceId()) || arrays.get(i.getInstanceId()); } }
public GCRoot getGCRoot(Instance instance) { Long instanceId = Long.valueOf(instance.getInstanceId()); return getGCRoot(instanceId); }
private void report(Instance i, String name, long instanceId) { marked.set(i.getInstanceId(), true); inbound.set(i.getInstanceId(), true); if (gcRoots.get(i.getInstanceId())) { System.out.println("#" + instanceId + " <- #" + i.getInstanceId() + name + " " + i.getJavaClass().getName() + " (GCRoot)"); } else { System.out.println("#" + instanceId + " <- #" + i.getInstanceId() + name + " " + i.getJavaClass().getName()); } } }
private void updateAdditionalIds(final long instanceId, final List<Long> additionalIds) { Instance i = heap.getInstanceByID(instanceId); //System.out.println("Inspecting "+printInstance(instanceIdObj)); if (i != null) { for (Object v : i.getFieldValues()) { if (v instanceof ObjectFieldValue) { Instance val = ((ObjectFieldValue)v).getInstance(); if (val != null) { long idp = val.getInstanceId(); Long idO = new Long(idp); Long idomO = map.get(idO); if (idomO != null && idomO.longValue() != 0) { additionalIds.add(idO); //System.out.println(" Adding "+printInstance(idO)); } } } } } }
@SuppressWarnings("unchecked") public static <T> T primitiveValue(Instance obj) { if (obj == null) { return null; } String className = obj.getJavaClass().getName(); if (BOX_TYPES.contains(className)) { return (T)obj.getValueOfField("value"); } else { throw new IllegalArgumentException("Is not a primitive wrapper: " + obj.getInstanceId() + " (" + obj.getJavaClass().getName() + ")"); } }
long getRetainedSize(Instance instance) { computeRetainedSize(); return idToOffsetMap.get(instance.getInstanceId()).getRetainedSize(); }
public static String stringValue(Instance obj) { if (obj == null) return null; if (!"java.lang.String".equals(obj.getJavaClass().getName())) throw new IllegalArgumentException("Is not a string: " + obj.getInstanceId() + " (" + obj.getJavaClass().getName() + ")"); Boolean COMPACT_STRINGS = (Boolean) obj.getJavaClass().getValueOfStaticField("COMPACT_STRINGS"); if (COMPACT_STRINGS == null) return stringValue_java8(obj); // We're pre Java 9 Object valueInstance = obj.getValueOfField("value"); PrimitiveArrayInstance chars = (PrimitiveArrayInstance) valueInstance; byte UTF16 = 1; byte coder = COMPACT_STRINGS ? (Byte) obj.getValueOfField("coder") : UTF16; int len = chars.getLength() >> coder; char[] text = new char[len]; List<String> values = (List) chars.getValues(); if (coder == UTF16) for (int i = 0; i < text.length; i++) { text[i] = (char) ((Integer.parseInt(values.get(i*2+1)) << 8) | (Integer.parseInt(values.get(i*2)) & 0xFF)); } else for (int i = 0; i < text.length; i++) text[i] = (char) Integer.parseInt(values.get(i)); return new String(text); }
throw new IllegalArgumentException("Is not a primitive array: " + obj.getInstanceId() + " (" + obj.getJavaClass().getName() + ")"); throw new IllegalArgumentException("Is not a primitive array: " + obj.getInstanceId() + " (" + obj.getJavaClass().getName() + ")");
public void accumulate(Instance i) { if (known != null) { if (known.getAndSet(i.getInstanceId(), true)) { // already accumulated return; } } total.add(i); String cn = i.getJavaClass().getName(); ClassRecord cr = classes.get(cn); if (cr == null) { cr = new ClassRecord(cn); classes.put(cn, cr); } ++cr.instanceCount; cr.totalSize += i.getSize(); }
instanceId = i.getInstanceId(); idom = getIdomId(instanceId); for (;idom!=0;idom=getIdomId(idom)) {
private long checkInstance(long instanceId, Instance refInstance) throws IOException { if (refInstance != null) { LongMap.Entry refEntry = heap.idToOffsetMap.get(refInstance.getInstanceId()); if (!refEntry.hasOnlyOneReference()) { return -1; } if (!refEntry.isTreeObj()) { return -1; } return refEntry.getRetainedSize(); } return 0; } }
Instance getNearestGCRootPointer(Instance instance) { if (heap.getGCRoot(instance) != null) { return instance; } computeGCRoots(); long nextGCPathId = heap.idToOffsetMap.get(instance.getInstanceId()).getNearestGCRootPointer(); return heap.getInstanceByID(nextGCPathId); }
throw new IllegalArgumentException("Is not a string: " + obj.getInstanceId() + " (" + obj.getJavaClass().getName() + ")");
private boolean processInstance(Instance instance, long size, long retainedSize) throws IOException { if (size != -1) { LongMap.Entry entry = heap.idToOffsetMap.get(instance.getInstanceId()); entry.setRetainedSize((int)(instance.getSize()+retainedSize)); entry.setTreeObj(); if (entry.hasOnlyOneReference()) { long gcRootPointer = entry.getNearestGCRootPointer(); if (gcRootPointer != 0) { if (!unique.contains(gcRootPointer)) { unique.add(gcRootPointer); writeLong(gcRootPointer); } } } return true; } return false; }
public void report() { for(Instance i: heap.getAllInstances()) { if (marked.get(i.getInstanceId())) { continue; try { Instance ii = heap.getInstanceByID(n); if (ii != null && ii.getInstanceId() != 0) { if (target.get(ii.getInstanceId())) { report(i, "[]", ii.getInstanceId()); break;
return; if (ignoreRefs.get(i.getInstanceId())) { return; ignoreRefs.set(i.getInstanceId(), true); return; if (details.objects.getAndSet(i.getInstanceId(), true)) { return; String type = i.getJavaClass().getName(); if (!accountShared || sharedRefs.get(i.getInstanceId())) { details.summary.accumulate(i); if (sharedRefs.get(i.getInstanceId())) { if (sharedPathListener != null) { sharedPathListener.onPath(details.root, path.toString(), i);
public void initRoots() { for(JavaClass jc: heap.getAllClasses()) { for(FieldValue fv: jc.getStaticFieldValues()) { if (fv instanceof ObjectFieldValue) { gcRoots.set(((ObjectFieldValue) fv).getInstanceId(), true); } } } for(GCRoot gcr: heap.getGCRoots()) { try { gcRoots.set(gcr.getInstance().getInstanceId(), true); } catch(IllegalInstanceIDException e) { // ignore } } }
for(Instance i : heap.getAllInstances()) { if (i.getJavaClass() == string) { strings.set(i.getInstanceId(), true); for(FieldValue fv: i.getFieldValues()) { if ("value".equals(fv.getField().getName())) {
protected void widthWalk(Cluster details, Instance root, boolean accountShared) { RefSet queue = new RefSet(); queue.set(root.getInstanceId(), true); @SuppressWarnings("unused") long count = 0; String type = i.getJavaClass().getName(); if (!accountShared || sharedRefs.get(i.getInstanceId())) { details.summary.accumulate(i);