Which debugging tool can list strings internalized?

本小妞迷上赌 提交于 2019-11-29 09:09:49

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!