Patch: RFC: fix non-BC / BC link problem

Tom Tromey tromey@redhat.com
Tue Aug 16 19:11:00 GMT 2005


I thought I'd post this for comment before committing.

Right now if you have a class compiled with the C++ ABI that inherits
from a class compiled with the BC ABI, you will get a crash.

This patch fixes the problem by changing the initial state of C++ ABI
classes, thus ensuring that their super classes are linked at the
proper time.

I was worried that this would cause a slowdown during class
initialization, but jonas profiling has shown that class linking is
down in the noise, so I'm not so worried about this.

Tested on x86 FC2 including jacks (mauve doesn't seem to be building
atm).  New test case included.

Tom

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

	* class.c (make_class_data): Always emit JV_STATE_PRELOADING for
	class' initial state.

Index: libjava/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* testsuite/libjava.lang/bclink.java: New file.
	* testsuite/libjava.lang/bclink.out: New file.
	* link.cc (print_class_loaded): Changed ABI test to look at
	various _syms fields.

Index: gcc/java/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.238
diff -u -r1.238 class.c
--- gcc/java/class.c 16 Aug 2005 16:06:42 -0000 1.238
+++ gcc/java/class.c 16 Aug 2005 19:05:55 -0000
@@ -1860,13 +1860,9 @@
   PUSH_FIELD_VALUE (cons, "loader", null_pointer_node);
   PUSH_FIELD_VALUE (cons, "interface_count",
 		    build_int_cst (NULL_TREE, interface_len));
-  PUSH_FIELD_VALUE 
-    (cons, "state",
-     convert (byte_type_node,
-	      build_int_cst (NULL_TREE,
-			     flag_indirect_dispatch
-			     ? JV_STATE_PRELOADING
-			     : JV_STATE_COMPILED)));
+  PUSH_FIELD_VALUE (cons, "state",
+		    convert (byte_type_node,
+			     build_int_cst (NULL_TREE, JV_STATE_PRELOADING)));
 
   PUSH_FIELD_VALUE (cons, "thread", null_pointer_node);
   PUSH_FIELD_VALUE (cons, "depth", integer_zero_node);

Index: libjava/link.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/link.cc,v
retrieving revision 1.16
diff -u -r1.16 link.cc
--- libjava/link.cc 15 Jun 2005 19:11:36 -0000 1.16
+++ libjava/link.cc 16 Aug 2005 19:05:59 -0000
@@ -1659,11 +1659,11 @@
   if (codesource == NULL)
     codesource = "<no code source>";
 
-  // We use a somewhat bogus test for the ABI here.
   char *abi;
   if (_Jv_IsInterpretedClass (klass))
     abi = "bytecode";
-  else if (klass->state == JV_STATE_PRELOADING)
+  // There isn't really a better test for the ABI type at this point.
+  else if (klass->otable_syms || klass->atable_syms || klass->itable_syms)
     abi = "BC-compiled";
   else
     abi = "pre-compiled";
Index: libjava/testsuite/libjava.lang/bclink.java
===================================================================
RCS file: libjava/testsuite/libjava.lang/bclink.java
diff -N libjava/testsuite/libjava.lang/bclink.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libjava/testsuite/libjava.lang/bclink.java 16 Aug 2005 19:06:00 -0000
@@ -0,0 +1,12 @@
+// This tests that a C++ ABI class can derive from a BC ABI class.
+// This can't always work, but if the base class does not change then
+// it will work fine.
+
+import org.xml.sax.*;
+
+public class bclink extends SAXParseException {
+  public bclink() { super ("hi", null); }
+
+  public static void main(String[] args) throws Throwable {
+  }
+}
Index: libjava/testsuite/libjava.lang/bclink.out
===================================================================
RCS file: libjava/testsuite/libjava.lang/bclink.out
diff -N libjava/testsuite/libjava.lang/bclink.out



More information about the Java-patches mailing list