I have a Java heap dump that I'm analyzing, looking for high consumers of memory. More than 50% of the memory in the dump is in use by two StringBuffers, each of which holds a char[] which (naturally) accounts for most of the memory in the respective StringBuffer. However, when I inspect the char[] in the instance viewer the contents are elided, I think because the strings are so large. I've also tried using .toString()
in VisualVM's OQL, but that apparently only works on String objects.
Is there any way to figure out what the contents of those arrays is?
You can try to write the contents of the internal char arrays of all the StringBuffer
instances to disk using the following OQL:
map(heap.objects('java.lang.StringBuffer'),
function(it, index) {
var writer = new java.io.FileWriter("c:/temp/oql/stringbuffer_0x" + it.id.toString(16) + ".txt");
var chars = it.value;
for (var i=0; i<chars.length; i++) {
writer.write(chars[i]);
}
writer.close();
})