first active use of a class
Godmar Back
gback@cs.utah.edu
Thu Apr 8 08:39:00 GMT 1999
I think he said that the way to bend the rules is to create
"active uses" before invoking main(). The JLS spec supposedly
leaves open what is done before main(). Hence, one could insert
code that uses non-constant static fields.
Or, you could have your JNI driver first invoke a Class.forName(, true)
for all classes you're interested in before it invokes main().
- Godmar
>
> >>>>> "Godmar" == Godmar Back <gback@cs.utah.edu> writes:
> Godmar> A couple of weeks ago, we had Guy Steele visiting the
> Godmar> University of Utah. We had the chance to discuss some Java
> Godmar> issues with him.
>
> Godmar> One issue was the issue of "first active use" of a class. I
> Godmar> pointed out that WAT compilers such as gcj are being penalized
> Godmar> because they have to insert code that checks for each possible
> Godmar> first use of a class whether its <clinit> initializer needs to
> Godmar> be invoked.
>
> Godmar> He said that his interpretation of the JLS gives such compiler
> Godmar> writers the freedom to preinitialize all classes before you
> Godmar> even invoke the main method; essentially saving that test.
>
> There's a (not well publicized) clarification note from Sun that
> amongst other things addresses class initialization:
>
> http://java.sun.com/docs/books/jls/clarify.html
>
> The description (paraphrasing) says that a class will be initialized
> "immediately before" the first occurrence of a few different types of
> uses. So this comes down to your interpretation of the term
> "immediately before" being used.
>
> -jvp
>
> ------------------------------
> Jim Van_Peursem, Ph.D.
> Motorola, Inc.
> 1301 E. Algonquin Rd.
> Schaumburg, IL 60196
> e-mail: jvp@ccrl.mot.com
> ------------------------------
> I don't speak for Motorola
> Motorola doesn't speak for me
> ------------------------------
>
More information about the Java
mailing list