GCJ: Trouble with static initialization

Jeff Sturm jsturm@one-point.com
Tue Jul 15 03:42:00 GMT 2003


On 14 Jul 2003, Craig A. Vanderborgh wrote:
> The weird thing about it is the failure is stochastic - about half the
> time the program runs to completion, the other half it fails in
> startup.

Ouch.  Sounds like a hairy one to debug.  I assume this target has
threads?  Does it run normally on other hosted environments (if that's
possible)?

> What I would like to ask is this - does GCJ have the same
> cross-translation-unit initialization rules that C++ does?  That is,
> does GCJ "get static initialization done somehow" when the
> initialization of an object in translation unit A depends on the value
> of another object in a different translation unit, and that second
> object itself requires initialization?

The rules for class initialization are quite clear, and Java will attempt
to initialize a class whenever you access a static member or construct an
instance.  It is possible to access classes that are partly initialized,
such as in two classes with mutually-dependent static initializers, even
so the results should be deterministic.

I'm not aware of any gcj bugs in this area, aside from possible race
conditions on a multiprocessor.

Are you confident in the locking primitives of your embedded platform?

Jeff



More information about the Java mailing list