jmap使用方法及原理

火山方舟向量数据库大模型
  1. jmap常用命令

在cmd或者shell窗口输入jmap -h,输出如下结果:


        
Usage:  
    jmap [option] <pid>  
        (to connect to running process)  
    jmap [option] <executable <core>  
        (to connect to a core file)  
    jmap [option] [server_id@]<remote server IP or hostname>  
        (to connect to remote debug server)  
  
where <option> is one of:  
    <none>               to print same info as Solaris pmap  
    -heap                to print java heap summary  
    -histo[:live]        to print histogram of java object heap; if the "live"  
                         suboption is specified, only count live objects  
    -clstats             to print class loader statistics  
    -finalizerinfo       to print information on objects awaiting finalization  
    -dump:<dump-options> to dump java heap in hprof binary format  
                         dump-options:  
                           live         dump only live objects; if not specified,  
                                        all objects in the heap are dumped.  
                           format=b     binary format  
                           file=<file>  dump heap to <file>  
                         Example: jmap -dump:live,format=b,file=heap.bin <pid>  
    -F                   force. Use with -dump:<dump-options> <pid> or -histo  
                         to force a heap dump or histogram when <pid> does not  
                         respond. The "live" suboption is not supported  
                         in this mode.  
    -h | -help           to print this help message  
    -J<flag>             to pass <flag> directly to the runtime system  

    

1. jmap -heap

查看java堆的信息以及垃圾回收算法等

picture.image

可以看到堆的分代情况以及各区域的使用情况,垃圾收集器使用的是Parallel GC与java -XX:+PrintCommandLineFlags -version得到的结果一致:

picture.image

2. jmap -histo[:live]

打印当前java堆中所有对象的实例数和大小等,加了live选项则只打印存活的对象

picture.image

3. jmap -clstas

打印class loader的统计信息

4. jmap -finalizerinfo

打印在等待执行finalize方法的对象

5. jmap -dump:

dump-options主要有:

  • live 只dump存活的对象,如果不加则会dump所有对象
  • format=b 表示以二进制格式
  • file=filepath 输出到某个文件中

把java堆中的对象dump到本地文件,然后使用第三方工具进行分析,如MAT,JProfile,IBM的分析工具等

6. jmap -F

与-dump 和-histo一起使用,强制执行后者 jmap -F -dump:live,format=b,file=heap.bin

  1. 与jvm通信方式attach机制

attach 就是jvm提供一种jvm进程间通信的能力,能让一个进程传命令给另外一个进程,并让它执行内部的一些操作:

  1. jmap操作所使用的attach机制

  • -dump和-histo[:live] 默认使用的是VirtualMachine.attach
  • -pmap 、-heap、-heap:format=b、-clstats、-finalizerinfo、-J默认使用的是SA
  • -F可以把默认使用VirtualMachine.attach的方式改成SA attach方式

参考文档: [1]:https://www.jianshu.com/p/542e50edc8e3[2]:[https://mp.weixin.qq.com/s?\_\_biz=MzIzNjI1ODc2OA==∣=2650886799&idx=1&sn=108c5fdfcd2695594d4f80ff02fc9a70&mpshare=1&scene=21&srcid=0114WsKpUmDXhRtqy8x7JX5w#wechat\_redirect](https://mp.weixin.qq.com/s?__biz=MzIzNjI1ODc2OA==&mid=2650886799&idx=1&sn=108c5fdfcd2695594d4f80ff02fc9a70&mpshare=1&scene=21&srcid=0114WsKpUmDXhRtqy8x7JX5w#wechat_redirect) [3]:http://lovestblog.cn/blog/2014/06/18/jvm-attach/[4]:https://blog.csdn.net/kisimple/article/details/46496721[5]:http://openjdk.java.net/groups/hotspot/docs/Serviceability.html?spm=a2c4e.11153940.blogcont20231.40.3b423a04qaT68H#bsa

0
0
0
0
关于作者
关于作者

文章

0

获赞

0

收藏

0

相关资源
基于 ByteHouse 引擎的增强型数据导入技术实践
ByteHouse 基于自研 HaMergeTree,构建增强型物化 MySQL、HaKafka 引擎,实现数据快速集成,加速业务数据分析性能与效率,本次 talk 主要介绍物化 MySQL 与 HaKafka 数据导入方案和业务实践。
相关产品
评论
未登录
看完啦,登录分享一下感受吧~
暂无评论