This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: MissingResourceException with Date under mingw port
- From: Eric Blake <ebb9 at email dot byu dot edu>
- To: Adam Megacz <gcj at lists dot megacz dot com>
- Cc: java at gcc dot gnu dot org
- Date: Wed, 10 Apr 2002 13:20:46 -0600
- Subject: Re: MissingResourceException with Date under mingw port
- Organization: BYU Student
- References: <20020410131202.C24689@dreammechanics.com> <86r8lnzcpo.fsf@megacz.com>
Adam Megacz wrote:
>
> Yeah, the linkage between java.util.Date and gnu.java.locale.Calendar
> is weak -- Date only references Calendar via reflection. GNU ld
> doesn't understand this sort of linkage, so it doesn't include
> gnu.java.locale.Calendar when creating a static binary.
>
> Here's the standard prelude I throw into all my gcj programs to force
> the linker to include all the required classes:
>
> // static references to these classes ensure that the linker will include them
> private static Class c1 = gnu.java.locale.Calendar.class;
> private static Class c2 = java.util.GregorianCalendar.class;
> private static Class c3 = gnu.gcj.convert.Input_ASCII.class;
> private static Class c4 = gnu.gcj.convert.Input_UTF8.class;
> private static Class c5 = gnu.gcj.convert.Input_8859_1.class;
> private static Class c6 = gnu.java.locale.LocaleInformation.class;
> private static Class c7 = gnu.gcj.convert.Output_ASCII.class;
So why not add this line to Calendar?
private static Class c1 = gnu.java.locale.Calendar.class;
That way, ld will pick up gnu.java.locale.Calendar, but only when
java.util.Date is referenced. This is a better option than putting it
in FirstThread, which would always pick up the helper class in a static
compile, and it takes the burden away from the user of needing to list a
"standard prelude" of classes. This should also be done for the other
classes in your list, wherever the current library uses them by
reflection only.
Actually, to reduce the number of wasted class variables allocated in
Date, it would be nicer to use this paradigm, using the stack instead of
static data (although I'm not sure if it would be optimized away on the
knowledge that c is unused, and hence defeat the intended purpose):
static
{
Class c = gnu.java.locale.Calendar.class;
}
Or, to reduce the bytecode when compiling with -C (as the .class literal
expression expands to quite a bit of bytecode), you could do this:
static
{
gnu.java.locale.Calendar c = null;
}
--
This signature intentionally left boring.
Eric Blake ebb9@email.byu.edu
BYU student, free software programmer