Skip to content

Instantly share code, notes, and snippets.

@Nessiesson
Created April 5, 2020 20:49
Show Gist options
  • Save Nessiesson/8eb5c5661e5f705ea8bce135abfd9616 to your computer and use it in GitHub Desktop.
Save Nessiesson/8eb5c5661e5f705ea8bce135abfd9616 to your computer and use it in GitHub Desktop.
Address locator for MSPT in MC1.12.2
// https://bitbucket.org/ekabanov/mat/
public class Main {
@SuppressWarnings("DuplicatedCode")
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.out.println("Please supply heap dump file");
System.exit(1);
}
IProgressListener listener = new VoidProgressListener();
SnapshotFactory sf = new SnapshotFactory();
ISnapshot snapshot = sf.openSnapshot(new File(args[0]), new HashMap<String, String>(), listener);
Collection<IClass> test = snapshot.getClassesByName("nz", true);
for (IClass clazz : test) {
IObject o = snapshot.getObject(clazz.getObjectIds()[0]);
ObjectReference hRef = (ObjectReference) ((IInstance) o).getField("h").getValue();
IObject hObj = snapshot.getObject(hRef.getObjectId());
System.out.println(hObj.getObjectAddress());
/*long[] h = (long[]) ((IPrimitiveArray) hObj).getValueArray();
double MSPT = average(h) * 1.0E-6D;
double TPS = 1000.0D / Math.max(50, MSPT);
System.out.printf("%.4f %.2f\n", MSPT, TPS);*/
}
}
public static double average(long[] values) {
long i = 0L;
for (long j : values) {
i += j;
}
return (double) i / (double) values.length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment