OpenJava Tutorial


7. Synchronization of Translation

As the default behavior of OpenJava compiler, there is no assurance of callee-side translation ordering. In the case that we make it sure to translate a class SubMyObject after a class MyObject, we can use the method waitTranslation() in java.lang.OJClass.

public void waitTranslation(OJClass)
    throws MOPException
At the invocation of this method, the translation on the current class declaration stops and it return to continue after the translation on the class given as the argument finished.

7.1. Simple Examples

Furthermore, the part where that class is used comes. There are several part related to the use of class. i.e. object allocations, method calls, field accesses, .. We call this kind of translation caller-side translation.

For the convenience of explanation, suppose a base class MyObject extended by a metaclass MyClass, like following:


public class SubMyObject instantiates SyncClass extends MyObject
{}
class MyObject instantiates AnotherClass
{}
class SubSubMyObject instantiates SyncClass extends SubMyObject
{}


public class SyncClass instantiates Metaclass extends OJClass
{
   void translateDefinition() throws MOPException {
       OJClass baseclazz = getSuperclass();
       System.out.println( getName() + " is waiting for " + base.getName() );
       waitTranslation( baseclazz );
       System.out.println( getName() + " finished" );
   }
}
We can see the following messages in running OpenJava compiler.

MyObject is waiting for java.lang.Object
MyObject finished
SubSubMyObject is waiting for SubMyObject
SubMyObject is waiting for MyObject
SubMyObject finished
SubSubMyObject finished

7.2. Deadlocks

In the case of the system detects some deadlocks, waitTranslation() throws an exception MOPException. If already the translation of a class A were waiting for the translation of a class B, the invocation of waitTranslation() on the translation of the class B would not block but throw an exception.


Please send any message to :
mich@acm.org

Copyright (C) 1999 by Michaki Tatsubori.
Java(TM) is a trademark of Sun Microsystems, Inc.