1.jinfo
描述:输出给定 java 进程所有的配置信息。包括 java 系统属性和 jvm 命令行标记等。
用法:
jinfo [ option ] pid
jinfo [ option ] executable core
jinfo [ option ] [server-id@]remote-hostname-or-IP
例子:
jinfo pid
得到结果如下:
JVM version is 14.0-b16 Java System Properties: java.runtime.name = Java(TM) SE Runtime Environment sun.boot.library.path = /work/ProgramFiles/jdk1.6.0_14/jre/lib/i386 java.vm.version = 14.0-b16 java.vm.vendor = Sun Microsystems Inc. java.vendor.url = http://java.sun.com/ path.separator = : java.vm.name = Java HotSpot(TM) Server VM file.encoding.pkg = sun.io sun.java.launcher = SUN_STANDARD user.country = CN sun.os.patch.level = unknown java.vm.specification.name = Java Virtual Machine Specification user.dir = /work/RateWorkspace/branches/rate/daemon java.runtime.version = 1.6.0_14-b08 java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment java.endorsed.dirs = /work/ProgramFiles/jdk1.6.0_14/jre/lib/endorsed os.arch = i386 java.io.tmpdir = /tmp line.separator = java.vm.specification.vendor = Sun Microsystems Inc. os.name = Linux sun.jnu.encoding = UTF-8 java.library.path = /work/ProgramFiles/jdk1.6.0_14/jre/lib/i386/server:/work/ProgramFiles/jdk1.6.0_14/jre/lib/i386:/work/ProgramFiles/jdk1.6.0_14/jre/../lib/i386:/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/xulrunner-addons:/usr/lib/xulrunner-addons:/usr/java/packages/lib/i386:/lib:/usr/lib java.specification.name = Java Platform API Specification java.class.version = 50.0 sun.management.compiler = HotSpot Tiered Compilers os.version = 2.6.28-19-generic user.home = /home/yblin user.timezone = PRC java.awt.printerjob = sun.print.PSPrinterJob file.encoding = GBK java.specification.version = 1.6 java.class.path = user.name = yblin java.vm.specification.version = 1.0 java.home = /work/ProgramFiles/jdk1.6.0_14/jre sun.arch.data.model = 32 user.language = zh java.specification.vendor = Sun Microsystems Inc. java.vm.info = mixed mode java.version = 1.6.0_14 java.ext.dirs = /work/ProgramFiles/jdk1.6.0_14/jre/lib/ext:/usr/java/packages/lib/ext sun.boot.class.path = /work/ProgramFiles/jdk1.6.0_14/jre/lib/resources.jar:/work/ProgramFiles/jdk1.6.0_14/jre/lib/rt.jar:/work/ProgramFiles/jdk1.6.0_14/jre/lib/sunrsasign.jar:/work/ProgramFiles/jdk1.6.0_14/jre/lib/jsse.jar:/work/ProgramFiles/jdk1.6.0_14/jre/lib/jce.jar:/work/ProgramFiles/jdk1.6.0_14/jre/lib/charsets.jar:/work/ProgramFiles/jdk1.6.0_14/jre/classes java.vendor = Sun Microsystems Inc. file.separator = / java.vendor.url.bug = http://java.sun.com/cgi-bin/bugreport.cgi sun.io.unicode.encoding = UnicodeLittle sun.cpu.endian = little sun.desktop = gnome sun.cpu.isalist = VM Flags: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:55948 -ea -Dfile.encoding=GBK
这个命令包含了 JDK 和 JVM 运行起来时的一些属性。
2.jmap
描述 :输出给定 java 进程所有的内存使用信息。
使用:
jmap [ option ] pid
jmap [ option ] executable core
jmap [ option ] [server-id@]remote-hostname-or-IP
<no option>
没有可选项时,会输出所有共享的对象映射。
开始地址,映射大小,全路径。
直接 jmap pid得到如下结果:
0x08048000 46K /work/ProgramFiles/jdk1.6.0_14/bin/java
0xb6763000 74K /work/ProgramFiles/jdk1.6.0_14/jre/lib/i386/libzip.so
0xb6774000 41K /lib/tls/i686/cmov/libnss_files-2.9.so
0xb6780000 37K /lib/tls/i686/cmov/libnss_nis-2.9.so
0xb678b000 29K /lib/tls/i686/cmov/libnss_compat-2.9.so
目前还说不是很理解这个执行结果是什么意思。经询问同事了解,是加载的文件的信息。
-heap 选项
jmap -heap pid : 查看堆的配置和大当前各个区块的使用情况,如伊甸区、老年代,永久代。可以用此来判断内存目前的使用情况以及垃圾回收情况:
jmap -heap pid,得到如下结果:
<strong>Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 859832320 (820.0MB) NewSize = 1048576 (1.0MB) MaxNewSize = 4294901760 (4095.9375MB) OldSize = 4194304 (4.0MB) NewRatio = 8 SurvivorRatio = 8 PermSize = 16777216 (16.0MB) MaxPermSize = 67108864 (64.0MB) Heap Usage: PS Young Generation Eden Space: capacity = 9043968 (8.625MB) used = 6820384 (6.504425048828125MB) free = 2223584 (2.120574951171875MB) 75.41362375452898% used From Space: capacity = 720896 (0.6875MB) used = 704680 (0.6720352172851562MB) free = 16216 (0.01546478271484375MB) 97.7505770596591% used To Space: capacity = 720896 (0.6875MB) used = 0 (0.0MB) free = 720896 (0.6875MB) 0.0% used PS Old Generation capacity = 47710208 (45.5MB) used = 589184 (0.5618896484375MB) free = 47121024 (44.9381103515625MB) 1.2349223042582418% used PS Perm Generation capacity = 16777216 (16.0MB) used = 5179648 (4.939697265625MB) free = 11597568 (11.060302734375MB) 30.87310791015625% used </strong>
-histo 选项
内存使用的柱状图,包含每个类,对象使用的内存大小。 VM 内部的类名以 * 前缀开头。
-permstat 选项
输出所有类装载器在堆里产生的对象
包括每个装载器的名字,活跃,地址,父装载器,和其总共加载的类大小。
jmap -permstat pid
得到如下结果:
通过 jstack pid, 得到如下部分结果:
可以看到只有线程 thrad75 是 RUNNABLE 状态的,其他的都是 BLOCKED 状态。因为其他的线程在竞争控制台输出的时候都被阻塞了。