Why does class _Jv_Utf8Const have only 16 bits of the String hash code?
David Daney
ddaney@avtrex.com
Tue Mar 14 02:18:00 GMT 2006
If we look at the structure:
class _Jv_Utf8Const
{
_Jv_ushort hash;
_Jv_ushort length; /* In bytes, of data portion, without final '\0'. */
char data[1]; /* In Utf8 format, with final '\0'. */
public:
/** Return same value of java.lang.String's hashCode. */
jint hash32() { return _Jv_hashUtf8String(data, length); }
/** Return a hash code that has at least 16 bits of information. */
_Jv_ushort hash16 () { return hash; }
/** Return a hash code that has at least 8 bits of information. */
_Jv_ushort hash8 () { return hash; }
.
.
.
If we need the full 32 bit hash code, it is calculated on demand.
Grepping the sources shows exactly two places where the 16 bit hash code
is used natClass.cc and natClassLoader.cc
There are many thousands of these things in libgcj or a typical program.
I don't really know what to make of it all, but it seems like it could
be an ABI breaking win to either get rid of the hash or increase its
size to 32 bits.
David Daney.
More information about the Java
mailing list