natString.cc (intern): If string's data does not point to this String, make a fresh...
authorPer Bothner <per@bothner.com>
Sun, 1 Apr 2001 21:54:10 +0000 (14:54 -0700)
committerPer Bothner <bothner@gcc.gnu.org>
Sun, 1 Apr 2001 21:54:10 +0000 (14:54 -0700)
* java/lang/natString.cc (intern):  If string's data does not point to
this String, make a fresh String that does.

* java/lang/natString.cc (unintern):  Replace by static function.
* java/lang/String.java (unintern):  Remove method.

From-SVN: r40990

libjava/ChangeLog
libjava/java/lang/String.java
libjava/java/lang/natString.cc

index 3c1ef11541094aea6a791a6e7f43753451818d55..177052ffc736f7536bff5a7a9b6ce53aaabc37bc 100644 (file)
@@ -1,3 +1,11 @@
+2001-04-01  Per Bothner  <per@bothner.com>
+
+       * java/lang/natString.cc (intern):  If string's data does not point to
+       this String, make a fresh String that does.
+
+       * java/lang/natString.cc (unintern):  Replace by static function.
+       * java/lang/String.java (unintern):  Remove method.
+
 2001-04-01  Per Bothner  <per@bothner.com>
 
        * DeflaterOutputStream.java (deflate):  Loop while def.needsInput.
index 22e11530f77c24f2d387a1deaaa09b2a2efacdd5..b985cf4186cb1165fbc6de99741615e0bf0ec6a3 100644 (file)
@@ -347,6 +347,5 @@ public final class String implements Serializable, Comparable
   private native void init (byte[] chars, int hibyte, int offset, int count);
   private native void init (byte[] chars, int offset, int count, String enc)
     throws UnsupportedEncodingException;
-  private static native void unintern (Object obj);
   private static native void rehash ();
 }
index c052905dc480aded28206a7388757db7f3f22168..1c71bfd97e2b0551e1cad4604b154dfa161141cb 100644 (file)
@@ -29,6 +29,7 @@ details.  */
 #include <gnu/gcj/convert/BytesToUnicode.h>
 #include <jvm.h>
 
+static void unintern (jobject);
 static jstring* strhash = NULL;
 static int strhash_count = 0;  /* Number of slots used in strhash. */
 static int strhash_size = 0;  /* Number of slots available in strhash.
@@ -174,17 +175,19 @@ java::lang::String::intern()
       *ptr = (jstring) MASK_PTR (*ptr);
       return (jstring) UNMASK_PTR (*ptr);
     }
-  SET_STRING_IS_INTERNED(this);
+  jstring str = this->data == this ? this
+    : _Jv_NewString(JvGetStringChars(this), this->length());
+  SET_STRING_IS_INTERNED(str);
   strhash_count++;
-  *ptr = this;
+  *ptr = str;
   // When string is GC'd, clear the slot in the hash table.
-  _Jv_RegisterFinalizer ((void *) this, unintern);
-  return this;
+  _Jv_RegisterFinalizer ((void *) str, unintern);
+  return str;
 }
 
 /* Called by String fake finalizer. */
-void
-java::lang::String::unintern (jobject obj)
+static void
+unintern (jobject obj)
 {
   JvSynchronize sync (&StringClass);
   jstring str = reinterpret_cast<jstring> (obj);