Handling circular dependency in <clinit>

Godmar Back gback at cs.utah.edu
Mon Oct 19 16:30:34 PDT 1998

> Suppose in class A's <clinit>, we instantiate class B
> and in the <init> for class B, we instantiate class A.
> How is this handled?
> As I see it, to instantiate class B in class A's <init>
> somehow the <clinit> for class A has to complete.
> I am at a loss to see how the JVM might be handling 
> this problem.

 Even simpler case:

class A
    static {
	A a = new A();

This is legal, used and works.
I think the trick is simply to a) not rely on the completion of a
static initializer in your class and b) as far as the JVM is concerned,
to make sure you can handle that case.  Kaffe should be able to handle
it by marking the different states during the processing of a class.

If you have a specific problem, let us know and send a test case to
reproduce it.

Hope that helps,


More information about the kaffe mailing list