[OT] Is loading the second Java application faster than loading the first?

D

David Segall

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?
 
C

Chris Uppal

[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
 
T

Thomas Kellerer

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?

In addition to the CSD that Chris mentioned:

My understanding why subsequent startups are faster is the OS level file
cache. The JRE reads a substantial amount of data from rt.jar and all
the .dlls
Once those files are loaded the first time, the OS will keep them in the
file system cache for a certain amount of time. Each subsequent start
will not require any disk access (or at least a lot less disk access)
compared to the first start.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top