---
title: "java 命令简单查看jvm内存使用状况"
author: "wangmuchang"
date: "2014-07-04T10:53:33Z"
tags: []
categories: ["编程语言"]
slug: "java-jvm"
draft: false
lastmod: "2014-07-04T10:54:40Z"
id: 2088201
url: "https://wangmuchang.iteye.com/blog/2088201"
---

1、jps 虚拟机进程状况工具

语法  jsp \[option] \[hostid]

选项 作用 -q 只显示lvmid -m 输出虚拟机启用时传入main方法参数 -l 输出主类全名 -v 输出jvm参数

 

注意：

如果在linux环境中jps命令不能输出vmid数据（jdk1.6.0.23/24 bug），需要修改catalina.sh文件

if \[ -z "$CATALINA\_TMPDIR" ] ; then  
\# Define the java.io.tmpdir to use for Catalina  
\# CATALINA\_TMPDIR="$CATALINA\_BASE"/temp  
CATALINA\_TMPDIR=/tmp  
fi

修改CATALINA\_TMPDIR路径

 

2、jstat 虚拟机统计信息监控工具

语法：

jstat \[option vmid \[interval\[s|ms]] \[count]]

option选项

 

[class](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#class_option) 统计class loader行为信息 [compiler](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#compiler_option) 统计编译行为信息 [gc](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#gc_option) 统计jdk gc时heap信息 [gccapacity](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#gccapacity_option) 统计堆内存不同代的heap容量信息 [gccause](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#gccause_option) 统计gc的情况（同-gcutil）和引起gc的事件 [gcnew](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#gcnew_option) 统计gc时新生代的信息(相比gcutil更详细) [gcnewcapacity](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#gcnewcapacity_option) 统计gc时新生代heap容量 [gcold](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#gcold_option) 统计gc时，老年区的情况 [gcoldcapacity](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#gcoldcapacity_option) 统计gc时，老年区heap容量 [gcpermcapacity](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#gcpermcapacity_option) 统计gc时，permanent区heap容量 [gcutil](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#gcutil_option) 统计gc时，heap情况 [printcompilation](http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html#printcompilation_option) 统计编译行为信息

 

 

例如：

jstat -gc 1111 250 2

查看vmid为1111的虚拟机每个250毫秒执行一次，共执行两次

 

结果分析

[]()-class option:Class Loader Statistics

**Column** **Description** Loaded Number of classes loaded. Bytes Number of Kbytes loaded. Unloaded Number of classes unloaded. Bytes Number of Kbytes unloaded. Time Time spent performing class load and unload operations.

[]()-compiler:HotSpot Just-In-Time Compiler Statistics

**Column** **Description** Compiled Number of compilation tasks performed. Failed Number of compilation tasks that failed. Invalid Number of compilation tasks that were invalidated. Time Time spent performing compilation tasks. FailedType Compile type of the last failed compilation. FailedMethod Class name and method for the last failed compilation.

[]()-gc Option:Garbage-collected heap statistics

**Column** **Description** S0C Current survivor space 0 capacity (KB). S1C Current survivor space 1 capacity (KB). S0U Survivor space 0 utilization (KB). S1U Survivor space 1 utilization (KB). EC Current eden space capacity (KB). EU Eden space utilization (KB). OC Current old space capacity (KB). OU Old space utilization (KB). PC Current permanent space capacity (KB). PU Permanent space utilization (KB). YGC Number of young generation GC Events. YGCT Young generation garbage collection time. FGC Number of full GC events. FGCT Full garbage collection time. GCT Total garbage collection time.

[]()-gccapacity Option:Memory Pool Generation and Space Capacities

**Column** **Description** NGCMN Minimum new generation capacity (KB). NGCMX Maximum new generation capacity (KB). NGC Current new generation capacity (KB). S0C Current survivor space 0 capacity (KB). S1C Current survivor space 1 capacity (KB). EC Current eden space capacity (KB). OGCMN Minimum old generation capacity (KB). OGCMX Maximum old generation capacity (KB). OGC Current old generation capacity (KB). OC Current old space capacity (KB). PGCMN Minimum permanent generation capacity (KB). PGCMX Maximum Permanent generation capacity (KB). PGC Current Permanent generation capacity (KB). PC Current Permanent space capacity (KB). YGC Number of Young generation GC Events. FGC Number of Full GC Events.

[]()-gccause Option:Garbage Collection Statistics, Including GC Events

**Column** **Description** LGCC Cause of last Garbage Collection. GCC Cause of current Garbage Collection.

前面的字段与gcutil相同.

[]()-gcnew Option:New Generation Statistics

**Column** **Description** S0C Current survivor space 0 capacity (KB). S1C Current survivor space 1 capacity (KB). S0U Survivor space 0 utilization (KB). S1U Survivor space 1 utilization (KB). TT Tenuring threshold. MTT Maximum tenuring threshold. DSS Desired survivor size (KB). EC Current eden space capacity (KB). EU Eden space utilization (KB). YGC Number of young generation GC events. YGCT Young generation garbage collection time.

[]()-gcnewcapacity Option:New Generation Space Size Statistics

**Column** **Description** NGCMN Minimum new generation capacity (KB). NGCMX Maximum new generation capacity (KB). NGC Current new generation capacity (KB). S0CMX Maximum survivor space 0 capacity (KB). S0C Current survivor space 0 capacity (KB). S1CMX Maximum survivor space 1 capacity (KB). S1C Current survivor space 1 capacity (KB). ECMX Maximum eden space capacity (KB). EC Current eden space capacity (KB). YGC Number of young generation GC events. FGC Number of Full GC Events.

[]()-gcold Option:Old and Permanent Generation Statistics

**Column** **Description** PC Current permanent space capacity (KB). PU Permanent space utilization (KB). OC Current old space capacity (KB). OU old space utilization (KB). YGC Number of young generation GC events. FGC Number of full GC events. FGCT Full garbage collection time. GCT Total garbage collection time.

[]()-gcoldcapacity Option:Old Generation Statistics

**Column** **Description** OGCMN Minimum old generation capacity (KB). OGCMX Maximum old generation capacity (KB). OGC Current old generation capacity (KB). OC Current old space capacity (KB). YGC Number of young generation GC events. FGC Number of full GC events. FGCT Full garbage collection time. GCT Total garbage collection time.

[]()-gcpermcapacity Option: Permanent Generation Statistics

**Column** **Description** PGCMN Minimum permanent generation capacity (KB). PGCMX Maximum permanent generation capacity (KB). PGC Current permanent generation capacity (KB). PC Current permanent space capacity (KB). YGC Number of young generation GC events. FGC Number of full GC events. FGCT Full garbage collection time. GCT Total garbage collection time.

[]()-gcutil Option:Summary of Garbage Collection Statistics

**Column** **Description** S0 Survivor space 0 utilization as a percentage of the space's current capacity. S1 Survivor space 1 utilization as a percentage of the space's current capacity. E Eden space utilization as a percentage of the space's current capacity. O Old space utilization as a percentage of the space's current capacity. P Permanent space utilization as a percentage of the space's current capacity. YGC Number of young generation GC events. YGCT Young generation garbage collection time. FGC Number of full GC events. FGCT Full garbage collection time. GCT Total garbage collection time.

[]()-printcompilation Option: HotSpot Compiler Method Statistics

**Column** **Description** Compiled Number of compilation tasks performed. Size Number of bytes of bytecode for the method. Type Compilation type. Method Class name and method name identifying the compiled method. Class name uses "/" instead of "." as namespace separator. Method name is the method within the given class. The format for these two fields is consistent with the HotSpot - **XX:+PrintComplation** option.