Getting the parameters of a running JVM

前端 未结 12 551
栀梦
栀梦 2020-12-04 05:43

Is there a way to get the parameters of a running JVM? Is there a command line tool like jstat which takes as input the pid of the JVM and returns its starting parameters? I

相关标签:
12条回答
  • 2020-12-04 06:03

    You can use jps like

    jps -lvm
    

    prints something like

    4050 com.intellij.idea.Main -Xms128m -Xmx512m -XX:MaxPermSize=250m -ea -Xbootclasspath/a:../lib/boot.jar -Djb.restart.code=88
    4667 sun.tools.jps.Jps -lvm -Dapplication.home=/opt/java/jdk1.6.0_22 -Xms8m
    
    0 讨论(0)
  • 2020-12-04 06:04

    Alternatively, you can use jinfo

    jinfo -flags <vmid> 
    jinfo -sysprops <vmid>
    
    0 讨论(0)
  • 2020-12-04 06:05

    I am adding this new answer because as per JDK8 documentation jcmd is suggested approach now.

    It is suggested to use the latest utility, jcmd instead of the previous jstack, jinfo, and jmap utilities for enhanced diagnostics and reduced performance overhead.

    Below are commands to get your properties/flags you want.

    jcmd pid VM.system_properties
    jcmd pid VM.flags
    

    We need pid, for this use jcmd -l, like below

    username@users-Air:~/javacode$ jcmd -l 
    11441 Test 
    6294 Test 
    29197 jdk.jcmd/sun.tools.jcmd.JCmd -l 
    

    Now time to use these pids to get properties/flags you want

    Command: jcmd 11441 VM.system_properties

    11441:
    #Tue Oct 17 12:44:50 IST 2017
    gopherProxySet=false
    awt.toolkit=sun.lwawt.macosx.LWCToolkit
    file.encoding.pkg=sun.io
    java.specification.version=9
    sun.cpu.isalist=
    sun.jnu.encoding=UTF-8
    java.class.path=.
    java.vm.vendor=Oracle Corporation
    sun.arch.data.model=64
    java.vendor.url=http\://java.oracle.com/
    user.timezone=Asia/Kolkata
    java.vm.specification.version=9
    os.name=Mac OS X
    sun.java.launcher=SUN_STANDARD
    user.country=US
    sun.boot.library.path=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/lib
    sun.java.command=Test
    http.nonProxyHosts=local|*.local|169.254/16|*.169.254/16
    jdk.debug=release
    sun.cpu.endian=little
    user.home=/Users/XXXX
    user.language=en
    java.specification.vendor=Oracle Corporation
    java.home=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
    file.separator=/
    java.vm.compressedOopsMode=Zero based
    line.separator=\n
    java.specification.name=Java Platform API Specification
    java.vm.specification.vendor=Oracle Corporation
    java.awt.graphicsenv=sun.awt.CGraphicsEnvironment
    sun.management.compiler=HotSpot 64-Bit Tiered Compilers
    ftp.nonProxyHosts=local|*.local|169.254/16|*.169.254/16
    java.runtime.version=9+181
    user.name=XXXX
    path.separator=\:
    os.version=10.12.6
    java.runtime.name=Java(TM) SE Runtime Environment
    file.encoding=UTF-8
    java.vm.name=Java HotSpot(TM) 64-Bit Server VM
    java.vendor.url.bug=http\://bugreport.java.com/bugreport/
    java.io.tmpdir=/var/folders/dm/gd6lc90d0hg220lzw_m7krr00000gn/T/
    java.version=9
    user.dir=/Users/XXXX/javacode
    os.arch=x86_64
    java.vm.specification.name=Java Virtual Machine Specification
    java.awt.printerjob=sun.lwawt.macosx.CPrinterJob
    sun.os.patch.level=unknown
    MyParam=2
    java.library.path=/Users/XXXX/Library/Java/Extensions\:/Library/Java/Extensions\:/Network/Library/Java/Extensions\:/System/Library/Java/Extensions\:/usr/lib/java\:.
    java.vm.info=mixed mode
    java.vendor=Oracle Corporation
    java.vm.version=9+181
    sun.io.unicode.encoding=UnicodeBig
    java.class.version=53.0
    socksNonProxyHosts=local|*.local|169.254/16|*.169.254/16
    

    Command : jcmd 11441 VM.flags output:

    11441:
    -XX:CICompilerCount=3 -XX:ConcGCThreads=1 -XX:G1ConcRefinementThreads=4 -XX:G1HeapRegionSize=1048576 -XX:InitialHeapSize=67108864 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=1073741824 -XX:MaxNewSize=643825664 -XX:MinHeapDeltaBytes=1048576 -XX:NonNMethodCodeHeapSize=5830092 -XX:NonProfiledCodeHeapSize=122914074 -XX:ProfiledCodeHeapSize=122914074 -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:-UseAOT -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC 
    

    For more instructions of usages of jcmd, see my blog post

    0 讨论(0)
  • 2020-12-04 06:05

    Windows 10 or Windows Server 2016 provide such information in their standard task manager. A rare case for production, but if the target JVM is running on Windows, the simplest way to see its parameters is to press Ctrl+Alt+Delete, choose the Processes tab and add the Command line column (by clicking the right mouse button on any existing column header).

    0 讨论(0)
  • 2020-12-04 06:06

    On linux, you can run this command and see the result :

    ps aux | grep "java"
    
    0 讨论(0)
  • 2020-12-04 06:06

    _JAVA_OPTIONS is an env variable that can be expanded.

    echo $_JAVA_OPTIONS
    
    0 讨论(0)
提交回复
热议问题