3

I was studying and reading about Java String pool and I did some examples to understand this feature, but I have a doubt: Is possible, is there a way to access or see the content of the string pool?

Robert
  • 10,403
  • 14
  • 67
  • 117
  • I think all you can get out of it is statistics (`-XX:+PrintStringTableStatistics`), not the actual content. – biziclop Apr 26 '15 at 22:34
  • You can ask a specific question about your doubt too. – biziclop Apr 26 '15 at 22:36
  • Chances are very high that you can't; such a pool, if it exists at all, is an implementation detail of the JVM, therefore it is highly unlikely that an API exists to access it. – fge Apr 26 '15 at 22:36
  • 1
    @fge Just because it's an implementation detail, it doesn't mean you can't access it using diagnostic tools, just look at the things Java Flight Recorder does. – biziclop Apr 26 '15 at 22:38
  • If you are using openJDK/hotspot JVM, than there is much easier solution, than replacing rt.jar with hook for strings (which also is incorrect). You can use Serviceability Agent, which is VM-specific (and that's exactly how Flight Recorder works). If someone will re-open answer I can show the actual code for attaching to jvm and printing string pool's content – qwwdfsad Apr 26 '15 at 23:02
  • That will be nice, because the answers in the other questions are not accepted and also they don't answer my question? thanks @qwwdfsad – Robert Apr 26 '15 at 23:06
  • You can try to flag the question for moderator attention – qwwdfsad Apr 26 '15 at 23:12
  • 1
    Yes it is possible if you run Oracle JDK / OpenJDK. [ServiceabilityAgent](http://openjdk.java.net/groups/hotspot/docs/Serviceability.html#bsa) can do this. See [example](https://github.com/odnoklassniki/jvm-serviceability-examples/blob/master/src/demo3/InternedStrings.java). – apangin Apr 26 '15 at 23:21

0 Answers0