From: Per Bothner Date: Tue, 10 Apr 2001 22:46:11 +0000 (-0700) Subject: natString.cc (_Jv_NewStringUtf8Const): Register finalizer. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ab9fa4b5d4af4a4908ea881b380c5bb73a1a4386;p=gcc.git natString.cc (_Jv_NewStringUtf8Const): Register finalizer. * java/lang/natString.cc (_Jv_NewStringUtf8Const): Register finalizer. Recalculate hash, since Utf8Const's hash is only 16 bits. * java/lang/natString.cc (_Jv_StringFindSlot, rehash): Use high-order bits of hash to calculate step for chaining. * java/lang/natString.cc (intern, _Jv_NewStringUtf8Const): Rehash when 2/3 full, rather than 3/4 full. From-SVN: r41233 --- diff --git a/libjava/ChangeLog b/libjava/ChangeLog index b68b23a3418..3d2ae9dc035 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,14 @@ +2001-04-08 Per Bothner + + * java/lang/natString.cc (_Jv_NewStringUtf8Const): Register finalizer. + Recalculate hash, since Utf8Const's hash is only 16 bits. + + * java/lang/natString.cc (_Jv_StringFindSlot, rehash): Use high-order + bits of hash to calculate step for chaining. + + * java/lang/natString.cc (intern, _Jv_NewStringUtf8Const): Rehash + when 2/3 full, rather than 3/4 full. + 2001-04-06 Tom Tromey * jni.cc (wrap_value, wrap_value): Removed. diff --git a/libjava/java/lang/natString.cc b/libjava/java/lang/natString.cc index 1c71bfd97e2..be0c91cd334 100644 --- a/libjava/java/lang/natString.cc +++ b/libjava/java/lang/natString.cc @@ -62,7 +62,7 @@ _Jv_StringFindSlot (jchar* data, jint len, jint hash) int index = start_index; /* step must be non-zero, and relatively prime with strhash_size. */ - int step = 8 * hash + 7; + jint step = (hash ^ (hash >> 16)) | 1; for (;;) { jstring* ptr = &strhash[index]; @@ -145,7 +145,7 @@ java::lang::String::rehash() jstring val = (jstring) UNMASK_PTR (*ptr); jint hash = val->hashCode(); jint index = hash & (nsize - 1); - jint step = 8 * hash + 7; + jint step = (hash ^ (hash >> 16)) | 1; for (;;) { if (next[index] == NULL) @@ -166,7 +166,7 @@ jstring java::lang::String::intern() { JvSynchronize sync (&StringClass); - if (4 * strhash_count >= 3 * strhash_size) + if (3 * strhash_count >= 2 * strhash_size) rehash(); jstring* ptr = _Jv_StringGetSlot(this); if (*ptr != NULL && *ptr != DELETED_STRING) @@ -265,14 +265,18 @@ _Jv_NewStringUtf8Const (Utf8Const* str) chrs = JvGetStringChars(jstr); } + jint hash = 0; while (data < limit) - *chrs++ = UTF8_GET(data, limit); + { + jchar ch = UTF8_GET(data, limit); + hash = (31 * hash) + ch; + *chrs++ = ch; + } chrs -= length; JvSynchronize sync (&StringClass); - if (4 * strhash_count >= 3 * strhash_size) + if (3 * strhash_count >= 2 * strhash_size) java::lang::String::rehash(); - int hash = str->hash; jstring* ptr = _Jv_StringFindSlot (chrs, length, hash); if (*ptr != NULL && *ptr != DELETED_STRING) return (jstring) UNMASK_PTR (*ptr); @@ -285,6 +289,8 @@ _Jv_NewStringUtf8Const (Utf8Const* str) } *ptr = jstr; SET_STRING_IS_INTERNED(jstr); + // When string is GC'd, clear the slot in the hash table. + _Jv_RegisterFinalizer ((void *) jstr, unintern); return jstr; }