[code-reflection] RFR: Model synchronized statements

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Aug 23 08:59:26 UTC 2024


On Tue, 20 Aug 2024 20:43:44 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

> Model synchronized statements.
> 
> A synchronized op has two bodies one for the expression yielding the monitor and one for the synchronized block that covers the monitor enter and exit.
> 
> The lowering of synchronized op produces a model containing monitor enter and exit operations and operations covered by exception regions, ensuring that a monitor exits under exceptional circumstances. 
> 
> The interpreter has been updated, but locking is currently on a best effort basis using `ReentrantLock` instances thus we cannot consistently apply synchronization on objects across interpretation, executing in a single thread, and bytecode executing in one or more other threads.  We would need to update the interpreter to use native methods that invoke the JNI `MonitorEnter` and `MonitorExit` methods, although it is not clear if those can be mixed in a nested manner with JVM execution of monitor enter and exit bytecode instructions.
> 
> A simple test for generated bytecode has been included that tests for the expected number of monitor enter and exit instructions, and single threaded execution for non-exceptional and exceptional cases.

javac changes (and test) look good

-------------

Marked as reviewed by mcimadamore (Reviewer).

PR Review: https://git.openjdk.org/babylon/pull/217#pullrequestreview-2256729950


More information about the babylon-dev mailing list