• 请不要在回答技术问题时复制粘贴 AI 生成的内容
rizon
V2EX  ›  程序员

Java 代码中有没有打印 jvm heap 的方法,类似 idea 的 debug 工具

  •  
  •   rizon ·
    othorizon · Mar 5, 2019 · 1727 views
    This topic created in 2649 days ago, the information mentioned may be changed or developed.

    idea 的 debug 中又一个 memory 栏,可以查看断点处的 jvm heap。
    比如我想看某个对象的 count 数量。
    有没有办法在代码里也打印这个?

    1 replies    2019-03-05 15:41:02 +08:00
    c4f36e5766583218
        1
    c4f36e5766583218  
       Mar 5, 2019
    给你个 java tool 源码:
    https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/996dd3ce1ec5/src/share/classes/sun/tools/jmap/JMap.java#l221
    VirtualMachine.attach(pid)
    HotSpotVirtualMachine#heapHisto
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3020 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 06:19 · PVG 14:19 · LAX 23:19 · JFK 02:19
    ♥ Do have faith in what you're doing.