[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Synchronisation and Optimisation



Stephen Cheng wrote:
> I would however argue that it is not necessary for the
> optimisation algorithms to produce a "correct" optimised version if the
> original program does not correctly synchronise all shared variable.
> Under the Java VM specification, such programs (even unoptimised) would
> never not have a deterministic behaviour, and they would behave
> differently under different VMs.

This is not a sufficient reason to disregard synchronization rules. What if the
improper synchronization is unintended? What if the incorrect code is actually
the result of a buggy compiler? To account for these unkowns, Soot must do the
only reasonable thing: preserve the original semantics of the input, regardless
of whether it is "sensible" or not. This is the only way a programmer can be
expected to debug faulty code.

Having said that, we are interested in analyses that provide a more exact
picture of synchronization so that we might improve Soot's optimization. One
particular example is code motion. If we can refine the scope to which a
synchronization operation applies, we may be able to move unrelated code accross
the monitor statements. Currently, Soot must make overly-general assumptions
that limit such optimizations in the presence of synchronization.

If you are interested in contributing a synchronization analysis, I'm sure it
would be appreciated. You may want to start by reading Erik Ruf's PLDI 2000
paper: Effective synchronization removal for Java
(http://portal.acm.org/citation.cfm?id=349299.349327).

With regards to flushing values of an object, I believe this is the
responsiblity of the VM's implementation of the monitorenter & monitorexit
bytecodes. The actual implementation (assuming it is correct) should have no
relevance to effects at the Jimple level.

I am not that familiar with Soot's handling of synchronization relative to the
standard optimizations. Perhaps someone else could comment.

Rhodes

--
Rhodes Brown
Sable Research - McGill University

Web:    http://www.sable.mcgill.ca
Email:  rhodesb@sable.mcgill.ca