Cette page appartient aux archives web de l'EPFL et n'est plus tenue à jour.
This page belongs to EPFL's web archive and is no longer updated.

Idea for lock extension for Java

I have a "simple" idea for lock composition. Everyone knows that locks are not scalable because they don't compose, not without breaking encapsulation at least.
Modern JVM's can merge locks of the same object if they are used inside the same function block (see http://www.ibm.com/developerworks/java/library/j-jtp10185/).
The idea is to use let the programmer specify explicitly which locks are composable, something like:
composable synchronized void add(int _v) {}
Both compiler and runtime would treat these synchronized methods & blocks differently. There are at least two possible scenarios: (#1) When composable locks are enclosed by a common parent lock, and (#2) no parent lock but just sibling locks.
 
(#1)
synchronized (foo) {
add(1);
add(2);
}
  The VM would force a thread to always acquire the parent lock of a composable lock (recursive).
 
(#2)
add(1);
add(2); 
  All sibling composable locks should be acquired in the same order.
 
This is just a pre-draft of the idea, any comment is welcomed.
Posted by Daniel Tralamazza on Tuesday 3 March 2009 at 14:34