Yes such a thing (kind of) exists: http://java.sun.com/javase/6/docs/api/java/lang/instrument/package-summary.html
You merely have to create a java agent jar which then gets access to this magical interface. Here is a sourceforge project: http://sourceforge.net/projects/sizeof My measurements on java 1.6 64 bits, OS X: - empty object = 16 bytes - array of bytes: byte size + 24 bytes - ByteBuffer = 56 bytes (storage separately) - object, 1 int = 24 bytes - object, 2 ints = 24 bytes - object, 1 long = 24 bytes It seems pretty obvious that java -d64 is using dword/qword (32/64 bit) alignment. Objects seem to be 64 bit aligned, but fields are not necessairly. This is from the 1 int vs 2 int = 24 byte test. This aligns with the results of Erik's HeapSize values. I dont know how much overhead a java agent has like this, so it might not be worthwhile to use except as validation/verification of our HeapSize assumptions. With the use of ByteBuffer and 0-copy we can extract good memory performance, well, except the ByteBuffer instance itself is not exactly super light weight (56 bytes?) for what is essentially a few pointers (plus control bytes, plus blah blah). So keeping the number of extraneous ByteBuffer instances low will help. -ryan
