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 method.invoke() for interpreted interfaces


This patch adds some code to set the method->index fields for interfaces in the runtime. This fixes a bug with interpreted interfaces where Method.invoke() would crash because the index fields was not valid.

I'm checking this in to HEAD and also to the abi branch.

Bryce

2004-04-21  Bryce McKinlay  <mckinlay@redhat.com>

	* java/lang/natClass.cc (_Jv_LayoutInterfaceMethods): New method.
	Set method->index values for interface methods to their itable index.
	(initializeClass): Call _Jv_LayoutInterfaceMethods.
	* java/lang/Class.h (_Jv_LayoutInterfaceMethods): New prototype.

Index: Class.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Class.h,v
retrieving revision 1.65
diff -u -r1.65 Class.h
--- Class.h	20 Apr 2004 01:38:46 -0000	1.65
+++ Class.h	21 Apr 2004 18:52:46 -0000
@@ -339,6 +339,7 @@
   friend jshort _Jv_AppendPartialITable (jclass, jclass, void **, jshort);
   friend jshort _Jv_FindIIndex (jclass *, jshort *, jshort);
   friend void _Jv_LinkSymbolTable (jclass);
+  friend void _Jv_LayoutInterfaceMethods (jclass);
   friend void _Jv_LayoutVTableMethods (jclass klass);
   friend void _Jv_SetVTableEntries (jclass, _Jv_VTable *, jboolean *);
   friend void _Jv_MakeVTable (jclass);
Index: natClass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClass.cc,v
retrieving revision 1.76
diff -u -r1.76 natClass.cc
--- natClass.cc	20 Apr 2004 01:38:46 -0000	1.76
+++ natClass.cc	21 Apr 2004 18:52:46 -0000
@@ -790,6 +790,9 @@
 	}
     }
 
+  if (isInterface ())
+    _Jv_LayoutInterfaceMethods (this);
+
   _Jv_PrepareConstantTimeTables (this);
 
   if (vtable == NULL)
@@ -1785,6 +1788,20 @@
 _Jv_abstractMethodError (void)
 {
   throw new java::lang::AbstractMethodError();
+}
+
+// Set itable method indexes for members of interface IFACE.
+void
+_Jv_LayoutInterfaceMethods (jclass iface)
+{
+  if (! iface->isInterface())
+    return;
+  
+  // itable indexes start at 1. 
+  // FIXME: Static initalizers currently get a NULL placeholder entry in the
+  // itable so they are also assigned an index here.
+  for (int i = 0; i < iface->method_count; i++)
+    iface->methods[i].index = i + 1;
 }
 
 // Prepare virtual method declarations in KLASS, and any superclasses as 

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