aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPer Bothner <per@bothner.com>2001-04-10 15:46:11 -0700
committerPer Bothner <bothner@gcc.gnu.org>2001-04-10 15:46:11 -0700
commitab9fa4b5d4af4a4908ea881b380c5bb73a1a4386 (patch)
treedf2e8ca8e14d5dd7808d9be2ae190259468360b9
parent03829ad289cd82c9780720a5ac786576f8a3057e (diff)
downloadgcc-ab9fa4b5d4af4a4908ea881b380c5bb73a1a4386.zip
gcc-ab9fa4b5d4af4a4908ea881b380c5bb73a1a4386.tar.gz
gcc-ab9fa4b5d4af4a4908ea881b380c5bb73a1a4386.tar.bz2
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
-rw-r--r--libjava/ChangeLog11
-rw-r--r--libjava/java/lang/natString.cc18
2 files changed, 23 insertions, 6 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index b68b23a..3d2ae9d 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,14 @@
+2001-04-08 Per Bothner <per@bothner.com>
+
+ * 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 <tromey@redhat.com>
* jni.cc (wrap_value<jobject>, wrap_value<jclass>): Removed.
diff --git a/libjava/java/lang/natString.cc b/libjava/java/lang/natString.cc
index 1c71bfd..be0c91c 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;
}