This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: GCJ: Trouble with static initialization
- From: Jeff Sturm <jsturm at one-point dot com>
- To: "Craig A. Vanderborgh" <craigv at voxware dot com>
- Cc: java at gcc dot gnu dot org
- Date: Mon, 14 Jul 2003 23:42:43 -0400 (EDT)
- Subject: Re: GCJ: Trouble with static initialization
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