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

Discussion in 'Java' started by David Segall, Jan 2, 2007.

  1. David Segall

    David Segall Guest

    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?
     
    David Segall, Jan 2, 2007
    #1
    1. Advertising

  2. David Segall

    Chris Uppal Guest

    [What's OT about this ?]

    David Segall wrote:

    > 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
     
    Chris Uppal, Jan 2, 2007
    #2
    1. Advertising

  3. Re: [OT] Is loading the second Java application faster than loadingthe first?

    On 02.01.2007 16:42 David Segall wrote:
    > 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
     
    Thomas Kellerer, Jan 2, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    43
    Views:
    7,372
    Benji
    Nov 2, 2005
  2. Julie
    Replies:
    140
    Views:
    5,046
    George Neuner
    Jun 6, 2004
  3. Sanny
    Replies:
    12
    Views:
    584
    Andrew Thompson
    Dec 15, 2006
  4. Rishi Boparai

    Java Faster Than C ?

    Rishi Boparai, Apr 1, 2008, in forum: Java
    Replies:
    23
    Views:
    1,043
    Martin Gregorie
    Jul 6, 2008
  5. jalanb3
    Replies:
    0
    Views:
    220
    jalanb3
    Jan 23, 2009
Loading...

Share This Page