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.
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.
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:
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.
© 2022 - 2024 — McMap. All rights reserved.
(this==this.intern())?("^"+toString()):toString()
. Can you explain what you need the tool for? Is it because you rely on equality-testing, or are you looking at memory usage, or... – Anthemion