Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access the value of a StringBuilder in a heap dump in VisualVM

I am willing to write the value of a large StringBuilder with index 827 to disk. I am trying to do that using the following OQL:

map(heap.objects('java.lang.StringBuilder'),
 function(it, index) {
  if (index == 827.0) {
      var writer = new java.io.FileWriter("/Users/username/output/sb_0x" + it.id.toString(16) + ".txt");
      var chars = it.value;
      for (var i = 0; i < chars.length; i++) {
          writer.write(chars[i]);
      }
      writer.close();
  }
  return index;
})

However, nothing gets written. I now that the builder exists, since I have inspected it:

All StringBuilder objects

It seems that the result gets truncated after the builder with index 99 (i.e. it works for 99, but doesn't work for 100):

Truncated after 100

Any suggestions how can I get the value of the StringBuilder with id 827?

like image 400
Ivaylo Toskov Avatar asked Jan 26 '26 12:01

Ivaylo Toskov


1 Answers

You can use the following query:

filter(heap.objects('java.lang.StringBuilder'),
 function(it, index) {
  if (index == 827.0) {
      var writer = new java.io.FileWriter("/Users/username/output/sb_0x" + it.id.toString(16) + ".txt");
      var chars = it.value;
      for (var i = 0; i < chars.length; i++) {
          writer.write(chars[i]);
      }
      writer.close();
      return true;
  }
  return false;
})
like image 56
Tomas Hurka Avatar answered Jan 29 '26 02:01

Tomas Hurka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!