implementing escape analysis

Boehm, Hans hans.boehm@hp.com
Thu Feb 16 20:28:00 GMT 2006


Whether or not you can remove locks based on escape analysis is very
dependent on the details of the language thread semantics or memory
model.  Whether it matters is highly dependent on the usage model.

In Java 1.5 and later, you can remove synchronizations on thread-local
objects.  According to the pre-1.5 spec, you generally could not, since
such synchronization still had memory ordering implications.  This may
not have been understood in a 1999 paper.

With pthreads, I believe you technically cannot eliminate locking on
thread-locals, at least in all contexts, for very subtle reasons.
(Actually, according to the straightforward interpretation, you can't.
If you look more closely, you almost can, but not quite.  If you really
want to know, see
http://www.hpl.hp.com/techreports/2005/HPL-2005-217.pdf, particularly
section 6 and footnote 10.)

I think synchronization elimination is important for Java, since a lot
of the library implicitly synchronizes, whether you want it to or not.
I'm not convinced this is a positive feature.  This is mostly not a
problem with the C/C++ libraries, with the notable exception of things
like putc() in stdio.  Thus I'm not really sure to what extent the
benefit here really carries over between languages.

There are similar issues with stack allocation.  C/C++ code tends to
stack allocate itself if it's easy.  Java code can't.

It makes sense to me to do this in a language independent way if it's
not much harder.  If it is much harder, I don't know ...

Hans



More information about the Java mailing list