Saturday, March 9, 2013

Just In Time


JIT - Just In Time   

A famous phrase to say to someone who just arrives when there is a reference.

JRockit JVM uses JIT in similar way - compiles the method calls (byte code to Machine code) just in time i.e. when the method is called
JVM with JIT is like a 4 stroke engine - picks up slowly but cruises afterwards. Similarly, with JIT, application start up may be a bit slow initially as there will lot of method call in the initial run phase of the application there by JIT taking time to compile the byte code to machine code and then JVM calls the machine code directly there by crusing on the machine code instructions.

And then, there comes some more intelligence with JRockit JVM - The cruise control ! - The Optimization.

JVM monitors the threads and looks for the methods that require some optimization, like the most frequently used methods ('HOT' methods). Once these are identified, the optimizations will be done in the background which is basically boosting these 'Hot' methods execution by eliminating duplicate code logic, reducing number of costly references (like local variable vs. object method calls) etc.,

On the other side, often JIT is blamed when ever there is a slow start of JVM and the application.To validate this, we can do some simple checks like

(1) Inserting timers in the application to measure application startup
(2) Starting the JVM with a command line option -Xverbose:codegen -- This gives the information about a method being compiled like name, memory location, duration of compilation, time since compilation started
(3) Check the initial heap(-Xms) and max heap (-Xmx) sizes. It is a good practice to have these two values the same. If these two are not the same and -Xms is too small then it forces JVM to do more inintial full GCs until it pushes the roof (commited bytes) towards reserved bytes (-Xmx). On the other hand if these two values are vey large then it takes time for JVM to reserve huge memory and then commit huge memory
(4) Record using JRA to analyse the JVM actions
(5) Sometimes the optimization process of JVM may also cause slowness.Try restarting JVM with -XnoOpt command and see the difference.
(6) And, try to eliminate those methods from optimization process which take too long for optimization by creating optfile and sending runtime diagnostics commands using JRCMD, Ctrl+Break, JRockit Management Console.




No comments:

Post a Comment