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]
Other format: [Raw text]

Patch: FYI: fix interface dispatch bug


I'm checking this in.

Andrew noticed that my fix for PR 26638 caused crashes in some
situations.

To reproduce you need an interface with a <clinit> method which
appears in the method array before the method which you're trying to
call.  gcj seems to always put <clinit> at the end of the method
array; but this can be done using ecj.

In this situation, _Jv_getInterfaceMethod will compute the wrong
offset into the IDT for the method.

The fix is to ignore <clinit> in _Jv_getInterfaceMethod, as we do
elsewhere.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* java/lang/natClass.cc (_Jv_getInterfaceMethod): Skip <clinit>.

Index: java/lang/natClass.cc
===================================================================
--- java/lang/natClass.cc	(revision 113226)
+++ java/lang/natClass.cc	(working copy)
@@ -1182,9 +1182,14 @@
       if (!klass->isInterface ())
 	return false;
       
-      int i = klass->method_count;
-      while (--i >= 0)
+      int max = klass->method_count;
+      int offset = 0;
+      for (int i = 0; i < max; ++i)
 	{
+	  // Skip <clinit> here, as it will not be in the IDT.
+	  if (klass->methods[i].name->first() == '<')
+	    continue;
+
 	  if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name)
 	      && _Jv_equalUtf8Consts (klass->methods[i].signature, utf_sig))
 	    {
@@ -1197,9 +1202,11 @@
 
 	      found_class = klass;
 	      // Interface method indexes count from 1.
-	      index = i+1;
+	      index = offset + 1;
 	      return true;
 	    }
+
+	  ++offset;
 	}
     }
 
@@ -1211,8 +1218,8 @@
 	{
 	  using namespace java::lang::reflect;
 	  bool found = _Jv_getInterfaceMethod (search_class->interfaces[i], 
-					   found_class, index,
-					   utf_name, utf_sig);
+					       found_class, index,
+					       utf_name, utf_sig);
 	  if (found)
 	    return true;
 	}


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