/**
* Attempts to dump physical object's memory as a string.
*/
public static String objectMemoryAsString(Object o) {
final Unsafe unsafe = getUnsafe();
final ByteOrder byteOrder = ByteOrder.nativeOrder();
StringBuilder b = new StringBuilder();
final int obSize = (int) RamUsageEstimator.shallowSizeOf(o);
for (int i = 0; i < obSize; i += 2) {
if ((i & 0xf) == 0) {
if (i > 0) b.append("\n");
b.append(String.format(Locale.ENGLISH, "%#06x", i));
}
// we go short by short because J9 fails on odd addresses (everything is aligned,
// including byte fields.
int shortValue = unsafe.getShort(o, (long) i);
if (byteOrder == ByteOrder.BIG_ENDIAN) {
b.append(String.format(Locale.ENGLISH, " %02x", (shortValue >>> 8) & 0xff));
b.append(String.format(Locale.ENGLISH, " %02x", (shortValue & 0xff)));
} else {