简体   繁体   中英

JVM heap size issues

I am just started R&D on JVM heap size and observed some strange behavior.

  • My system RAM size is 4 GB
  • OS is 64-bit windows 7
  • Java version is 1.7

Here is the observations:

I wrote a sample main program which starts & immediately went to wait state.

When I run the program from eclipse with -Xms1024m -Xmx1024m parameters it can able to run 3 times/parallel-process from eclipse ie 3 parallel process only as my RAM is 4GB only. This is expected behavior.

Hence I had rerun the same with -Xms512m -Xmx512m parameters and it can able to run 19 times/parallel-process from eclipse even my RAM is 4GB. HOW?

I used VisualVM tool to cross-check and I can see 19 process ids and each process id is allocated with 512m even my RAM size is 4GB, but HOW?

I have goggled it & gone through lot oracle documentation about the Memory management & optimization but those articles not answered my question.

Thanks in advance.

Thanks, Baji

I wonder why you couldn't start more than 3 processes with -Xmx1024M -Xms1024M. I tested it on my 4GB Linux system, and I could start at least 6 such processes; I didn't try to start more.

Anyway, this is due to the fact that the program doesn't actually use that memory if you just start it with -Xmx1024M -Xms1024M. These just specify the maximum size of the heap. If you don't allocate that amount of data, this memory won't get actually used then.

"top" shows the virtual set size to be more than 1024M for such processes, but it isn't actually using that memory. It has just allocated address space but never used it.

The actual memory in your PC and the memory that is allocated must not match each other. In fact your operating system is moving data from the RAM ontothe hdd when your ram is full. This is called swapping / Ram-paging. Thats why windows has the swap-file on the hdd and unix has a swap partition.

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