1. 程式人生 > >Java效能調優工具——Jinfo

Java效能調優工具——Jinfo

一、命令說明
jinfo(Java Virtual Machine Configuration Info for Java)是從JDK1.5自帶的工具,用於檢視Java應用程式的引數(JVM引數 + 系統引數),甚至支援在執行時調整部分引數,可以調整的引數如下表。

C:\Users\Administrator>java -XX:+PrintFlagsFinal -version | findstr manageable
     intx CMSAbortablePrecleanWaitMillis            = 100                                 {manageable}
     intx CMSTriggerInterval                        = -1
{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 PrintGCID = false {manageable} bool PrintGCTimeStamps = false {manageable} java version "1.8.0_77" Java(TM) SE Runtime Environment (build 1.8.0_77-b03) Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

二、引數說明

C:\Users\Administrator>jinfo -help
Usage:
    jinfo [option] <pid>
        (to connect to running process)
    jinfo [option] <executable <core>
        (to connect to a core file)
    jinfo [option] [[email protected]]<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的引數格式如下:

jinfo [option] pid

三、使用示例
1 .jinfo -flags pid : 列印Java應用的JVM引數

C:\Users\Administrator>jinfo -flags 7048
Attaching to process ID 7048, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03
Non-default VM flags: -XX:CICompilerCount=3 -XX:+HeapDumpAfterFullGC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=null -XX:InitialHeapSize=2147483648 -XX:+Ma
nagementServer -XX:MaxHeapSize=4294967296 -XX:MaxMetaspaceSize=2147483648 -XX:MaxNewSize=1073741824 -XX:MaxTenuringThreshold=6 -XX:MinHeapDeltaBytes=196608 -XX:N
ewSize=1073741824 -XX:OldPLABSize=16 -XX:OldSize=1073741824 -XX:+PrintGCDetails -XX:ThreadStackSize=1024 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -
XX:+UseConcMarkSweepGC -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParNewGC
Command line:  -Djava.util.logging.config.file=E:\V6.0\tomcat8\bin\..\conf\logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -
Xms2G -Xmx4G -Xss1m -XX:NewSize=1G -XX:MaxNewSize=1G -XX:MaxMetaspaceSize=2G -XX:+UseConcMarkSweepGC -Dcom.sun.management.jmxremote -DA8.datasource.properies.fil
epath=E:\V6.0\tomcat8\bin\..\../base/conf/datasourceCtp.properties -Dsun.rmi.dgc.client.gcInterval=21600000 -Dsun.rmi.dgc.server.gcInterval=21600000 -XX:+HeapDum
pOnOutOfMemoryError -Dsun.zip.disableMemoryMapping=true -Dorg.apache.el.parser.COERCE_TO_ZERO=true -Djgroups.bind_addr=0.0.0.0 -DDEE_HOME=E:\V6.0\tomcat8\bin\..\
../base/dee/ -Djgroups.tcpping.initial_hosts= -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Xdebug -Xnoagent -
Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787 -Dignore.endorsed.dirs= -Dcatalina.base=E:\V6.0\tomcat8\bin\.. -Dcatalina.home=
E:\V6.0\tomcat8\bin\.. -Djava.io.tmpdir=E:\V6.0\tomcat8\bin\..\temp

2 . jinfo -sysprops : 列印Java應用程式系統變數(這是檢視本機開啟的Eclipse的系統變數

C:\Users\Administrator>jinfo -sysprops 6924
Attaching to process ID 6924, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03
java.vendor = Oracle Corporation
osgi.bundles.defaultStartLevel = 4
org.eclipse.debug.ui.breakpoints.toggleFactoriesUsed = true
org.osgi.supports.framework.extension = true
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
eclipse.p2.profile = DefaultProfile
os.name = Windows 7
sun.boot.class.path = D:\Program Files (x86)\jdk1.8.0_77\jre\lib\resources.jar;D:\Program Files (x86)\jdk1.8.0_77\jre\lib\rt.jar;D:\Program Files (x86)\jdk1.8.0_
77\jre\lib\sunrsasign.jar;D:\Program Files (x86)\jdk1.8.0_77\jre\lib\jsse.jar;D:\Program Files (x86)\jdk1.8.0_77\jre\lib\jce.jar;D:\Program Files (x86)\jdk1.8.0_
77\jre\lib\charsets.jar;D:\Program Files (x86)\jdk1.8.0_77\jre\lib\jfr.jar;D:\Program Files (x86)\jdk1.8.0_77\jre\classes
osgi.ws = win32
sun.desktop = windows
java.vm.specification.vendor = Oracle Corporation
java.runtime.version = 1.8.0_77-b03
osgi.instance.area = file:/D:/eclipse-developwork/workplace/
org.osgi.framework.uuid = 53b4b372-a45e-44a2-97f4-a4581eafd1c5
groovy.enable.parameterized.type.cache = false
org.eclipse.m2e.log.dir = D:\eclipse-developwork\workplace\.metadata\.plugins\org.eclipse.m2e.logback.configuration
user.name = Administrator
osgi.framework.extensions = reference:file:org.eclipse.equinox.weaving.hook_1.2.0.v20160929-1449.jar,reference:file:org.eclipse.osgi.compatibility.state_1.1.0.v2
0170516-1513.jar
org.osgi.framework.system.packages = javax.accessibility,javax.activation,javax.activity,javax.annotation,javax.annotation.processing,javax.crypto,javax.crypto.i
nterfaces,javax.crypto.spec,javax.imageio,javax.imageio.event,javax.imageio.metadata,javax.imageio.plugins.bmp,javax.imageio.plugins.jpeg,javax.imageio.spi,javax
.imageio.stream,javax.jws,javax.jws.soap,javax.lang.model,javax.lang.model.element,javax.lang.model.type,javax.lang.model.util,javax.management,javax.management.
loading,javax.management.modelmbean,javax.management.monitor,javax.management.openmbean,javax.management.relation,javax.management.remote,javax.management.remote
.rmi,javax.management.timer,javax.naming,javax.naming.directory,javax.naming.event,javax.naming.ldap,javax.naming.spi,javax.net,javax.net.ssl,javax.print,javax.p
rint.attribute,javax.print.attribute.standard,javax.print.event,javax.rmi,javax.rmi.CORBA,javax.rmi.ssl,javax.script,javax.security.auth,javax.security.auth.call
back,javax.security.auth.kerberos,javax.security.auth.login,javax.security.auth.spi,javax.security.auth.x500,javax.security.cert,javax.security.sasl,javax.sound.
midi,javax.sound.midi.spi,javax.sound.sampled,javax.sound.sampled.spi,javax.sql,javax.sql.rowset,javax.sql.rowset.serial,javax.sql.rowset.spi,javax.swing,javax.s
wing.border,javax.swing.colorchooser,javax.swing.event,javax.swing.filechooser,javax.swing.plaf,javax.swing.plaf.basic,javax.swing.plaf.metal,javax.swing.plaf.mu
lti,javax.swing.plaf.nimbus,javax.swing.plaf.synth,javax.swing.table,javax.swing.text,javax.swing.text.html,javax.swing.text.html.parser,javax.swing.text.rtf,jav
ax.swing.tree,javax.swing.undo,javax.tools,javax.transaction,javax.transaction.xa,javax.xml,javax.xml.bind,javax.xml.bind.annotation,javax.xml.bind.annotation.ad
apters,javax.xml.bind.attachment,javax.xml.bind.helpers,javax.xml.bind.util,javax.xml.crypto,javax.xml.crypto.dom,javax.xml.crypto.dsig,javax.xml.crypto.dsig.dom
,javax.xml.crypto.dsig.keyinfo,javax.xml.crypto.dsig.spec,javax.xml.datatype,javax.xml.namespace,javax.xml.parsers,javax.xml.soap,javax.xml.stream,javax.xml.stre
am.events,javax.xml.stream.util,javax.xml.transform,javax.xml.transform.dom,javax.xml.transform.sax,javax.xml.transform.stax,javax.xml.transform.stream,javax.xml
.validation,javax.xml.ws,javax.xml.ws.handler,javax.xml.ws.handler.soap,javax.xml.ws.http,javax.xml.ws.soap,javax.xml.ws.spi,javax.xml.ws.spi.http,javax.xml.ws.w
saddressing,javax.xml.xpath,org.ietf.jgss,org.omg.CORBA,org.omg.CORBA_2_3,org.omg.CORBA_2_3.portable,org.omg.CORBA.DynAnyPackage,org.omg.CORBA.ORBPackage,org.omg
.CORBA.portable,org.omg.CORBA.TypeCodePackage,org.omg.CosNaming,org.omg.CosNaming.NamingContextExtPackage,org.omg.CosNaming.NamingContextPackage,org.omg.Dynamic,
org.omg.DynamicAny,org.omg.DynamicAny.DynAnyFactoryPackage,org.omg.DynamicAny.DynAnyPackage,org.omg.IOP,org.omg.IOP.CodecFactoryPackage,org.omg.IOP.CodecPackage,
org.omg.Messaging,org.omg.PortableInterceptor,org.omg.PortableInterceptor.ORBInitInfoPackage,org.omg.PortableServer,org.omg.PortableServer.CurrentPackage,org.omg
.PortableServer.POAManagerPackage,org.omg.PortableServer.POAPackage,org.omg.PortableServer.portable,org.omg.PortableServer.ServantLocatorPackage,org.omg.SendingC
ontext,org.omg.stub.java.rmi,org.w3c.dom,org.w3c.dom.bootstrap,org.w3c.dom.css,org.w3c.dom.events,org.w3c.dom.html,org.w3c.dom.ls,org.w3c.dom.ranges,org.w3c.dom.
stylesheets,org.w3c.dom.traversal,org.w3c.dom.views,org.w3c.dom.xpath,org.xml.sax,org.xml.sax.ext,org.xml.sax.helpers
guice.disable.misplaced.annotation.check = true
eclipse.launcher = D:\sts-bundle\sts-3.9.4.RELEASE\STS.exe
eclipse.launcher.name = STS
equinox.use.ds = true
osgi.frameworkClassPath = ., file:d:/sts-bundle/sts-3.9.4.RELEASE/plugins/org.eclipse.equinox.weaving.hook_1.2.0.v20160929-1449.jar, file:d:/sts-bundle/sts-3.9.4
.RELEASE/plugins/org.eclipse.osgi.compatibility.state_1.1.0.v20170516-1513.jar
org.osgi.framework.language = zh
org.eclipse.swt.internal.deviceZoom = 100
user.language = zh
org.osgi.framework.processor = x86-64
sun.boot.library.path = D:\Program Files (x86)\jdk1.8.0_77\jre\bin
osgi.syspath = d:\sts-bundle\sts-3.9.4.RELEASE\plugins
osgi.compatibility.bootdelegation.default = true
org.osgi.framework.system.capabilities = osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0, 1.1, 1.2",osgi.ee; osgi.ee="JRE"; version:List<Version>="1.
0, 1.1",osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8",osgi.ee; osgi.ee="JavaSE/compact1"; version:List<Version>=
"1.8",osgi.ee; osgi.ee="JavaSE/compact2"; version:List<Version>="1.8",osgi.ee; osgi.ee="JavaSE/compact3"; version:List<Version>="1.8"
osgi.compatibility.bootdelegation = true
java.version = 1.8.0_77
user.timezone = Asia/Shanghai
org.osgi.framework.os.name = Windows7
osgi.bundles = reference:file:org.eclipse.equinox.weaving.hook_1.2.0.v20160929-1449.jar,reference:file:org.eclipse.osgi.compatibility.state_1.1.0.v20170516-1513.
jar,reference:file:[email protected]1:start
sun.arch.data.model = 64
java.endorsed.dirs = D:\Program Files (x86)\jdk1.8.0_77\jre\lib\endorsed
osgi.tracefile = D:\eclipse-developwork\workplace\.metadata\trace.log
file.encoding.pkg = sun.io
sun.jnu.encoding = GBK
sun.cpu.isalist = amd64
eclipse.application = org.eclipse.ui.ide.workbench
org.osgi.framework.vendor = Eclipse
equinox.init.uuid = true
java.specification.name = Java Platform API Specification
file.separator = \
java.class.version = 52.0
user.country = CN
org.eclipse.equinox.launcher.splash.location = d:\sts-bundle\sts-3.9.4.RELEASE\configuration\org.eclipse.equinox.launcher\org.springsource.sts_3.9.4.201804120921
-RELEASE\splash.bmp
java.home = D:\Program Files (x86)\jdk1.8.0_77\jre
osgi.os = win32
eclipse.commands = -os
win32
-ws
win32
-arch
x86_64
-showsplash
-launcher
D:\sts-bundle\sts-3.9.4.RELEASE\STS.exe
-name
STS
--launcher.library
D:\sts-bundle\sts-3.9.4.RELEASE\\plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.551.v20171108-1834\eclipse_1630.dll
-startup
D:\sts-bundle\sts-3.9.4.RELEASE\\plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar
--launcher.overrideVmargs
-product
org.springsource.sts.ide
-vm
D:\Program Files (x86)\jdk1.8.0_77\bin\..\jre\bin\server\jvm.dll

java.vm.info = mixed mode
osgi.splashLocation = d:\sts-bundle\sts-3.9.4.RELEASE\configuration\org.eclipse.equinox.launcher\org.springsource.sts_3.9.4.201804120921-RELEASE\splash.bmp
os.version = 6.1
osgi.arch = x86_64
path.separator = ;
java.vm.version = 25.77-b03
org.osgi.supports.framework.fragment = true
user.variant =
osgi.framework.shape = jar
java.awt.printerjob = sun.awt.windows.WPrinterJob
osgi.instance.area.default = file:/C:/Users/Administrator/Documents/workspace-sts-3.9.4.RELEASE/
org.eclipse.swt.browser.IEVersion = 10001
sun.io.unicode.encoding = UnicodeLittle
org.osgi.framework.version = 1.8.0
org.osgi.framework.storage = D:\sts-bundle\sts-3.9.4.RELEASE\configuration
awt.toolkit = sun.awt.windows.WToolkit
user.script =
eclipse.stateSaveDelayInterval = 30000
osgi.install.area = file:/D:/sts-bundle/sts-3.9.4.RELEASE/
osgi.framework = file:/d:/sts-bundle/sts-3.9.4.RELEASE/plugins/org.eclipse.osgi_3.12.100.v20180210-1608.jar
user.home = C:\Users\Administrator
org.eclipse.equinox.simpleconfigurator.configUrl = file:org.eclipse.equinox.simpleconfigurator/bundles.info
osgi.framework.useSystemProperties = true
osgi.splashPath = platform:/base/plugins/org.springsource.sts
java.specification.vendor = Oracle Corporation
osgi.nl = zh_CN
java.library.path = D:\sts-bundle\sts-3.9.4.RELEASE;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/Program Files (x86)/jdk1.8.0_77/bin/../jre/bin/serv
er;D:/Program Files (x86)/jdk1.8.0_77/bin/../jre/bin;D:/Program Files (x86)/jdk1.8.0_77/bin/../jre/lib/amd64;D:\gradle-4.8.1\bin;C:\Program Files\MySQL\MySQL Ser
ver 5.5\bin;D:\Program Files (x86)\jdk1.8.0_77\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\Program
 Files (x86)\apache-ant-1.9.4\bin;D:\Program Files (x86)\apache-maven-3.3.3\bin;D:\Program Files\putty;C:\Users\Administrator\AppData\Roaming\npm;C:\Seeyon\A8\..
\UC\bin;C:\Program Files\wget;C:\Program Files\Git\cmd;C:\Users\Administrator\AppData\Local\Programs\Fiddler;D:\sts-bundle\sts-3.9.4.RELEASE;;.
java.vendor.url = http://java.oracle.com/
eclipse.startTime = 1536804605516
org.osgi.framework.os.version = 6.1.0
eclipse.p2.data.area = @config.dir/../p2/
java.vm.vendor = Oracle Corporation
java.runtime.name = Java(TM) SE Runtime Environment
java.class.path = D:\sts-bundle\sts-3.9.4.RELEASE\\plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar
ds.delayed.keepInstances = true
osgi.requiredJavaVersion = 1.8
org.eclipse.update.reconcile = false
eclipse.vm = D:\Program Files (x86)\jdk1.8.0_77\bin\..\jre\bin\server\jvm.dll
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.version = 1.8
sun.cpu.endian = little
sun.os.patch.level = Service Pack 1
gosh.args = --nointeractive
java.io.tmpdir = C:\Users\ADMINI~1\AppData\Local\Temp\
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
applicationXMI = org.eclipse.ui.workbench/LegacyIDE.e4xmi
eclipse.product = org.springsource.sts.ide
eclipse.home.location = file:/D:/sts-bundle/sts-3.9.4.RELEASE/
os.arch = amd64
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
java.ext.dirs = D:\Program Files (x86)\jdk1.8.0_77\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
user.dir = D:\sts-bundle\sts-3.9.4.RELEASE
org.osgi.supports.framework.requirebundle = true
line.separator =

java.vm.name = Java HotSpot(TM) 64-Bit Server VM
org.apache.commons.logging.Log = org.apache.commons.logging.impl.NoOpLog
file.encoding = GBK
osgi.module.lock.timeout = 10
eclipse.buildId = 3.9.4.201804120921-RELEASE-e47
eclipse.vmargs = -Dosgi.requiredJavaVersion=1.8
-Xms40m
-Dosgi.module.lock.timeout=10
-Dorg.eclipse.swt.browser.IEVersion=10001
-Xmx1200m
-Djava.class.path=D:\sts-bundle\sts-3.9.4.RELEASE\\plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar

java.specification.version = 1.8
osgi.user.area = file:/C:/Users/Administrator/user/
org.osgi.framework.executionenvironment = OSGi/Minimum-1.0,OSGi/Minimum-1.1,OSGi/Minimum-1.2,JavaSE/compact1-1.8,JavaSE/compact2-1.8,JavaSE/compact3-1.8,JRE-1.1,
J2SE-1.2,J2SE-1.3,J2SE-1.4,J2SE-1.5,JavaSE-1.6,JavaSE-1.7,JavaSE-1.8
osgi.logfile = D:\eclipse-developwork\workplace\.metadata\.log
osgi.configuration.area = file:/D:/sts-bundle/sts-3.9.4.RELEASE/configuration/

3 . jinfo -flag [name]:檢視具體JVM變數的引數值

C:\Users\Administrator>jinfo -flag PrintGC 7048
-XX:-PrintGC

4 . jinfo -flag +/-name :啟用/停用JVM變數

C:\Users\Administrator>jinfo -flag +PrintGC 7048

C:\Users\Administrator>jinfo -flag PrintGC 7048
-XX:+PrintGC

5 .jinfo -flag name= :設定JVM變數值

C:\Users\Administrator>jinfo -flag HeapDumpPath=E:/V6.0/tomcat8/dumps/ 7048

C:\Users\Administrator>jinfo -flag HeapDumpPath 7048
-XX:HeapDumpPath=E:/V6.0/tomcat8/dumps/

注意:此處設定的HeapDumpPath只能在jinfo中檢視,即使使用jinfo -flags 7048檢視的時候,發現值並不是剛設定的值.
這裡寫圖片描述