Java Reference
In-Depth Information
1. Inlining is the most beneficial optimization the compiler can make, particularly
for object-oriented code where attributes are well encapsulated.
2. Tuning the inlining flags is rarely needed, and recommendations to do so often
fail to account for the relationship between normal inlining and frequent inlining.
Make sure to account for both cases when investigating the effects of inlining.
Escape Analysis
The server compiler performs some very aggressive optimizations if escape analysis is en-
abled ( -XX:+DoEscapeAnalysis , which is true by default). For example, consider this class
to work with factorials:
public class
class Factorial
Factorial {
private BigInteger factorial ;
private int
int n ;
public Factorial ( int
int n ) {
this . n = n ;
public synchronized
synchronized BigInteger getFactorial () {
iif ( factorial == null
null )
factorial = ...;
return factorial ;
To store the first 100 factorial values in an array, this code would be used:
ArrayList < BigInteger > list = new
new ArrayList < BigInteger >();
for ( int
int i = 0 ; i < 100 ; i ++) {
Factorial factorial = new
new Factorial ( i );
list . add ( factorial . getFactorial ());
The factorial object is referenced only inside that loop; no other code can ever access that
object. Hence, the JVM is free to perform a number of optimizations on that object:
Search WWH ::

Custom Search