Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which debugging tool can list strings internalized?

I am looking to a debugging tool that can list the strings that have been internalized? Ideally, I would like to put a mark and have a list of the strings that been added after that mark.

Thanks in advance.

like image 688
Guillaume Coté Avatar asked May 30 '11 19:05

Guillaume Coté


2 Answers

Perhaps the easiest way is to use a bytecode viewer. Any String that is interned will be present in the constant_pool of the class file the String literal is included in. For instance, on a recent class file from another StackOverflow question I answered, I had the following String literal in my code: "sun.awt.noerasebackground". This shows up in the constant pool as a 'String_info' type. The bytecode viewer (and editor, so beware!) that I use is the JBE. JBE Download

like image 138
Josh Avatar answered Nov 03 '22 00:11

Josh


On recent Hotspot VM, interned strings look just like any other - the only difference is that the underlying char array is being tracked by the VM (I thought that it has an extra JNI reference, but it does not show on YourKit dump - will be interesting to investigate).

That said, Yourkit provides a memory inspection for duplicated strings, which I believe does what you need. If you combine it with 'Trace Allocations', you can get straight to the code that allocated these strings.

See http://www.yourkit.com/docs/95/help/inspections_mem.jsp#duplicate_strings

--

Getting list of strings added between two points in time is easier:

  1. Get two heap-dumps using jmap or your favorite profiler
  2. Do a diff of the heaps
  3. Show all instances of the String class

Should be doable with any profiler or even jhat (if you are patient enough). If you use YourKit, you can use the bookmark feature and take only one heap snapshot.

like image 25
ddimitrov Avatar answered Nov 03 '22 00:11

ddimitrov