Initialization test

Godmar Back gback at cs.utah.edu
Wed Oct 28 22:30:53 PST 1998


 Kaffe and the JDK pass the tests, and the tests are correct.
As for tests 1 and 3: no method or constructor of these classes is ever
invoked, and no non-constant variable is ever accessed, hence the classes
are not initialized.

Essentially, the initialization behavior does not depend on all possible
paths that could be taken, but only on those actually taken.  Clearly,
compiled code takes a hit here (gcj, for instance, always puts a call
to the static class initializer before any static access).  Kaffe
inserts a softcall_initialise_class if needed.

The relevant quote for this behavior is given by John:
> 
>      Here are the initialization rules as I read them, reading from both
> examples and text in JLS 12.4.1: static initializers should be called when
> any constructor or method (static or otherwise) in the class is invoked, or
> when a non-constant variable (static or otherwise) that is *not* constant is
> used.  By constant, it means final, static, and initialized from the pool of
> compile-time constants.  There is some reason that makes it so that this
> variable will *always* have its initialized value and not the uninitialized
> one.
> 

There is no argument as to test 2.

It is hard to see how to make a JVM fail test 4, given that the main
function of InitClass does not contain any reference to Class 4 at 
all.  The access to the final static variable is compiled into an 
ICONST_5 instruction.

	- Godmar



More information about the kaffe mailing list