当前位置:首页 > java > 正文内容

java 对象内存分析工具 jmap

root2年前 (2021-12-30)java638

jmap — 打印指定进程的共享对象内存映射或堆内存细节

jmap 命令可以获得运行中的jvm的堆的快照,从而可以离线分析堆,以检查内存泄漏,检查一些严重影响性能的大对象的创建,检查系统中什么对象最多,各种对象所占内存的大小等等。可以使用jmap生成Heap Dump


java memory = direct memory(直接内存) + jvm memory(MaxPermSize +Xmx)


命令简介

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

重要参数说明

  • -heap:打印jvm heap的情况

  • -histo:打印jvm heap的直方图。其输出信息包括类名,对象数量,对象占用大小。

  • -histo:live :同上,但是只答应存活对象的情况

  • -permstat:打印permanent generation heap情况



具体使用

首先查询出一个java 运行的程序 的pid

如下pid 15665

image.png

查看对象内存情况

jmap -histo  15665

image.png


排序查询

jmap -histo:live  15665

 还可以过滤

jmap -histo:live  15665 |grep ArrayList


查询出来的信息比较多,重定向到文件中

jmap -histo:live  15665 |grep ArrayList > a.log


原文

扫描二维码推送至手机访问。

版权声明:本文由一叶知秋发布,如需转载请注明出处。

本文链接:https://zhiqiu.top/?id=194

分享给朋友:

相关文章

java springboot @ApiModelProperty用法

@ApiModelProperty()用于方法,字段; 表示对model属性的说明或者数据操作更改 value–字段说明 name–重写属性名字 dataType–重写属性类型 required–是否...

spring程序开发步骤

1、导入Spring开发的基本包坐标2、编写Dao接口和实现类3、创建Spring核心配置文件4、在Spring配置文件中配置xxDaoImpl5、使用Spring的API获取Bean实例...

pom.xml文件的标签含义

<?xml version="1.0" encoding="UTF-8"?>声明xml的版本<project xmlns="http://maven.apache.org/...

linux wget 下载java、maven

下载jdkwget  --no-cookies --no-check-certificate \ --header "Cookie: gpw_e24=http%3A%2...

类内方法的引用

在类的内部想要引用该类的其他方法,直接this.方法。main函数想要执行方法需要先实例该类...

java-Springboot的几个重要注解@controller、@service、 @repository、@component

1、@controller 控制器(注入服务)用于标注控制层,相当于struts中的action层2、@service 服务(注入dao)用于标注服务层,主要用来进行业务的逻辑处理3、@repository(实现dao访问)用于标注数据访问...