Can access by local method variables be faster then access by member variables ?
Martin Buchholz
martinrb at google.com
Fri Aug 15 18:04:11 PDT 2008
The practice in java.util.concurrent, following Doug Lea,
is to copy an unmodified field into a local
at the beginning of a method,
and then use that local for the duration of the method
E.g.:
private void interruptWorkers() {
final ReentrantLock mainLock = this.mainLock;
mainLock.lock();
try {
........................
} finally {
mainLock.unlock();
}
}
It is believed this gives a performance win
even when the field in question is final,
where the jit (or even javac?) should be
able to easily make such an optimization.
Martin
More information about the hotspot-dev
mailing list