I am trying to debug why a program that prints Helloand then Thread.sleep(3600*1000)uses ~ 404 MB of virtual memory under Linux (with OpenJDK and Sun JVM) on both CentOS 5 and Ubuntu 10.04 servers. (MediaTemple (dv) and (ve), respectively).
But more specifically, when I connect using VisualVM or JConsole, I see what looks like a reasonable use of memory: a bunch of 820KM (after GC); 8.4MB PermGen; Loaded 1136 classes.
Why the discrepancy?
Does the JVM just work using this large memory? I tried to run two Hello applications to find out if the scales use linearity, and this does:
I started by using 78 MB of shared RAM. Running one welcome application allows you to use memory up to 376 MB. Launching another hello application gives a total use of 656 MB of RAM, so the memory doesn't seem to be very well used. (these numbers are not virtual memory
(these specific numbers are with OpenJDK, but using Sun 6 JDK gives acceptable, but slightly lower memory usage)
the code:
public class Hello {
public static void main(String[] args) throws Throwable {
System.out.println("HI");
Thread.sleep(3600 * 1000);
return;
}
}
Command line:
java -Xmx32m -Xms32m Hello
With JMX:
java -Dcom.sun.management.jmxremote.port=8005 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Xmx32m -Xms32m Hello
Thank you for your help.
Wiktor
source
share