Knut Anders Hatlen wrote:
Daniel John Debrunner <[EMAIL PROTECTED]> writes:
Knut Anders Hatlen wrote:
They use a pattern of first copying the instance
variables into local variables, then do the work on the local
variables, and finally write back to the instance variables. While I
find that a little confusing because I would expect the run-time
compiler to be able to perform that kind of optimization itself,
that's a different issue from what is discussed in this thread.
Can the run-time optimizer/compiler perform such an optimization when
the instance variable is not final? I would have thought not.
Yes, I believe it can. Java's memory model basically allows the
compiler to assume that the variables are accessed by a single thread
as long as it doesn't hit a memory barrier (like a volatile variable
or a synchronized block).
How effective can this be when the accesses to the instance field are
intermixed with method calls of other objects, especially when those
methods are interface calls?
Dan.