简体   繁体   中英

java max heap size and OS top output

i'm trying to run a jar file but i want to handle jvm max heap size. Size i'm using -Xmx80m param in order to set max head size 80MB.

I use "top" command of my linux OS to monitor my application's memory allocation and i'm surprised that jvm uses more memory than i specified with -Xmx param (java -Xmx80m -jar myapp.jar). More specifically from my top output

VIRT: 257m
RES: 109m

I think that RES should be at max 80mb and if my application needs more than 80mb jvm would trow exception "out of memory" (or something like this)

In my application i'm using an external library. Does this library uses its own memory apart from heap that i specified with param?

In any case how can i limit the memory usage of jvm in order not to overcome what i set with parameter?

Update:
Is it a good solution to use ulimit (unix command) to limit the resources used by JVM?

I'm using:

java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Server VM (build 22.0-b10, mixed mode)

on a fedora 8 pc

You should not expect that -Xmx would place a hard constraint on the total memory used by the JVM.

-Xmx places a limit on the size of the Java heap. Any memory outside the Java heap is not subject to this limit. This includes code, class metadata, constant pools, etc.

One additional thing you can tweak is the size of the permanent space ( -XX:MaxPermSize ), since it is not included in -Xmx .

The -mx or -Xmx option sets the maximum heap size. This virtual memory is allocated on start up and used as the program runs. As @aix notes, non-heap memory can be more.

An external native library will use its own, non-heap memory. The maximum will limit the heap across all libraries. (Its pre-allocated and cannot increase)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM