Patch: RFA: Fix PR libgcj/21906

Tom Tromey tromey@redhat.com
Wed Jun 15 16:08:00 GMT 2005


In PR 21906, the problem is that a method pointer is NULL.  This
causes a hang.

This fix works by ensuring that we never see a NULL in a method table
entry.  Instead all abstract methods refer to _Jv_ThrowAbstractMethodError.

Tested on x86 FC2 including jacks.  Ok?

Tom

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

	PR libgcj/21906:
	* class.c (make_method_value): Use soft_abstractmethod_node for
	abstract method.
	* java-tree.h (soft_abstractmethod_node): New define.
	(JTI_SOFT_ABSTRACTMETHOD_NODE): New enum constant.
	* decl.c (java_init_decl_processing): Initialize
	soft_abstractmethod_node.

Index: gcc/java/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.232
diff -u -r1.232 class.c
--- gcc/java/class.c 12 Jun 2005 19:54:58 -0000 1.232
+++ gcc/java/class.c 15 Jun 2005 15:20:30 -0000
@@ -1315,7 +1315,10 @@
     index = integer_minus_one_node;
 
   code = null_pointer_node;
-  if (!METHOD_ABSTRACT (mdecl))
+  if (METHOD_ABSTRACT (mdecl))
+    code = build1 (ADDR_EXPR, nativecode_ptr_type_node,
+		   soft_abstractmethod_node);
+  else
     code = build1 (ADDR_EXPR, nativecode_ptr_type_node, 
 		   make_local_function_alias (mdecl));
   START_RECORD_CONSTRUCTOR (minit, method_type_node);
Index: gcc/java/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.223
diff -u -r1.223 decl.c
--- gcc/java/decl.c 26 May 2005 21:07:03 -0000 1.223
+++ gcc/java/decl.c 15 Jun 2005 15:20:30 -0000
@@ -1107,6 +1107,15 @@
   TREE_THIS_VOLATILE (soft_nullpointer_node) = 1;
   TREE_SIDE_EFFECTS (soft_nullpointer_node) = 1;
 
+  soft_abstractmethod_node
+    = builtin_function ("_Jv_ThrowAbstractMethodError",
+			build_function_type (void_type_node, endlink),
+			0, NOT_BUILT_IN, NULL, NULL_TREE);
+  /* Mark soft_abstractmethod_node as a `noreturn' function with side
+     effects.  */
+  TREE_THIS_VOLATILE (soft_abstractmethod_node) = 1;
+  TREE_SIDE_EFFECTS (soft_abstractmethod_node) = 1;
+
   t = tree_cons (NULL_TREE, class_ptr_type,
 		 tree_cons (NULL_TREE, object_ptr_type_node, endlink));
   soft_checkcast_node
Index: gcc/java/java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.235
diff -u -r1.235 java-tree.h
--- gcc/java/java-tree.h 9 Jun 2005 10:54:59 -0000 1.235
+++ gcc/java/java-tree.h 15 Jun 2005 15:20:31 -0000
@@ -386,6 +386,7 @@
   JTI_SOFT_MULTIANEWARRAY_NODE,
   JTI_SOFT_BADARRAYINDEX_NODE,
   JTI_SOFT_NULLPOINTER_NODE,
+  JTI_SOFT_ABSTRACTMETHOD_NODE,
   JTI_SOFT_CHECKARRAYSTORE_NODE,
   JTI_SOFT_MONITORENTER_NODE,
   JTI_SOFT_MONITOREXIT_NODE,
@@ -645,6 +646,8 @@
   java_global_trees[JTI_SOFT_BADARRAYINDEX_NODE]
 #define soft_nullpointer_node \
   java_global_trees[JTI_SOFT_NULLPOINTER_NODE]
+#define soft_abstractmethod_node \
+  java_global_trees[JTI_SOFT_ABSTRACTMETHOD_NODE]
 #define soft_checkarraystore_node \
   java_global_trees[JTI_SOFT_CHECKARRAYSTORE_NODE]
 #define soft_monitorenter_node \
Index: libjava/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	PR libgcj/21906:
	* defineclass.cc (handleMethodsEnd): Set ncode for abstract
	methods.
	* include/jvm.h (_Jv_ThrowAbstractMethodError): Declare.
	* link.cc (_Jv_ThrowAbstractMethodError): Renamed.  No longer
	static.
	(append_partial_itable): Use it.
	(set_vtable_entries): Likewise.

Index: libjava/defineclass.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/defineclass.cc,v
retrieving revision 1.45
diff -u -r1.45 defineclass.cc
--- libjava/defineclass.cc 10 Mar 2005 19:02:16 -0000 1.45
+++ libjava/defineclass.cc 15 Jun 2005 15:20:34 -0000
@@ -1378,6 +1378,7 @@
 	{
 	  if (def_interp->interpreted_methods[i] != 0)
 	    throw_class_format_error ("code provided for abstract method");
+	  method->ncode = (void *) &_Jv_ThrowAbstractMethodError;
 	}
       else
 	{
Index: libjava/link.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/link.cc,v
retrieving revision 1.15
diff -u -r1.15 link.cc
--- libjava/link.cc 13 May 2005 01:02:33 -0000 1.15
+++ libjava/link.cc 15 Jun 2005 15:20:34 -0000
@@ -714,8 +714,8 @@
 }
 
 // This is put in empty vtable slots.
-static void
-_Jv_abstractMethodError (void)
+void
+_Jv_ThrowAbstractMethodError ()
 {
   throw new java::lang::AbstractMethodError();
 }
@@ -767,7 +767,7 @@
 	      (_Jv_GetMethodString (klass, meth));
 
  	  if ((meth->accflags & Modifier::ABSTRACT) != 0)
-	    itable[pos] = (void *) &_Jv_abstractMethodError;
+	    itable[pos] = (void *) &_Jv_ThrowAbstractMethodError;
 	  else
 	    itable[pos] = meth->ncode;
 	}
@@ -1228,7 +1228,8 @@
       if ((meth->accflags & Modifier::ABSTRACT))
 	// FIXME: it might be nice to have a libffi trampoline here,
 	// so we could pass in the method name and other information.
-	vtable->set_method(meth->index, (void *) &_Jv_abstractMethodError);
+	vtable->set_method(meth->index,
+			   (void *) &_Jv_ThrowAbstractMethodError);
       else
 	vtable->set_method(meth->index, meth->ncode);
     }
Index: libjava/include/jvm.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.87
diff -u -r1.87 jvm.h
--- libjava/include/jvm.h 26 May 2005 21:07:04 -0000 1.87
+++ libjava/include/jvm.h 15 Jun 2005 15:20:35 -0000
@@ -482,6 +482,8 @@
 extern jobject _Jv_NewMultiArray (jclass, jint ndims, jint* dims)
   __attribute__((__malloc__));
 
+extern "C" void _Jv_ThrowAbstractMethodError () __attribute__((__noreturn__));
+
 /* Checked divide subroutines. */
 extern "C"
 {



More information about the Java-patches mailing list