Table of contents
Abstract........................................................................................................................................1
Introduction .................................................................................................................................1
JIT technology.............................................................................................................................2
Compilation happens during run time ...................................................................................................... 2
Strategy: Focus optimization effort on important code .................................................................... 2
Inlining...................................................................................................................................................... 3
Strategy: Aggressively inline method calls ...................................................................................... 3
Virtual and interface methods .................................................................................................................. 3
Strategy: Devirtualize as many call sites as possible ...................................................................... 3
Heap allocations ...................................................................................................................................... 4
Strategy: Optimize for object locality................................................................................................ 4
Java coding guidelines...............................................................................................................5
Object allocations..................................................................................................................................... 5
Guideline: Avoid creating objects inside loops ................................................................................ 5
Guideline: Minimize object allocations, if possible........................................................................... 7
Guideline: Use immutable fields ...................................................................................................... 8
Methods ................................................................................................................................................... 8
Guideline: Keep methods small ....................................................................................................... 8
Guideline: Use exceptions and reflection rarely .............................................................................. 9
Loops ..................................................................................................................................................... 10
Guideline: Do not modify the loop bounds within the loop body.................................................... 10
Guideline: Increment the loop index by a single value across all paths ........................................ 12
Guideline: Make loops as compact as possible ............................................................................. 13
Guideline: Use locals instead of fields or static variables, where possible.................................... 13
Guideline: System.arraycopy() is well-optimized by the JIT .......................................................... 13
Guideline: TRJIT can also optimize special loops such as memset and array translate............... 14
Synchronization ..................................................................................................................................... 15
Tuning ........................................................................................................................................16
Tuning application code ........................................................................................ 16
Tuning JVM parameters ........................................................................................ 16
Tuning the garbage collector ................................................................................. 16
Tuning JVM parameters for application startup......................................................... 17
Diagnostic techniques and tools available for performance problems ........................... 18
Summary....................................................................................................................................18
Footnotes ...................................................................................................................................19
Resources ..................................................................................................................................20
About the authors .....................................................................................................................21
Trademarks and special notices..............................................................................................22
IBM Just-In-Time Compiler (JIT) for Java
Best practices and coding guidelines for improving performance