• <i id='kB7cx'><tr id='kB7cx'><dt id='kB7cx'><q id='kB7cx'><span id='kB7cx'><b id='kB7cx'><form id='kB7cx'><ins id='kB7cx'></ins><ul id='kB7cx'></ul><sub id='kB7cx'></sub></form><legend id='kB7cx'></legend><bdo id='kB7cx'><pre id='kB7cx'><center id='kB7cx'></center></pre></bdo></b><th id='kB7cx'></th></span></q></dt></tr></i><div id='kB7cx'><tfoot id='kB7cx'></tfoot><dl id='kB7cx'><fieldset id='kB7cx'></fieldset></dl></div>
    <legend id='kB7cx'><style id='kB7cx'><dir id='kB7cx'><q id='kB7cx'></q></dir></style></legend>

  • <tfoot id='kB7cx'></tfoot>
    1. <small id='kB7cx'></small><noframes id='kB7cx'>

          <bdo id='kB7cx'></bdo><ul id='kB7cx'></ul>

        是否有一种简单的方法可以在 Java 中获取特定类的所有对象实例

        时间:2023-08-25
      1. <i id='RnVJT'><tr id='RnVJT'><dt id='RnVJT'><q id='RnVJT'><span id='RnVJT'><b id='RnVJT'><form id='RnVJT'><ins id='RnVJT'></ins><ul id='RnVJT'></ul><sub id='RnVJT'></sub></form><legend id='RnVJT'></legend><bdo id='RnVJT'><pre id='RnVJT'><center id='RnVJT'></center></pre></bdo></b><th id='RnVJT'></th></span></q></dt></tr></i><div id='RnVJT'><tfoot id='RnVJT'></tfoot><dl id='RnVJT'><fieldset id='RnVJT'></fieldset></dl></div>
      2. <small id='RnVJT'></small><noframes id='RnVJT'>

        <legend id='RnVJT'><style id='RnVJT'><dir id='RnVJT'><q id='RnVJT'></q></dir></style></legend>
        • <bdo id='RnVJT'></bdo><ul id='RnVJT'></ul>

                <tbody id='RnVJT'></tbody>

              <tfoot id='RnVJT'></tfoot>

                  本文介绍了是否有一种简单的方法可以在 Java 中获取特定类的所有对象实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  目前我正在开发一个 Java 代理来组装内存统计信息.借助 instrumentation API 我可以掌握这些类(并操纵它们).使用纯 Java,我可以估计每个对象使用的资源.到目前为止,一切顺利.

                  Currently I am working on a Java agent to assemble memory stats. With the help of the instrumentation API I can get a hold of the classes (and manipulate them). With plain Java I can get an estimate of the resources used for each object. So far, so good.

                  我现在面临的问题是如何获取特定类的每个 Object 实例".我可以进行字节码操作以获取对象实例,但我希望有另一个我不知道的 API,帮助我在没有如此繁重的侵入步骤的情况下完成我的目标.最后,应将性能影响降至最低.有什么想法吗?

                  The question I am faced with right now is "how to get a hold of every Object instance of a specific class". I can do byte code manipulation in order to get a hold of the object instance, but I was hoping there is another API I am not aware of, helping me to accomplish my goal without such a rather heavy intrusive step. At the end, the performance impact should be kept to a minimum. Any ideas?

                  推荐答案

                  Eclipse中的调试器可以向您展示一个类的所有实例,所以我查看了 Eclipse 的源代码.Eclipse 使用 Java Debug Wire Protocol,它允许您(从 Java 6 开始)查找所请求类的所有实例.如果您想走这条路,请获取 Eclipse 源代码的副本并查看 org.eclipse.jdi.internal.ReferenceTypeImplinstances 方法.

                  The debugger in Eclipse can show you all the instances of a class, so I looked around Eclipse's sources. Eclipse uses the Java Debug Wire Protocol, which allows you (since Java 6) to look up all the instances of the requested class. If you want to go down this path, grab a copy of Eclipse sources and check out the instances method of org.eclipse.jdi.internal.ReferenceTypeImpl.

                  更简单的方法是使用 Java调试接口.注意 ReferenceType.instances 方法.

                  A simpler way is to use the Java Debug Interface. Note the ReferenceType.instances method.

                  我还没有弄清楚如何使用 JDI 连接到正在运行的进程以及如何获取 ReferenceType 的实例.JDK 包含几个 examples,所以我我确定这是可行的.

                  I still haven't figured out how to use JDI to connect to a running process and how to obtain an instance of ReferenceType. The JDK contains several examples, so I'm sure it's doable.

                  这篇关于是否有一种简单的方法可以在 Java 中获取特定类的所有对象实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:JVM 什么时候使用内部函数 下一篇:如何使 JVM 崩溃?

                  相关文章

                    <i id='SAaR4'><tr id='SAaR4'><dt id='SAaR4'><q id='SAaR4'><span id='SAaR4'><b id='SAaR4'><form id='SAaR4'><ins id='SAaR4'></ins><ul id='SAaR4'></ul><sub id='SAaR4'></sub></form><legend id='SAaR4'></legend><bdo id='SAaR4'><pre id='SAaR4'><center id='SAaR4'></center></pre></bdo></b><th id='SAaR4'></th></span></q></dt></tr></i><div id='SAaR4'><tfoot id='SAaR4'></tfoot><dl id='SAaR4'><fieldset id='SAaR4'></fieldset></dl></div>

                    • <bdo id='SAaR4'></bdo><ul id='SAaR4'></ul>
                    <legend id='SAaR4'><style id='SAaR4'><dir id='SAaR4'><q id='SAaR4'></q></dir></style></legend><tfoot id='SAaR4'></tfoot>

                    <small id='SAaR4'></small><noframes id='SAaR4'>