wiki:JavaParty/RMA

Remote Monitor Access (RMA)

Since JavaParty 1.07a

KaRMI is able to remotely access synchronization monitors of objects on far nodes. With this construct the implementation of transparent synchronized blocks on remote objects is possible.

Implementing remote monitor access is non-trivial, because there are specific restrictions regarding the byte code instructions dealing with acquiring and releasing the monitor of an object. These instructions must always be paired, to assert that a monitor acquired in some block of code is released when the control flow leaves this block. This restriction is checked by the byte code verifier at class loading time.

Since Java synchronization is bound on static blocks even in byte code, one can not implement an remote monitor acquire by calling a remote method of an object and issuing a single monitorEnter instruction there. The corresponding monitorExit instruction must occur before the control flow leaves this remote method.

Using the unique representative thread approach described in the section Distributed Threads, it is nevertheless possible to instruct a representative thread for the current distributed thread to acquire and hold the lock of a remote object, while executing a code block locally. The implementation in KaRMI is done using a special remote invocation with early return capabilities as seen in figure 1.

source:trunk/jp/src/doc/image/distributed-threads-rma1.png
Figure 1. Sequence diagram of remote monitor access.

When the red thread in figure 1 wants to acquire the monitor of remote object b, it sends a request to the node where object b lives and instructs the representative thread for the current distributed thread (the green one) to enter a synchronized block on object b. Immediately after the representative thread has entered the synchronized block, it sends an early return code back to the original thread. The red one now can be sure to hold the lock of object b on the remote node. The green representative thread on the home node of object b does not leave the synchronized block until it receives a second request to release the monitor. While staying within the synchronized block, the gree representative thread stays also listening for remote method invocations that may arrive at its node while holding the lock of object b. If such invocation occurred, they would be executed also by the green thread to make sure they can re-enter the synchronization already acquired remotely.

See also the paper Transparent Distributed Threads for Java.

Last modified 10 years ago Last modified on Jan 17, 2007 10:33:45 AM