3

I'm running my Java app through command line without passing in any JVM settings (i.e. java -cp some.jar).

VisualVM shows the Java app allocated ~740M of Heap space.

Since I didn't pass in any JVM settings, how can I view what JVM settings my app is using?

5
  • Is this answer helpful? Commented Oct 12, 2016 at 5:26
  • @rD. Thanks but no. jps -lvm only shows explicit parameters being passed in. It's not showing what Xmx the JVM has for the app. Commented Oct 12, 2016 at 5:49
  • The maximum heap is typically 1/4 of main memory unless you have the 32-bit windows JVM. I guess you have around 3 GB if 740MB is your maximum. Commented Oct 12, 2016 at 8:21
  • @PeterLawrey My machine has 16GB of ram. Do you mean 1/4 of all memory or available memory? If I don’t specify Xmx when launching my java app, is there a limit to how much heap the JVM will allocate? Commented Oct 12, 2016 at 12:48
  • 1
    @Glide the heap will be 1/4 of how much the memory the OS says you have (which can be slightly less) this is the heap limit but the JVM can use more memory for other purposes. Commented Oct 12, 2016 at 14:16

2 Answers 2

3

You can use java.lang.management.MemoryUsage:

MemoryUsage mu = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

and get max memory from it

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

3 Comments

Is it possible not to modify the code to find the max memory? I can currently find the max memory with VisualVM. I'm just curious what JVM settings my app is using when no VM parameters are passed in when starting the app.
@Glide: well, you could use JVisualVM for it. Wait—you do already…so…what’s your question?
@Holger You're right, I must've been blind because I didn't see the Max listed along with Size and Used under the Heap tab.
1

I would use a Profiling Tool and analyze the memory. Also if you know how much memory is used, the problem is not solved. Next step is to know why so much memory is used.

Try to profil your program with Java Mission Control

The tool is part of any newer JDK like: "C:\Program Files (x86)\Java\jdk1.8.0_20\bin\jmc.exe"

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.