如何列出在 jvm 中内化的字符串?
可能的重复:
Java - 判断字符串是否被实习?
我想要已被 jvm 内部化的字符串列表,要么因为它们是文字,要么因为方法 实习生 被称为在他们身上。我怎样才能生成它?
Possible Duplicate:
Java - tell if a String is interned?
I would like to have a list of the string that have been internalized by a jvm, either because they are literal are because the method intern as been called on them. How can I generate it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以获得所有驻留字符串的总大小:
You can get the total size of all interned strings as:
你不能在正在运行的程序中。没有用于迭代实习字符串池的 API。
理论上您可以通过调试代理来完成此操作。它将涉及:
String
实例。str == str.intern()
。然而,这个过程会很昂贵,并且会因为大量不必要的字符串而污染字符串池(永久堆)。此外,这仅在调试代理停止所有应用程序线程时才有效,因此应用程序无法使用此方法来检查其自己的字符串池。
You can't within a running program. There is no API for iterating the intern'd string pool.
You could in theory do it via a debug agent. It would involve:
String
instances.str == str.intern()
.However, this process is going to be expensive, and is going to pollute the string pool (the permgen heap) with lots of Strings that have been interned unnecessarily. Besides, this only works when all application threads have been stopped by the debug agent, so an application can't use this approach to examine its own string pool.