jmap 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

jmap 命令安装:


-bash/zsh: jmap command not found

# Windows (WSL2)
sudo apt-get update sudo apt-get install openjdk-12-jdk-headless

# Debian
apt-get install openjdk-12-jdk-headless

# Ubuntu
apt-get install openjdk-12-jdk-headless

# Arch Linux
pacman -S java-environment-common

# Kali Linux
apt-get install openjdk-11-jdk-headless

# Fedora
dnf install java-9-openjdk-devel-debug-1

# Raspbian
apt-get install openjdk-8-jdk

# Dockerfile
dockerfile.run/jmap

jmap 命令补充说明:


jmap 命令是一个命令行实用程序,包含在 Java™ Development Kit (JDK) 的 Linux® 版本中(但不包含在 Windows® 版本中)。此实用程序可打印正在运行的 JVM 或核心文件的内存相关统计信息。注意:此命令是实验性的且不受支持。

如果使用 jmap 时不带任何命令行选项,则它会打印已加载的共享对象列表。如需更具体的信息,您可以使用 -heap-histo-permstat 选项。

-heap
      Use the –heap option to obtain the following information:
      - the name of the garbage collector
      - algorithm–specific details (such as the number of threads used for parallel garbage collection)
      - heap configuration information
      - a heap usage summary

-histo
      Use the -histo option to obtain a class–wise histogram of the heap. For each class, it prints the number of instances in the heap, the total amount of memory used by those objects in bytes, and the fully qualified class name. The histogram is useful when you want to understand how the heap is used.

-permstat
      Configuring the size of the permanent generation can be important for applications that dynamically generate and load many classes (for example, Java Server Pages and web containers). If an application loads too many classes, then an OutOfMemoryError exception is thrown. Use the –permstat option to the jmap command to get statistics for the objects in the permanent generation.

jmap 命令语法:


jmap [options] pid

jmap 命令选项:


-clstats pid
      Connects to a running process and prints class loader statistics of Java heap.

-finalizerinfo pid
      Connects to a running process and prints information on objects awaiting finalization.

-histo[:live] pid
      Connects to a running process and prints a histogram of the Java object heap. If the live suboption is specified, it then counts only live objects.

-dump:dump_options pid
      Connects to a running process and dumps the Java heap. The dump_options include:

live --- When specified, dumps only the live objects; if not specified, then dumps all objects in the heap.

format=b --- Dumps the Java heap in hprof binary format

file=filename --- Dumps the heap to filename

Example: jmap -dump:live,format=b,file=heap.bin pid

jmap 命令实例:


jmap 打印 Java 进程的共享对象映射(输出类似 pmap):

jmap java_pid

jmap 打印堆摘要信息:

jmap -heap filename.jar java_pid

jmap 按类型打印堆使用情况的直方图:

jmap -histo java_pid

jmap 将堆内容转储到二进制文件中,以便使用 jhat 进行分析:

jmap -dump:format=b,file=path/to/file java_pid

jmap 将堆中的活动对象转储到二进制文件中,以便使用 jhat 进行分析:

jmap -dump:live,format=b,file=path/to/file java_pid

jmap 扩展阅读:




jmap 命令评论