JVM Server vs Client Mode

25/11/2012

JVM is launched in client mode by default in SUN/Orace JDK. JVM provides option to launch it in server or client mode. These two modes give different run time performance options.

At high level there are two steps from java source to running program. In first step we compile the java source to binary class file. In next step binary class is executed. In java class execution, combination of interpretation and compilation is done. Generally it is interpretation and to boost the performance JVM uses a just-in-time (JIT) compiler.

JIT compiles selective block of code to native instructions. Because running native instructions is always better and gives good performance. This is done at the cost of spending resource to compile code to native. There will be a performance benefit, if that block of code is used repeatedly as in subsequent runs instead of interpreting the binary code the native instructions will be executed.

When the JVM is launched in ‘server’ mode, it performs aggressive optimization than the ‘client’ mode. So server mode is better suited for production deployments and gives better performance. In case of tiny programs, where there is minimal scope for optimization server mode may not be best suited and in times it can even give worst performance than the client mode because of the additional cost of native code conversion.

The policy of having a JIT compiler and the performance optimization algorithm are completely the choice of the JVM implementors and it is not enforced in JVM specification. So when we study this behavior it is completely specific to the JVM we use and it cannot be generalized.

How to choose between client and server jvm mode?

To choose between server and client mode we can have client mode for small programs that are not executed for a longer period and server mode otherwise. The startup of the JVM might be slower in server mode and the runtime memory footprint also will be larger. Client mode starts JVM in quicker time and memory footprint is also lesser. This is because client mode does not try to optimize many code blocks as the server mode does. Therefore the shorter startup time and less memory usage.

Ads by Google

So what is the special optimization done by server mode? One example is in lining of virtual method invocations wherever it is used. This is done by adaptive compilation. One more thing done by server mode is, it does not give back the memory acquired back to the OS till the execution is complete. But in case of client mode if a certain block of memory is left unused it may give back to the OS during the execution of the program. Initial options like InitialHeapSize and MaxHeapSize are taken as large numbers in server mode on launch in comparison with client mode.

JVM hotspot VM options provide rich set of opportunities to calibrate the runtime performance. So to launch is client mode we need not give any options as by default the JVM launches in client mode. To launch in server mode just use “- server” when we run java tool like,

java -server ClassName

This is based on SUN/Oracle JDK. If it is JRockit VM the default is server mode and client mode should be launched using option “-client”. Ah I forgot to mention a thing, as always the same java class can be used for running in both the modes. When we download JDK we get both the modes bundled. If we download JRE alone, then we get only the client mode with it.

Just in case if you don’t know what JVM you are using then the following java code should help.

String jvmName = System.getProperty("java.vm.name");  // jvmName = Java HotSpot(TM) Server VM

In a future article, I plan to showcase performance benchmark of sever and client mode.

This Core Java tutorial was posted on 25/11/2012.
Ads by Google

32 comments on “JVM Server vs Client Mode

  1. Wonderful article. Every line is worth reading. You keep on giving nice information. Thanks. Thanks.

  2. Articles like this help us understand the internals of java. Thanks a lot Joe.

  3. Its really helpful information…

    Thanks a lot Sir….

  4. its really a good concept. Thnks Sir

  5. Thanks!

    Why we dont have Server/jvm.dll under JRE?

    • When we install JRE separately, we don’t get the server (server/jvm.dll) mode.

      Inside the JDK there is a JRE and the jvm.dll can be found at “\Java\jdk1.7.0_07\jre\bin\server” which will be used when we use server mode.

      • Thanks for the Info…

        I know that,
        1,When we install JDK:
        we can get the jvm.dll both in Server and Client under JDK–>JRE.

        2, When we install JRE seperately:
        Why we are not having server/jvm.dll under JRE.?but we are having client/jvm.dll in it?

        why we dont have server mode option under JRE, when we install JRE seperately?

        Please clarify!

  6. Good article!
    I’d love to hear more about inlining of virtual method invocations and adaptive compilation though.

  7. Hi,

    Very nice example and explanation.

    Thanks a lot for sharing this info.

    Regards,
    Suyash Bhalekar

  8. can you write about jboss configuration in full detail

  9. Should be noted that there is no client mode in 64bit JVM!

  10. Hi Joe, Please keep an index page of all the links in the site to browse quickly to the required article.

  11. Great Article. Its well articulated with all required details.

  12. Pingback: Performance of JVM Server and Client Mode

  13. I always listen my project manager that “in production environmnt latency will not be there” but didnt know why he tell like this
    With this article i came to know why in production application behaves faster.
    Thanks Joe for a nice article!

  14. You keep on giving nice information.Thanks

  15. Thank you for good article. A lot of thing I don’t know about Java. :(

  16. THANKS FOR YOUR INFORMATION AND HELPFUL FOR MY PROJECT

  17. Hello Sir,

    Thank you so much for this article,

    Thanks
    Dhandapani

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>