Command to find out -Xms and -Xmx variable values for a given java process?
Asked Answered
P

3

17

I have a java program, which i ran and figured out its process id with jps.

How can i see what is the value of -Xms and -Xmx variable for this java process ?

Penmanship answered 15/1, 2015 at 9:0 Comment(2)
From you answer to SQL.injection's answer, it seems like you have a different jps on your Mac than I do. Can you add the following information to your question: (1) Which MacOS X version. (2) Which java version. (3) Results of running which jps. (4) Results of running file $(which jps).Surtout
answers for questions :- 1) which jps - /usr/bin/jps 2) whic java version - java version "1.7.0_55" , 3) which MacOSX - 10.7.5 4) file $(which jps) -> /usr/bin/jps: Mach-O universal binary with 2 architectures /usr/bin/jps (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/jps (for architecture i386): Mach-O executable i386Penmanship
C
22

Try

jcmd <PID> VM.command_line
jcmd <PID> VM.flags
Chap answered 15/1, 2015 at 10:26 Comment(2)
the output gave me this - -XX:InitialHeapSize=1073741824 -XX:MaxHeapSize=17179869184 -XX:+UseCompressedOops -XX:+UseParallelGC Is It in Bytes . If the max heap size is in 17 GB , how is it even possible , because before running my program , my JAVA_OPTS was set as export JAVA_OPTS='-Xms128m -Xmx1024m' , it should not be more than 1 GBPenmanship
@AdonSmith JVM itself does not recoginze JAVA_OPTS. Try _JAVA_OPTIONS instead.Chap
A
8

you can use jps and do it from the command line:

jps # shows pids
jps -v <pid> # shows params
jps -v <localhost:pid> # the host must be indicated

if this is not enough you can do it programmatically inside the program to check the maximum amount of memory that the Java virtual machine will attempt to use:

Runtime.getRuntime().maxMemory()

and you can also use use the class MemoryUsage to get the initial, used and max ammount that can be used for memory management.

MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    memoryBean.getHeapMemoryUsage().getMax()
    memoryBean.getHeapMemoryUsage().getUsed()
    memoryBean.getHeapMemoryUsage().getInit()
Armillas answered 15/1, 2015 at 9:14 Comment(6)
I am on mac OS 10.10 - when i typed the command jps -v <pid> , it failed- grep: 89038: No such file or directoryPenmanship
I don't want to do it programmatically . Need a command only :(Penmanship
@AdonSmith you need to indicate the host. See again my awnserArmillas
i ran it - jps -v localhost:89038, but it gave me an output - grep: localhost:89038: No such file or directoryPenmanship
@AdonSmith most likely there is no process id with that number. I suggest just running jps -lvm without the id.Ledda
See i am running mac os, so may be your commands are not proper for that , can that be a reason ? because there is a processId , i found it by doing jpsPenmanship
F
6

I think jmap command will give you everything you want.
usage: jmap -heap {pid}

root@BobServerStation:/usr/local $ jmap -heap 3280
Attaching to process ID 3280, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.65-b04

using thread-local object allocation.
Parallel GC with 8 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 0
   MaxHeapFreeRatio = 100
   MaxHeapSize      = 4116709376 (3926.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 85983232 (82.0MB)
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 65011712 (62.0MB)
   used     = 42273152 (40.3148193359375MB)
   free     = 22738560 (21.6851806640625MB)
   65.0239021547379% used
From Space:
   capacity = 10485760 (10.0MB)
   used     = 10479760 (9.994277954101562MB)
   free     = 6000 (0.0057220458984375MB)
   99.94277954101562% used
To Space:
   capacity = 10485760 (10.0MB)
   used     = 0 (0.0MB)
   free     = 10485760 (10.0MB)
   0.0% used
PS Old Generation
   capacity = 171442176 (163.5MB)
   used     = 376368 (0.3589324951171875MB)
   free     = 171065808 (163.1410675048828MB)
   0.21953057805332568% used
PS Perm Generation
   capacity = 22020096 (21.0MB)
   used     = 15401488 (14.688003540039062MB)
   free     = 6618608 (6.3119964599609375MB)
   69.94287400018601% used

8464 interned Strings occupying 699456 bytes.
Footrope answered 15/1, 2015 at 11:34 Comment(2)
it gives me error : attach: task_for_pid(18830) failed (5) Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the processPenmanship
please use sudo jmap -heap {pid} @Adon SmithFootrope

© 2022 - 2024 — McMap. All rights reserved.