Getting parameters of a running JVM

Is there a way to get the parameters of a running JVM? Is there a command line tool like jstat that takes the pid of the JVM as input and returns its initial parameters? I am particularly interested in the values ​​-Xmx and -Xms that were specified when starting the JVM. Thank.

Change To clarify my limitations. The JVM that we would like to test runs on a production server. Therefore, we prefer minimal disruption. We can track the JVM using jstat, so we hope that there will be a similar simple solution for accessing parameters.

Change We also tried to get parameters using jvisualvm. But in order to connect to the remote jvm, we need to run jstatd and change the JVM security settings, which we found very destructive and risky on the production server.

+73
java jvm
Mar 15 '11 at 19:48
source share
11 answers

You can use jps, for example

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 
+118
Mar 15 '11 at 19:55
source share
— -

Alternatively you can use jinfo

 jinfo -flags <vmid> jinfo -sysprops <vmid> 
+20
Jul 01 '13 at 8:36
source share

I am adding this new answer because, according to the JDK8 documentation, jcmd is now proposed.

It is recommended that you use the latest jcmd utility instead of the previous jstack, jinfo, and jmap utilities for advanced diagnostics and reduced performance.

Below are the commands to get the desired properties / flags.

 jcmd pid VM.system_properties jcmd pid VM.flags 

We need a pid, for this use jcmd -l as shown below

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

Now it's time to use these pids to get the properties / flags you need

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 Output from VM.flags:

 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 on using jcmd, see my blog.

+20
Oct 17 '17 at 7:22
source share

If you can do this in java, try:

RuntimeMXBean

ManagementFactory

Example:

 RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List<String> jvmArgs = runtimeMXBean.getInputArguments(); for (String arg : jvmArgs) { System.out.println(arg); } 
+13
Mar 15 '11 at 19:53
source share

On Linux:

 java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize' 

On Mac OSX:

 java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize' 

On Windows:

 C:\>java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize" 

Source: https://www.mkyong.com/java/find-out-your-java-heap-memory-size/

+13
Aug 17 '16 at 21:19
source share

JConsole can do this. You can also use the powerful jvisualVM tool, which is also included in the JDK from version 1.6.0.8.

+8
Mar 15 '11 at 19:53
source share

This method is applied to any java application working locally or remotely.

  • Launch a Java application.
  • Run JVisualVM found in you JDK (e.g. C: \ Program Files \ Java \ jdk1.8.0_05 \ Bin \ jvisualvm.exe).
  • When this useful tool starts looking at the list of running Java applications under the "local" node tree.
  • Double-click [your application] (pid [n]).
  • On the right of the tab, the contents of the expression check will be displayed. In the middle of the Overview tab, you will see the JVM arguments for the application.

jvisualvm can be found in any JDK since the JDK 6 7 update. A video tutorial on jvisualvm is here.

+1
Jul 08 '14 at 5:19
source share

Windows 10 or Windows Server 2016 provides this information in their standard task manager. A rare case for production, but if the target JVM is running on Windows, the easiest way to view its parameters is to press Ctrl + Alt + Delete, select the Processes tab and add a command line column (right-clicking on any existing column heading).

+1
Jan 22 '19 at 15:57
source share

If you are interested in getting the JVM parameters of a running Java process, just kill -3 java-pid. You will get a main memory dump file in which you can find the jvm parameters used when starting the java application.

+1
Apr 2 '19 at 14:50
source share

You can use the JConsole command (or any other JMX client) to access this information.

0
Mar 15 '11 at 19:57
source share

Can we extract the properties of the application.

My application is in Grails, and the configuration file is great. The file has been deleted, but the application is still functioning, the application has been deployed to tomcat. Is it possible to extract application property key values ​​from the JVM.

0
Jun 30 '19 at 13:44 on
source share



All Articles