JVM系列:jinfo命令

在JDK bundle中隐藏着一个精悍的小工具——jinfo。作为一个命令行工具,jinfo用于收集正在运行的Java进程的配置信息。jinfo吸引眼球的地方在于,它能通过-flag选项动态修改指定的Java进程中的某些JVM flag的值。虽然这样的flag数量有限,但它们偶尔能够帮助到你。

1、通过以下的命令你便能看到JVM中哪些flag可以被jinfo动态修改:

# java -XX:+PrintFlagsFinal -version|grep manageable  
     intx CMSAbortablePrecleanWaitMillis            = 100             {manageable}          
     intx CMSWaitDuration                           = 2000            {manageable}          
     bool HeapDumpAfterFullGC                       = false           {manageable}          
     bool HeapDumpBeforeFullGC                      = false           {manageable}          
     bool HeapDumpOnOutOfMemoryError                = false           {manageable}          
    ccstr HeapDumpPath                              =                 {manageable}          
    uintx MaxHeapFreeRatio                          = 100             {manageable}          
    uintx MinHeapFreeRatio                          = 0               {manageable}          
     bool PrintClassHistogram                       = false           {manageable}          
     bool PrintClassHistogramAfterFullGC            = false           {manageable}          
     bool PrintClassHistogramBeforeFullGC           = false           {manageable}          
     bool PrintConcurrentLocks                      = false           {manageable}          
     bool PrintGC                                   = false           {manageable}          
     bool PrintGCDateStamps                         = false           {manageable}          
     bool PrintGCDetails                            = false           {manageable}          
     bool PrintGCTimeStamps                         = false           {manageable}          
java version "1.7.0_79"  
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)  
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)  

  

通过选项-XX:+PrintFlagsFinal可以列出所有的JVM flag,而其中的标注为manageable 的flag则是值得我们关注的部分。这些flag可通过JDK management interface(-XX:+PrintFlagsFinal)动态修改。

 

【实例】

1、查看参数值:

# ps -ef | grep 8807

root      8807     1  2 14:54 ?        00:03:11 /data/apps/jdk/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Xms20480m -Xmx20480m -Xss2m -XX:PermSize=512M -XX:MaxNewSize=512m -XX:MaxPermSize=512m -XX:NewRatio=2 -XX:+CMSParallelRemarkEnabled -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -verbose:gc -XX:+DisableExplicitGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10M -Xloggc:/data/logs/tomcat/gc.log -Dcom.sun.management.jmxremote.port=1999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start

  


# jinfo -flag GCLogFileSize 8807
-XX:GCLogFileSize=10485760


2、打开gc:

在jinfo中需要打开-XX:+PrintGC和 -XX:+PrintGCDetails两个选项才能开启GC日志,这与用命令行参数的方式实现有着细微的差别——如果你通过启动脚本(startup script)来设置参数,仅需-XX:+PrintGCDetails即可,因为-XX:+PrintGC会被自动打开。

 

# jinfo -flag +PrintGCDetails 12278

# jinfo -flag +PrintGC 12278



3、关闭gc:
若想关闭GC日志功能,只需要执行jinfo -flag -PrintGCDetails 12278和 jinfo -flag -PrintGC 12278命令即可。

 

4、查看jvm配置基本信息

参考:https://www.bbsmax.com/A/ZOJPZgKodv/

 

posted on 2018-05-29 10:06  腾飞的鹰  阅读(612)  评论(0编辑  收藏  举报

导航