classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String/Hashtable bootstrapping problem


From: Brendan Macmillan
Subject: Re: String/Hashtable bootstrapping problem
Date: Fri, 6 Jul 2001 12:33:19 +1000 (EST)

Hi Patrick,

> I'm talking about these lines from java.util.Hashtable:
> 
>   // used for serializing instances of this class
>   private static final ObjectStreamField[] serialPersistentFields =
>     { new ObjectStreamField("loadFactor", float.class),
>       new ObjectStreamField("threshold", int.class) };
> 
> This leads to LDC instructions in Hashtable.<clinit> which grab the
> strings "loadFactor" and "threshold" from the constant pool.  To make
> these strings, I need to have initialized java.lang.String and to call the
> "intern" function, which requires the Hashtable to be initialized, etc.
> 
> Of course, these things are private and they're never used in the class.
> Why are they there?  Are they accessed by reflection during serialization?
> Maybe I'll just comment them out for now.

Sorry if I am coming in at the wrong level - I don't even know what "LDC
instructions" are - but maybe I can help with the serialization aspect:

Yes, they are usually used for serialization.

I'm not familiar with the innards of Hashtable, but readObject() should have
use "getField()", and writeObject() uses "putField()".  Without the 
serialPersistentFields above, this won't work anymore - so probably best to
leave it in! ;-)

The function of serialPersistentFields and putField() and getField() is 
usually to make the serialized form appear to have those fields - sort of
virtual fields, or a "Adapter" Design Pattern API but applied to fields (data)
instead of methods (code), as it usually is.

This is useful for the same reason - so the implementation can evolve, without
change the appearance to the outside world.

Why these particular fields?  Well, my guess is that it is part of the 
integration of the old Hashtable into the new Collections - since they do
use the fields mentioned.  This last paragraph is just a guess, tho ;-)

HTH

Cheers,
Brendan
-- 
e:  address@hidden                         v:  +61 (3)  9905 1502
Email is checked daily                              Phone is rarely attended



reply via email to

[Prev in Thread] Current Thread [Next in Thread]