A technique for identifying and executing synchronized read regions and
synchronized write regions is provided. The technique processes program
code with a software tool to convert the code to an internal
representation for the software tool and constructs a control flow graph
of code blocks which also identifies the entry and exit points for each
region of code subject to a lock. For each code block in the control flow
graph, visibility analysis is performed. Each determined entry and exit
point is moved to enclose the smallest set of code blocks subject to a
lock which can be achieved without altering code semantics. A set of
trees is created to represent the manner in which the synchronized
regions are nested. If the tree contains at least one block previously
identified, then the tree is marked a write. Otherwise, the tree is
marked a read tree. A write lock is then created for the region in each
tree identified as a write tree and a read lock is created for the
regions in each tree identified as a read tree.