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 for correctly intializing interface class on Method.invoke()(Was: Line number support for interpreter)


Hi,

On Wed, 2004-05-19 at 23:47, Mark Wielaard wrote:
> What was happening was that jikes cleverly makes sure that the interface
> is never initialized. While gcj -C just gets us a initialized class when
> using the I.class construct.
> 
> The attached Test program does the same. And does fail with gij (CVS),
> but not with gij 3.4 (which wrongly initializes the interface I when the
> array is created). I'll add something like this to Mauve since I saw
> that more runtimes get this wrong.

Did some more reading about this issue and concluded that this is only
possible with interface classes since those are not initialized when
creating an object of a class that implements the interface.  Only super
classes of a class must explicitly be initialized when a instance is
created. (See VM Spec 2.17.4)

The following patch adds explicit initialization of interface classes to
Method.invoke() and also does the test whether the declaringClass is an
interface only when the method involved isn't a static method since
interfaces cannot contain static methods.

2004-05-20  Mark Wielaard  <mark@klomp.org>

       * java/lang/reflect/natMethod.cc (invoke): Only check isInterface()
       and set iface when method is non-static. Always initialize interface
       classes.

There is now a gnu.testlet.java.lang.Class.init test in Mauve.
gij-3.3 gives a couple of failures since it initializes the interface
class much too early. gij-3.4 (and gij CVS) crashes as soon as invoke()
is called on the interface method (but correctly delay initializing the
interface class). And with this patch gij CVS gives all PASSes for this
test. All regression tests in libjava/testsuite also still PASS.

OK to commit?

Cheers,

Mark
Index: java/lang/reflect/natMethod.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/reflect/natMethod.cc,v
retrieving revision 1.39
diff -u -r1.39 natMethod.cc
--- java/lang/reflect/natMethod.cc	20 Apr 2004 01:38:46 -0000	1.39
+++ java/lang/reflect/natMethod.cc	20 May 2004 09:20:47 -0000
@@ -165,6 +165,18 @@
      
       if (! _Jv_IsAssignableFrom (declaringClass, objClass))
         throw new java::lang::IllegalArgumentException;
+
+      // If the declaring class of the method is an interface we will
+      // have to explicitly initialize it.  Neither
+      // Class.get(Declared)Method nor creating an Object of a class
+      // that implements that interface has to initialize the
+      // interface class.  So this may be the first active use of the
+      // interface as class.
+      if (declaringClass->isInterface ())
+	{
+	  _Jv_InitClass (declaringClass);
+	  iface = declaringClass;
+	}
     }
 
   // Check accessibility, if required.
@@ -188,9 +200,6 @@
 	throw new IllegalAccessException;
     }
 
-  if (declaringClass->isInterface())
-    iface = declaringClass;
-  
   return _Jv_CallAnyMethodA (obj, return_type, meth, false,
 			     parameter_types, args, iface);
 }

Attachment: signature.asc
Description: This is a digitally signed message part


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