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]

[3.4] Patch: FYI: PR 15001


I'm checking this in on the 3.4 branch.

This is a patch that Andrew sent in December, but never checked in to
3.4.  See his message and the related thread:

    http://gcc.gnu.org/ml/java/2004-12/msg00060.html

This is needed for OOo.

Jakub, you might want to put this into the Red Hat branch.

Caolan, you started the thread referred to above; this is bug 142366
in Red Hat bugzilla.  It is already fixed on the gcc cvs trunk.

Test case included.

Tom

Index: ChangeLog
from  Andrew Haley  <aph@redhat.com>

	* java/lang/reflect/natMethod.cc (_Jv_CallAnyMethodA): In the case
	of virtual dispatch, if we have no method index, and no code
	pointer, look a method up by name.

2005-01-17  Tom Tromey  <tromey@redhat.com>

	* testsuite/libjava.jni/iface.c: New file.
	* testsuite/libjava.jni/iface.out: New file.
	* testsuite/libjava.jni/iface.java: New file.

Index: java/lang/reflect/natMethod.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/reflect/natMethod.cc,v
retrieving revision 1.36.6.1
diff -u -r1.36.6.1 natMethod.cc
--- java/lang/reflect/natMethod.cc 26 Feb 2004 15:21:11 -0000 1.36.6.1
+++ java/lang/reflect/natMethod.cc 17 Jan 2005 20:49:35 -0000
@@ -1,6 +1,6 @@
 // natMethod.cc - Native code for Method class.
 
-/* Copyright (C) 1998, 1999, 2000, 2001 , 2002, 2003 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001 , 2002, 2003, 2005 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -464,7 +464,7 @@
       break;
     }
 
-  void *ncode;
+  void *ncode = meth->ncode;
 
   // FIXME: If a vtable index is -1 at this point it is invalid, so we
   // have to use the ncode.  
@@ -473,16 +473,25 @@
   // vtable entries, but _Jv_isVirtualMethod() doesn't know that.  We
   // could solve this problem by allocating a vtable index for methods
   // in final classes.
-  if (is_virtual_call 
-      && ! Modifier::isFinal (meth->accflags)
-      && (_Jv_ushort)-1 != meth->index)
-    {
+  if (is_virtual_call)
+    { 
       _Jv_VTable *vtable = *(_Jv_VTable **) obj;
-      ncode = vtable->get_method (meth->index);
-    }
-  else
-    {
-      ncode = meth->ncode;
+      if ((_Jv_ushort)-1 == meth->index)
+	{
+	  if (ncode == NULL)
+	    // We have no vtable index, and we have no code pointer.
+	    // Look method up by name.
+	    ncode = _Jv_LookupInterfaceMethod (vtable->clas, 
+					       meth->name,
+					       meth->signature);
+	}
+      else
+	{ 
+	  // We have an index.  If METH is not final, use virtual
+	  // dispatch.
+	  if (! Modifier::isFinal (meth->accflags))
+	    ncode = vtable->get_method (meth->index);
+	}
     }
 
   try
Index: testsuite/libjava.jni/iface.c
===================================================================
RCS file: testsuite/libjava.jni/iface.c
diff -N testsuite/libjava.jni/iface.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/libjava.jni/iface.c 17 Jan 2005 20:49:36 -0000
@@ -0,0 +1,40 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <iface.h>
+
+void check (JNIEnv *);
+
+void check(JNIEnv *env)
+{
+  if ((*env)->ExceptionCheck(env) != JNI_FALSE)
+    {
+      fprintf(stderr, "UNEXPECTED EXCEPTION\n");
+      exit(-1);
+    }
+}
+
+void
+Java_iface_doCalls (JNIEnv *env, jobject self, jobject other)
+{
+  jclass iface_class, comparable_class;
+  jmethodID iface_meth, comparable_meth;
+  jvalue args[1];
+
+  iface_class = (*env)->FindClass(env, "iface");
+  check (env);
+  comparable_class = (*env)->FindClass (env, "mycomp");
+  check (env);
+
+  iface_meth = (*env)->GetMethodID (env, iface_class, "compareTo",
+				    "(Ljava/lang/Object;)I");
+  check (env);
+  comparable_meth = (*env)->GetMethodID (env, comparable_class, "compareTo",
+					 "(Ljava/lang/Object;)I");
+  check (env);
+
+  args[0].l = other;
+  (*env)->CallObjectMethodA (env, self, iface_meth, args);
+  check (env);
+  (*env)->CallObjectMethodA (env, self, comparable_meth, args);
+  check (env);
+}
Index: testsuite/libjava.jni/iface.java
===================================================================
RCS file: testsuite/libjava.jni/iface.java
diff -N testsuite/libjava.jni/iface.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/libjava.jni/iface.java 17 Jan 2005 20:49:36 -0000
@@ -0,0 +1,27 @@
+// JNI calls via an interface method were broken in a couple releases.
+
+interface mycomp
+{
+  int compareTo(Object x);
+}
+
+public class iface implements mycomp
+{
+  static
+  {
+    System.loadLibrary("iface");
+  }
+
+  public int compareTo (Object x)
+  {
+    System.out.println ("hi maude");
+    return 3;
+  }
+
+  public native void doCalls(Object x);
+
+  public static void main (String[] args)
+  {
+    new iface().doCalls(args);
+  }
+}
Index: testsuite/libjava.jni/iface.out
===================================================================
RCS file: testsuite/libjava.jni/iface.out
diff -N testsuite/libjava.jni/iface.out
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/libjava.jni/iface.out 17 Jan 2005 20:49:36 -0000
@@ -0,0 +1,2 @@
+hi maude
+hi maude


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