简介
jinfo(Java Configuration Info)主要用于打印配置信息,包括命令行参数、系统变量。
极少数的情况下,我们可以用其来修改命令行参数。
语法
➜ jinfo Usage: jinfo [option] <pid> (to connect to running process) jinfo [option] <executable <core> (to connect to a core file) jinfo [option] [server_id@]<remote server IP or hostname> (to connect to remote debug server) where <option> is one of: -flag <name> to print the value of the named VM flag -flag [+|-]<name> to enable or disable the named VM flag -flag <name>=<value> to set the named VM flag to the given value -flags to print VM flags -sysprops to print Java system properties <no option> to print both of the above -h | -help to print this help message
最主要的语法只有一个 jinfo [option] <pid>
。pid表示Java进程id,而对于option,我们将逐一来进行分析。
示例
1、jinfo pid
打印所有配置信息
[root@searching-search-service-7cbfd67967-lczgh /]# jinfo 19 Attaching to process ID 19, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.161-b12 Java System Properties: java.vendor = Oracle Corporation sun.java.launcher = SUN_STANDARD catalina.base = /usr/local/apache-tomcat-8.5.30 sun.nio.ch.bugLevel = sun.management.compiler = HotSpot 64-Bit Tiered Compilers catalina.useNaming = true os.name = Linux java.util.logging.config.file = /usr/local/apache-tomcat-8.5.30/conf/logging.properties sun.boot.class.path = /usr/local/jdk1.8.0_161/jre/lib/resources.jar:/usr/local/jdk1.8.0_161/jre/lib/rt.jar:/usr/local/jdk1.8.0_161/jre/lib/sunrsasign.jar:... dubbo.consumer.loadbalance = envRandomLoadBalance com.sun.management.jmxremote = true java.vm.specification.vendor = Oracle Corporation java.runtime.version = 1.8.0_161-b12 user.name = root tomcat.util.scan.StandardJarScanFilter.jarsToScan = log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar shared.loader = tomcat.util.buf.StringCache.byte.enabled = true dubbo.service.group = STG-search-service user.language = zh java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory sun.boot.library.path = /usr/local/jdk1.8.0_161/jre/lib/amd64 jdk.tls.ephemeralDHKeySize = 2048 java.version = 1.8.0_161 java.util.logging.manager = org.apache.juli.ClassLoaderLogManager user.timezone = Asia/Shanghai sun.arch.data.model = 64 java.util.concurrent.ForkJoinPool.common.threadFactory = org.apache.catalina.startup.SafeForkJoinWorkerThreadFactory java.endorsed.dirs = /usr/local/jdk1.8.0_161/jre/lib/endorsed java.rmi.server.randomIDs = true sun.cpu.isalist = sun.jnu.encoding = UTF-8 file.encoding.pkg = sun.io package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat. file.separator = / java.specification.name = Java Platform API Specification java.class.version = 52.0 user.country = CN java.home = /usr/local/jdk1.8.0_161/jre java.vm.info = mixed mode os.version = 3.10.0-693.el7.x86_64 path.separator = : java.vm.version = 25.161-b12 java.protocol.handler.pkgs = org.apache.catalina.webresources java.awt.printerjob = sun.print.PSPrinterJob sun.io.unicode.encoding = UnicodeLittle awt.toolkit = sun.awt.X11.XToolkit package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat. java.naming.factory.url.pkgs = org.apache.naming user.home = /root org.apache.catalina.security.SecurityListener.UMASK = 0027 sun.rmi.transport.tcp.responseTimeout = 5000 java.specification.vendor = Oracle Corporation skywalking.agent.service_name = search-service tomcat.util.scan.StandardJarScanFilter.jarsToSkip = bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jar,xom-*.jar java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib java.vendor.url = http://java.oracle.com/ java.vm.vendor = Oracle Corporation common.loader = "${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar" java.runtime.name = Java(TM) SE Runtime Environment sun.java.command = org.apache.catalina.startup.Bootstrap start java.class.path = /usr/local/apache-tomcat-8.5.30/bin/bootstrap.jar:/usr/local/apache-tomcat-8.5.30/bin/tomcat-juli.jar:... skywalking.agent.jvm_update_time = 300 java.vm.specification.name = Java Virtual Machine Specification java.vm.specification.version = 1.8 catalina.home = /usr/local/apache-tomcat-8.5.30 sun.cpu.endian = little sun.os.patch.level = unknown java.io.tmpdir = /usr/local/apache-tomcat-8.5.30/temp java.vendor.url.bug = http://bugreport.sun.com/bugreport/ server.loader = os.arch = amd64 skywalking.collector.backend_service = xxx.com:11800 java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment java.ext.dirs = /usr/local/jdk1.8.0_161/jre/lib/ext:/usr/java/packages/lib/ext user.dir = / line.separator = java.vm.name = Java HotSpot(TM) 64-Bit Server VM ignore.endorsed.dirs = file.encoding = UTF-8 dubbo.registry.protocol = envZkRegistry java.specification.version = 1.8 VM Flags: Non-default VM flags: -XX:CICompilerCount=15 -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=null -XX:InitialHeapSize=1342177280 。。。省略。。。 Command line: -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.5.30/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLog。。。省略。。。
2、 -flag <name>
用于打印虚拟机标记参数的值,name表示虚拟机标记参数的名称。
[root@searching-search-service-7cbfd67967-lczgh /]# jinfo -flag PrintGC 19 -XX:+PrintGC
3、-flag [+|-]<name>
用于开启或关闭虚拟机标记参数。+表示开启,-表示关闭。
[root@searching-search-service-7cbfd67967-lczgh /]# jinfo -flag -PrintGC 19 # 关闭 [root@searching-search-service-7cbfd67967-lczgh /]# jinfo -flag PrintGC 19 # 查看 -XX:-PrintGC [root@searching-search-service-7cbfd67967-lczgh /]# jinfo -flag +PrintGC 19 # 开启 [root@searching-search-service-7cbfd67967-lczgh /]# jinfo -flag PrintGC 19 # 查看 -XX:+PrintGC
4、-flag <name>=<value>
用于设置虚拟机标记参数,但并不是每个参数都可以被动态修改的,设置异常的表示不可被修改。
[root@searching-search-service-7cbfd67967-lczgh /]# jinfo -flag HeapDumpPath 19 # 查看 -XX:HeapDumpPath=/home/www/wwwroot/logs/java.hprof [root@searching-search-service-7cbfd67967-lczgh /]# [root@searching-search-service-7cbfd67967-lczgh /]# jinfo -flag HeapDumpPath=/home/www/wwwroot/logs/java-search.hprof 19 # 设置新路径 [root@searching-search-service-7cbfd67967-lczgh /]# [root@searching-search-service-7cbfd67967-lczgh /]# jinfo -flag HeapDumpPath 19 # 查看,已经被修改 -XX:HeapDumpPath=/home/www/wwwroot/logs/java-search.hprof [root@searching-search-service-7cbfd67967-lczgh /]#
5、-flags
打印虚拟机参数。什么是虚拟机参数呢?如-XX:NewSize,-XX:OldSize等就是虚拟机参数。
[root@searching-search-service-7cbfd67967-lczgh /]# jinfo -flags 19 Attaching to process ID 19, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.161-b12 Non-default VM flags: -XX:CICompilerCount=15 -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=null -XX:InitialHeapSize=1342177280 -XX:+ManagementServer -XX:MaxHeapSize=1342177280 -XX:MaxMetaspaceSize=268435456 -XX:MaxNewSize=447348736 -XX:MaxTenuringThreshold=6 -XX:MetaspaceSize=268435456 -XX:MinHeapDeltaBytes=196608 -XX:NewRatio=2 -XX:NewSize=447348736 -XX:OldPLABSize=16 -XX:OldSize=894828544 -XX:ParallelGCThreads=2 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:ReservedCodeCacheSize=134217728 -XX:+TraceClassLoading -XX:+TraceClassUnloading -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseFastUnorderedTimeStamps -XX:+UseParNewGC Command line: -Djava.util.logging.config.file=/usr/local/apache-tomcat-8.5.30/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -javaagent:/home/sysop/trace/env-transmission.jar -javaagent:/home/sysop/trace/skywalking-agent.jar -Dskywalking.collector.backend_service=stg-trace-service.xxx.com:11800 -Dskywalking.agent.service_name=search-service -Dskywalking.agent.jvm_update_time=300 -Ddubbo.service.group=STG-search-service -Ddubbo.registry.protocol=envZkRegistry -Ddubbo.consumer.loadbalance=envRandomLoadBalance -XX:+UseConcMarkSweepGC -XX:NewRatio=2 -XX:ParallelGCThreads=2 -XX:+PrintGCDetails -Xms1280m -Xmx1280m -XX:ReservedCodeCacheSize=128m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=256M -Dfile.encoding=UTF-8 -verbose:gc -Xloggc:gc.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+TraceClassLoading -XX:+PrintTenuringDistribution -XX:+TraceClassUnloading -XX:+CMSClassUnloadingEnabled -Dcom.sun.management.jmxremote=true -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/www/wwwroot/logs/java.hprof -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001 -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -Dcatalina.base=/usr/local/apache-tomcat-8.5.30 -Dcatalina.home=/usr/local/apache-tomcat-8.5.30 -Djava.io.tmpdir=/usr/local/apache-tomcat-8.5.30/temp
6、sysprops
打印系统参数。
jinfo -sysprops <pid> 结果与 jinfo <pid> 结果差不多,只是少了虚拟机参数
7、-h | -help
打印帮助信息。
总结
jinfo可用于打印和动态修改虚拟机参数,也可以打印系统参数。功能强大,但使用方式却很简单。另外,相对于jstat、jstack来说,jinfo的用法要简单很多。
常见JVM参数
-Xms:初始堆大小,默认为物理内存的1/64(<1GB);默认(MinHeapFreeRatio参数可以调整)空余堆内存小于40%时,JVM就会增大堆直到-Xmx的最大限制
-Xmx:最大堆大小,默认(MaxHeapFreeRatio参数可以调整)空余堆内存大于70%时,JVM会减少堆直到 -Xms的最小限制
-Xmn:新生代的内存空间大小,注意:此处的大小是(eden+ 2 survivor space)。
与jmap -heap中显示的New gen是不同的。整个堆大小=新生代大小 + 老生代大小 + 永久代大小。在保证堆大小不变的情况下,增大新生代后,将会减小老生代大小。此值对系统性能影响较大,Sun官方推荐配置为整个堆的3/8。
-XX:SurvivorRatio:新生代中Eden区域与Survivor区域的容量比值,默认值为8。两个Survivor区与一个Eden区的比值为2:8,一个Survivor区占整个年轻代的1/10。
-Xss:每个线程的堆栈大小。JDK5.0以后每个线程堆栈大小为1M,以前每个线程堆栈大小为256K。应根据应用的线程所需内存大小进行适当调整。在相同物理内存下,减小这个值能生成更多的线程。但是操作系统对一个进程内的线程数还是有限制的,不能无限生成,经验值在3000~5000左右。一般小的应用, 如果栈不是很深, 应该是128k够用的,大的应用建议使用256k。这个选项对性能影响比较大,需要严格的测试。
-XX:PermSize:设置永久代(perm gen)初始值。默认值为物理内存的1/64。
-XX:MaxPermSize:设置持久代最大值。物理内存的1/4。
未经允许请勿转载:程序喵 » jvm 指令工具 jinfo 命令(Java配置信息)