privatestaticfinal JavaClass[] EMPTY_CLASS_ARRAY = new JavaClass[0]; // my subclasses private JavaClass[] subclasses = EMPTY_CLASS_ARRAY;
// my instances private Vector<JavaHeapObject> instances = new Vector<JavaHeapObject>();
// Who I belong to. Set on resolve. private Snapshot mySnapshot;
// Size of an instance, including VM overhead privateint instanceSize; // Total number of fields including inherited ones privateint totalNumFields;
public JavaClass(long id, String name, long superclassId, long loaderId, long signersId, long protDomainId,
JavaField[] fields, JavaStatic[] statics, int instanceSize) { this.id = id; this.name = name; this.superclass = new JavaObjectRef(superclassId); this.loader = new JavaObjectRef(loaderId); this.signers = new JavaObjectRef(signersId); this.protectionDomain = new JavaObjectRef(protDomainId); this.fields = fields; this.statics = statics; this.instanceSize = instanceSize;
}
public JavaClass(String name, long superclassId, long loaderId, long signersId, long protDomainId,
JavaField[] fields, JavaStatic[] statics, int instanceSize) { this(-1L, name, superclassId, loaderId, signersId,
protDomainId, fields, statics, instanceSize);
}
/** *Getanumberedfieldfromthisclass
*/ public JavaField getField(int i) { if (i < 0 || i >= fields.length) { thrownew Error("No field " + i + " for " + name);
} return fields[i];
}
public Enumeration<JavaHeapObject> getInstances(boolean includeSubclasses) { if (includeSubclasses) {
Enumeration<JavaHeapObject> res = instances.elements(); for (int i = 0; i < subclasses.length; i++) {
res = new CompositeEnumeration(res,
subclasses[i].getInstances(true));
} return res;
} else { return instances.elements();
}
}
/** *@returnacountoftheinstancesofthisclass
*/ publicint getInstancesCount(boolean includeSubclasses) { int result = instances.size(); if (includeSubclasses) { for (int i = 0; i < subclasses.length; i++) {
result += subclasses[i].getInstancesCount(includeSubclasses);
}
} return result;
}
public JavaClass[] getSubclasses() { return subclasses;
}
/** *Thiscanonlysafelybecalledafterresolve()
*/ public JavaThing getSigners() { return signers;
}
/** *Thiscanonlysafelybecalledafterresolve()
*/ public JavaThing getProtectionDomain() { return protectionDomain;
}
public JavaField[] getFields() { return fields;
}
/** *Includessuperclassfields
*/ public JavaField[] getFieldsForInstance() {
Vector<JavaField> v = new Vector<JavaField>();
addFields(v);
JavaField[] result = new JavaField[v.size()]; for (int i = 0; i < v.size(); i++) {
result[i] = v.elementAt(i);
} return result;
}
public JavaStatic[] getStatics() { return statics;
}
// returns value of static field of given name public JavaThing getStaticField(String name) { for (int i = 0; i < statics.length; i++) {
JavaStatic s = statics[i]; if (s.getField().getName().equals(name)) { return s.getValue();
}
} returnnull;
}
public String toString() { return"class " + name;
}
// array class and non-zero count, we have to // get the size of each instance and sum it long result = 0; for (int i = 0; i < count; i++) {
JavaThing t = (JavaThing) instances.elementAt(i);
result += t.getSize();
} return result;
}
JavaThing other;
other = getLoader(); if (other instanceof JavaHeapObject) {
v.visit((JavaHeapObject)other);
}
other = getSigners(); if (other instanceof JavaHeapObject) {
v.visit((JavaHeapObject)other);
}
other = getProtectionDomain(); if (other instanceof JavaHeapObject) {
v.visit((JavaHeapObject)other);
}
for (int i = 0; i < statics.length; i++) {
JavaField f = statics[i].getField(); if (!v.exclude(this, f) && f.hasId()) {
other = statics[i].getValue(); if (other instanceof JavaHeapObject) {
v.visit((JavaHeapObject) other);
}
}
}
}
// package-privates below this point final ReadBuffer getReadBuffer() { return mySnapshot.getReadBuffer();
}
// Internals only below this point privatevoid addFields(Vector<JavaField> v) { if (superclass != null) {
((JavaClass) superclass).addFields(v);
} for (int i = 0; i < fields.length; i++) {
v.addElement(fields[i]);
}
}
privatevoid addSubclassInstances(Vector<JavaHeapObject> v) { for (int i = 0; i < subclasses.length; i++) {
subclasses[i].addSubclassInstances(v);
} for (int i = 0; i < instances.size(); i++) {
v.addElement(instances.elementAt(i));
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.