return null; if (!"java.lang.String".equals(obj.getJavaClass().getName())) { throw new IllegalArgumentException("Is not a string: " + obj.getInstanceId() + " (" + obj.getJavaClass().getName() + ")"); for(FieldValue f: obj.getFieldValues()) { Field ff = f.getField(); if ("value".equals(ff.getName())) {
static String getString(Instance stringInstance) { if (stringInstance == null) { return "*null*"; // NOI18N } String className = stringInstance.getJavaClass().getName(); if (String.class.getName().equals(className)) { PrimitiveArrayDump chars = (PrimitiveArrayDump) stringInstance.getValueOfField("value"); // NOI18N if (chars != null) { Integer offset = (Integer) stringInstance.getValueOfField("offset"); // NOI18N Integer len = (Integer) stringInstance.getValueOfField("count"); // NOI18N if (offset == null) { offset = Integer.valueOf(0); } if (len == null) { len = new Integer(chars.getLength()); } char[] charArr = chars.getChars(offset.intValue(), len.intValue()); return new String(charArr).intern(); } return "*null*"; // NOI18N } // what? Non-string in system properties? return "*"+className+"#"+stringInstance.getInstanceNumber()+"*"; // NOI18N } }
void addSizeForInstance(Instance i) { retainedSizeByClass+=i.getRetainedSize(); }
@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() + ")"); } }
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()); } } }
String printInstance(Long instanceid) { if (instanceid == null || instanceid.longValue() == 0) { return "null"; } Instance ii = heap.getInstanceByID(instanceid.longValue()); return ii.getJavaClass().getName()+"#"+ii.getInstanceNumber(); }
public void collect(Heap heap, InstanceCallback callback) { JavaClass string = heap.getJavaClassByName("java.lang.String"); 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())) { arrays.set(((ObjectFieldValue)fv).getInstanceId(), true); totalSize += i.getSize(); Instance s = heap.getInstanceByID(id); if (s != null) { totalSize += s.getSize();
continue; } else if (instance instanceof PrimitiveArrayInstance) { assert false:"Error - PrimitiveArrayInstance not allowed "+instance.getJavaClass().getName()+"#"+instance.getInstanceNumber(); continue; } else if (instance instanceof ClassDumpInstance) { fieldValues = instance.getFieldValues(); } else { if (instance == null) {
writeLeaf(instanceId,instance.getSize()); writeLeaf(instanceId,instance.getSize()); continue; } else if (instance instanceof ClassDumpInstance) { fieldValues = instance.getFieldValues(); } else { if (instance == null) { if (writeClassConnection(processedClasses, instanceId, instance.getJavaClass())) { hasValues = true; writeLeaf(instanceId,instance.getSize());
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)); } } } } } }
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(); }
@Override public void onPath(Instance root, String path, Instance shared) { System.err.println("DEEP REF: " + root.getInstanceId() + " " + HeapWalker.explainPath(root, path)); } }
if (lastStep != null) { String fname = lastStep.getFieldName(); for(FieldValue fv: i.getFieldValues()) { if ((fname == null && fv.getField().isStatic()) || (fname.equals(fv.getField().getName()))) { obj = i.getValueOfField(fv.getField().getName());
void seek() { while(nested.hasNext()) { Instance n = nested.next(); if (n.getJavaClass() == type) { instance = n; return; } } instance = null; }
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; }
private boolean checkReferences(final long refInstanceId, final long instanceId) { Instance instance = heap.getInstanceByID(instanceId); Iterator<FieldValue> fieldIt = instance.getFieldValues().iterator(); while (fieldIt.hasNext()) { Object field = fieldIt.next(); if (field instanceof HprofInstanceObjectValue) { HprofInstanceObjectValue objectValue = (HprofInstanceObjectValue) field; if (objectValue.getInstanceId() == refInstanceId) { return true; } } } return false; }
@Override public Iterator<Instance> walk(Instance instance) { Object t = instance.getValueOfField("table"); if (t instanceof ObjectArrayInstance) { return new InstanceIterator(".table", (ObjectArrayInstance) t); } else { return Collections.<Instance>emptySet().iterator(); } }
void add(Instance i) { ++instanceCount; totalSize += i.getSize(); }
private void printObjs(List<Long> changedIds, List<Long> oldDomIds, List<Long> newDomIds, List<Boolean> addedByDirtySet, List<Long> changedIdx) { if (changedIds.size()>20) return; TreeMap<Integer,String> m = new TreeMap(); for (int i=0; i<changedIds.size(); i++) { Long iid = changedIds.get(i); Long oldDom = oldDomIds.get(i); Long newDom = newDomIds.get(i); Long index = changedIdx.get(i); Boolean addedByDirt = addedByDirtySet.get(i); Instance ii = heap.getInstanceByID(iid.longValue()); int number = ii.getInstanceNumber(); String text = "Index: "+index+(addedByDirt?" New ":" Old ")+printInstance(iid); text+=" OldDom "+printInstance(oldDom); text+=" NewDom: "+printInstance(newDom); m.put(number,text); } for (Integer in : m.keySet()) { System.out.println(m.get(in)); } }
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); }