[What's OT about this ?]
David said:
It is often stated that each Java program runs in its own Java Virtual
Machine. Do those JVMs share some code or must all of it be loaded
again for every Java application. If they share some code does the
amount of code vary significantly between popular operating systems?
Somewhat speculative answer follows (so be warned)...
AFAIK, there are three things that could be shared between processes.
One is the JVM code itself which is loaded from a DLL or similar (depending on
OS and JVM implementation, of course). If the OS and JVM implementation are
such that that code is shared then it'll be shared ;-) As far as I know all
commercial JVM implementations for Windows package their JVM as a sharable DLL.
This will also apply to any DLLs loaded via JNI (including the system DLLs). I
/guess/ that the same is true for Linux and Unix implementations; God knows
what happens with J2ME and similar implementations.
Another is the "class data sharing" (CDS) information which was introduced for
some platforms in JDK 1.5. See:
http://java.sun.com/j2se/1.5.0/docs/guide/vm/class-data-sharing.html
for details. I believe (but am not certain) that that information is mapped
into the application's address space in a way which allows the OS to share it
amongst all the processes which use it.
The last is the application bytecode. I think that up until 1.5 (or 1.4?)
application (as opposed to platform) JARs were loaded by mapping them into
readonly memory, which would allow sharing (under the covers, inside the OS),
but I have seen it stated that file mapping has been dropped for JARs in later
JVMs from Sun, in which case the memory is presumably no longer shared.
It's worth mentioning that the JITed code representing the application or
platform bytecodes are not (as far as I know) shared, nor even sharable,
between processes even when the bytecode itself is identical. I don't have a
feel for how much dynamically-generated code there is in a typical Java
application compared with the "ordinary" code loaded from DLLs.
-- chris