user1453345
user1453345

Reputation: 338

Why there is memory usage difference between xmx and top?

I set the xmx of jvm equals to 4 G, but after running for a time, when I use top to see the memory, it shows the process used 12 G memory.

So what the xmx actually mean? what should I do if I want to limit the jvm memory to 4 G ?

command line: -server -Xms4g -Xmx4g

And another related question :)

If the gc happens, will the space of the objects that not used any more in young generation be inevitably released by JVM ? or some of them left to the next gc ?

thanks

Upvotes: 2

Views: 2877

Answers (1)

Strelok
Strelok

Reputation: 51481

The -Xmx option to the JVM specifies the maximum size of the Java garbage collected heap. It does NOT limit the size of the memory used by the JVM. The size of the process reported by ps or top will include that, plus any other memory used by the process. The following are examples of things that are not part of the garbage collected heap and yet are part of the memory required by the process:

  • Code to implement the JVM
  • The C manual heap for data structures implementing the JVM
  • Stacks for all of the threads in the system (app + JVM)
  • Cached Java bytecode (for libraries and the application)
  • JITed machine code (for libraries and the application)
  • Static variables of all loaded classes

Upvotes: 7

Related Questions