Can access by local method variables be faster then access by member variables ?

Martin Buchholz martinrb at
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

    private void interruptWorkers() {
        final ReentrantLock mainLock = this.mainLock;
        try {
          } finally {

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.


More information about the hotspot-dev mailing list