• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why there is 2 compiler in java?  RSS feed

 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In java, we have two compiler like HotSpot Client and Hotspot server compiler. Why we need two different types of compilers?

 
Tim Moores
Saloon Keeper
Posts: 4036
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usage patterns differ between a desktop and a server. For example, server JVMs tend to be long-running, possibly weeks or months, whereas a desktop JVM will rarely run for even a day. Also, for desktop JVMs quick startup time is important so that a user need not wait for long; that's less important on the server. It makes sense to optimize for those cases differently.
 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Moores,

Thanks for your reply.

So it will be depends on the OS, If I use normal OS like XP, it will be client.
If I use server OS like Windows 2000, it will be Server.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Intel Windows machines will always default to the client VM, other OSes depend on the machine spec.
Server or Client VM ?
 
Thennam Pandian
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let say, If I compile the java in windows and run the file in Other OS, Will it get the advantage of server VM?

Or, it won't get the advantage of server VM, as it is not compiled with the server compiler.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thennam Pandian wrote:Let say, If I compile the java in windows and run the file in Other OS, Will it get the advantage of server VM?

Or, it won't get the advantage of server VM, as it is not compiled with the server compiler.

The machine you compile your code on is irrelevant. This just converts the source code to byte code which is machine independent (it can run on any machine)
The machine specification (or the -server and -client command line options) decides if the server or client VM is run.
The VM includes a hotspot compiler which may or may not compile all or part of the byte code into machine code. This is done whilst the program is running. The machine code is machine dependent and the VM will include a different hotspot compiler for each machine architecture.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "-client" mode will use the JIT compiler originally developed by Apple -- and it does a straight to native upon the class load. It is great for relatively short lived programs.

The "-server" mode will use the JIT compiler developed by Sun -- and it actually uses the interpreter initially. During this phase, it will gather statistics. After a while, it will do a very optimized JIT compilation based on the data gathered during the interpreter phase. This is, of course, great for really long lived programs.

There is also a "-tiered" mode, developed by Azul, only for the Azul JVM, but I believe that it is being donated to the Open JDK (I think). With that mode, it will use a modified "-client" JIT initially (that also gathers statistics), and then use a "-server" JIT later when it has enough stats to do an optimized compilation. Arguably great for both short and long lived programs.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!