29

I'm creating an NSIS script, where the Xmx value for the java application being installed can be set during the installation process. I'm not sure if this parameter is being set correctly. Is there a way to check the configured Xmx value when the application is running?

0

6 Answers 6

29

In my case, jmap is the best solution I could find:

jmap -heap <pid>

The above command shows full heap configuration + current usage.

The jmap command is included inside the jdk in the bin directory.

Sign up to request clarification or add additional context in comments.

1 Comment

sudo jmap -heap <pid> worked for me
22

Cheap and dirty (not sure on reliability):

Runtime.getRuntime().maxMemory();

Have also used the following with success:

    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    memoryBean.getHeapMemoryUsage().getMax();

1 Comment

Thanks for the hint, it would have probably done the trick, but I'm fully happy with the tip to use 'jps -v <pid>'
19

jps is a good solution, just run

jps # shows pids
jps -v <pid> # shows params

remember to run it as the user that launched the process though, or it will not work properly.

2 Comments

Thanks! This was exactly what I was looking for. For the record, jps is part of the jdk; for my installation I've found it under C:\Program Files\Java\jdk1.6.0_24\bin
Thanks for the JSP tip, unfortunately it doesn't work on GrailsStarter
9

Doron Gold gave the correct answer for Java 8 and below. For Java 9 and above you can get the same info by using

jhsdb jmap --heap --pid <pid>

Comments

4

I'm a big fan of kill -3 < pid > , which will give you details on the current memory and garbage collections along with stacks for all threads.

2 Comments

Thanks for the idea, but the nsis installers target only windows platforms. Following the idea, I've checked if a pendent existed for windows, but taskkill (technet.microsoft.com/en-us/library/bb491009.aspx) successfully kills my process, but doesn't provide any further info.
Btw, for linux, the app is being started with a shell script, where the xmx can be configured in plain text. For OSX it's contained in the app file.
1

The following worked for me for JVM version 11.0.16 (I had installed OpenJDK 11)

sudo jhsdb jinfo --flags --pid <pid>

It may work for you without using "sudo".

I had to do this after sudo jhsdb jmap --heap --pid <pid> was giving me the following error message: Exception in thread "main" sun.jvm.hotspot.types.WrongTypeException: No suitable match for type of address

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.