I have a java standalone program with default settings. Now I have looked up the documentation and it says that the default heap size is 64Mb for 1.6 JVM. I am running in 64bit env so the documentation said a 30% will be added, which is around 83Mb.
Sure enough, in my standalone program, when I print Runtime.maxMemory(), I get the number 85196800.
Now the other thing I observe is that the "used" memory by calling this Runtime.getRuntime().totalMemory () - Runtime.getRuntime().freeMemory ();
I noticed that whenever that "used" number approaches near 85196800, it drops back down to the 6000000 range. Again, this makes perfect sense as I understand it because gc will try to clean up when it is near max heap size. So far so good, but correct me if I am wrong.
Now, the problem is this: if I use TOP in my unix server, I noticed that over time the Java process grows in the VIRT field. This field is suppose to represent the amount of virtual memory. It just keeps growing, and right now it is as 1450Mb. Why is this? I thought the whole point of the max heap size, is that the JVM will not grow past that amount of memory usage? Needless to say, this eats into my swap space and ultimately brought my server down to its knew (the machine only have 256mb ram).
Another side point is that the RES field is always at 160Mb. Now I don't quite understand how 160 is still bigger than the 83Mb, I'm guessing that the other 77 Mb is for some things that are outside of the heap
Can anyone explain what is really going on here? And how do I limit this jvm process such that it will not eat up all resources on this server and bring it to a halt?
Thanks!!