This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Is this bugfix correct (jni.cc)?


>>>>> "Martin" == Martin Kahlert <martin.kahlert@infineon.com> writes:

Martin> This looks like a bug to me:
Martin> If there is no open slot, the while loop runs forever.

I agree with your diagnosis.

Martin> With the following patch, my progs work a lot better.
Martin> If we find an open slot, we are done, otherwise we are done, too,
Martin> since there is no other possibility where else we could search.

We might have several _Jv_JNI_LocalFrame structures chained together.
All of the ones marked MARK_NONE constitute a single logical "user
frame".  I think we must search all of them.

Your second patch was incorrect because it failed to stop after
searching the MARK_USER frame.

Well, we don't have to search all of them.  This way is slow but more
efficient in space.  Perhaps that is the wrong tradeoff.

Nevertheless I'm checking in the appended.  I'm definitely open to
arguments as to whether and why it ought to be changed...

2001-06-15  Tom Tromey  <tromey@redhat.com>

	* jni.cc (_Jv_JNI_NewLocalRef): Search other frames.

Tom


Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.46
diff -u -r1.46 jni.cc
--- jni.cc	2001/06/15 22:09:10	1.46
+++ jni.cc	2001/06/15 23:40:45
@@ -278,16 +278,23 @@
   // Try to find an open slot somewhere in the topmost frame.
   _Jv_JNI_LocalFrame *frame = env->locals;
   bool done = false, set = false;
-  while (frame != NULL && ! done)
+  for (; frame != NULL && ! done; frame = frame->next)
     {
       for (int i = 0; i < frame->size; ++i)
-	if (frame->vec[i] == NULL)
-	  {
-	    set = true;
-	    done = true;
-	    frame->vec[i] = obj;
-	    break;
-	  }
+	{
+	  if (frame->vec[i] == NULL)
+	    {
+	      set = true;
+	      done = true;
+	      frame->vec[i] = obj;
+	      break;
+	    }
+	}
+
+      // If we found a slot, or if the frame we just searched is the
+      // mark frame, then we are done.
+      if (done || frame->marker != MARK_NONE)
+	break;
     }
 
   if (! set)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]