Notes on the Java server flag

I recently had an interesting discussion on performance gains resulting from the use of the -server flag when passed to the JVM to run benchmarks.

But first what is the effect of the server flag? In a nutshell it tells the JVM to spend more time on the optimization of the fragments of codes that are most often used (hotspots). It  leads to better performance at the price of a higher overhead at startup.

Therefore, when benchmarking an algorithm it would seem interesting to switch this on to reduce running times.

I tried it on my own benchmarks (on an Ubuntu 64bits machine) and found out that there were no significant change in runtime, while other people were talking of a reduction of 20 to 40%. It turned out that depending on the machine and operating system, the JVM would automatically turn this option on or off: in fact in any recent computer with an OS different from windows 32bits it will be turned on by default.

Please note that you will need to install the JDK to use the server mode on a 32bits windows machine.

More information can be found in the Java HotSpot FAQ:

What’s the difference between the -client and -server systems?
These two systems are different binaries. They are essentially two different compilers (JITs)interfacing to the same runtime system. The client system is optimal for applications which need fast startup times or small footprints, the server system is optimal for applications where the overall performance is most important. In general the client system is better suited for interactive applications such as GUIs. Some of the other differences include the compilation policy,heap defaults, and inlining policy.

Where do I get the server and client systems?
Client and server systems are both downloaded with the 32-bit Solaris and Linux downloads. For 32-bit Windows, if you download the JRE, you get only the client, you’ll need to download the SDK to get both systems.

For 64-bit, only the server system is included. On Solaris, the 64-bit JRE is an overlay on top of the 32-bit distribution. However, on Linux and Windows, it’s a completely separate distribution.

I would like java to default to -server. I have a lot of scripts which I cannot change (or do not want to change). Is there any way to do this?
Since Java SE 5.0, with the exception of 32-bit Windows, the server VM will automatically be selected on server-class machines.

The definition of a server-class machine can be found here:

In the J2SE platform version 5.0 a class of machine referred to as a server-class machine has been defined as a machine with

  • 2 or more physical processors
  • 2 or more Gbytes of physical memory

On server-class machines by default the following are selected.

  • Throughput garbage collector
  • Heap sizes
    • Initial heap size of 1/64 of physical memory up to 1Gbyte
    • Maximum heap size of ¼ of physical memory up to 1Gbyte
  •     Server runtime compiler
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s