[gcjx] Patch: FYI: make exceptions work

Tom Tromey tromey@redhat.com
Wed Oct 12 17:14:00 GMT 2005


I'm checking this in on the gcjx branch.

We weren't setting DECL_INITIAL on the exception class object, so
programs were crashing when trying to unwind.  This fixes a number of
libjava.lang failures; we're down to 31 failures out of 163 tests.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* abi.cc (get_catch_initializer): New methods.
	* abi.hh (gcj_abi::get_catch_initializer): Declare.
	(cxx_abi::get_catch_initializer): Declare.
	(bc_abi::get_catch_initializer): Declare.
	* builtins.cc (map_catch_class): Removed duplicate code.

Index: abi.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/abi.cc,v
retrieving revision 1.1.2.25
diff -u -r1.1.2.25 abi.cc
--- abi.cc 12 Oct 2005 13:27:29 -0000 1.1.2.25
+++ abi.cc 12 Oct 2005 17:12:25 -0000
@@ -302,6 +302,14 @@
   return build_int_cst (type_jint, klass->find_in_vtable (method));
 }
 
+tree
+cxx_abi::get_catch_initializer (tree_builtins *builtins,
+				model_class *klass)
+{
+  // We know a NULL argument here is always ok.
+  return build_class_reference (builtins, NULL, klass);
+}
+
 
 
 tree
@@ -592,3 +600,10 @@
 
   return n;
 }
+
+tree
+bc_abi::get_catch_initializer (tree_builtins *builtins,
+			       model_class *klass)
+{
+  return builtins->map_utf8const (klass->get_fully_qualified_name ());
+}
Index: abi.hh
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/abi.hh,v
retrieving revision 1.1.2.11
diff -u -r1.1.2.11 abi.hh
--- abi.hh 4 Apr 2005 04:30:32 -0000 1.1.2.11
+++ abi.hh 12 Oct 2005 17:12:25 -0000
@@ -139,6 +139,10 @@
   /// Return tree representing index into vtable where this method can
   /// be found.  Should return -1 for a static method or constructor.
   virtual tree get_vtable_index (aot_class *klass, model_method *method) = 0;
+
+  /// Return the initializer representing a 'catch' type.
+  virtual tree get_catch_initializer (tree_builtins *builtins,
+				      model_class *klass) = 0;
 };
 
 /// This class handles C++ ABI code.
@@ -201,6 +205,9 @@
   tree get_vtable (tree_builtins *, model_class *);
 
   tree get_vtable_index (aot_class *klass, model_method *method);
+
+  tree get_catch_initializer (tree_builtins *builtins,
+			      model_class *klass);
 };
 
 /// This class handles the binary compatibility ABI.
@@ -267,6 +274,8 @@
   {
     return integer_minus_one_node;
   }
+
+  tree get_catch_initializer (tree_builtins *builtins, model_class *klass);
 };
 
 #endif // GCC_JAVA_ABI_HH
Index: builtins.cc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/Attic/builtins.cc,v
retrieving revision 1.1.2.37
diff -u -r1.1.2.37 builtins.cc
--- builtins.cc 27 Apr 2005 17:40:36 -0000 1.1.2.37
+++ builtins.cc 12 Oct 2005 17:12:25 -0000
@@ -602,36 +602,35 @@
 tree_builtins::map_catch_class (model_class *current, model_class *caught)
 {
   catch_map_type::iterator it = catch_map.find (current);
-  if (it != catch_map.end ())
+  std::map<model_class *, tree> *inner_map;
+  if (it == catch_map.end ())
     {
-      std::map<model_class *, tree> &inner_map ((*it).second);
-      std::map<model_class *, tree>::iterator inner_it
-	= inner_map.find (caught);
-      if (inner_it != inner_map.end ())
-	return (*inner_it).second;
-
-      tree decl = build_decl (VAR_DECL, get_symbol (), type_class_ptr);
-      TREE_STATIC (decl) = 1;
-      DECL_ARTIFICIAL (decl) = 1;
-      DECL_IGNORED_P (decl) = 1;
-      rest_of_decl_compilation (decl, 1, 0);
-      pushdecl (decl);
-
-      inner_map[caught] = decl;
-      return decl;
+      std::map<model_class *, tree> new_map;
+      catch_map[current] = new_map;
+      inner_map = &new_map;
     }
+  else
+    inner_map = &((*it).second);
+
+  std::map<model_class *, tree>::iterator inner_it
+    = (*inner_map).find (caught);
+  if (inner_it != (*inner_map).end ())
+    return (*inner_it).second;
 
-  std::map<model_class *, tree> inner_map;
-  // FIXME: duplicated code.
   tree decl = build_decl (VAR_DECL, get_symbol (), type_class_ptr);
   TREE_STATIC (decl) = 1;
   DECL_ARTIFICIAL (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
-  pushdecl (decl);
+
+  // get_catch_initializer will always return the correct DECL_INITIAL
+  // -- but for the BC ABI do we need more processing as well?
+  gcj_abi *abi = find_abi ();
+  DECL_INITIAL (decl) = abi->get_catch_initializer (this, caught);
+
   rest_of_decl_compilation (decl, 1, 0);
-  inner_map[caught] = decl;
-  catch_map[current] = inner_map;
+  pushdecl (decl);
 
+  (*inner_map)[caught] = decl;
   return decl;
 }
 



More information about the Java-patches mailing list